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::{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        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
88            local_var_req_builder = local_var_req_builder
89                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
90        }
91        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
92            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
93        };
94        local_var_req_builder = local_var_req_builder.json(&uuid_colon_colon_uuid);
95
96        let local_var_req = local_var_req_builder.build()?;
97        let local_var_resp = local_var_client.execute(local_var_req).await?;
98
99        let local_var_status = local_var_resp.status();
100        let local_var_content_type = local_var_resp
101            .headers()
102            .get("content-type")
103            .and_then(|v| v.to_str().ok())
104            .unwrap_or("application/octet-stream");
105        let local_var_content_type = super::ContentType::from(local_var_content_type);
106        let local_var_content = local_var_resp.text().await?;
107
108        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
109            match local_var_content_type {
110                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
111                ContentType::Text => {
112                    return Err(Error::from(serde_json::Error::custom(
113                        "Received `text/plain` content type response that cannot be converted to `models::BulkDeleteResponseModelListResponseModel`",
114                    )));
115                }
116                ContentType::Unsupported(local_var_unknown_type) => {
117                    return Err(Error::from(serde_json::Error::custom(format!(
118                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::BulkDeleteResponseModelListResponseModel`"
119                    ))));
120                }
121            }
122        } else {
123            let local_var_entity: Option<BulkDeleteError> =
124                serde_json::from_str(&local_var_content).ok();
125            let local_var_error = ResponseContent {
126                status: local_var_status,
127                content: local_var_content,
128                entity: local_var_entity,
129            };
130            Err(Error::ResponseError(local_var_error))
131        }
132    }
133
134    async fn create<'a>(
135        &self,
136        organization_id: uuid::Uuid,
137        project_create_request_model: Option<models::ProjectCreateRequestModel>,
138    ) -> Result<models::ProjectResponseModel, Error<CreateError>> {
139        let local_var_configuration = &self.configuration;
140
141        let local_var_client = &local_var_configuration.client;
142
143        let local_var_uri_str = format!(
144            "{}/organizations/{organizationId}/projects",
145            local_var_configuration.base_path,
146            organizationId = organization_id
147        );
148        let mut local_var_req_builder =
149            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
150
151        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
152            local_var_req_builder = local_var_req_builder
153                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
154        }
155        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
156            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
157        };
158        local_var_req_builder = local_var_req_builder.json(&project_create_request_model);
159
160        let local_var_req = local_var_req_builder.build()?;
161        let local_var_resp = local_var_client.execute(local_var_req).await?;
162
163        let local_var_status = local_var_resp.status();
164        let local_var_content_type = local_var_resp
165            .headers()
166            .get("content-type")
167            .and_then(|v| v.to_str().ok())
168            .unwrap_or("application/octet-stream");
169        let local_var_content_type = super::ContentType::from(local_var_content_type);
170        let local_var_content = local_var_resp.text().await?;
171
172        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
173            match local_var_content_type {
174                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
175                ContentType::Text => {
176                    return Err(Error::from(serde_json::Error::custom(
177                        "Received `text/plain` content type response that cannot be converted to `models::ProjectResponseModel`",
178                    )));
179                }
180                ContentType::Unsupported(local_var_unknown_type) => {
181                    return Err(Error::from(serde_json::Error::custom(format!(
182                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ProjectResponseModel`"
183                    ))));
184                }
185            }
186        } else {
187            let local_var_entity: Option<CreateError> =
188                serde_json::from_str(&local_var_content).ok();
189            let local_var_error = ResponseContent {
190                status: local_var_status,
191                content: local_var_content,
192                entity: local_var_entity,
193            };
194            Err(Error::ResponseError(local_var_error))
195        }
196    }
197
198    async fn get<'a>(
199        &self,
200        id: uuid::Uuid,
201    ) -> Result<models::ProjectResponseModel, Error<GetError>> {
202        let local_var_configuration = &self.configuration;
203
204        let local_var_client = &local_var_configuration.client;
205
206        let local_var_uri_str = format!(
207            "{}/projects/{id}",
208            local_var_configuration.base_path,
209            id = id
210        );
211        let mut local_var_req_builder =
212            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
213
214        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
215            local_var_req_builder = local_var_req_builder
216                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
217        }
218        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
219            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
220        };
221
222        let local_var_req = local_var_req_builder.build()?;
223        let local_var_resp = local_var_client.execute(local_var_req).await?;
224
225        let local_var_status = local_var_resp.status();
226        let local_var_content_type = local_var_resp
227            .headers()
228            .get("content-type")
229            .and_then(|v| v.to_str().ok())
230            .unwrap_or("application/octet-stream");
231        let local_var_content_type = super::ContentType::from(local_var_content_type);
232        let local_var_content = local_var_resp.text().await?;
233
234        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
235            match local_var_content_type {
236                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
237                ContentType::Text => {
238                    return Err(Error::from(serde_json::Error::custom(
239                        "Received `text/plain` content type response that cannot be converted to `models::ProjectResponseModel`",
240                    )));
241                }
242                ContentType::Unsupported(local_var_unknown_type) => {
243                    return Err(Error::from(serde_json::Error::custom(format!(
244                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ProjectResponseModel`"
245                    ))));
246                }
247            }
248        } else {
249            let local_var_entity: Option<GetError> = serde_json::from_str(&local_var_content).ok();
250            let local_var_error = ResponseContent {
251                status: local_var_status,
252                content: local_var_content,
253                entity: local_var_entity,
254            };
255            Err(Error::ResponseError(local_var_error))
256        }
257    }
258
259    async fn list_by_organization<'a>(
260        &self,
261        organization_id: uuid::Uuid,
262    ) -> Result<models::ProjectResponseModelListResponseModel, Error<ListByOrganizationError>> {
263        let local_var_configuration = &self.configuration;
264
265        let local_var_client = &local_var_configuration.client;
266
267        let local_var_uri_str = format!(
268            "{}/organizations/{organizationId}/projects",
269            local_var_configuration.base_path,
270            organizationId = organization_id
271        );
272        let mut local_var_req_builder =
273            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
274
275        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
276            local_var_req_builder = local_var_req_builder
277                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
278        }
279        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
280            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
281        };
282
283        let local_var_req = local_var_req_builder.build()?;
284        let local_var_resp = local_var_client.execute(local_var_req).await?;
285
286        let local_var_status = local_var_resp.status();
287        let local_var_content_type = local_var_resp
288            .headers()
289            .get("content-type")
290            .and_then(|v| v.to_str().ok())
291            .unwrap_or("application/octet-stream");
292        let local_var_content_type = super::ContentType::from(local_var_content_type);
293        let local_var_content = local_var_resp.text().await?;
294
295        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
296            match local_var_content_type {
297                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
298                ContentType::Text => {
299                    return Err(Error::from(serde_json::Error::custom(
300                        "Received `text/plain` content type response that cannot be converted to `models::ProjectResponseModelListResponseModel`",
301                    )));
302                }
303                ContentType::Unsupported(local_var_unknown_type) => {
304                    return Err(Error::from(serde_json::Error::custom(format!(
305                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ProjectResponseModelListResponseModel`"
306                    ))));
307                }
308            }
309        } else {
310            let local_var_entity: Option<ListByOrganizationError> =
311                serde_json::from_str(&local_var_content).ok();
312            let local_var_error = ResponseContent {
313                status: local_var_status,
314                content: local_var_content,
315                entity: local_var_entity,
316            };
317            Err(Error::ResponseError(local_var_error))
318        }
319    }
320
321    async fn update<'a>(
322        &self,
323        id: uuid::Uuid,
324        project_update_request_model: Option<models::ProjectUpdateRequestModel>,
325    ) -> Result<models::ProjectResponseModel, Error<UpdateError>> {
326        let local_var_configuration = &self.configuration;
327
328        let local_var_client = &local_var_configuration.client;
329
330        let local_var_uri_str = format!(
331            "{}/projects/{id}",
332            local_var_configuration.base_path,
333            id = id
334        );
335        let mut local_var_req_builder =
336            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
337
338        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
339            local_var_req_builder = local_var_req_builder
340                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
341        }
342        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
343            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
344        };
345        local_var_req_builder = local_var_req_builder.json(&project_update_request_model);
346
347        let local_var_req = local_var_req_builder.build()?;
348        let local_var_resp = local_var_client.execute(local_var_req).await?;
349
350        let local_var_status = local_var_resp.status();
351        let local_var_content_type = local_var_resp
352            .headers()
353            .get("content-type")
354            .and_then(|v| v.to_str().ok())
355            .unwrap_or("application/octet-stream");
356        let local_var_content_type = super::ContentType::from(local_var_content_type);
357        let local_var_content = local_var_resp.text().await?;
358
359        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
360            match local_var_content_type {
361                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
362                ContentType::Text => {
363                    return Err(Error::from(serde_json::Error::custom(
364                        "Received `text/plain` content type response that cannot be converted to `models::ProjectResponseModel`",
365                    )));
366                }
367                ContentType::Unsupported(local_var_unknown_type) => {
368                    return Err(Error::from(serde_json::Error::custom(format!(
369                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ProjectResponseModel`"
370                    ))));
371                }
372            }
373        } else {
374            let local_var_entity: Option<UpdateError> =
375                serde_json::from_str(&local_var_content).ok();
376            let local_var_error = ResponseContent {
377                status: local_var_status,
378                content: local_var_content,
379                entity: local_var_entity,
380            };
381            Err(Error::ResponseError(local_var_error))
382        }
383    }
384}
385
386/// struct for typed errors of method [`ProjectsApi::bulk_delete`]
387#[derive(Debug, Clone, Serialize, Deserialize)]
388#[serde(untagged)]
389pub enum BulkDeleteError {
390    UnknownValue(serde_json::Value),
391}
392/// struct for typed errors of method [`ProjectsApi::create`]
393#[derive(Debug, Clone, Serialize, Deserialize)]
394#[serde(untagged)]
395pub enum CreateError {
396    UnknownValue(serde_json::Value),
397}
398/// struct for typed errors of method [`ProjectsApi::get`]
399#[derive(Debug, Clone, Serialize, Deserialize)]
400#[serde(untagged)]
401pub enum GetError {
402    UnknownValue(serde_json::Value),
403}
404/// struct for typed errors of method [`ProjectsApi::list_by_organization`]
405#[derive(Debug, Clone, Serialize, Deserialize)]
406#[serde(untagged)]
407pub enum ListByOrganizationError {
408    UnknownValue(serde_json::Value),
409}
410/// struct for typed errors of method [`ProjectsApi::update`]
411#[derive(Debug, Clone, Serialize, Deserialize)]
412#[serde(untagged)]
413pub enum UpdateError {
414    UnknownValue(serde_json::Value),
415}