bitwarden_api_api/apis/
organization_connections_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::{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 OrganizationConnectionsApi: Send + Sync {
29    /// GET /organizations/connections/enabled
30    async fn connections_enabled(&self) -> Result<bool, Error<ConnectionsEnabledError>>;
31
32    /// POST /organizations/connections
33    async fn create_connection<'a>(
34        &self,
35        organization_connection_request_model: Option<models::OrganizationConnectionRequestModel>,
36    ) -> Result<models::OrganizationConnectionResponseModel, Error<CreateConnectionError>>;
37
38    /// DELETE /organizations/connections/{organizationConnectionId}
39    async fn delete_connection<'a>(
40        &self,
41        organization_connection_id: uuid::Uuid,
42    ) -> Result<(), Error<DeleteConnectionError>>;
43
44    /// GET /organizations/connections/{organizationId}/{type}
45    async fn get_connection<'a>(
46        &self,
47        organization_id: uuid::Uuid,
48        r#type: models::OrganizationConnectionType,
49    ) -> Result<models::OrganizationConnectionResponseModel, Error<GetConnectionError>>;
50
51    /// PUT /organizations/connections/{organizationConnectionId}
52    async fn update_connection<'a>(
53        &self,
54        organization_connection_id: uuid::Uuid,
55        organization_connection_request_model: Option<models::OrganizationConnectionRequestModel>,
56    ) -> Result<models::OrganizationConnectionResponseModel, Error<UpdateConnectionError>>;
57}
58
59pub struct OrganizationConnectionsApiClient {
60    configuration: Arc<configuration::Configuration>,
61}
62
63impl OrganizationConnectionsApiClient {
64    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
65        Self { configuration }
66    }
67}
68
69#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
70#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
71impl OrganizationConnectionsApi for OrganizationConnectionsApiClient {
72    async fn connections_enabled(&self) -> Result<bool, Error<ConnectionsEnabledError>> {
73        let local_var_configuration = &self.configuration;
74
75        let local_var_client = &local_var_configuration.client;
76
77        let local_var_uri_str = format!(
78            "{}/organizations/connections/enabled",
79            local_var_configuration.base_path
80        );
81        let mut local_var_req_builder =
82            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
83
84        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
85            local_var_req_builder = local_var_req_builder
86                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
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
92        let local_var_req = local_var_req_builder.build()?;
93        let local_var_resp = local_var_client.execute(local_var_req).await?;
94
95        let local_var_status = local_var_resp.status();
96        let local_var_content_type = local_var_resp
97            .headers()
98            .get("content-type")
99            .and_then(|v| v.to_str().ok())
100            .unwrap_or("application/octet-stream");
101        let local_var_content_type = super::ContentType::from(local_var_content_type);
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            match local_var_content_type {
106                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
107                ContentType::Text => {
108                    return Err(Error::from(serde_json::Error::custom(
109                        "Received `text/plain` content type response that cannot be converted to `bool`",
110                    )));
111                }
112                ContentType::Unsupported(local_var_unknown_type) => {
113                    return Err(Error::from(serde_json::Error::custom(format!(
114                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `bool`"
115                    ))));
116                }
117            }
118        } else {
119            let local_var_entity: Option<ConnectionsEnabledError> =
120                serde_json::from_str(&local_var_content).ok();
121            let local_var_error = ResponseContent {
122                status: local_var_status,
123                content: local_var_content,
124                entity: local_var_entity,
125            };
126            Err(Error::ResponseError(local_var_error))
127        }
128    }
129
130    async fn create_connection<'a>(
131        &self,
132        organization_connection_request_model: Option<models::OrganizationConnectionRequestModel>,
133    ) -> Result<models::OrganizationConnectionResponseModel, Error<CreateConnectionError>> {
134        let local_var_configuration = &self.configuration;
135
136        let local_var_client = &local_var_configuration.client;
137
138        let local_var_uri_str = format!(
139            "{}/organizations/connections",
140            local_var_configuration.base_path
141        );
142        let mut local_var_req_builder =
143            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
144
145        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
146            local_var_req_builder = local_var_req_builder
147                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
148        }
149        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
150            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
151        };
152        local_var_req_builder = local_var_req_builder.json(&organization_connection_request_model);
153
154        let local_var_req = local_var_req_builder.build()?;
155        let local_var_resp = local_var_client.execute(local_var_req).await?;
156
157        let local_var_status = local_var_resp.status();
158        let local_var_content_type = local_var_resp
159            .headers()
160            .get("content-type")
161            .and_then(|v| v.to_str().ok())
162            .unwrap_or("application/octet-stream");
163        let local_var_content_type = super::ContentType::from(local_var_content_type);
164        let local_var_content = local_var_resp.text().await?;
165
166        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
167            match local_var_content_type {
168                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
169                ContentType::Text => {
170                    return Err(Error::from(serde_json::Error::custom(
171                        "Received `text/plain` content type response that cannot be converted to `models::OrganizationConnectionResponseModel`",
172                    )));
173                }
174                ContentType::Unsupported(local_var_unknown_type) => {
175                    return Err(Error::from(serde_json::Error::custom(format!(
176                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::OrganizationConnectionResponseModel`"
177                    ))));
178                }
179            }
180        } else {
181            let local_var_entity: Option<CreateConnectionError> =
182                serde_json::from_str(&local_var_content).ok();
183            let local_var_error = ResponseContent {
184                status: local_var_status,
185                content: local_var_content,
186                entity: local_var_entity,
187            };
188            Err(Error::ResponseError(local_var_error))
189        }
190    }
191
192    async fn delete_connection<'a>(
193        &self,
194        organization_connection_id: uuid::Uuid,
195    ) -> Result<(), Error<DeleteConnectionError>> {
196        let local_var_configuration = &self.configuration;
197
198        let local_var_client = &local_var_configuration.client;
199
200        let local_var_uri_str = format!(
201            "{}/organizations/connections/{organizationConnectionId}",
202            local_var_configuration.base_path,
203            organizationConnectionId = organization_connection_id
204        );
205        let mut local_var_req_builder =
206            local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
207
208        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
209            local_var_req_builder = local_var_req_builder
210                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
211        }
212        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
213            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
214        };
215
216        let local_var_req = local_var_req_builder.build()?;
217        let local_var_resp = local_var_client.execute(local_var_req).await?;
218
219        let local_var_status = local_var_resp.status();
220        let local_var_content = local_var_resp.text().await?;
221
222        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
223            Ok(())
224        } else {
225            let local_var_entity: Option<DeleteConnectionError> =
226                serde_json::from_str(&local_var_content).ok();
227            let local_var_error = ResponseContent {
228                status: local_var_status,
229                content: local_var_content,
230                entity: local_var_entity,
231            };
232            Err(Error::ResponseError(local_var_error))
233        }
234    }
235
236    async fn get_connection<'a>(
237        &self,
238        organization_id: uuid::Uuid,
239        r#type: models::OrganizationConnectionType,
240    ) -> Result<models::OrganizationConnectionResponseModel, Error<GetConnectionError>> {
241        let local_var_configuration = &self.configuration;
242
243        let local_var_client = &local_var_configuration.client;
244
245        let local_var_uri_str = format!("{}/organizations/connections/{organizationId}/{type}", local_var_configuration.base_path, organizationId=organization_id, type=r#type.to_string());
246        let mut local_var_req_builder =
247            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
248
249        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
250            local_var_req_builder = local_var_req_builder
251                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
252        }
253        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
254            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
255        };
256
257        let local_var_req = local_var_req_builder.build()?;
258        let local_var_resp = local_var_client.execute(local_var_req).await?;
259
260        let local_var_status = local_var_resp.status();
261        let local_var_content_type = local_var_resp
262            .headers()
263            .get("content-type")
264            .and_then(|v| v.to_str().ok())
265            .unwrap_or("application/octet-stream");
266        let local_var_content_type = super::ContentType::from(local_var_content_type);
267        let local_var_content = local_var_resp.text().await?;
268
269        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
270            match local_var_content_type {
271                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
272                ContentType::Text => {
273                    return Err(Error::from(serde_json::Error::custom(
274                        "Received `text/plain` content type response that cannot be converted to `models::OrganizationConnectionResponseModel`",
275                    )));
276                }
277                ContentType::Unsupported(local_var_unknown_type) => {
278                    return Err(Error::from(serde_json::Error::custom(format!(
279                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::OrganizationConnectionResponseModel`"
280                    ))));
281                }
282            }
283        } else {
284            let local_var_entity: Option<GetConnectionError> =
285                serde_json::from_str(&local_var_content).ok();
286            let local_var_error = ResponseContent {
287                status: local_var_status,
288                content: local_var_content,
289                entity: local_var_entity,
290            };
291            Err(Error::ResponseError(local_var_error))
292        }
293    }
294
295    async fn update_connection<'a>(
296        &self,
297        organization_connection_id: uuid::Uuid,
298        organization_connection_request_model: Option<models::OrganizationConnectionRequestModel>,
299    ) -> Result<models::OrganizationConnectionResponseModel, Error<UpdateConnectionError>> {
300        let local_var_configuration = &self.configuration;
301
302        let local_var_client = &local_var_configuration.client;
303
304        let local_var_uri_str = format!(
305            "{}/organizations/connections/{organizationConnectionId}",
306            local_var_configuration.base_path,
307            organizationConnectionId = organization_connection_id
308        );
309        let mut local_var_req_builder =
310            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
311
312        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
313            local_var_req_builder = local_var_req_builder
314                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
315        }
316        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
317            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
318        };
319        local_var_req_builder = local_var_req_builder.json(&organization_connection_request_model);
320
321        let local_var_req = local_var_req_builder.build()?;
322        let local_var_resp = local_var_client.execute(local_var_req).await?;
323
324        let local_var_status = local_var_resp.status();
325        let local_var_content_type = local_var_resp
326            .headers()
327            .get("content-type")
328            .and_then(|v| v.to_str().ok())
329            .unwrap_or("application/octet-stream");
330        let local_var_content_type = super::ContentType::from(local_var_content_type);
331        let local_var_content = local_var_resp.text().await?;
332
333        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
334            match local_var_content_type {
335                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
336                ContentType::Text => {
337                    return Err(Error::from(serde_json::Error::custom(
338                        "Received `text/plain` content type response that cannot be converted to `models::OrganizationConnectionResponseModel`",
339                    )));
340                }
341                ContentType::Unsupported(local_var_unknown_type) => {
342                    return Err(Error::from(serde_json::Error::custom(format!(
343                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::OrganizationConnectionResponseModel`"
344                    ))));
345                }
346            }
347        } else {
348            let local_var_entity: Option<UpdateConnectionError> =
349                serde_json::from_str(&local_var_content).ok();
350            let local_var_error = ResponseContent {
351                status: local_var_status,
352                content: local_var_content,
353                entity: local_var_entity,
354            };
355            Err(Error::ResponseError(local_var_error))
356        }
357    }
358}
359
360/// struct for typed errors of method [`OrganizationConnectionsApi::connections_enabled`]
361#[derive(Debug, Clone, Serialize, Deserialize)]
362#[serde(untagged)]
363pub enum ConnectionsEnabledError {
364    UnknownValue(serde_json::Value),
365}
366/// struct for typed errors of method [`OrganizationConnectionsApi::create_connection`]
367#[derive(Debug, Clone, Serialize, Deserialize)]
368#[serde(untagged)]
369pub enum CreateConnectionError {
370    UnknownValue(serde_json::Value),
371}
372/// struct for typed errors of method [`OrganizationConnectionsApi::delete_connection`]
373#[derive(Debug, Clone, Serialize, Deserialize)]
374#[serde(untagged)]
375pub enum DeleteConnectionError {
376    UnknownValue(serde_json::Value),
377}
378/// struct for typed errors of method [`OrganizationConnectionsApi::get_connection`]
379#[derive(Debug, Clone, Serialize, Deserialize)]
380#[serde(untagged)]
381pub enum GetConnectionError {
382    UnknownValue(serde_json::Value),
383}
384/// struct for typed errors of method [`OrganizationConnectionsApi::update_connection`]
385#[derive(Debug, Clone, Serialize, Deserialize)]
386#[serde(untagged)]
387pub enum UpdateConnectionError {
388    UnknownValue(serde_json::Value),
389}