bitwarden_api_api/apis/
secret_versions_api.rs1use 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 async fn bulk_delete<'a>(
31 &self,
32 uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
33 ) -> Result<(), Error>;
34
35 async fn get_by_id<'a>(
37 &self,
38 id: uuid::Uuid,
39 ) -> Result<models::SecretVersionResponseModel, Error>;
40
41 async fn get_many_by_ids<'a>(
43 &self,
44 uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
45 ) -> Result<models::SecretVersionResponseModelListResponseModel, Error>;
46
47 async fn get_versions_by_secret_id<'a>(
49 &self,
50 secret_id: uuid::Uuid,
51 ) -> Result<models::SecretVersionResponseModelListResponseModel, Error>;
52
53 async fn restore_version<'a>(
55 &self,
56 secret_id: uuid::Uuid,
57 restore_secret_version_request_model: Option<models::RestoreSecretVersionRequestModel>,
58 ) -> Result<models::SecretResponseModel, Error>;
59}
60
61pub struct SecretVersionsApiClient {
62 configuration: Arc<configuration::Configuration>,
63}
64
65impl SecretVersionsApiClient {
66 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
67 Self { configuration }
68 }
69}
70
71#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
72#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
73impl SecretVersionsApi for SecretVersionsApiClient {
74 async fn bulk_delete<'a>(
75 &self,
76 uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
77 ) -> Result<(), Error> {
78 let local_var_configuration = &self.configuration;
79
80 let local_var_client = &local_var_configuration.client;
81
82 let local_var_uri_str = format!(
83 "{}/secret-versions/delete",
84 local_var_configuration.base_path
85 );
86 let mut local_var_req_builder =
87 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
88
89 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
90 local_var_req_builder = local_var_req_builder.json(&uuid_colon_colon_uuid);
91
92 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
93 }
94
95 async fn get_by_id<'a>(
96 &self,
97 id: uuid::Uuid,
98 ) -> Result<models::SecretVersionResponseModel, Error> {
99 let local_var_configuration = &self.configuration;
100
101 let local_var_client = &local_var_configuration.client;
102
103 let local_var_uri_str = format!(
104 "{}/secret-versions/{id}",
105 local_var_configuration.base_path,
106 id = id
107 );
108 let mut local_var_req_builder =
109 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
110
111 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
112
113 bitwarden_api_base::process_with_json_response(local_var_req_builder).await
114 }
115
116 async fn get_many_by_ids<'a>(
117 &self,
118 uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
119 ) -> Result<models::SecretVersionResponseModelListResponseModel, Error> {
120 let local_var_configuration = &self.configuration;
121
122 let local_var_client = &local_var_configuration.client;
123
124 let local_var_uri_str = format!(
125 "{}/secret-versions/get-by-ids",
126 local_var_configuration.base_path
127 );
128 let mut local_var_req_builder =
129 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
130
131 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
132 local_var_req_builder = local_var_req_builder.json(&uuid_colon_colon_uuid);
133
134 bitwarden_api_base::process_with_json_response(local_var_req_builder).await
135 }
136
137 async fn get_versions_by_secret_id<'a>(
138 &self,
139 secret_id: uuid::Uuid,
140 ) -> Result<models::SecretVersionResponseModelListResponseModel, Error> {
141 let local_var_configuration = &self.configuration;
142
143 let local_var_client = &local_var_configuration.client;
144
145 let local_var_uri_str = format!(
146 "{}/secrets/{secretId}/versions",
147 local_var_configuration.base_path,
148 secretId = secret_id
149 );
150 let mut local_var_req_builder =
151 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
152
153 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
154
155 bitwarden_api_base::process_with_json_response(local_var_req_builder).await
156 }
157
158 async fn restore_version<'a>(
159 &self,
160 secret_id: uuid::Uuid,
161 restore_secret_version_request_model: Option<models::RestoreSecretVersionRequestModel>,
162 ) -> Result<models::SecretResponseModel, Error> {
163 let local_var_configuration = &self.configuration;
164
165 let local_var_client = &local_var_configuration.client;
166
167 let local_var_uri_str = format!(
168 "{}/secrets/{secretId}/versions/restore",
169 local_var_configuration.base_path,
170 secretId = secret_id
171 );
172 let mut local_var_req_builder =
173 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
174
175 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
176 local_var_req_builder = local_var_req_builder.json(&restore_secret_version_request_model);
177
178 bitwarden_api_base::process_with_json_response(local_var_req_builder).await
179 }
180}