bitwarden_api_api/apis/
organization_domain_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 OrganizationDomainApi: Send + Sync {
29    /// GET /organizations/{orgId}/domain/{id}
30    async fn get<'a>(
31        &self,
32        org_id: uuid::Uuid,
33        id: uuid::Uuid,
34    ) -> Result<models::OrganizationDomainResponseModel, Error<GetError>>;
35
36    /// GET /organizations/{orgId}/domain
37    async fn get_all<'a>(
38        &self,
39        org_id: uuid::Uuid,
40    ) -> Result<models::OrganizationDomainResponseModelListResponseModel, Error<GetAllError>>;
41
42    /// POST /organizations/domain/sso/details
43    async fn get_org_domain_sso_details<'a>(
44        &self,
45        organization_domain_sso_details_request_model: Option<
46            models::OrganizationDomainSsoDetailsRequestModel,
47        >,
48    ) -> Result<models::OrganizationDomainSsoDetailsResponseModel, Error<GetOrgDomainSsoDetailsError>>;
49
50    /// POST /organizations/domain/sso/verified
51    async fn get_verified_org_domain_sso_details<'a>(
52        &self,
53        organization_domain_sso_details_request_model: Option<
54            models::OrganizationDomainSsoDetailsRequestModel,
55        >,
56    ) -> Result<
57        models::VerifiedOrganizationDomainSsoDetailsResponseModel,
58        Error<GetVerifiedOrgDomainSsoDetailsError>,
59    >;
60
61    /// POST /organizations/{orgId}/domain
62    async fn post<'a>(
63        &self,
64        org_id: uuid::Uuid,
65        organization_domain_request_model: Option<models::OrganizationDomainRequestModel>,
66    ) -> Result<models::OrganizationDomainResponseModel, Error<PostError>>;
67
68    /// DELETE /organizations/{orgId}/domain/{id}
69    async fn remove_domain<'a>(
70        &self,
71        org_id: uuid::Uuid,
72        id: uuid::Uuid,
73    ) -> Result<(), Error<RemoveDomainError>>;
74
75    /// POST /organizations/{orgId}/domain/{id}/verify
76    async fn verify<'a>(
77        &self,
78        org_id: uuid::Uuid,
79        id: uuid::Uuid,
80    ) -> Result<models::OrganizationDomainResponseModel, Error<VerifyError>>;
81}
82
83pub struct OrganizationDomainApiClient {
84    configuration: Arc<configuration::Configuration>,
85}
86
87impl OrganizationDomainApiClient {
88    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
89        Self { configuration }
90    }
91}
92
93#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
94#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
95impl OrganizationDomainApi for OrganizationDomainApiClient {
96    async fn get<'a>(
97        &self,
98        org_id: uuid::Uuid,
99        id: uuid::Uuid,
100    ) -> Result<models::OrganizationDomainResponseModel, Error<GetError>> {
101        let local_var_configuration = &self.configuration;
102
103        let local_var_client = &local_var_configuration.client;
104
105        let local_var_uri_str = format!(
106            "{}/organizations/{orgId}/domain/{id}",
107            local_var_configuration.base_path,
108            orgId = org_id,
109            id = id
110        );
111        let mut local_var_req_builder =
112            local_var_client.request(reqwest::Method::GET, 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
119        let local_var_req = local_var_req_builder.build()?;
120        let local_var_resp = local_var_client.execute(local_var_req).await?;
121
122        let local_var_status = local_var_resp.status();
123        let local_var_content_type = local_var_resp
124            .headers()
125            .get("content-type")
126            .and_then(|v| v.to_str().ok())
127            .unwrap_or("application/octet-stream");
128        let local_var_content_type = super::ContentType::from(local_var_content_type);
129        let local_var_content = local_var_resp.text().await?;
130
131        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
132            match local_var_content_type {
133                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
134                ContentType::Text => {
135                    return Err(Error::from(serde_json::Error::custom(
136                        "Received `text/plain` content type response that cannot be converted to `models::OrganizationDomainResponseModel`",
137                    )));
138                }
139                ContentType::Unsupported(local_var_unknown_type) => {
140                    return Err(Error::from(serde_json::Error::custom(format!(
141                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::OrganizationDomainResponseModel`"
142                    ))));
143                }
144            }
145        } else {
146            let local_var_entity: Option<GetError> = serde_json::from_str(&local_var_content).ok();
147            let local_var_error = ResponseContent {
148                status: local_var_status,
149                content: local_var_content,
150                entity: local_var_entity,
151            };
152            Err(Error::ResponseError(local_var_error))
153        }
154    }
155
156    async fn get_all<'a>(
157        &self,
158        org_id: uuid::Uuid,
159    ) -> Result<models::OrganizationDomainResponseModelListResponseModel, Error<GetAllError>> {
160        let local_var_configuration = &self.configuration;
161
162        let local_var_client = &local_var_configuration.client;
163
164        let local_var_uri_str = format!(
165            "{}/organizations/{orgId}/domain",
166            local_var_configuration.base_path,
167            orgId = org_id
168        );
169        let mut local_var_req_builder =
170            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
171
172        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
173            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
174        };
175        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
176
177        let local_var_req = local_var_req_builder.build()?;
178        let local_var_resp = local_var_client.execute(local_var_req).await?;
179
180        let local_var_status = local_var_resp.status();
181        let local_var_content_type = local_var_resp
182            .headers()
183            .get("content-type")
184            .and_then(|v| v.to_str().ok())
185            .unwrap_or("application/octet-stream");
186        let local_var_content_type = super::ContentType::from(local_var_content_type);
187        let local_var_content = local_var_resp.text().await?;
188
189        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
190            match local_var_content_type {
191                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
192                ContentType::Text => {
193                    return Err(Error::from(serde_json::Error::custom(
194                        "Received `text/plain` content type response that cannot be converted to `models::OrganizationDomainResponseModelListResponseModel`",
195                    )));
196                }
197                ContentType::Unsupported(local_var_unknown_type) => {
198                    return Err(Error::from(serde_json::Error::custom(format!(
199                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::OrganizationDomainResponseModelListResponseModel`"
200                    ))));
201                }
202            }
203        } else {
204            let local_var_entity: Option<GetAllError> =
205                serde_json::from_str(&local_var_content).ok();
206            let local_var_error = ResponseContent {
207                status: local_var_status,
208                content: local_var_content,
209                entity: local_var_entity,
210            };
211            Err(Error::ResponseError(local_var_error))
212        }
213    }
214
215    async fn get_org_domain_sso_details<'a>(
216        &self,
217        organization_domain_sso_details_request_model: Option<
218            models::OrganizationDomainSsoDetailsRequestModel,
219        >,
220    ) -> Result<models::OrganizationDomainSsoDetailsResponseModel, Error<GetOrgDomainSsoDetailsError>>
221    {
222        let local_var_configuration = &self.configuration;
223
224        let local_var_client = &local_var_configuration.client;
225
226        let local_var_uri_str = format!(
227            "{}/organizations/domain/sso/details",
228            local_var_configuration.base_path
229        );
230        let mut local_var_req_builder =
231            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
232
233        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
234            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
235        };
236        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
237        local_var_req_builder =
238            local_var_req_builder.json(&organization_domain_sso_details_request_model);
239
240        let local_var_req = local_var_req_builder.build()?;
241        let local_var_resp = local_var_client.execute(local_var_req).await?;
242
243        let local_var_status = local_var_resp.status();
244        let local_var_content_type = local_var_resp
245            .headers()
246            .get("content-type")
247            .and_then(|v| v.to_str().ok())
248            .unwrap_or("application/octet-stream");
249        let local_var_content_type = super::ContentType::from(local_var_content_type);
250        let local_var_content = local_var_resp.text().await?;
251
252        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
253            match local_var_content_type {
254                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
255                ContentType::Text => {
256                    return Err(Error::from(serde_json::Error::custom(
257                        "Received `text/plain` content type response that cannot be converted to `models::OrganizationDomainSsoDetailsResponseModel`",
258                    )));
259                }
260                ContentType::Unsupported(local_var_unknown_type) => {
261                    return Err(Error::from(serde_json::Error::custom(format!(
262                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::OrganizationDomainSsoDetailsResponseModel`"
263                    ))));
264                }
265            }
266        } else {
267            let local_var_entity: Option<GetOrgDomainSsoDetailsError> =
268                serde_json::from_str(&local_var_content).ok();
269            let local_var_error = ResponseContent {
270                status: local_var_status,
271                content: local_var_content,
272                entity: local_var_entity,
273            };
274            Err(Error::ResponseError(local_var_error))
275        }
276    }
277
278    async fn get_verified_org_domain_sso_details<'a>(
279        &self,
280        organization_domain_sso_details_request_model: Option<
281            models::OrganizationDomainSsoDetailsRequestModel,
282        >,
283    ) -> Result<
284        models::VerifiedOrganizationDomainSsoDetailsResponseModel,
285        Error<GetVerifiedOrgDomainSsoDetailsError>,
286    > {
287        let local_var_configuration = &self.configuration;
288
289        let local_var_client = &local_var_configuration.client;
290
291        let local_var_uri_str = format!(
292            "{}/organizations/domain/sso/verified",
293            local_var_configuration.base_path
294        );
295        let mut local_var_req_builder =
296            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
297
298        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
299            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
300        };
301        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
302        local_var_req_builder =
303            local_var_req_builder.json(&organization_domain_sso_details_request_model);
304
305        let local_var_req = local_var_req_builder.build()?;
306        let local_var_resp = local_var_client.execute(local_var_req).await?;
307
308        let local_var_status = local_var_resp.status();
309        let local_var_content_type = local_var_resp
310            .headers()
311            .get("content-type")
312            .and_then(|v| v.to_str().ok())
313            .unwrap_or("application/octet-stream");
314        let local_var_content_type = super::ContentType::from(local_var_content_type);
315        let local_var_content = local_var_resp.text().await?;
316
317        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
318            match local_var_content_type {
319                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
320                ContentType::Text => {
321                    return Err(Error::from(serde_json::Error::custom(
322                        "Received `text/plain` content type response that cannot be converted to `models::VerifiedOrganizationDomainSsoDetailsResponseModel`",
323                    )));
324                }
325                ContentType::Unsupported(local_var_unknown_type) => {
326                    return Err(Error::from(serde_json::Error::custom(format!(
327                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::VerifiedOrganizationDomainSsoDetailsResponseModel`"
328                    ))));
329                }
330            }
331        } else {
332            let local_var_entity: Option<GetVerifiedOrgDomainSsoDetailsError> =
333                serde_json::from_str(&local_var_content).ok();
334            let local_var_error = ResponseContent {
335                status: local_var_status,
336                content: local_var_content,
337                entity: local_var_entity,
338            };
339            Err(Error::ResponseError(local_var_error))
340        }
341    }
342
343    async fn post<'a>(
344        &self,
345        org_id: uuid::Uuid,
346        organization_domain_request_model: Option<models::OrganizationDomainRequestModel>,
347    ) -> Result<models::OrganizationDomainResponseModel, Error<PostError>> {
348        let local_var_configuration = &self.configuration;
349
350        let local_var_client = &local_var_configuration.client;
351
352        let local_var_uri_str = format!(
353            "{}/organizations/{orgId}/domain",
354            local_var_configuration.base_path,
355            orgId = org_id
356        );
357        let mut local_var_req_builder =
358            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
359
360        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
361            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
362        };
363        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
364        local_var_req_builder = local_var_req_builder.json(&organization_domain_request_model);
365
366        let local_var_req = local_var_req_builder.build()?;
367        let local_var_resp = local_var_client.execute(local_var_req).await?;
368
369        let local_var_status = local_var_resp.status();
370        let local_var_content_type = local_var_resp
371            .headers()
372            .get("content-type")
373            .and_then(|v| v.to_str().ok())
374            .unwrap_or("application/octet-stream");
375        let local_var_content_type = super::ContentType::from(local_var_content_type);
376        let local_var_content = local_var_resp.text().await?;
377
378        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
379            match local_var_content_type {
380                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
381                ContentType::Text => {
382                    return Err(Error::from(serde_json::Error::custom(
383                        "Received `text/plain` content type response that cannot be converted to `models::OrganizationDomainResponseModel`",
384                    )));
385                }
386                ContentType::Unsupported(local_var_unknown_type) => {
387                    return Err(Error::from(serde_json::Error::custom(format!(
388                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::OrganizationDomainResponseModel`"
389                    ))));
390                }
391            }
392        } else {
393            let local_var_entity: Option<PostError> = serde_json::from_str(&local_var_content).ok();
394            let local_var_error = ResponseContent {
395                status: local_var_status,
396                content: local_var_content,
397                entity: local_var_entity,
398            };
399            Err(Error::ResponseError(local_var_error))
400        }
401    }
402
403    async fn remove_domain<'a>(
404        &self,
405        org_id: uuid::Uuid,
406        id: uuid::Uuid,
407    ) -> Result<(), Error<RemoveDomainError>> {
408        let local_var_configuration = &self.configuration;
409
410        let local_var_client = &local_var_configuration.client;
411
412        let local_var_uri_str = format!(
413            "{}/organizations/{orgId}/domain/{id}",
414            local_var_configuration.base_path,
415            orgId = org_id,
416            id = id
417        );
418        let mut local_var_req_builder =
419            local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
420
421        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
422            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
423        };
424        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
425
426        let local_var_req = local_var_req_builder.build()?;
427        let local_var_resp = local_var_client.execute(local_var_req).await?;
428
429        let local_var_status = local_var_resp.status();
430        let local_var_content = local_var_resp.text().await?;
431
432        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
433            Ok(())
434        } else {
435            let local_var_entity: Option<RemoveDomainError> =
436                serde_json::from_str(&local_var_content).ok();
437            let local_var_error = ResponseContent {
438                status: local_var_status,
439                content: local_var_content,
440                entity: local_var_entity,
441            };
442            Err(Error::ResponseError(local_var_error))
443        }
444    }
445
446    async fn verify<'a>(
447        &self,
448        org_id: uuid::Uuid,
449        id: uuid::Uuid,
450    ) -> Result<models::OrganizationDomainResponseModel, Error<VerifyError>> {
451        let local_var_configuration = &self.configuration;
452
453        let local_var_client = &local_var_configuration.client;
454
455        let local_var_uri_str = format!(
456            "{}/organizations/{orgId}/domain/{id}/verify",
457            local_var_configuration.base_path,
458            orgId = org_id,
459            id = id
460        );
461        let mut local_var_req_builder =
462            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
463
464        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
465            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
466        };
467        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
468
469        let local_var_req = local_var_req_builder.build()?;
470        let local_var_resp = local_var_client.execute(local_var_req).await?;
471
472        let local_var_status = local_var_resp.status();
473        let local_var_content_type = local_var_resp
474            .headers()
475            .get("content-type")
476            .and_then(|v| v.to_str().ok())
477            .unwrap_or("application/octet-stream");
478        let local_var_content_type = super::ContentType::from(local_var_content_type);
479        let local_var_content = local_var_resp.text().await?;
480
481        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
482            match local_var_content_type {
483                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
484                ContentType::Text => {
485                    return Err(Error::from(serde_json::Error::custom(
486                        "Received `text/plain` content type response that cannot be converted to `models::OrganizationDomainResponseModel`",
487                    )));
488                }
489                ContentType::Unsupported(local_var_unknown_type) => {
490                    return Err(Error::from(serde_json::Error::custom(format!(
491                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::OrganizationDomainResponseModel`"
492                    ))));
493                }
494            }
495        } else {
496            let local_var_entity: Option<VerifyError> =
497                serde_json::from_str(&local_var_content).ok();
498            let local_var_error = ResponseContent {
499                status: local_var_status,
500                content: local_var_content,
501                entity: local_var_entity,
502            };
503            Err(Error::ResponseError(local_var_error))
504        }
505    }
506}
507
508/// struct for typed errors of method [`OrganizationDomainApi::get`]
509#[derive(Debug, Clone, Serialize, Deserialize)]
510#[serde(untagged)]
511pub enum GetError {
512    UnknownValue(serde_json::Value),
513}
514/// struct for typed errors of method [`OrganizationDomainApi::get_all`]
515#[derive(Debug, Clone, Serialize, Deserialize)]
516#[serde(untagged)]
517pub enum GetAllError {
518    UnknownValue(serde_json::Value),
519}
520/// struct for typed errors of method [`OrganizationDomainApi::get_org_domain_sso_details`]
521#[derive(Debug, Clone, Serialize, Deserialize)]
522#[serde(untagged)]
523pub enum GetOrgDomainSsoDetailsError {
524    UnknownValue(serde_json::Value),
525}
526/// struct for typed errors of method [`OrganizationDomainApi::get_verified_org_domain_sso_details`]
527#[derive(Debug, Clone, Serialize, Deserialize)]
528#[serde(untagged)]
529pub enum GetVerifiedOrgDomainSsoDetailsError {
530    UnknownValue(serde_json::Value),
531}
532/// struct for typed errors of method [`OrganizationDomainApi::post`]
533#[derive(Debug, Clone, Serialize, Deserialize)]
534#[serde(untagged)]
535pub enum PostError {
536    UnknownValue(serde_json::Value),
537}
538/// struct for typed errors of method [`OrganizationDomainApi::remove_domain`]
539#[derive(Debug, Clone, Serialize, Deserialize)]
540#[serde(untagged)]
541pub enum RemoveDomainError {
542    UnknownValue(serde_json::Value),
543}
544/// struct for typed errors of method [`OrganizationDomainApi::verify`]
545#[derive(Debug, Clone, Serialize, Deserialize)]
546#[serde(untagged)]
547pub enum VerifyError {
548    UnknownValue(serde_json::Value),
549}