bitwarden_api_api/apis/
trash_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 TrashApi: Send + Sync {
29    /// POST /secrets/{organizationId}/trash/empty
30    async fn empty_trash<'a>(
31        &self,
32        organization_id: uuid::Uuid,
33        uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
34    ) -> Result<(), Error<EmptyTrashError>>;
35
36    /// GET /secrets/{organizationId}/trash
37    async fn list_by_organization<'a>(
38        &self,
39        organization_id: uuid::Uuid,
40    ) -> Result<models::SecretWithProjectsListResponseModel, Error<ListByOrganizationError>>;
41
42    /// POST /secrets/{organizationId}/trash/restore
43    async fn restore_trash<'a>(
44        &self,
45        organization_id: uuid::Uuid,
46        uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
47    ) -> Result<(), Error<RestoreTrashError>>;
48}
49
50pub struct TrashApiClient {
51    configuration: Arc<configuration::Configuration>,
52}
53
54impl TrashApiClient {
55    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
56        Self { configuration }
57    }
58}
59
60#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
61#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
62impl TrashApi for TrashApiClient {
63    async fn empty_trash<'a>(
64        &self,
65        organization_id: uuid::Uuid,
66        uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
67    ) -> Result<(), Error<EmptyTrashError>> {
68        let local_var_configuration = &self.configuration;
69
70        let local_var_client = &local_var_configuration.client;
71
72        let local_var_uri_str = format!(
73            "{}/secrets/{organizationId}/trash/empty",
74            local_var_configuration.base_path,
75            organizationId = organization_id
76        );
77        let mut local_var_req_builder =
78            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
79
80        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
81            local_var_req_builder = local_var_req_builder
82                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
83        }
84        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
85            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
86        };
87        local_var_req_builder = local_var_req_builder.json(&uuid_colon_colon_uuid);
88
89        let local_var_req = local_var_req_builder.build()?;
90        let local_var_resp = local_var_client.execute(local_var_req).await?;
91
92        let local_var_status = local_var_resp.status();
93        let local_var_content = local_var_resp.text().await?;
94
95        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
96            Ok(())
97        } else {
98            let local_var_entity: Option<EmptyTrashError> =
99                serde_json::from_str(&local_var_content).ok();
100            let local_var_error = ResponseContent {
101                status: local_var_status,
102                content: local_var_content,
103                entity: local_var_entity,
104            };
105            Err(Error::ResponseError(local_var_error))
106        }
107    }
108
109    async fn list_by_organization<'a>(
110        &self,
111        organization_id: uuid::Uuid,
112    ) -> Result<models::SecretWithProjectsListResponseModel, Error<ListByOrganizationError>> {
113        let local_var_configuration = &self.configuration;
114
115        let local_var_client = &local_var_configuration.client;
116
117        let local_var_uri_str = format!(
118            "{}/secrets/{organizationId}/trash",
119            local_var_configuration.base_path,
120            organizationId = organization_id
121        );
122        let mut local_var_req_builder =
123            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
124
125        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
126            local_var_req_builder = local_var_req_builder
127                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
128        }
129        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
130            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
131        };
132
133        let local_var_req = local_var_req_builder.build()?;
134        let local_var_resp = local_var_client.execute(local_var_req).await?;
135
136        let local_var_status = local_var_resp.status();
137        let local_var_content_type = local_var_resp
138            .headers()
139            .get("content-type")
140            .and_then(|v| v.to_str().ok())
141            .unwrap_or("application/octet-stream");
142        let local_var_content_type = super::ContentType::from(local_var_content_type);
143        let local_var_content = local_var_resp.text().await?;
144
145        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
146            match local_var_content_type {
147                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
148                ContentType::Text => {
149                    return Err(Error::from(serde_json::Error::custom(
150                        "Received `text/plain` content type response that cannot be converted to `models::SecretWithProjectsListResponseModel`",
151                    )));
152                }
153                ContentType::Unsupported(local_var_unknown_type) => {
154                    return Err(Error::from(serde_json::Error::custom(format!(
155                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::SecretWithProjectsListResponseModel`"
156                    ))));
157                }
158            }
159        } else {
160            let local_var_entity: Option<ListByOrganizationError> =
161                serde_json::from_str(&local_var_content).ok();
162            let local_var_error = ResponseContent {
163                status: local_var_status,
164                content: local_var_content,
165                entity: local_var_entity,
166            };
167            Err(Error::ResponseError(local_var_error))
168        }
169    }
170
171    async fn restore_trash<'a>(
172        &self,
173        organization_id: uuid::Uuid,
174        uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
175    ) -> Result<(), Error<RestoreTrashError>> {
176        let local_var_configuration = &self.configuration;
177
178        let local_var_client = &local_var_configuration.client;
179
180        let local_var_uri_str = format!(
181            "{}/secrets/{organizationId}/trash/restore",
182            local_var_configuration.base_path,
183            organizationId = organization_id
184        );
185        let mut local_var_req_builder =
186            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
187
188        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
189            local_var_req_builder = local_var_req_builder
190                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
191        }
192        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
193            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
194        };
195        local_var_req_builder = local_var_req_builder.json(&uuid_colon_colon_uuid);
196
197        let local_var_req = local_var_req_builder.build()?;
198        let local_var_resp = local_var_client.execute(local_var_req).await?;
199
200        let local_var_status = local_var_resp.status();
201        let local_var_content = local_var_resp.text().await?;
202
203        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
204            Ok(())
205        } else {
206            let local_var_entity: Option<RestoreTrashError> =
207                serde_json::from_str(&local_var_content).ok();
208            let local_var_error = ResponseContent {
209                status: local_var_status,
210                content: local_var_content,
211                entity: local_var_entity,
212            };
213            Err(Error::ResponseError(local_var_error))
214        }
215    }
216}
217
218/// struct for typed errors of method [`TrashApi::empty_trash`]
219#[derive(Debug, Clone, Serialize, Deserialize)]
220#[serde(untagged)]
221pub enum EmptyTrashError {
222    UnknownValue(serde_json::Value),
223}
224/// struct for typed errors of method [`TrashApi::list_by_organization`]
225#[derive(Debug, Clone, Serialize, Deserialize)]
226#[serde(untagged)]
227pub enum ListByOrganizationError {
228    UnknownValue(serde_json::Value),
229}
230/// struct for typed errors of method [`TrashApi::restore_trash`]
231#[derive(Debug, Clone, Serialize, Deserialize)]
232#[serde(untagged)]
233pub enum RestoreTrashError {
234    UnknownValue(serde_json::Value),
235}