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