Skip to main content

bitwarden_api_api/apis/
service_accounts_api.rs

1/*
2 * Bitwarden Internal API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: latest
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use 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    /// POST /service-accounts/delete
30    async fn bulk_delete<'a>(
31        &self,
32        uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
33    ) -> Result<models::BulkDeleteResponseModelListResponseModel, Error<BulkDeleteError>>;
34
35    /// POST /organizations/{organizationId}/service-accounts
36    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    /// POST /service-accounts/{id}/access-tokens
43    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    /// GET /service-accounts/{id}/access-tokens
50    async fn get_access_tokens<'a>(
51        &self,
52        id: uuid::Uuid,
53    ) -> Result<models::AccessTokenResponseModelListResponseModel, Error<GetAccessTokensError>>;
54
55    /// GET /service-accounts/{id}
56    async fn get_by_service_account_id<'a>(
57        &self,
58        id: uuid::Uuid,
59    ) -> Result<models::ServiceAccountResponseModel, Error<GetByServiceAccountIdError>>;
60
61    /// GET /organizations/{organizationId}/service-accounts
62    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    /// POST /service-accounts/{id}/access-tokens/revoke
72    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    /// PUT /service-accounts/{id}
79    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        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
115        local_var_req_builder = local_var_req_builder.json(&uuid_colon_colon_uuid);
116
117        let local_var_resp = local_var_req_builder.send().await?;
118
119        let local_var_status = local_var_resp.status();
120        let local_var_content_type = local_var_resp
121            .headers()
122            .get("content-type")
123            .and_then(|v| v.to_str().ok())
124            .unwrap_or("application/octet-stream");
125        let local_var_content_type = super::ContentType::from(local_var_content_type);
126        let local_var_content = local_var_resp.text().await?;
127
128        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
129            match local_var_content_type {
130                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
131                ContentType::Text => {
132                    return Err(Error::from(serde_json::Error::custom(
133                        "Received `text/plain` content type response that cannot be converted to `models::BulkDeleteResponseModelListResponseModel`",
134                    )));
135                }
136                ContentType::Unsupported(local_var_unknown_type) => {
137                    return Err(Error::from(serde_json::Error::custom(format!(
138                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::BulkDeleteResponseModelListResponseModel`"
139                    ))));
140                }
141            }
142        } else {
143            let local_var_entity: Option<BulkDeleteError> =
144                serde_json::from_str(&local_var_content).ok();
145            let local_var_error = ResponseContent {
146                status: local_var_status,
147                content: local_var_content,
148                entity: local_var_entity,
149            };
150            Err(Error::ResponseError(local_var_error))
151        }
152    }
153
154    async fn create<'a>(
155        &self,
156        organization_id: uuid::Uuid,
157        service_account_create_request_model: Option<models::ServiceAccountCreateRequestModel>,
158    ) -> Result<models::ServiceAccountResponseModel, Error<CreateError>> {
159        let local_var_configuration = &self.configuration;
160
161        let local_var_client = &local_var_configuration.client;
162
163        let local_var_uri_str = format!(
164            "{}/organizations/{organizationId}/service-accounts",
165            local_var_configuration.base_path,
166            organizationId = organization_id
167        );
168        let mut local_var_req_builder =
169            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
170
171        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
172        local_var_req_builder = local_var_req_builder.json(&service_account_create_request_model);
173
174        let local_var_resp = local_var_req_builder.send().await?;
175
176        let local_var_status = local_var_resp.status();
177        let local_var_content_type = local_var_resp
178            .headers()
179            .get("content-type")
180            .and_then(|v| v.to_str().ok())
181            .unwrap_or("application/octet-stream");
182        let local_var_content_type = super::ContentType::from(local_var_content_type);
183        let local_var_content = local_var_resp.text().await?;
184
185        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
186            match local_var_content_type {
187                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
188                ContentType::Text => {
189                    return Err(Error::from(serde_json::Error::custom(
190                        "Received `text/plain` content type response that cannot be converted to `models::ServiceAccountResponseModel`",
191                    )));
192                }
193                ContentType::Unsupported(local_var_unknown_type) => {
194                    return Err(Error::from(serde_json::Error::custom(format!(
195                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ServiceAccountResponseModel`"
196                    ))));
197                }
198            }
199        } else {
200            let local_var_entity: Option<CreateError> =
201                serde_json::from_str(&local_var_content).ok();
202            let local_var_error = ResponseContent {
203                status: local_var_status,
204                content: local_var_content,
205                entity: local_var_entity,
206            };
207            Err(Error::ResponseError(local_var_error))
208        }
209    }
210
211    async fn create_access_token<'a>(
212        &self,
213        id: uuid::Uuid,
214        access_token_create_request_model: Option<models::AccessTokenCreateRequestModel>,
215    ) -> Result<models::AccessTokenCreationResponseModel, Error<CreateAccessTokenError>> {
216        let local_var_configuration = &self.configuration;
217
218        let local_var_client = &local_var_configuration.client;
219
220        let local_var_uri_str = format!(
221            "{}/service-accounts/{id}/access-tokens",
222            local_var_configuration.base_path,
223            id = id
224        );
225        let mut local_var_req_builder =
226            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
227
228        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
229        local_var_req_builder = local_var_req_builder.json(&access_token_create_request_model);
230
231        let local_var_resp = local_var_req_builder.send().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::AccessTokenCreationResponseModel`",
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::AccessTokenCreationResponseModel`"
253                    ))));
254                }
255            }
256        } else {
257            let local_var_entity: Option<CreateAccessTokenError> =
258                serde_json::from_str(&local_var_content).ok();
259            let local_var_error = ResponseContent {
260                status: local_var_status,
261                content: local_var_content,
262                entity: local_var_entity,
263            };
264            Err(Error::ResponseError(local_var_error))
265        }
266    }
267
268    async fn get_access_tokens<'a>(
269        &self,
270        id: uuid::Uuid,
271    ) -> Result<models::AccessTokenResponseModelListResponseModel, Error<GetAccessTokensError>>
272    {
273        let local_var_configuration = &self.configuration;
274
275        let local_var_client = &local_var_configuration.client;
276
277        let local_var_uri_str = format!(
278            "{}/service-accounts/{id}/access-tokens",
279            local_var_configuration.base_path,
280            id = id
281        );
282        let mut local_var_req_builder =
283            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
284
285        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
286
287        let local_var_resp = local_var_req_builder.send().await?;
288
289        let local_var_status = local_var_resp.status();
290        let local_var_content_type = local_var_resp
291            .headers()
292            .get("content-type")
293            .and_then(|v| v.to_str().ok())
294            .unwrap_or("application/octet-stream");
295        let local_var_content_type = super::ContentType::from(local_var_content_type);
296        let local_var_content = local_var_resp.text().await?;
297
298        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
299            match local_var_content_type {
300                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
301                ContentType::Text => {
302                    return Err(Error::from(serde_json::Error::custom(
303                        "Received `text/plain` content type response that cannot be converted to `models::AccessTokenResponseModelListResponseModel`",
304                    )));
305                }
306                ContentType::Unsupported(local_var_unknown_type) => {
307                    return Err(Error::from(serde_json::Error::custom(format!(
308                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::AccessTokenResponseModelListResponseModel`"
309                    ))));
310                }
311            }
312        } else {
313            let local_var_entity: Option<GetAccessTokensError> =
314                serde_json::from_str(&local_var_content).ok();
315            let local_var_error = ResponseContent {
316                status: local_var_status,
317                content: local_var_content,
318                entity: local_var_entity,
319            };
320            Err(Error::ResponseError(local_var_error))
321        }
322    }
323
324    async fn get_by_service_account_id<'a>(
325        &self,
326        id: uuid::Uuid,
327    ) -> Result<models::ServiceAccountResponseModel, Error<GetByServiceAccountIdError>> {
328        let local_var_configuration = &self.configuration;
329
330        let local_var_client = &local_var_configuration.client;
331
332        let local_var_uri_str = format!(
333            "{}/service-accounts/{id}",
334            local_var_configuration.base_path,
335            id = id
336        );
337        let mut local_var_req_builder =
338            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
339
340        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
341
342        let local_var_resp = local_var_req_builder.send().await?;
343
344        let local_var_status = local_var_resp.status();
345        let local_var_content_type = local_var_resp
346            .headers()
347            .get("content-type")
348            .and_then(|v| v.to_str().ok())
349            .unwrap_or("application/octet-stream");
350        let local_var_content_type = super::ContentType::from(local_var_content_type);
351        let local_var_content = local_var_resp.text().await?;
352
353        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
354            match local_var_content_type {
355                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
356                ContentType::Text => {
357                    return Err(Error::from(serde_json::Error::custom(
358                        "Received `text/plain` content type response that cannot be converted to `models::ServiceAccountResponseModel`",
359                    )));
360                }
361                ContentType::Unsupported(local_var_unknown_type) => {
362                    return Err(Error::from(serde_json::Error::custom(format!(
363                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ServiceAccountResponseModel`"
364                    ))));
365                }
366            }
367        } else {
368            let local_var_entity: Option<GetByServiceAccountIdError> =
369                serde_json::from_str(&local_var_content).ok();
370            let local_var_error = ResponseContent {
371                status: local_var_status,
372                content: local_var_content,
373                entity: local_var_entity,
374            };
375            Err(Error::ResponseError(local_var_error))
376        }
377    }
378
379    async fn list_by_organization<'a>(
380        &self,
381        organization_id: uuid::Uuid,
382        include_access_to_secrets: Option<bool>,
383    ) -> Result<
384        models::ServiceAccountSecretsDetailsResponseModelListResponseModel,
385        Error<ListByOrganizationError>,
386    > {
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}/service-accounts",
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) = include_access_to_secrets {
400            local_var_req_builder = local_var_req_builder
401                .query(&[("includeAccessToSecrets", &param_value.to_string())]);
402        }
403        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
404
405        let local_var_resp = local_var_req_builder.send().await?;
406
407        let local_var_status = local_var_resp.status();
408        let local_var_content_type = local_var_resp
409            .headers()
410            .get("content-type")
411            .and_then(|v| v.to_str().ok())
412            .unwrap_or("application/octet-stream");
413        let local_var_content_type = super::ContentType::from(local_var_content_type);
414        let local_var_content = local_var_resp.text().await?;
415
416        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
417            match local_var_content_type {
418                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
419                ContentType::Text => {
420                    return Err(Error::from(serde_json::Error::custom(
421                        "Received `text/plain` content type response that cannot be converted to `models::ServiceAccountSecretsDetailsResponseModelListResponseModel`",
422                    )));
423                }
424                ContentType::Unsupported(local_var_unknown_type) => {
425                    return Err(Error::from(serde_json::Error::custom(format!(
426                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ServiceAccountSecretsDetailsResponseModelListResponseModel`"
427                    ))));
428                }
429            }
430        } else {
431            let local_var_entity: Option<ListByOrganizationError> =
432                serde_json::from_str(&local_var_content).ok();
433            let local_var_error = ResponseContent {
434                status: local_var_status,
435                content: local_var_content,
436                entity: local_var_entity,
437            };
438            Err(Error::ResponseError(local_var_error))
439        }
440    }
441
442    async fn revoke_access_tokens<'a>(
443        &self,
444        id: uuid::Uuid,
445        revoke_access_tokens_request: Option<models::RevokeAccessTokensRequest>,
446    ) -> Result<(), Error<RevokeAccessTokensError>> {
447        let local_var_configuration = &self.configuration;
448
449        let local_var_client = &local_var_configuration.client;
450
451        let local_var_uri_str = format!(
452            "{}/service-accounts/{id}/access-tokens/revoke",
453            local_var_configuration.base_path,
454            id = id
455        );
456        let mut local_var_req_builder =
457            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
458
459        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
460        local_var_req_builder = local_var_req_builder.json(&revoke_access_tokens_request);
461
462        let local_var_resp = local_var_req_builder.send().await?;
463
464        let local_var_status = local_var_resp.status();
465        let local_var_content = local_var_resp.text().await?;
466
467        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
468            Ok(())
469        } else {
470            let local_var_entity: Option<RevokeAccessTokensError> =
471                serde_json::from_str(&local_var_content).ok();
472            let local_var_error = ResponseContent {
473                status: local_var_status,
474                content: local_var_content,
475                entity: local_var_entity,
476            };
477            Err(Error::ResponseError(local_var_error))
478        }
479    }
480
481    async fn update<'a>(
482        &self,
483        id: uuid::Uuid,
484        service_account_update_request_model: Option<models::ServiceAccountUpdateRequestModel>,
485    ) -> Result<models::ServiceAccountResponseModel, Error<UpdateError>> {
486        let local_var_configuration = &self.configuration;
487
488        let local_var_client = &local_var_configuration.client;
489
490        let local_var_uri_str = format!(
491            "{}/service-accounts/{id}",
492            local_var_configuration.base_path,
493            id = id
494        );
495        let mut local_var_req_builder =
496            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
497
498        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
499        local_var_req_builder = local_var_req_builder.json(&service_account_update_request_model);
500
501        let local_var_resp = local_var_req_builder.send().await?;
502
503        let local_var_status = local_var_resp.status();
504        let local_var_content_type = local_var_resp
505            .headers()
506            .get("content-type")
507            .and_then(|v| v.to_str().ok())
508            .unwrap_or("application/octet-stream");
509        let local_var_content_type = super::ContentType::from(local_var_content_type);
510        let local_var_content = local_var_resp.text().await?;
511
512        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
513            match local_var_content_type {
514                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
515                ContentType::Text => {
516                    return Err(Error::from(serde_json::Error::custom(
517                        "Received `text/plain` content type response that cannot be converted to `models::ServiceAccountResponseModel`",
518                    )));
519                }
520                ContentType::Unsupported(local_var_unknown_type) => {
521                    return Err(Error::from(serde_json::Error::custom(format!(
522                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ServiceAccountResponseModel`"
523                    ))));
524                }
525            }
526        } else {
527            let local_var_entity: Option<UpdateError> =
528                serde_json::from_str(&local_var_content).ok();
529            let local_var_error = ResponseContent {
530                status: local_var_status,
531                content: local_var_content,
532                entity: local_var_entity,
533            };
534            Err(Error::ResponseError(local_var_error))
535        }
536    }
537}
538
539/// struct for typed errors of method [`ServiceAccountsApi::bulk_delete`]
540#[derive(Debug, Clone, Serialize, Deserialize)]
541#[serde(untagged)]
542pub enum BulkDeleteError {
543    UnknownValue(serde_json::Value),
544}
545/// struct for typed errors of method [`ServiceAccountsApi::create`]
546#[derive(Debug, Clone, Serialize, Deserialize)]
547#[serde(untagged)]
548pub enum CreateError {
549    UnknownValue(serde_json::Value),
550}
551/// struct for typed errors of method [`ServiceAccountsApi::create_access_token`]
552#[derive(Debug, Clone, Serialize, Deserialize)]
553#[serde(untagged)]
554pub enum CreateAccessTokenError {
555    UnknownValue(serde_json::Value),
556}
557/// struct for typed errors of method [`ServiceAccountsApi::get_access_tokens`]
558#[derive(Debug, Clone, Serialize, Deserialize)]
559#[serde(untagged)]
560pub enum GetAccessTokensError {
561    UnknownValue(serde_json::Value),
562}
563/// struct for typed errors of method [`ServiceAccountsApi::get_by_service_account_id`]
564#[derive(Debug, Clone, Serialize, Deserialize)]
565#[serde(untagged)]
566pub enum GetByServiceAccountIdError {
567    UnknownValue(serde_json::Value),
568}
569/// struct for typed errors of method [`ServiceAccountsApi::list_by_organization`]
570#[derive(Debug, Clone, Serialize, Deserialize)]
571#[serde(untagged)]
572pub enum ListByOrganizationError {
573    UnknownValue(serde_json::Value),
574}
575/// struct for typed errors of method [`ServiceAccountsApi::revoke_access_tokens`]
576#[derive(Debug, Clone, Serialize, Deserialize)]
577#[serde(untagged)]
578pub enum RevokeAccessTokensError {
579    UnknownValue(serde_json::Value),
580}
581/// struct for typed errors of method [`ServiceAccountsApi::update`]
582#[derive(Debug, Clone, Serialize, Deserialize)]
583#[serde(untagged)]
584pub enum UpdateError {
585    UnknownValue(serde_json::Value),
586}