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 SecretsApi: Send + Sync {
29 async fn bulk_delete<'a>(
31 &self,
32 uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
33 ) -> Result<models::BulkDeleteResponseModelListResponseModel, Error<BulkDeleteError>>;
34
35 async fn create<'a>(
37 &self,
38 organization_id: uuid::Uuid,
39 secret_create_request_model: Option<models::SecretCreateRequestModel>,
40 ) -> Result<models::SecretResponseModel, Error<CreateError>>;
41
42 async fn get<'a>(&self, id: uuid::Uuid)
44 -> Result<models::SecretResponseModel, Error<GetError>>;
45
46 async fn get_secrets_by_ids<'a>(
48 &self,
49 get_secrets_request_model: Option<models::GetSecretsRequestModel>,
50 ) -> Result<models::BaseSecretResponseModelListResponseModel, Error<GetSecretsByIdsError>>;
51
52 async fn get_secrets_by_project<'a>(
54 &self,
55 project_id: uuid::Uuid,
56 ) -> Result<models::SecretWithProjectsListResponseModel, Error<GetSecretsByProjectError>>;
57
58 async fn get_secrets_sync<'a>(
60 &self,
61 organization_id: uuid::Uuid,
62 last_synced_date: Option<String>,
63 ) -> Result<models::SecretsSyncResponseModel, Error<GetSecretsSyncError>>;
64
65 async fn list_by_organization<'a>(
67 &self,
68 organization_id: uuid::Uuid,
69 ) -> Result<models::SecretWithProjectsListResponseModel, Error<ListByOrganizationError>>;
70
71 async fn update_secret<'a>(
73 &self,
74 id: uuid::Uuid,
75 secret_update_request_model: Option<models::SecretUpdateRequestModel>,
76 ) -> Result<models::SecretResponseModel, Error<UpdateSecretError>>;
77}
78
79pub struct SecretsApiClient {
80 configuration: Arc<configuration::Configuration>,
81}
82
83impl SecretsApiClient {
84 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
85 Self { configuration }
86 }
87}
88
89#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
90#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
91impl SecretsApi for SecretsApiClient {
92 async fn bulk_delete<'a>(
93 &self,
94 uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
95 ) -> Result<models::BulkDeleteResponseModelListResponseModel, Error<BulkDeleteError>> {
96 let local_var_configuration = &self.configuration;
97
98 let local_var_client = &local_var_configuration.client;
99
100 let local_var_uri_str = format!("{}/secrets/delete", local_var_configuration.base_path);
101 let mut local_var_req_builder =
102 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
103
104 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
105 local_var_req_builder = local_var_req_builder.json(&uuid_colon_colon_uuid);
106
107 let local_var_resp = local_var_req_builder.send().await?;
108
109 let local_var_status = local_var_resp.status();
110 let local_var_content_type = local_var_resp
111 .headers()
112 .get("content-type")
113 .and_then(|v| v.to_str().ok())
114 .unwrap_or("application/octet-stream");
115 let local_var_content_type = super::ContentType::from(local_var_content_type);
116 let local_var_content = local_var_resp.text().await?;
117
118 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
119 match local_var_content_type {
120 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
121 ContentType::Text => {
122 return Err(Error::from(serde_json::Error::custom(
123 "Received `text/plain` content type response that cannot be converted to `models::BulkDeleteResponseModelListResponseModel`",
124 )));
125 }
126 ContentType::Unsupported(local_var_unknown_type) => {
127 return Err(Error::from(serde_json::Error::custom(format!(
128 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::BulkDeleteResponseModelListResponseModel`"
129 ))));
130 }
131 }
132 } else {
133 let local_var_entity: Option<BulkDeleteError> =
134 serde_json::from_str(&local_var_content).ok();
135 let local_var_error = ResponseContent {
136 status: local_var_status,
137 content: local_var_content,
138 entity: local_var_entity,
139 };
140 Err(Error::ResponseError(local_var_error))
141 }
142 }
143
144 async fn create<'a>(
145 &self,
146 organization_id: uuid::Uuid,
147 secret_create_request_model: Option<models::SecretCreateRequestModel>,
148 ) -> Result<models::SecretResponseModel, Error<CreateError>> {
149 let local_var_configuration = &self.configuration;
150
151 let local_var_client = &local_var_configuration.client;
152
153 let local_var_uri_str = format!(
154 "{}/organizations/{organizationId}/secrets",
155 local_var_configuration.base_path,
156 organizationId = organization_id
157 );
158 let mut local_var_req_builder =
159 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
160
161 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
162 local_var_req_builder = local_var_req_builder.json(&secret_create_request_model);
163
164 let local_var_resp = local_var_req_builder.send().await?;
165
166 let local_var_status = local_var_resp.status();
167 let local_var_content_type = local_var_resp
168 .headers()
169 .get("content-type")
170 .and_then(|v| v.to_str().ok())
171 .unwrap_or("application/octet-stream");
172 let local_var_content_type = super::ContentType::from(local_var_content_type);
173 let local_var_content = local_var_resp.text().await?;
174
175 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
176 match local_var_content_type {
177 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
178 ContentType::Text => {
179 return Err(Error::from(serde_json::Error::custom(
180 "Received `text/plain` content type response that cannot be converted to `models::SecretResponseModel`",
181 )));
182 }
183 ContentType::Unsupported(local_var_unknown_type) => {
184 return Err(Error::from(serde_json::Error::custom(format!(
185 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::SecretResponseModel`"
186 ))));
187 }
188 }
189 } else {
190 let local_var_entity: Option<CreateError> =
191 serde_json::from_str(&local_var_content).ok();
192 let local_var_error = ResponseContent {
193 status: local_var_status,
194 content: local_var_content,
195 entity: local_var_entity,
196 };
197 Err(Error::ResponseError(local_var_error))
198 }
199 }
200
201 async fn get<'a>(
202 &self,
203 id: uuid::Uuid,
204 ) -> Result<models::SecretResponseModel, Error<GetError>> {
205 let local_var_configuration = &self.configuration;
206
207 let local_var_client = &local_var_configuration.client;
208
209 let local_var_uri_str = format!(
210 "{}/secrets/{id}",
211 local_var_configuration.base_path,
212 id = id
213 );
214 let mut local_var_req_builder =
215 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
216
217 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
218
219 let local_var_resp = local_var_req_builder.send().await?;
220
221 let local_var_status = local_var_resp.status();
222 let local_var_content_type = local_var_resp
223 .headers()
224 .get("content-type")
225 .and_then(|v| v.to_str().ok())
226 .unwrap_or("application/octet-stream");
227 let local_var_content_type = super::ContentType::from(local_var_content_type);
228 let local_var_content = local_var_resp.text().await?;
229
230 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
231 match local_var_content_type {
232 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
233 ContentType::Text => {
234 return Err(Error::from(serde_json::Error::custom(
235 "Received `text/plain` content type response that cannot be converted to `models::SecretResponseModel`",
236 )));
237 }
238 ContentType::Unsupported(local_var_unknown_type) => {
239 return Err(Error::from(serde_json::Error::custom(format!(
240 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::SecretResponseModel`"
241 ))));
242 }
243 }
244 } else {
245 let local_var_entity: Option<GetError> = serde_json::from_str(&local_var_content).ok();
246 let local_var_error = ResponseContent {
247 status: local_var_status,
248 content: local_var_content,
249 entity: local_var_entity,
250 };
251 Err(Error::ResponseError(local_var_error))
252 }
253 }
254
255 async fn get_secrets_by_ids<'a>(
256 &self,
257 get_secrets_request_model: Option<models::GetSecretsRequestModel>,
258 ) -> Result<models::BaseSecretResponseModelListResponseModel, Error<GetSecretsByIdsError>> {
259 let local_var_configuration = &self.configuration;
260
261 let local_var_client = &local_var_configuration.client;
262
263 let local_var_uri_str = format!("{}/secrets/get-by-ids", local_var_configuration.base_path);
264 let mut local_var_req_builder =
265 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
266
267 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
268 local_var_req_builder = local_var_req_builder.json(&get_secrets_request_model);
269
270 let local_var_resp = local_var_req_builder.send().await?;
271
272 let local_var_status = local_var_resp.status();
273 let local_var_content_type = local_var_resp
274 .headers()
275 .get("content-type")
276 .and_then(|v| v.to_str().ok())
277 .unwrap_or("application/octet-stream");
278 let local_var_content_type = super::ContentType::from(local_var_content_type);
279 let local_var_content = local_var_resp.text().await?;
280
281 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
282 match local_var_content_type {
283 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
284 ContentType::Text => {
285 return Err(Error::from(serde_json::Error::custom(
286 "Received `text/plain` content type response that cannot be converted to `models::BaseSecretResponseModelListResponseModel`",
287 )));
288 }
289 ContentType::Unsupported(local_var_unknown_type) => {
290 return Err(Error::from(serde_json::Error::custom(format!(
291 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::BaseSecretResponseModelListResponseModel`"
292 ))));
293 }
294 }
295 } else {
296 let local_var_entity: Option<GetSecretsByIdsError> =
297 serde_json::from_str(&local_var_content).ok();
298 let local_var_error = ResponseContent {
299 status: local_var_status,
300 content: local_var_content,
301 entity: local_var_entity,
302 };
303 Err(Error::ResponseError(local_var_error))
304 }
305 }
306
307 async fn get_secrets_by_project<'a>(
308 &self,
309 project_id: uuid::Uuid,
310 ) -> Result<models::SecretWithProjectsListResponseModel, Error<GetSecretsByProjectError>> {
311 let local_var_configuration = &self.configuration;
312
313 let local_var_client = &local_var_configuration.client;
314
315 let local_var_uri_str = format!(
316 "{}/projects/{projectId}/secrets",
317 local_var_configuration.base_path,
318 projectId = project_id
319 );
320 let mut local_var_req_builder =
321 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
322
323 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
324
325 let local_var_resp = local_var_req_builder.send().await?;
326
327 let local_var_status = local_var_resp.status();
328 let local_var_content_type = local_var_resp
329 .headers()
330 .get("content-type")
331 .and_then(|v| v.to_str().ok())
332 .unwrap_or("application/octet-stream");
333 let local_var_content_type = super::ContentType::from(local_var_content_type);
334 let local_var_content = local_var_resp.text().await?;
335
336 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
337 match local_var_content_type {
338 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
339 ContentType::Text => {
340 return Err(Error::from(serde_json::Error::custom(
341 "Received `text/plain` content type response that cannot be converted to `models::SecretWithProjectsListResponseModel`",
342 )));
343 }
344 ContentType::Unsupported(local_var_unknown_type) => {
345 return Err(Error::from(serde_json::Error::custom(format!(
346 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::SecretWithProjectsListResponseModel`"
347 ))));
348 }
349 }
350 } else {
351 let local_var_entity: Option<GetSecretsByProjectError> =
352 serde_json::from_str(&local_var_content).ok();
353 let local_var_error = ResponseContent {
354 status: local_var_status,
355 content: local_var_content,
356 entity: local_var_entity,
357 };
358 Err(Error::ResponseError(local_var_error))
359 }
360 }
361
362 async fn get_secrets_sync<'a>(
363 &self,
364 organization_id: uuid::Uuid,
365 last_synced_date: Option<String>,
366 ) -> Result<models::SecretsSyncResponseModel, Error<GetSecretsSyncError>> {
367 let local_var_configuration = &self.configuration;
368
369 let local_var_client = &local_var_configuration.client;
370
371 let local_var_uri_str = format!(
372 "{}/organizations/{organizationId}/secrets/sync",
373 local_var_configuration.base_path,
374 organizationId = organization_id
375 );
376 let mut local_var_req_builder =
377 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
378
379 if let Some(ref param_value) = last_synced_date {
380 local_var_req_builder =
381 local_var_req_builder.query(&[("lastSyncedDate", ¶m_value.to_string())]);
382 }
383 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
384
385 let local_var_resp = local_var_req_builder.send().await?;
386
387 let local_var_status = local_var_resp.status();
388 let local_var_content_type = local_var_resp
389 .headers()
390 .get("content-type")
391 .and_then(|v| v.to_str().ok())
392 .unwrap_or("application/octet-stream");
393 let local_var_content_type = super::ContentType::from(local_var_content_type);
394 let local_var_content = local_var_resp.text().await?;
395
396 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
397 match local_var_content_type {
398 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
399 ContentType::Text => {
400 return Err(Error::from(serde_json::Error::custom(
401 "Received `text/plain` content type response that cannot be converted to `models::SecretsSyncResponseModel`",
402 )));
403 }
404 ContentType::Unsupported(local_var_unknown_type) => {
405 return Err(Error::from(serde_json::Error::custom(format!(
406 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::SecretsSyncResponseModel`"
407 ))));
408 }
409 }
410 } else {
411 let local_var_entity: Option<GetSecretsSyncError> =
412 serde_json::from_str(&local_var_content).ok();
413 let local_var_error = ResponseContent {
414 status: local_var_status,
415 content: local_var_content,
416 entity: local_var_entity,
417 };
418 Err(Error::ResponseError(local_var_error))
419 }
420 }
421
422 async fn list_by_organization<'a>(
423 &self,
424 organization_id: uuid::Uuid,
425 ) -> Result<models::SecretWithProjectsListResponseModel, Error<ListByOrganizationError>> {
426 let local_var_configuration = &self.configuration;
427
428 let local_var_client = &local_var_configuration.client;
429
430 let local_var_uri_str = format!(
431 "{}/organizations/{organizationId}/secrets",
432 local_var_configuration.base_path,
433 organizationId = organization_id
434 );
435 let mut local_var_req_builder =
436 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
437
438 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
439
440 let local_var_resp = local_var_req_builder.send().await?;
441
442 let local_var_status = local_var_resp.status();
443 let local_var_content_type = local_var_resp
444 .headers()
445 .get("content-type")
446 .and_then(|v| v.to_str().ok())
447 .unwrap_or("application/octet-stream");
448 let local_var_content_type = super::ContentType::from(local_var_content_type);
449 let local_var_content = local_var_resp.text().await?;
450
451 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
452 match local_var_content_type {
453 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
454 ContentType::Text => {
455 return Err(Error::from(serde_json::Error::custom(
456 "Received `text/plain` content type response that cannot be converted to `models::SecretWithProjectsListResponseModel`",
457 )));
458 }
459 ContentType::Unsupported(local_var_unknown_type) => {
460 return Err(Error::from(serde_json::Error::custom(format!(
461 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::SecretWithProjectsListResponseModel`"
462 ))));
463 }
464 }
465 } else {
466 let local_var_entity: Option<ListByOrganizationError> =
467 serde_json::from_str(&local_var_content).ok();
468 let local_var_error = ResponseContent {
469 status: local_var_status,
470 content: local_var_content,
471 entity: local_var_entity,
472 };
473 Err(Error::ResponseError(local_var_error))
474 }
475 }
476
477 async fn update_secret<'a>(
478 &self,
479 id: uuid::Uuid,
480 secret_update_request_model: Option<models::SecretUpdateRequestModel>,
481 ) -> Result<models::SecretResponseModel, Error<UpdateSecretError>> {
482 let local_var_configuration = &self.configuration;
483
484 let local_var_client = &local_var_configuration.client;
485
486 let local_var_uri_str = format!(
487 "{}/secrets/{id}",
488 local_var_configuration.base_path,
489 id = id
490 );
491 let mut local_var_req_builder =
492 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
493
494 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
495 local_var_req_builder = local_var_req_builder.json(&secret_update_request_model);
496
497 let local_var_resp = local_var_req_builder.send().await?;
498
499 let local_var_status = local_var_resp.status();
500 let local_var_content_type = local_var_resp
501 .headers()
502 .get("content-type")
503 .and_then(|v| v.to_str().ok())
504 .unwrap_or("application/octet-stream");
505 let local_var_content_type = super::ContentType::from(local_var_content_type);
506 let local_var_content = local_var_resp.text().await?;
507
508 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
509 match local_var_content_type {
510 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
511 ContentType::Text => {
512 return Err(Error::from(serde_json::Error::custom(
513 "Received `text/plain` content type response that cannot be converted to `models::SecretResponseModel`",
514 )));
515 }
516 ContentType::Unsupported(local_var_unknown_type) => {
517 return Err(Error::from(serde_json::Error::custom(format!(
518 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::SecretResponseModel`"
519 ))));
520 }
521 }
522 } else {
523 let local_var_entity: Option<UpdateSecretError> =
524 serde_json::from_str(&local_var_content).ok();
525 let local_var_error = ResponseContent {
526 status: local_var_status,
527 content: local_var_content,
528 entity: local_var_entity,
529 };
530 Err(Error::ResponseError(local_var_error))
531 }
532 }
533}
534
535#[derive(Debug, Clone, Serialize, Deserialize)]
537#[serde(untagged)]
538pub enum BulkDeleteError {
539 UnknownValue(serde_json::Value),
540}
541#[derive(Debug, Clone, Serialize, Deserialize)]
543#[serde(untagged)]
544pub enum CreateError {
545 UnknownValue(serde_json::Value),
546}
547#[derive(Debug, Clone, Serialize, Deserialize)]
549#[serde(untagged)]
550pub enum GetError {
551 UnknownValue(serde_json::Value),
552}
553#[derive(Debug, Clone, Serialize, Deserialize)]
555#[serde(untagged)]
556pub enum GetSecretsByIdsError {
557 UnknownValue(serde_json::Value),
558}
559#[derive(Debug, Clone, Serialize, Deserialize)]
561#[serde(untagged)]
562pub enum GetSecretsByProjectError {
563 UnknownValue(serde_json::Value),
564}
565#[derive(Debug, Clone, Serialize, Deserialize)]
567#[serde(untagged)]
568pub enum GetSecretsSyncError {
569 UnknownValue(serde_json::Value),
570}
571#[derive(Debug, Clone, Serialize, Deserialize)]
573#[serde(untagged)]
574pub enum ListByOrganizationError {
575 UnknownValue(serde_json::Value),
576}
577#[derive(Debug, Clone, Serialize, Deserialize)]
579#[serde(untagged)]
580pub enum UpdateSecretError {
581 UnknownValue(serde_json::Value),
582}