Skip to main content

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