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