1use std::sync::Arc;
12
13use async_trait::async_trait;
14#[cfg(feature = "mockall")]
15use mockall::automock;
16use reqwest;
17use serde::{Deserialize, Serialize, de::Error as _};
18
19use super::{Error, configuration};
20use crate::{
21 apis::{ContentType, ResponseContent},
22 models,
23};
24
25#[cfg_attr(feature = "mockall", automock)]
26#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
27#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
28pub trait SecurityTaskApi: Send + Sync {
29 async fn bulk_create_tasks<'a>(
31 &self,
32 org_id: uuid::Uuid,
33 bulk_create_security_tasks_request_model: Option<
34 models::BulkCreateSecurityTasksRequestModel,
35 >,
36 ) -> Result<models::SecurityTasksResponseModelListResponseModel, Error<BulkCreateTasksError>>;
37
38 async fn complete<'a>(&self, task_id: uuid::Uuid) -> Result<(), Error<CompleteError>>;
40
41 async fn get<'a>(
43 &self,
44 status: Option<models::SecurityTaskStatus>,
45 ) -> Result<models::SecurityTasksResponseModelListResponseModel, Error<GetError>>;
46
47 async fn get_task_metrics_for_organization<'a>(
49 &self,
50 organization_id: uuid::Uuid,
51 ) -> Result<models::SecurityTaskMetricsResponseModel, Error<GetTaskMetricsForOrganizationError>>;
52
53 async fn list_for_organization<'a>(
55 &self,
56 organization_id: Option<uuid::Uuid>,
57 status: Option<models::SecurityTaskStatus>,
58 ) -> Result<models::SecurityTasksResponseModelListResponseModel, Error<ListForOrganizationError>>;
59}
60
61pub struct SecurityTaskApiClient {
62 configuration: Arc<configuration::Configuration>,
63}
64
65impl SecurityTaskApiClient {
66 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
67 Self { configuration }
68 }
69}
70
71#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
72#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
73impl SecurityTaskApi for SecurityTaskApiClient {
74 async fn bulk_create_tasks<'a>(
75 &self,
76 org_id: uuid::Uuid,
77 bulk_create_security_tasks_request_model: Option<
78 models::BulkCreateSecurityTasksRequestModel,
79 >,
80 ) -> Result<models::SecurityTasksResponseModelListResponseModel, Error<BulkCreateTasksError>>
81 {
82 let local_var_configuration = &self.configuration;
83
84 let local_var_client = &local_var_configuration.client;
85
86 let local_var_uri_str = format!(
87 "{}/tasks/{orgId}/bulk-create",
88 local_var_configuration.base_path,
89 orgId = org_id
90 );
91 let mut local_var_req_builder =
92 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
93
94 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
95 local_var_req_builder = local_var_req_builder
96 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
97 }
98 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
99 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
100 };
101 local_var_req_builder =
102 local_var_req_builder.json(&bulk_create_security_tasks_request_model);
103
104 let local_var_req = local_var_req_builder.build()?;
105 let local_var_resp = local_var_client.execute(local_var_req).await?;
106
107 let local_var_status = local_var_resp.status();
108 let local_var_content_type = local_var_resp
109 .headers()
110 .get("content-type")
111 .and_then(|v| v.to_str().ok())
112 .unwrap_or("application/octet-stream");
113 let local_var_content_type = super::ContentType::from(local_var_content_type);
114 let local_var_content = local_var_resp.text().await?;
115
116 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
117 match local_var_content_type {
118 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
119 ContentType::Text => {
120 return Err(Error::from(serde_json::Error::custom(
121 "Received `text/plain` content type response that cannot be converted to `models::SecurityTasksResponseModelListResponseModel`",
122 )));
123 }
124 ContentType::Unsupported(local_var_unknown_type) => {
125 return Err(Error::from(serde_json::Error::custom(format!(
126 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::SecurityTasksResponseModelListResponseModel`"
127 ))));
128 }
129 }
130 } else {
131 let local_var_entity: Option<BulkCreateTasksError> =
132 serde_json::from_str(&local_var_content).ok();
133 let local_var_error = ResponseContent {
134 status: local_var_status,
135 content: local_var_content,
136 entity: local_var_entity,
137 };
138 Err(Error::ResponseError(local_var_error))
139 }
140 }
141
142 async fn complete<'a>(&self, task_id: uuid::Uuid) -> Result<(), Error<CompleteError>> {
143 let local_var_configuration = &self.configuration;
144
145 let local_var_client = &local_var_configuration.client;
146
147 let local_var_uri_str = format!(
148 "{}/tasks/{taskId}/complete",
149 local_var_configuration.base_path,
150 taskId = task_id
151 );
152 let mut local_var_req_builder =
153 local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
154
155 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
156 local_var_req_builder = local_var_req_builder
157 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
158 }
159 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
160 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
161 };
162
163 let local_var_req = local_var_req_builder.build()?;
164 let local_var_resp = local_var_client.execute(local_var_req).await?;
165
166 let local_var_status = local_var_resp.status();
167 let local_var_content = local_var_resp.text().await?;
168
169 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
170 Ok(())
171 } else {
172 let local_var_entity: Option<CompleteError> =
173 serde_json::from_str(&local_var_content).ok();
174 let local_var_error = ResponseContent {
175 status: local_var_status,
176 content: local_var_content,
177 entity: local_var_entity,
178 };
179 Err(Error::ResponseError(local_var_error))
180 }
181 }
182
183 async fn get<'a>(
184 &self,
185 status: Option<models::SecurityTaskStatus>,
186 ) -> Result<models::SecurityTasksResponseModelListResponseModel, Error<GetError>> {
187 let local_var_configuration = &self.configuration;
188
189 let local_var_client = &local_var_configuration.client;
190
191 let local_var_uri_str = format!("{}/tasks", local_var_configuration.base_path);
192 let mut local_var_req_builder =
193 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
194
195 if let Some(ref param_value) = status {
196 local_var_req_builder =
197 local_var_req_builder.query(&[("status", ¶m_value.to_string())]);
198 }
199 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
200 local_var_req_builder = local_var_req_builder
201 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
202 }
203 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
204 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
205 };
206
207 let local_var_req = local_var_req_builder.build()?;
208 let local_var_resp = local_var_client.execute(local_var_req).await?;
209
210 let local_var_status = local_var_resp.status();
211 let local_var_content_type = local_var_resp
212 .headers()
213 .get("content-type")
214 .and_then(|v| v.to_str().ok())
215 .unwrap_or("application/octet-stream");
216 let local_var_content_type = super::ContentType::from(local_var_content_type);
217 let local_var_content = local_var_resp.text().await?;
218
219 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
220 match local_var_content_type {
221 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
222 ContentType::Text => {
223 return Err(Error::from(serde_json::Error::custom(
224 "Received `text/plain` content type response that cannot be converted to `models::SecurityTasksResponseModelListResponseModel`",
225 )));
226 }
227 ContentType::Unsupported(local_var_unknown_type) => {
228 return Err(Error::from(serde_json::Error::custom(format!(
229 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::SecurityTasksResponseModelListResponseModel`"
230 ))));
231 }
232 }
233 } else {
234 let local_var_entity: Option<GetError> = serde_json::from_str(&local_var_content).ok();
235 let local_var_error = ResponseContent {
236 status: local_var_status,
237 content: local_var_content,
238 entity: local_var_entity,
239 };
240 Err(Error::ResponseError(local_var_error))
241 }
242 }
243
244 async fn get_task_metrics_for_organization<'a>(
245 &self,
246 organization_id: uuid::Uuid,
247 ) -> Result<models::SecurityTaskMetricsResponseModel, Error<GetTaskMetricsForOrganizationError>>
248 {
249 let local_var_configuration = &self.configuration;
250
251 let local_var_client = &local_var_configuration.client;
252
253 let local_var_uri_str = format!(
254 "{}/tasks/{organizationId}/metrics",
255 local_var_configuration.base_path,
256 organizationId = organization_id
257 );
258 let mut local_var_req_builder =
259 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
260
261 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
262 local_var_req_builder = local_var_req_builder
263 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
264 }
265 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
266 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
267 };
268
269 let local_var_req = local_var_req_builder.build()?;
270 let local_var_resp = local_var_client.execute(local_var_req).await?;
271
272 let local_var_status = local_var_resp.status();
273 let local_var_content_type = local_var_resp
274 .headers()
275 .get("content-type")
276 .and_then(|v| v.to_str().ok())
277 .unwrap_or("application/octet-stream");
278 let local_var_content_type = super::ContentType::from(local_var_content_type);
279 let local_var_content = local_var_resp.text().await?;
280
281 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
282 match local_var_content_type {
283 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
284 ContentType::Text => {
285 return Err(Error::from(serde_json::Error::custom(
286 "Received `text/plain` content type response that cannot be converted to `models::SecurityTaskMetricsResponseModel`",
287 )));
288 }
289 ContentType::Unsupported(local_var_unknown_type) => {
290 return Err(Error::from(serde_json::Error::custom(format!(
291 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::SecurityTaskMetricsResponseModel`"
292 ))));
293 }
294 }
295 } else {
296 let local_var_entity: Option<GetTaskMetricsForOrganizationError> =
297 serde_json::from_str(&local_var_content).ok();
298 let local_var_error = ResponseContent {
299 status: local_var_status,
300 content: local_var_content,
301 entity: local_var_entity,
302 };
303 Err(Error::ResponseError(local_var_error))
304 }
305 }
306
307 async fn list_for_organization<'a>(
308 &self,
309 organization_id: Option<uuid::Uuid>,
310 status: Option<models::SecurityTaskStatus>,
311 ) -> Result<models::SecurityTasksResponseModelListResponseModel, Error<ListForOrganizationError>>
312 {
313 let local_var_configuration = &self.configuration;
314
315 let local_var_client = &local_var_configuration.client;
316
317 let local_var_uri_str = format!("{}/tasks/organization", local_var_configuration.base_path);
318 let mut local_var_req_builder =
319 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
320
321 if let Some(ref param_value) = organization_id {
322 local_var_req_builder =
323 local_var_req_builder.query(&[("organizationId", ¶m_value.to_string())]);
324 }
325 if let Some(ref param_value) = status {
326 local_var_req_builder =
327 local_var_req_builder.query(&[("status", ¶m_value.to_string())]);
328 }
329 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
330 local_var_req_builder = local_var_req_builder
331 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
332 }
333 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
334 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
335 };
336
337 let local_var_req = local_var_req_builder.build()?;
338 let local_var_resp = local_var_client.execute(local_var_req).await?;
339
340 let local_var_status = local_var_resp.status();
341 let local_var_content_type = local_var_resp
342 .headers()
343 .get("content-type")
344 .and_then(|v| v.to_str().ok())
345 .unwrap_or("application/octet-stream");
346 let local_var_content_type = super::ContentType::from(local_var_content_type);
347 let local_var_content = local_var_resp.text().await?;
348
349 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
350 match local_var_content_type {
351 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
352 ContentType::Text => {
353 return Err(Error::from(serde_json::Error::custom(
354 "Received `text/plain` content type response that cannot be converted to `models::SecurityTasksResponseModelListResponseModel`",
355 )));
356 }
357 ContentType::Unsupported(local_var_unknown_type) => {
358 return Err(Error::from(serde_json::Error::custom(format!(
359 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::SecurityTasksResponseModelListResponseModel`"
360 ))));
361 }
362 }
363 } else {
364 let local_var_entity: Option<ListForOrganizationError> =
365 serde_json::from_str(&local_var_content).ok();
366 let local_var_error = ResponseContent {
367 status: local_var_status,
368 content: local_var_content,
369 entity: local_var_entity,
370 };
371 Err(Error::ResponseError(local_var_error))
372 }
373 }
374}
375
376#[derive(Debug, Clone, Serialize, Deserialize)]
378#[serde(untagged)]
379pub enum BulkCreateTasksError {
380 UnknownValue(serde_json::Value),
381}
382#[derive(Debug, Clone, Serialize, Deserialize)]
384#[serde(untagged)]
385pub enum CompleteError {
386 UnknownValue(serde_json::Value),
387}
388#[derive(Debug, Clone, Serialize, Deserialize)]
390#[serde(untagged)]
391pub enum GetError {
392 UnknownValue(serde_json::Value),
393}
394#[derive(Debug, Clone, Serialize, Deserialize)]
396#[serde(untagged)]
397pub enum GetTaskMetricsForOrganizationError {
398 UnknownValue(serde_json::Value),
399}
400#[derive(Debug, Clone, Serialize, Deserialize)]
402#[serde(untagged)]
403pub enum ListForOrganizationError {
404 UnknownValue(serde_json::Value),
405}