bitwarden_api_api/apis/
self_hosted_organization_sponsorships_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 SelfHostedOrganizationSponsorshipsApi: Send + Sync {
29    /// DELETE /organization/sponsorship/self-hosted/{sponsoringOrgId}/{sponsoredFriendlyName}/
30    /// revoke
31    async fn admin_initiated_revoke_sponsorship<'a>(
32        &self,
33        sponsoring_org_id: uuid::Uuid,
34        sponsored_friendly_name: &'a str,
35    ) -> Result<(), Error<AdminInitiatedRevokeSponsorshipError>>;
36
37    /// POST /organization/sponsorship/self-hosted/{sponsoringOrgId}/families-for-enterprise
38    async fn create_sponsorship<'a>(
39        &self,
40        sponsoring_org_id: uuid::Uuid,
41        organization_sponsorship_create_request_model: Option<
42            models::OrganizationSponsorshipCreateRequestModel,
43        >,
44    ) -> Result<(), Error<CreateSponsorshipError>>;
45
46    /// GET /organization/sponsorship/self-hosted/{orgId}/sponsored
47    async fn get_sponsored_organizations<'a>(
48        &self,
49        org_id: uuid::Uuid,
50    ) -> Result<
51        models::OrganizationSponsorshipInvitesResponseModelListResponseModel,
52        Error<GetSponsoredOrganizationsError>,
53    >;
54
55    /// DELETE /organization/sponsorship/self-hosted/{sponsoringOrgId}
56    async fn revoke_sponsorship<'a>(
57        &self,
58        sponsoring_org_id: uuid::Uuid,
59    ) -> Result<(), Error<RevokeSponsorshipError>>;
60}
61
62pub struct SelfHostedOrganizationSponsorshipsApiClient {
63    configuration: Arc<configuration::Configuration>,
64}
65
66impl SelfHostedOrganizationSponsorshipsApiClient {
67    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
68        Self { configuration }
69    }
70}
71
72#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
73#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
74impl SelfHostedOrganizationSponsorshipsApi for SelfHostedOrganizationSponsorshipsApiClient {
75    async fn admin_initiated_revoke_sponsorship<'a>(
76        &self,
77        sponsoring_org_id: uuid::Uuid,
78        sponsored_friendly_name: &'a str,
79    ) -> Result<(), Error<AdminInitiatedRevokeSponsorshipError>> {
80        let local_var_configuration = &self.configuration;
81
82        let local_var_client = &local_var_configuration.client;
83
84        let local_var_uri_str = format!(
85            "{}/organization/sponsorship/self-hosted/{sponsoringOrgId}/{sponsoredFriendlyName}/revoke",
86            local_var_configuration.base_path,
87            sponsoringOrgId = sponsoring_org_id,
88            sponsoredFriendlyName = crate::apis::urlencode(sponsored_friendly_name)
89        );
90        let mut local_var_req_builder =
91            local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
92
93        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
94            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
95        };
96        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
97
98        let local_var_req = local_var_req_builder.build()?;
99        let local_var_resp = local_var_client.execute(local_var_req).await?;
100
101        let local_var_status = local_var_resp.status();
102        let local_var_content = local_var_resp.text().await?;
103
104        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
105            Ok(())
106        } else {
107            let local_var_entity: Option<AdminInitiatedRevokeSponsorshipError> =
108                serde_json::from_str(&local_var_content).ok();
109            let local_var_error = ResponseContent {
110                status: local_var_status,
111                content: local_var_content,
112                entity: local_var_entity,
113            };
114            Err(Error::ResponseError(local_var_error))
115        }
116    }
117
118    async fn create_sponsorship<'a>(
119        &self,
120        sponsoring_org_id: uuid::Uuid,
121        organization_sponsorship_create_request_model: Option<
122            models::OrganizationSponsorshipCreateRequestModel,
123        >,
124    ) -> Result<(), Error<CreateSponsorshipError>> {
125        let local_var_configuration = &self.configuration;
126
127        let local_var_client = &local_var_configuration.client;
128
129        let local_var_uri_str = format!(
130            "{}/organization/sponsorship/self-hosted/{sponsoringOrgId}/families-for-enterprise",
131            local_var_configuration.base_path,
132            sponsoringOrgId = sponsoring_org_id
133        );
134        let mut local_var_req_builder =
135            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
136
137        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
138            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
139        };
140        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
141        local_var_req_builder =
142            local_var_req_builder.json(&organization_sponsorship_create_request_model);
143
144        let local_var_req = local_var_req_builder.build()?;
145        let local_var_resp = local_var_client.execute(local_var_req).await?;
146
147        let local_var_status = local_var_resp.status();
148        let local_var_content = local_var_resp.text().await?;
149
150        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
151            Ok(())
152        } else {
153            let local_var_entity: Option<CreateSponsorshipError> =
154                serde_json::from_str(&local_var_content).ok();
155            let local_var_error = ResponseContent {
156                status: local_var_status,
157                content: local_var_content,
158                entity: local_var_entity,
159            };
160            Err(Error::ResponseError(local_var_error))
161        }
162    }
163
164    async fn get_sponsored_organizations<'a>(
165        &self,
166        org_id: uuid::Uuid,
167    ) -> Result<
168        models::OrganizationSponsorshipInvitesResponseModelListResponseModel,
169        Error<GetSponsoredOrganizationsError>,
170    > {
171        let local_var_configuration = &self.configuration;
172
173        let local_var_client = &local_var_configuration.client;
174
175        let local_var_uri_str = format!(
176            "{}/organization/sponsorship/self-hosted/{orgId}/sponsored",
177            local_var_configuration.base_path,
178            orgId = org_id
179        );
180        let mut local_var_req_builder =
181            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
182
183        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
184            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
185        };
186        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
187
188        let local_var_req = local_var_req_builder.build()?;
189        let local_var_resp = local_var_client.execute(local_var_req).await?;
190
191        let local_var_status = local_var_resp.status();
192        let local_var_content_type = local_var_resp
193            .headers()
194            .get("content-type")
195            .and_then(|v| v.to_str().ok())
196            .unwrap_or("application/octet-stream");
197        let local_var_content_type = super::ContentType::from(local_var_content_type);
198        let local_var_content = local_var_resp.text().await?;
199
200        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
201            match local_var_content_type {
202                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
203                ContentType::Text => {
204                    return Err(Error::from(serde_json::Error::custom(
205                        "Received `text/plain` content type response that cannot be converted to `models::OrganizationSponsorshipInvitesResponseModelListResponseModel`",
206                    )));
207                }
208                ContentType::Unsupported(local_var_unknown_type) => {
209                    return Err(Error::from(serde_json::Error::custom(format!(
210                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::OrganizationSponsorshipInvitesResponseModelListResponseModel`"
211                    ))));
212                }
213            }
214        } else {
215            let local_var_entity: Option<GetSponsoredOrganizationsError> =
216                serde_json::from_str(&local_var_content).ok();
217            let local_var_error = ResponseContent {
218                status: local_var_status,
219                content: local_var_content,
220                entity: local_var_entity,
221            };
222            Err(Error::ResponseError(local_var_error))
223        }
224    }
225
226    async fn revoke_sponsorship<'a>(
227        &self,
228        sponsoring_org_id: uuid::Uuid,
229    ) -> Result<(), Error<RevokeSponsorshipError>> {
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            "{}/organization/sponsorship/self-hosted/{sponsoringOrgId}",
236            local_var_configuration.base_path,
237            sponsoringOrgId = sponsoring_org_id
238        );
239        let mut local_var_req_builder =
240            local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
241
242        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
243            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
244        };
245        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
246
247        let local_var_req = local_var_req_builder.build()?;
248        let local_var_resp = local_var_client.execute(local_var_req).await?;
249
250        let local_var_status = local_var_resp.status();
251        let local_var_content = local_var_resp.text().await?;
252
253        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
254            Ok(())
255        } else {
256            let local_var_entity: Option<RevokeSponsorshipError> =
257                serde_json::from_str(&local_var_content).ok();
258            let local_var_error = ResponseContent {
259                status: local_var_status,
260                content: local_var_content,
261                entity: local_var_entity,
262            };
263            Err(Error::ResponseError(local_var_error))
264        }
265    }
266}
267
268/// struct for typed errors of method
269/// [`SelfHostedOrganizationSponsorshipsApi::admin_initiated_revoke_sponsorship`]
270#[derive(Debug, Clone, Serialize, Deserialize)]
271#[serde(untagged)]
272pub enum AdminInitiatedRevokeSponsorshipError {
273    UnknownValue(serde_json::Value),
274}
275/// struct for typed errors of method [`SelfHostedOrganizationSponsorshipsApi::create_sponsorship`]
276#[derive(Debug, Clone, Serialize, Deserialize)]
277#[serde(untagged)]
278pub enum CreateSponsorshipError {
279    UnknownValue(serde_json::Value),
280}
281/// struct for typed errors of method
282/// [`SelfHostedOrganizationSponsorshipsApi::get_sponsored_organizations`]
283#[derive(Debug, Clone, Serialize, Deserialize)]
284#[serde(untagged)]
285pub enum GetSponsoredOrganizationsError {
286    UnknownValue(serde_json::Value),
287}
288/// struct for typed errors of method [`SelfHostedOrganizationSponsorshipsApi::revoke_sponsorship`]
289#[derive(Debug, Clone, Serialize, Deserialize)]
290#[serde(untagged)]
291pub enum RevokeSponsorshipError {
292    UnknownValue(serde_json::Value),
293}