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