Skip to main content

bitwarden_api_api/apis/
projects_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 ProjectsApi: Send + Sync {
29    /// POST /projects/delete
30    async fn bulk_delete<'a>(
31        &self,
32        uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
33    ) -> Result<models::BulkDeleteResponseModelListResponseModel, Error<BulkDeleteError>>;
34
35    /// POST /organizations/{organizationId}/projects
36    async fn create<'a>(
37        &self,
38        organization_id: uuid::Uuid,
39        project_create_request_model: Option<models::ProjectCreateRequestModel>,
40    ) -> Result<models::ProjectResponseModel, Error<CreateError>>;
41
42    /// GET /projects/{id}
43    async fn get<'a>(
44        &self,
45        id: uuid::Uuid,
46    ) -> Result<models::ProjectResponseModel, Error<GetError>>;
47
48    /// GET /organizations/{organizationId}/projects
49    async fn list_by_organization<'a>(
50        &self,
51        organization_id: uuid::Uuid,
52    ) -> Result<models::ProjectResponseModelListResponseModel, Error<ListByOrganizationError>>;
53
54    /// PUT /projects/{id}
55    async fn update<'a>(
56        &self,
57        id: uuid::Uuid,
58        project_update_request_model: Option<models::ProjectUpdateRequestModel>,
59    ) -> Result<models::ProjectResponseModel, Error<UpdateError>>;
60}
61
62pub struct ProjectsApiClient {
63    configuration: Arc<configuration::Configuration>,
64}
65
66impl ProjectsApiClient {
67    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
68        Self { configuration }
69    }
70}
71
72#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
73#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
74impl ProjectsApi for ProjectsApiClient {
75    async fn bulk_delete<'a>(
76        &self,
77        uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
78    ) -> Result<models::BulkDeleteResponseModelListResponseModel, Error<BulkDeleteError>> {
79        let local_var_configuration = &self.configuration;
80
81        let local_var_client = &local_var_configuration.client;
82
83        let local_var_uri_str = format!("{}/projects/delete", local_var_configuration.base_path);
84        let mut local_var_req_builder =
85            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
86
87        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
88        local_var_req_builder = local_var_req_builder.json(&uuid_colon_colon_uuid);
89
90        let local_var_resp = local_var_req_builder.send().await?;
91
92        let local_var_status = local_var_resp.status();
93        let local_var_content_type = local_var_resp
94            .headers()
95            .get("content-type")
96            .and_then(|v| v.to_str().ok())
97            .unwrap_or("application/octet-stream");
98        let local_var_content_type = super::ContentType::from(local_var_content_type);
99        let local_var_content = local_var_resp.text().await?;
100
101        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
102            match local_var_content_type {
103                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
104                ContentType::Text => {
105                    return Err(Error::from(serde_json::Error::custom(
106                        "Received `text/plain` content type response that cannot be converted to `models::BulkDeleteResponseModelListResponseModel`",
107                    )));
108                }
109                ContentType::Unsupported(local_var_unknown_type) => {
110                    return Err(Error::from(serde_json::Error::custom(format!(
111                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::BulkDeleteResponseModelListResponseModel`"
112                    ))));
113                }
114            }
115        } else {
116            let local_var_entity: Option<BulkDeleteError> =
117                serde_json::from_str(&local_var_content).ok();
118            let local_var_error = ResponseContent {
119                status: local_var_status,
120                content: local_var_content,
121                entity: local_var_entity,
122            };
123            Err(Error::ResponseError(local_var_error))
124        }
125    }
126
127    async fn create<'a>(
128        &self,
129        organization_id: uuid::Uuid,
130        project_create_request_model: Option<models::ProjectCreateRequestModel>,
131    ) -> Result<models::ProjectResponseModel, Error<CreateError>> {
132        let local_var_configuration = &self.configuration;
133
134        let local_var_client = &local_var_configuration.client;
135
136        let local_var_uri_str = format!(
137            "{}/organizations/{organizationId}/projects",
138            local_var_configuration.base_path,
139            organizationId = organization_id
140        );
141        let mut local_var_req_builder =
142            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
143
144        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
145        local_var_req_builder = local_var_req_builder.json(&project_create_request_model);
146
147        let local_var_resp = local_var_req_builder.send().await?;
148
149        let local_var_status = local_var_resp.status();
150        let local_var_content_type = local_var_resp
151            .headers()
152            .get("content-type")
153            .and_then(|v| v.to_str().ok())
154            .unwrap_or("application/octet-stream");
155        let local_var_content_type = super::ContentType::from(local_var_content_type);
156        let local_var_content = local_var_resp.text().await?;
157
158        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
159            match local_var_content_type {
160                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
161                ContentType::Text => {
162                    return Err(Error::from(serde_json::Error::custom(
163                        "Received `text/plain` content type response that cannot be converted to `models::ProjectResponseModel`",
164                    )));
165                }
166                ContentType::Unsupported(local_var_unknown_type) => {
167                    return Err(Error::from(serde_json::Error::custom(format!(
168                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ProjectResponseModel`"
169                    ))));
170                }
171            }
172        } else {
173            let local_var_entity: Option<CreateError> =
174                serde_json::from_str(&local_var_content).ok();
175            let local_var_error = ResponseContent {
176                status: local_var_status,
177                content: local_var_content,
178                entity: local_var_entity,
179            };
180            Err(Error::ResponseError(local_var_error))
181        }
182    }
183
184    async fn get<'a>(
185        &self,
186        id: uuid::Uuid,
187    ) -> Result<models::ProjectResponseModel, Error<GetError>> {
188        let local_var_configuration = &self.configuration;
189
190        let local_var_client = &local_var_configuration.client;
191
192        let local_var_uri_str = format!(
193            "{}/projects/{id}",
194            local_var_configuration.base_path,
195            id = id
196        );
197        let mut local_var_req_builder =
198            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
199
200        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
201
202        let local_var_resp = local_var_req_builder.send().await?;
203
204        let local_var_status = local_var_resp.status();
205        let local_var_content_type = local_var_resp
206            .headers()
207            .get("content-type")
208            .and_then(|v| v.to_str().ok())
209            .unwrap_or("application/octet-stream");
210        let local_var_content_type = super::ContentType::from(local_var_content_type);
211        let local_var_content = local_var_resp.text().await?;
212
213        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
214            match local_var_content_type {
215                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
216                ContentType::Text => {
217                    return Err(Error::from(serde_json::Error::custom(
218                        "Received `text/plain` content type response that cannot be converted to `models::ProjectResponseModel`",
219                    )));
220                }
221                ContentType::Unsupported(local_var_unknown_type) => {
222                    return Err(Error::from(serde_json::Error::custom(format!(
223                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ProjectResponseModel`"
224                    ))));
225                }
226            }
227        } else {
228            let local_var_entity: Option<GetError> = serde_json::from_str(&local_var_content).ok();
229            let local_var_error = ResponseContent {
230                status: local_var_status,
231                content: local_var_content,
232                entity: local_var_entity,
233            };
234            Err(Error::ResponseError(local_var_error))
235        }
236    }
237
238    async fn list_by_organization<'a>(
239        &self,
240        organization_id: uuid::Uuid,
241    ) -> Result<models::ProjectResponseModelListResponseModel, Error<ListByOrganizationError>> {
242        let local_var_configuration = &self.configuration;
243
244        let local_var_client = &local_var_configuration.client;
245
246        let local_var_uri_str = format!(
247            "{}/organizations/{organizationId}/projects",
248            local_var_configuration.base_path,
249            organizationId = organization_id
250        );
251        let mut local_var_req_builder =
252            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
253
254        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
255
256        let local_var_resp = local_var_req_builder.send().await?;
257
258        let local_var_status = local_var_resp.status();
259        let local_var_content_type = local_var_resp
260            .headers()
261            .get("content-type")
262            .and_then(|v| v.to_str().ok())
263            .unwrap_or("application/octet-stream");
264        let local_var_content_type = super::ContentType::from(local_var_content_type);
265        let local_var_content = local_var_resp.text().await?;
266
267        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
268            match local_var_content_type {
269                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
270                ContentType::Text => {
271                    return Err(Error::from(serde_json::Error::custom(
272                        "Received `text/plain` content type response that cannot be converted to `models::ProjectResponseModelListResponseModel`",
273                    )));
274                }
275                ContentType::Unsupported(local_var_unknown_type) => {
276                    return Err(Error::from(serde_json::Error::custom(format!(
277                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ProjectResponseModelListResponseModel`"
278                    ))));
279                }
280            }
281        } else {
282            let local_var_entity: Option<ListByOrganizationError> =
283                serde_json::from_str(&local_var_content).ok();
284            let local_var_error = ResponseContent {
285                status: local_var_status,
286                content: local_var_content,
287                entity: local_var_entity,
288            };
289            Err(Error::ResponseError(local_var_error))
290        }
291    }
292
293    async fn update<'a>(
294        &self,
295        id: uuid::Uuid,
296        project_update_request_model: Option<models::ProjectUpdateRequestModel>,
297    ) -> Result<models::ProjectResponseModel, Error<UpdateError>> {
298        let local_var_configuration = &self.configuration;
299
300        let local_var_client = &local_var_configuration.client;
301
302        let local_var_uri_str = format!(
303            "{}/projects/{id}",
304            local_var_configuration.base_path,
305            id = id
306        );
307        let mut local_var_req_builder =
308            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
309
310        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
311        local_var_req_builder = local_var_req_builder.json(&project_update_request_model);
312
313        let local_var_resp = local_var_req_builder.send().await?;
314
315        let local_var_status = local_var_resp.status();
316        let local_var_content_type = local_var_resp
317            .headers()
318            .get("content-type")
319            .and_then(|v| v.to_str().ok())
320            .unwrap_or("application/octet-stream");
321        let local_var_content_type = super::ContentType::from(local_var_content_type);
322        let local_var_content = local_var_resp.text().await?;
323
324        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
325            match local_var_content_type {
326                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
327                ContentType::Text => {
328                    return Err(Error::from(serde_json::Error::custom(
329                        "Received `text/plain` content type response that cannot be converted to `models::ProjectResponseModel`",
330                    )));
331                }
332                ContentType::Unsupported(local_var_unknown_type) => {
333                    return Err(Error::from(serde_json::Error::custom(format!(
334                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ProjectResponseModel`"
335                    ))));
336                }
337            }
338        } else {
339            let local_var_entity: Option<UpdateError> =
340                serde_json::from_str(&local_var_content).ok();
341            let local_var_error = ResponseContent {
342                status: local_var_status,
343                content: local_var_content,
344                entity: local_var_entity,
345            };
346            Err(Error::ResponseError(local_var_error))
347        }
348    }
349}
350
351/// struct for typed errors of method [`ProjectsApi::bulk_delete`]
352#[derive(Debug, Clone, Serialize, Deserialize)]
353#[serde(untagged)]
354pub enum BulkDeleteError {
355    UnknownValue(serde_json::Value),
356}
357/// struct for typed errors of method [`ProjectsApi::create`]
358#[derive(Debug, Clone, Serialize, Deserialize)]
359#[serde(untagged)]
360pub enum CreateError {
361    UnknownValue(serde_json::Value),
362}
363/// struct for typed errors of method [`ProjectsApi::get`]
364#[derive(Debug, Clone, Serialize, Deserialize)]
365#[serde(untagged)]
366pub enum GetError {
367    UnknownValue(serde_json::Value),
368}
369/// struct for typed errors of method [`ProjectsApi::list_by_organization`]
370#[derive(Debug, Clone, Serialize, Deserialize)]
371#[serde(untagged)]
372pub enum ListByOrganizationError {
373    UnknownValue(serde_json::Value),
374}
375/// struct for typed errors of method [`ProjectsApi::update`]
376#[derive(Debug, Clone, Serialize, Deserialize)]
377#[serde(untagged)]
378pub enum UpdateError {
379    UnknownValue(serde_json::Value),
380}