Skip to main content

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::{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 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        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
93        local_var_req_builder = local_var_req_builder.json(&uuid_colon_colon_uuid);
94
95        let local_var_resp = local_var_req_builder.send().await?;
96
97        let local_var_status = local_var_resp.status();
98        let local_var_content = local_var_resp.text().await?;
99
100        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
101            Ok(())
102        } else {
103            let local_var_entity: Option<BulkDeleteError> =
104                serde_json::from_str(&local_var_content).ok();
105            let local_var_error = ResponseContent {
106                status: local_var_status,
107                content: local_var_content,
108                entity: local_var_entity,
109            };
110            Err(Error::ResponseError(local_var_error))
111        }
112    }
113
114    async fn get_by_id<'a>(
115        &self,
116        id: uuid::Uuid,
117    ) -> Result<models::SecretVersionResponseModel, Error<GetByIdError>> {
118        let local_var_configuration = &self.configuration;
119
120        let local_var_client = &local_var_configuration.client;
121
122        let local_var_uri_str = format!(
123            "{}/secret-versions/{id}",
124            local_var_configuration.base_path,
125            id = id
126        );
127        let mut local_var_req_builder =
128            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
129
130        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
131
132        let local_var_resp = local_var_req_builder.send().await?;
133
134        let local_var_status = local_var_resp.status();
135        let local_var_content_type = local_var_resp
136            .headers()
137            .get("content-type")
138            .and_then(|v| v.to_str().ok())
139            .unwrap_or("application/octet-stream");
140        let local_var_content_type = super::ContentType::from(local_var_content_type);
141        let local_var_content = local_var_resp.text().await?;
142
143        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
144            match local_var_content_type {
145                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
146                ContentType::Text => {
147                    return Err(Error::from(serde_json::Error::custom(
148                        "Received `text/plain` content type response that cannot be converted to `models::SecretVersionResponseModel`",
149                    )));
150                }
151                ContentType::Unsupported(local_var_unknown_type) => {
152                    return Err(Error::from(serde_json::Error::custom(format!(
153                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::SecretVersionResponseModel`"
154                    ))));
155                }
156            }
157        } else {
158            let local_var_entity: Option<GetByIdError> =
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_many_by_ids<'a>(
170        &self,
171        uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
172    ) -> Result<models::SecretVersionResponseModelListResponseModel, Error<GetManyByIdsError>> {
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!(
178            "{}/secret-versions/get-by-ids",
179            local_var_configuration.base_path
180        );
181        let mut local_var_req_builder =
182            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
183
184        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
185        local_var_req_builder = local_var_req_builder.json(&uuid_colon_colon_uuid);
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::SecretVersionResponseModelListResponseModel`",
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::SecretVersionResponseModelListResponseModel`"
209                    ))));
210                }
211            }
212        } else {
213            let local_var_entity: Option<GetManyByIdsError> =
214                serde_json::from_str(&local_var_content).ok();
215            let local_var_error = ResponseContent {
216                status: local_var_status,
217                content: local_var_content,
218                entity: local_var_entity,
219            };
220            Err(Error::ResponseError(local_var_error))
221        }
222    }
223
224    async fn get_versions_by_secret_id<'a>(
225        &self,
226        secret_id: uuid::Uuid,
227    ) -> Result<
228        models::SecretVersionResponseModelListResponseModel,
229        Error<GetVersionsBySecretIdError>,
230    > {
231        let local_var_configuration = &self.configuration;
232
233        let local_var_client = &local_var_configuration.client;
234
235        let local_var_uri_str = format!(
236            "{}/secrets/{secretId}/versions",
237            local_var_configuration.base_path,
238            secretId = secret_id
239        );
240        let mut local_var_req_builder =
241            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
242
243        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
244
245        let local_var_resp = local_var_req_builder.send().await?;
246
247        let local_var_status = local_var_resp.status();
248        let local_var_content_type = local_var_resp
249            .headers()
250            .get("content-type")
251            .and_then(|v| v.to_str().ok())
252            .unwrap_or("application/octet-stream");
253        let local_var_content_type = super::ContentType::from(local_var_content_type);
254        let local_var_content = local_var_resp.text().await?;
255
256        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
257            match local_var_content_type {
258                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
259                ContentType::Text => {
260                    return Err(Error::from(serde_json::Error::custom(
261                        "Received `text/plain` content type response that cannot be converted to `models::SecretVersionResponseModelListResponseModel`",
262                    )));
263                }
264                ContentType::Unsupported(local_var_unknown_type) => {
265                    return Err(Error::from(serde_json::Error::custom(format!(
266                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::SecretVersionResponseModelListResponseModel`"
267                    ))));
268                }
269            }
270        } else {
271            let local_var_entity: Option<GetVersionsBySecretIdError> =
272                serde_json::from_str(&local_var_content).ok();
273            let local_var_error = ResponseContent {
274                status: local_var_status,
275                content: local_var_content,
276                entity: local_var_entity,
277            };
278            Err(Error::ResponseError(local_var_error))
279        }
280    }
281
282    async fn restore_version<'a>(
283        &self,
284        secret_id: uuid::Uuid,
285        restore_secret_version_request_model: Option<models::RestoreSecretVersionRequestModel>,
286    ) -> Result<models::SecretResponseModel, Error<RestoreVersionError>> {
287        let local_var_configuration = &self.configuration;
288
289        let local_var_client = &local_var_configuration.client;
290
291        let local_var_uri_str = format!(
292            "{}/secrets/{secretId}/versions/restore",
293            local_var_configuration.base_path,
294            secretId = secret_id
295        );
296        let mut local_var_req_builder =
297            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
298
299        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
300        local_var_req_builder = local_var_req_builder.json(&restore_secret_version_request_model);
301
302        let local_var_resp = local_var_req_builder.send().await?;
303
304        let local_var_status = local_var_resp.status();
305        let local_var_content_type = local_var_resp
306            .headers()
307            .get("content-type")
308            .and_then(|v| v.to_str().ok())
309            .unwrap_or("application/octet-stream");
310        let local_var_content_type = super::ContentType::from(local_var_content_type);
311        let local_var_content = local_var_resp.text().await?;
312
313        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
314            match local_var_content_type {
315                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
316                ContentType::Text => {
317                    return Err(Error::from(serde_json::Error::custom(
318                        "Received `text/plain` content type response that cannot be converted to `models::SecretResponseModel`",
319                    )));
320                }
321                ContentType::Unsupported(local_var_unknown_type) => {
322                    return Err(Error::from(serde_json::Error::custom(format!(
323                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::SecretResponseModel`"
324                    ))));
325                }
326            }
327        } else {
328            let local_var_entity: Option<RestoreVersionError> =
329                serde_json::from_str(&local_var_content).ok();
330            let local_var_error = ResponseContent {
331                status: local_var_status,
332                content: local_var_content,
333                entity: local_var_entity,
334            };
335            Err(Error::ResponseError(local_var_error))
336        }
337    }
338}
339
340/// struct for typed errors of method [`SecretVersionsApi::bulk_delete`]
341#[derive(Debug, Clone, Serialize, Deserialize)]
342#[serde(untagged)]
343pub enum BulkDeleteError {
344    UnknownValue(serde_json::Value),
345}
346/// struct for typed errors of method [`SecretVersionsApi::get_by_id`]
347#[derive(Debug, Clone, Serialize, Deserialize)]
348#[serde(untagged)]
349pub enum GetByIdError {
350    UnknownValue(serde_json::Value),
351}
352/// struct for typed errors of method [`SecretVersionsApi::get_many_by_ids`]
353#[derive(Debug, Clone, Serialize, Deserialize)]
354#[serde(untagged)]
355pub enum GetManyByIdsError {
356    UnknownValue(serde_json::Value),
357}
358/// struct for typed errors of method [`SecretVersionsApi::get_versions_by_secret_id`]
359#[derive(Debug, Clone, Serialize, Deserialize)]
360#[serde(untagged)]
361pub enum GetVersionsBySecretIdError {
362    UnknownValue(serde_json::Value),
363}
364/// struct for typed errors of method [`SecretVersionsApi::restore_version`]
365#[derive(Debug, Clone, Serialize, Deserialize)]
366#[serde(untagged)]
367pub enum RestoreVersionError {
368    UnknownValue(serde_json::Value),
369}