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