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