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 reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17/// struct for typed errors of method [`organizations_organization_id_service_accounts_get`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum OrganizationsOrganizationIdServiceAccountsGetError {
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`organizations_organization_id_service_accounts_post`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum OrganizationsOrganizationIdServiceAccountsPostError {
28    UnknownValue(serde_json::Value),
29}
30
31/// struct for typed errors of method [`service_accounts_delete_post`]
32#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum ServiceAccountsDeletePostError {
35    UnknownValue(serde_json::Value),
36}
37
38/// struct for typed errors of method [`service_accounts_id_access_tokens_get`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum ServiceAccountsIdAccessTokensGetError {
42    UnknownValue(serde_json::Value),
43}
44
45/// struct for typed errors of method [`service_accounts_id_access_tokens_post`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum ServiceAccountsIdAccessTokensPostError {
49    UnknownValue(serde_json::Value),
50}
51
52/// struct for typed errors of method [`service_accounts_id_access_tokens_revoke_post`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum ServiceAccountsIdAccessTokensRevokePostError {
56    UnknownValue(serde_json::Value),
57}
58
59/// struct for typed errors of method [`service_accounts_id_get`]
60#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum ServiceAccountsIdGetError {
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method [`service_accounts_id_put`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum ServiceAccountsIdPutError {
70    UnknownValue(serde_json::Value),
71}
72
73pub async fn organizations_organization_id_service_accounts_get(
74    configuration: &configuration::Configuration,
75    organization_id: uuid::Uuid,
76    include_access_to_secrets: Option<bool>,
77) -> Result<
78    models::ServiceAccountSecretsDetailsResponseModelListResponseModel,
79    Error<OrganizationsOrganizationIdServiceAccountsGetError>,
80> {
81    // add a prefix to parameters to efficiently prevent name collisions
82    let p_organization_id = organization_id;
83    let p_include_access_to_secrets = include_access_to_secrets;
84
85    let uri_str = format!(
86        "{}/organizations/{organizationId}/service-accounts",
87        configuration.base_path,
88        organizationId = crate::apis::urlencode(p_organization_id.to_string())
89    );
90    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
91
92    if let Some(ref param_value) = p_include_access_to_secrets {
93        req_builder = req_builder.query(&[("includeAccessToSecrets", &param_value.to_string())]);
94    }
95    if let Some(ref user_agent) = configuration.user_agent {
96        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
97    }
98    if let Some(ref token) = configuration.oauth_access_token {
99        req_builder = req_builder.bearer_auth(token.to_owned());
100    };
101
102    let req = req_builder.build()?;
103    let resp = configuration.client.execute(req).await?;
104
105    let status = resp.status();
106    let content_type = resp
107        .headers()
108        .get("content-type")
109        .and_then(|v| v.to_str().ok())
110        .unwrap_or("application/octet-stream");
111    let content_type = super::ContentType::from(content_type);
112
113    if !status.is_client_error() && !status.is_server_error() {
114        let content = resp.text().await?;
115        match content_type {
116            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
117            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ServiceAccountSecretsDetailsResponseModelListResponseModel`"))),
118            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ServiceAccountSecretsDetailsResponseModelListResponseModel`")))),
119        }
120    } else {
121        let content = resp.text().await?;
122        let entity: Option<OrganizationsOrganizationIdServiceAccountsGetError> =
123            serde_json::from_str(&content).ok();
124        Err(Error::ResponseError(ResponseContent {
125            status,
126            content,
127            entity,
128        }))
129    }
130}
131
132pub async fn organizations_organization_id_service_accounts_post(
133    configuration: &configuration::Configuration,
134    organization_id: uuid::Uuid,
135    service_account_create_request_model: Option<models::ServiceAccountCreateRequestModel>,
136) -> Result<
137    models::ServiceAccountResponseModel,
138    Error<OrganizationsOrganizationIdServiceAccountsPostError>,
139> {
140    // add a prefix to parameters to efficiently prevent name collisions
141    let p_organization_id = organization_id;
142    let p_service_account_create_request_model = service_account_create_request_model;
143
144    let uri_str = format!(
145        "{}/organizations/{organizationId}/service-accounts",
146        configuration.base_path,
147        organizationId = crate::apis::urlencode(p_organization_id.to_string())
148    );
149    let mut req_builder = configuration
150        .client
151        .request(reqwest::Method::POST, &uri_str);
152
153    if let Some(ref user_agent) = configuration.user_agent {
154        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
155    }
156    if let Some(ref token) = configuration.oauth_access_token {
157        req_builder = req_builder.bearer_auth(token.to_owned());
158    };
159    req_builder = req_builder.json(&p_service_account_create_request_model);
160
161    let req = req_builder.build()?;
162    let resp = configuration.client.execute(req).await?;
163
164    let status = resp.status();
165    let content_type = resp
166        .headers()
167        .get("content-type")
168        .and_then(|v| v.to_str().ok())
169        .unwrap_or("application/octet-stream");
170    let content_type = super::ContentType::from(content_type);
171
172    if !status.is_client_error() && !status.is_server_error() {
173        let content = resp.text().await?;
174        match content_type {
175            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
176            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ServiceAccountResponseModel`"))),
177            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ServiceAccountResponseModel`")))),
178        }
179    } else {
180        let content = resp.text().await?;
181        let entity: Option<OrganizationsOrganizationIdServiceAccountsPostError> =
182            serde_json::from_str(&content).ok();
183        Err(Error::ResponseError(ResponseContent {
184            status,
185            content,
186            entity,
187        }))
188    }
189}
190
191pub async fn service_accounts_delete_post(
192    configuration: &configuration::Configuration,
193    uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
194) -> Result<models::BulkDeleteResponseModelListResponseModel, Error<ServiceAccountsDeletePostError>>
195{
196    // add a prefix to parameters to efficiently prevent name collisions
197    let p_uuid_colon_colon_uuid = uuid_colon_colon_uuid;
198
199    let uri_str = format!("{}/service-accounts/delete", configuration.base_path);
200    let mut req_builder = configuration
201        .client
202        .request(reqwest::Method::POST, &uri_str);
203
204    if let Some(ref user_agent) = configuration.user_agent {
205        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
206    }
207    if let Some(ref token) = configuration.oauth_access_token {
208        req_builder = req_builder.bearer_auth(token.to_owned());
209    };
210    req_builder = req_builder.json(&p_uuid_colon_colon_uuid);
211
212    let req = req_builder.build()?;
213    let resp = configuration.client.execute(req).await?;
214
215    let status = resp.status();
216    let content_type = resp
217        .headers()
218        .get("content-type")
219        .and_then(|v| v.to_str().ok())
220        .unwrap_or("application/octet-stream");
221    let content_type = super::ContentType::from(content_type);
222
223    if !status.is_client_error() && !status.is_server_error() {
224        let content = resp.text().await?;
225        match content_type {
226            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
227            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BulkDeleteResponseModelListResponseModel`"))),
228            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::BulkDeleteResponseModelListResponseModel`")))),
229        }
230    } else {
231        let content = resp.text().await?;
232        let entity: Option<ServiceAccountsDeletePostError> = serde_json::from_str(&content).ok();
233        Err(Error::ResponseError(ResponseContent {
234            status,
235            content,
236            entity,
237        }))
238    }
239}
240
241pub async fn service_accounts_id_access_tokens_get(
242    configuration: &configuration::Configuration,
243    id: uuid::Uuid,
244) -> Result<
245    models::AccessTokenResponseModelListResponseModel,
246    Error<ServiceAccountsIdAccessTokensGetError>,
247> {
248    // add a prefix to parameters to efficiently prevent name collisions
249    let p_id = id;
250
251    let uri_str = format!(
252        "{}/service-accounts/{id}/access-tokens",
253        configuration.base_path,
254        id = crate::apis::urlencode(p_id.to_string())
255    );
256    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
257
258    if let Some(ref user_agent) = configuration.user_agent {
259        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
260    }
261    if let Some(ref token) = configuration.oauth_access_token {
262        req_builder = req_builder.bearer_auth(token.to_owned());
263    };
264
265    let req = req_builder.build()?;
266    let resp = configuration.client.execute(req).await?;
267
268    let status = resp.status();
269    let content_type = resp
270        .headers()
271        .get("content-type")
272        .and_then(|v| v.to_str().ok())
273        .unwrap_or("application/octet-stream");
274    let content_type = super::ContentType::from(content_type);
275
276    if !status.is_client_error() && !status.is_server_error() {
277        let content = resp.text().await?;
278        match content_type {
279            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
280            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessTokenResponseModelListResponseModel`"))),
281            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::AccessTokenResponseModelListResponseModel`")))),
282        }
283    } else {
284        let content = resp.text().await?;
285        let entity: Option<ServiceAccountsIdAccessTokensGetError> =
286            serde_json::from_str(&content).ok();
287        Err(Error::ResponseError(ResponseContent {
288            status,
289            content,
290            entity,
291        }))
292    }
293}
294
295pub async fn service_accounts_id_access_tokens_post(
296    configuration: &configuration::Configuration,
297    id: uuid::Uuid,
298    access_token_create_request_model: Option<models::AccessTokenCreateRequestModel>,
299) -> Result<models::AccessTokenCreationResponseModel, Error<ServiceAccountsIdAccessTokensPostError>>
300{
301    // add a prefix to parameters to efficiently prevent name collisions
302    let p_id = id;
303    let p_access_token_create_request_model = access_token_create_request_model;
304
305    let uri_str = format!(
306        "{}/service-accounts/{id}/access-tokens",
307        configuration.base_path,
308        id = crate::apis::urlencode(p_id.to_string())
309    );
310    let mut req_builder = configuration
311        .client
312        .request(reqwest::Method::POST, &uri_str);
313
314    if let Some(ref user_agent) = configuration.user_agent {
315        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
316    }
317    if let Some(ref token) = configuration.oauth_access_token {
318        req_builder = req_builder.bearer_auth(token.to_owned());
319    };
320    req_builder = req_builder.json(&p_access_token_create_request_model);
321
322    let req = req_builder.build()?;
323    let resp = configuration.client.execute(req).await?;
324
325    let status = resp.status();
326    let content_type = resp
327        .headers()
328        .get("content-type")
329        .and_then(|v| v.to_str().ok())
330        .unwrap_or("application/octet-stream");
331    let content_type = super::ContentType::from(content_type);
332
333    if !status.is_client_error() && !status.is_server_error() {
334        let content = resp.text().await?;
335        match content_type {
336            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
337            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessTokenCreationResponseModel`"))),
338            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::AccessTokenCreationResponseModel`")))),
339        }
340    } else {
341        let content = resp.text().await?;
342        let entity: Option<ServiceAccountsIdAccessTokensPostError> =
343            serde_json::from_str(&content).ok();
344        Err(Error::ResponseError(ResponseContent {
345            status,
346            content,
347            entity,
348        }))
349    }
350}
351
352pub async fn service_accounts_id_access_tokens_revoke_post(
353    configuration: &configuration::Configuration,
354    id: uuid::Uuid,
355    revoke_access_tokens_request: Option<models::RevokeAccessTokensRequest>,
356) -> Result<(), Error<ServiceAccountsIdAccessTokensRevokePostError>> {
357    // add a prefix to parameters to efficiently prevent name collisions
358    let p_id = id;
359    let p_revoke_access_tokens_request = revoke_access_tokens_request;
360
361    let uri_str = format!(
362        "{}/service-accounts/{id}/access-tokens/revoke",
363        configuration.base_path,
364        id = crate::apis::urlencode(p_id.to_string())
365    );
366    let mut req_builder = configuration
367        .client
368        .request(reqwest::Method::POST, &uri_str);
369
370    if let Some(ref user_agent) = configuration.user_agent {
371        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
372    }
373    if let Some(ref token) = configuration.oauth_access_token {
374        req_builder = req_builder.bearer_auth(token.to_owned());
375    };
376    req_builder = req_builder.json(&p_revoke_access_tokens_request);
377
378    let req = req_builder.build()?;
379    let resp = configuration.client.execute(req).await?;
380
381    let status = resp.status();
382
383    if !status.is_client_error() && !status.is_server_error() {
384        Ok(())
385    } else {
386        let content = resp.text().await?;
387        let entity: Option<ServiceAccountsIdAccessTokensRevokePostError> =
388            serde_json::from_str(&content).ok();
389        Err(Error::ResponseError(ResponseContent {
390            status,
391            content,
392            entity,
393        }))
394    }
395}
396
397pub async fn service_accounts_id_get(
398    configuration: &configuration::Configuration,
399    id: uuid::Uuid,
400) -> Result<models::ServiceAccountResponseModel, Error<ServiceAccountsIdGetError>> {
401    // add a prefix to parameters to efficiently prevent name collisions
402    let p_id = id;
403
404    let uri_str = format!(
405        "{}/service-accounts/{id}",
406        configuration.base_path,
407        id = crate::apis::urlencode(p_id.to_string())
408    );
409    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
410
411    if let Some(ref user_agent) = configuration.user_agent {
412        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
413    }
414    if let Some(ref token) = configuration.oauth_access_token {
415        req_builder = req_builder.bearer_auth(token.to_owned());
416    };
417
418    let req = req_builder.build()?;
419    let resp = configuration.client.execute(req).await?;
420
421    let status = resp.status();
422    let content_type = resp
423        .headers()
424        .get("content-type")
425        .and_then(|v| v.to_str().ok())
426        .unwrap_or("application/octet-stream");
427    let content_type = super::ContentType::from(content_type);
428
429    if !status.is_client_error() && !status.is_server_error() {
430        let content = resp.text().await?;
431        match content_type {
432            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
433            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ServiceAccountResponseModel`"))),
434            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ServiceAccountResponseModel`")))),
435        }
436    } else {
437        let content = resp.text().await?;
438        let entity: Option<ServiceAccountsIdGetError> = serde_json::from_str(&content).ok();
439        Err(Error::ResponseError(ResponseContent {
440            status,
441            content,
442            entity,
443        }))
444    }
445}
446
447pub async fn service_accounts_id_put(
448    configuration: &configuration::Configuration,
449    id: uuid::Uuid,
450    service_account_update_request_model: Option<models::ServiceAccountUpdateRequestModel>,
451) -> Result<models::ServiceAccountResponseModel, Error<ServiceAccountsIdPutError>> {
452    // add a prefix to parameters to efficiently prevent name collisions
453    let p_id = id;
454    let p_service_account_update_request_model = service_account_update_request_model;
455
456    let uri_str = format!(
457        "{}/service-accounts/{id}",
458        configuration.base_path,
459        id = crate::apis::urlencode(p_id.to_string())
460    );
461    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
462
463    if let Some(ref user_agent) = configuration.user_agent {
464        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
465    }
466    if let Some(ref token) = configuration.oauth_access_token {
467        req_builder = req_builder.bearer_auth(token.to_owned());
468    };
469    req_builder = req_builder.json(&p_service_account_update_request_model);
470
471    let req = req_builder.build()?;
472    let resp = configuration.client.execute(req).await?;
473
474    let status = resp.status();
475    let content_type = resp
476        .headers()
477        .get("content-type")
478        .and_then(|v| v.to_str().ok())
479        .unwrap_or("application/octet-stream");
480    let content_type = super::ContentType::from(content_type);
481
482    if !status.is_client_error() && !status.is_server_error() {
483        let content = resp.text().await?;
484        match content_type {
485            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
486            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ServiceAccountResponseModel`"))),
487            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ServiceAccountResponseModel`")))),
488        }
489    } else {
490        let content = resp.text().await?;
491        let entity: Option<ServiceAccountsIdPutError> = serde_json::from_str(&content).ok();
492        Err(Error::ResponseError(ResponseContent {
493            status,
494            content,
495            entity,
496        }))
497    }
498}