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