Skip to main content

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        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
94
95        let local_var_resp = local_var_req_builder.send().await?;
96
97        let local_var_status = local_var_resp.status();
98        let local_var_content = local_var_resp.text().await?;
99
100        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
101            Ok(())
102        } else {
103            let local_var_entity: Option<AdminInitiatedRevokeSponsorshipError> =
104                serde_json::from_str(&local_var_content).ok();
105            let local_var_error = ResponseContent {
106                status: local_var_status,
107                content: local_var_content,
108                entity: local_var_entity,
109            };
110            Err(Error::ResponseError(local_var_error))
111        }
112    }
113
114    async fn create_sponsorship<'a>(
115        &self,
116        sponsoring_org_id: uuid::Uuid,
117        organization_sponsorship_create_request_model: Option<
118            models::OrganizationSponsorshipCreateRequestModel,
119        >,
120    ) -> Result<(), Error<CreateSponsorshipError>> {
121        let local_var_configuration = &self.configuration;
122
123        let local_var_client = &local_var_configuration.client;
124
125        let local_var_uri_str = format!(
126            "{}/organization/sponsorship/self-hosted/{sponsoringOrgId}/families-for-enterprise",
127            local_var_configuration.base_path,
128            sponsoringOrgId = sponsoring_org_id
129        );
130        let mut local_var_req_builder =
131            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
132
133        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
134        local_var_req_builder =
135            local_var_req_builder.json(&organization_sponsorship_create_request_model);
136
137        let local_var_resp = local_var_req_builder.send().await?;
138
139        let local_var_status = local_var_resp.status();
140        let local_var_content = local_var_resp.text().await?;
141
142        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
143            Ok(())
144        } else {
145            let local_var_entity: Option<CreateSponsorshipError> =
146                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_sponsored_organizations<'a>(
157        &self,
158        org_id: uuid::Uuid,
159    ) -> Result<
160        models::OrganizationSponsorshipInvitesResponseModelListResponseModel,
161        Error<GetSponsoredOrganizationsError>,
162    > {
163        let local_var_configuration = &self.configuration;
164
165        let local_var_client = &local_var_configuration.client;
166
167        let local_var_uri_str = format!(
168            "{}/organization/sponsorship/self-hosted/{orgId}/sponsored",
169            local_var_configuration.base_path,
170            orgId = org_id
171        );
172        let mut local_var_req_builder =
173            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
174
175        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
176
177        let local_var_resp = local_var_req_builder.send().await?;
178
179        let local_var_status = local_var_resp.status();
180        let local_var_content_type = local_var_resp
181            .headers()
182            .get("content-type")
183            .and_then(|v| v.to_str().ok())
184            .unwrap_or("application/octet-stream");
185        let local_var_content_type = super::ContentType::from(local_var_content_type);
186        let local_var_content = local_var_resp.text().await?;
187
188        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
189            match local_var_content_type {
190                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
191                ContentType::Text => {
192                    return Err(Error::from(serde_json::Error::custom(
193                        "Received `text/plain` content type response that cannot be converted to `models::OrganizationSponsorshipInvitesResponseModelListResponseModel`",
194                    )));
195                }
196                ContentType::Unsupported(local_var_unknown_type) => {
197                    return Err(Error::from(serde_json::Error::custom(format!(
198                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::OrganizationSponsorshipInvitesResponseModelListResponseModel`"
199                    ))));
200                }
201            }
202        } else {
203            let local_var_entity: Option<GetSponsoredOrganizationsError> =
204                serde_json::from_str(&local_var_content).ok();
205            let local_var_error = ResponseContent {
206                status: local_var_status,
207                content: local_var_content,
208                entity: local_var_entity,
209            };
210            Err(Error::ResponseError(local_var_error))
211        }
212    }
213
214    async fn revoke_sponsorship<'a>(
215        &self,
216        sponsoring_org_id: uuid::Uuid,
217    ) -> Result<(), Error<RevokeSponsorshipError>> {
218        let local_var_configuration = &self.configuration;
219
220        let local_var_client = &local_var_configuration.client;
221
222        let local_var_uri_str = format!(
223            "{}/organization/sponsorship/self-hosted/{sponsoringOrgId}",
224            local_var_configuration.base_path,
225            sponsoringOrgId = sponsoring_org_id
226        );
227        let mut local_var_req_builder =
228            local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
229
230        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
231
232        let local_var_resp = local_var_req_builder.send().await?;
233
234        let local_var_status = local_var_resp.status();
235        let local_var_content = local_var_resp.text().await?;
236
237        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
238            Ok(())
239        } else {
240            let local_var_entity: Option<RevokeSponsorshipError> =
241                serde_json::from_str(&local_var_content).ok();
242            let local_var_error = ResponseContent {
243                status: local_var_status,
244                content: local_var_content,
245                entity: local_var_entity,
246            };
247            Err(Error::ResponseError(local_var_error))
248        }
249    }
250}
251
252/// struct for typed errors of method
253/// [`SelfHostedOrganizationSponsorshipsApi::admin_initiated_revoke_sponsorship`]
254#[derive(Debug, Clone, Serialize, Deserialize)]
255#[serde(untagged)]
256pub enum AdminInitiatedRevokeSponsorshipError {
257    UnknownValue(serde_json::Value),
258}
259/// struct for typed errors of method [`SelfHostedOrganizationSponsorshipsApi::create_sponsorship`]
260#[derive(Debug, Clone, Serialize, Deserialize)]
261#[serde(untagged)]
262pub enum CreateSponsorshipError {
263    UnknownValue(serde_json::Value),
264}
265/// struct for typed errors of method
266/// [`SelfHostedOrganizationSponsorshipsApi::get_sponsored_organizations`]
267#[derive(Debug, Clone, Serialize, Deserialize)]
268#[serde(untagged)]
269pub enum GetSponsoredOrganizationsError {
270    UnknownValue(serde_json::Value),
271}
272/// struct for typed errors of method [`SelfHostedOrganizationSponsorshipsApi::revoke_sponsorship`]
273#[derive(Debug, Clone, Serialize, Deserialize)]
274#[serde(untagged)]
275pub enum RevokeSponsorshipError {
276    UnknownValue(serde_json::Value),
277}