Skip to main content

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