bitwarden_api_api/apis/
security_task_api.rs

1/*
2 * Bitwarden Internal API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: latest
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use 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::{AuthRequired, 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    /// POST /tasks/{orgId}/bulk-create
30    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    /// PATCH /tasks/{taskId}/complete
39    async fn complete<'a>(&self, task_id: uuid::Uuid) -> Result<(), Error<CompleteError>>;
40
41    /// GET /tasks
42    async fn get<'a>(
43        &self,
44        status: Option<models::SecurityTaskStatus>,
45    ) -> Result<models::SecurityTasksResponseModelListResponseModel, Error<GetError>>;
46
47    /// GET /tasks/{organizationId}/metrics
48    async fn get_task_metrics_for_organization<'a>(
49        &self,
50        organization_id: uuid::Uuid,
51    ) -> Result<models::SecurityTaskMetricsResponseModel, Error<GetTaskMetricsForOrganizationError>>;
52
53    /// GET /tasks/organization
54    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_token) = local_var_configuration.oauth_access_token {
95            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
96        };
97        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
98        local_var_req_builder =
99            local_var_req_builder.json(&bulk_create_security_tasks_request_model);
100
101        let local_var_req = local_var_req_builder.build()?;
102        let local_var_resp = local_var_client.execute(local_var_req).await?;
103
104        let local_var_status = local_var_resp.status();
105        let local_var_content_type = local_var_resp
106            .headers()
107            .get("content-type")
108            .and_then(|v| v.to_str().ok())
109            .unwrap_or("application/octet-stream");
110        let local_var_content_type = super::ContentType::from(local_var_content_type);
111        let local_var_content = local_var_resp.text().await?;
112
113        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
114            match local_var_content_type {
115                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
116                ContentType::Text => {
117                    return Err(Error::from(serde_json::Error::custom(
118                        "Received `text/plain` content type response that cannot be converted to `models::SecurityTasksResponseModelListResponseModel`",
119                    )));
120                }
121                ContentType::Unsupported(local_var_unknown_type) => {
122                    return Err(Error::from(serde_json::Error::custom(format!(
123                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::SecurityTasksResponseModelListResponseModel`"
124                    ))));
125                }
126            }
127        } else {
128            let local_var_entity: Option<BulkCreateTasksError> =
129                serde_json::from_str(&local_var_content).ok();
130            let local_var_error = ResponseContent {
131                status: local_var_status,
132                content: local_var_content,
133                entity: local_var_entity,
134            };
135            Err(Error::ResponseError(local_var_error))
136        }
137    }
138
139    async fn complete<'a>(&self, task_id: uuid::Uuid) -> Result<(), Error<CompleteError>> {
140        let local_var_configuration = &self.configuration;
141
142        let local_var_client = &local_var_configuration.client;
143
144        let local_var_uri_str = format!(
145            "{}/tasks/{taskId}/complete",
146            local_var_configuration.base_path,
147            taskId = task_id
148        );
149        let mut local_var_req_builder =
150            local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
151
152        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
153            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
154        };
155        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
156
157        let local_var_req = local_var_req_builder.build()?;
158        let local_var_resp = local_var_client.execute(local_var_req).await?;
159
160        let local_var_status = local_var_resp.status();
161        let local_var_content = local_var_resp.text().await?;
162
163        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
164            Ok(())
165        } else {
166            let local_var_entity: Option<CompleteError> =
167                serde_json::from_str(&local_var_content).ok();
168            let local_var_error = ResponseContent {
169                status: local_var_status,
170                content: local_var_content,
171                entity: local_var_entity,
172            };
173            Err(Error::ResponseError(local_var_error))
174        }
175    }
176
177    async fn get<'a>(
178        &self,
179        status: Option<models::SecurityTaskStatus>,
180    ) -> Result<models::SecurityTasksResponseModelListResponseModel, Error<GetError>> {
181        let local_var_configuration = &self.configuration;
182
183        let local_var_client = &local_var_configuration.client;
184
185        let local_var_uri_str = format!("{}/tasks", local_var_configuration.base_path);
186        let mut local_var_req_builder =
187            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
188
189        if let Some(ref param_value) = status {
190            local_var_req_builder =
191                local_var_req_builder.query(&[("status", &param_value.to_string())]);
192        }
193        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
194            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
195        };
196        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
197
198        let local_var_req = local_var_req_builder.build()?;
199        let local_var_resp = local_var_client.execute(local_var_req).await?;
200
201        let local_var_status = local_var_resp.status();
202        let local_var_content_type = local_var_resp
203            .headers()
204            .get("content-type")
205            .and_then(|v| v.to_str().ok())
206            .unwrap_or("application/octet-stream");
207        let local_var_content_type = super::ContentType::from(local_var_content_type);
208        let local_var_content = local_var_resp.text().await?;
209
210        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
211            match local_var_content_type {
212                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
213                ContentType::Text => {
214                    return Err(Error::from(serde_json::Error::custom(
215                        "Received `text/plain` content type response that cannot be converted to `models::SecurityTasksResponseModelListResponseModel`",
216                    )));
217                }
218                ContentType::Unsupported(local_var_unknown_type) => {
219                    return Err(Error::from(serde_json::Error::custom(format!(
220                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::SecurityTasksResponseModelListResponseModel`"
221                    ))));
222                }
223            }
224        } else {
225            let local_var_entity: Option<GetError> = serde_json::from_str(&local_var_content).ok();
226            let local_var_error = ResponseContent {
227                status: local_var_status,
228                content: local_var_content,
229                entity: local_var_entity,
230            };
231            Err(Error::ResponseError(local_var_error))
232        }
233    }
234
235    async fn get_task_metrics_for_organization<'a>(
236        &self,
237        organization_id: uuid::Uuid,
238    ) -> Result<models::SecurityTaskMetricsResponseModel, Error<GetTaskMetricsForOrganizationError>>
239    {
240        let local_var_configuration = &self.configuration;
241
242        let local_var_client = &local_var_configuration.client;
243
244        let local_var_uri_str = format!(
245            "{}/tasks/{organizationId}/metrics",
246            local_var_configuration.base_path,
247            organizationId = organization_id
248        );
249        let mut local_var_req_builder =
250            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
251
252        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
253            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
254        };
255        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
256
257        let local_var_req = local_var_req_builder.build()?;
258        let local_var_resp = local_var_client.execute(local_var_req).await?;
259
260        let local_var_status = local_var_resp.status();
261        let local_var_content_type = local_var_resp
262            .headers()
263            .get("content-type")
264            .and_then(|v| v.to_str().ok())
265            .unwrap_or("application/octet-stream");
266        let local_var_content_type = super::ContentType::from(local_var_content_type);
267        let local_var_content = local_var_resp.text().await?;
268
269        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
270            match local_var_content_type {
271                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
272                ContentType::Text => {
273                    return Err(Error::from(serde_json::Error::custom(
274                        "Received `text/plain` content type response that cannot be converted to `models::SecurityTaskMetricsResponseModel`",
275                    )));
276                }
277                ContentType::Unsupported(local_var_unknown_type) => {
278                    return Err(Error::from(serde_json::Error::custom(format!(
279                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::SecurityTaskMetricsResponseModel`"
280                    ))));
281                }
282            }
283        } else {
284            let local_var_entity: Option<GetTaskMetricsForOrganizationError> =
285                serde_json::from_str(&local_var_content).ok();
286            let local_var_error = ResponseContent {
287                status: local_var_status,
288                content: local_var_content,
289                entity: local_var_entity,
290            };
291            Err(Error::ResponseError(local_var_error))
292        }
293    }
294
295    async fn list_for_organization<'a>(
296        &self,
297        organization_id: Option<uuid::Uuid>,
298        status: Option<models::SecurityTaskStatus>,
299    ) -> Result<models::SecurityTasksResponseModelListResponseModel, Error<ListForOrganizationError>>
300    {
301        let local_var_configuration = &self.configuration;
302
303        let local_var_client = &local_var_configuration.client;
304
305        let local_var_uri_str = format!("{}/tasks/organization", local_var_configuration.base_path);
306        let mut local_var_req_builder =
307            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
308
309        if let Some(ref param_value) = organization_id {
310            local_var_req_builder =
311                local_var_req_builder.query(&[("organizationId", &param_value.to_string())]);
312        }
313        if let Some(ref param_value) = status {
314            local_var_req_builder =
315                local_var_req_builder.query(&[("status", &param_value.to_string())]);
316        }
317        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
318            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
319        };
320        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
321
322        let local_var_req = local_var_req_builder.build()?;
323        let local_var_resp = local_var_client.execute(local_var_req).await?;
324
325        let local_var_status = local_var_resp.status();
326        let local_var_content_type = local_var_resp
327            .headers()
328            .get("content-type")
329            .and_then(|v| v.to_str().ok())
330            .unwrap_or("application/octet-stream");
331        let local_var_content_type = super::ContentType::from(local_var_content_type);
332        let local_var_content = local_var_resp.text().await?;
333
334        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
335            match local_var_content_type {
336                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
337                ContentType::Text => {
338                    return Err(Error::from(serde_json::Error::custom(
339                        "Received `text/plain` content type response that cannot be converted to `models::SecurityTasksResponseModelListResponseModel`",
340                    )));
341                }
342                ContentType::Unsupported(local_var_unknown_type) => {
343                    return Err(Error::from(serde_json::Error::custom(format!(
344                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::SecurityTasksResponseModelListResponseModel`"
345                    ))));
346                }
347            }
348        } else {
349            let local_var_entity: Option<ListForOrganizationError> =
350                serde_json::from_str(&local_var_content).ok();
351            let local_var_error = ResponseContent {
352                status: local_var_status,
353                content: local_var_content,
354                entity: local_var_entity,
355            };
356            Err(Error::ResponseError(local_var_error))
357        }
358    }
359}
360
361/// struct for typed errors of method [`SecurityTaskApi::bulk_create_tasks`]
362#[derive(Debug, Clone, Serialize, Deserialize)]
363#[serde(untagged)]
364pub enum BulkCreateTasksError {
365    UnknownValue(serde_json::Value),
366}
367/// struct for typed errors of method [`SecurityTaskApi::complete`]
368#[derive(Debug, Clone, Serialize, Deserialize)]
369#[serde(untagged)]
370pub enum CompleteError {
371    UnknownValue(serde_json::Value),
372}
373/// struct for typed errors of method [`SecurityTaskApi::get`]
374#[derive(Debug, Clone, Serialize, Deserialize)]
375#[serde(untagged)]
376pub enum GetError {
377    UnknownValue(serde_json::Value),
378}
379/// struct for typed errors of method [`SecurityTaskApi::get_task_metrics_for_organization`]
380#[derive(Debug, Clone, Serialize, Deserialize)]
381#[serde(untagged)]
382pub enum GetTaskMetricsForOrganizationError {
383    UnknownValue(serde_json::Value),
384}
385/// struct for typed errors of method [`SecurityTaskApi::list_for_organization`]
386#[derive(Debug, Clone, Serialize, Deserialize)]
387#[serde(untagged)]
388pub enum ListForOrganizationError {
389    UnknownValue(serde_json::Value),
390}