Skip to main content

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