bitwarden_api_api/apis/
auth_requests_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 AuthRequestsApi: Send + Sync {
29    /// GET /auth-requests/{id}
30    async fn get<'a>(
31        &self,
32        id: uuid::Uuid,
33    ) -> Result<models::AuthRequestResponseModel, Error<GetError>>;
34
35    /// GET /auth-requests
36    async fn get_all(
37        &self,
38    ) -> Result<models::AuthRequestResponseModelListResponseModel, Error<GetAllError>>;
39
40    /// GET /auth-requests/pending
41    async fn get_pending_auth_requests(
42        &self,
43    ) -> Result<
44        models::PendingAuthRequestResponseModelListResponseModel,
45        Error<GetPendingAuthRequestsError>,
46    >;
47
48    /// GET /auth-requests/{id}/response
49    async fn get_response<'a>(
50        &self,
51        id: uuid::Uuid,
52        code: Option<&'a str>,
53    ) -> Result<models::AuthRequestResponseModel, Error<GetResponseError>>;
54
55    /// POST /auth-requests
56    async fn post<'a>(
57        &self,
58        auth_request_create_request_model: Option<models::AuthRequestCreateRequestModel>,
59    ) -> Result<models::AuthRequestResponseModel, Error<PostError>>;
60
61    /// POST /auth-requests/admin-request
62    async fn post_admin_request<'a>(
63        &self,
64        auth_request_create_request_model: Option<models::AuthRequestCreateRequestModel>,
65    ) -> Result<models::AuthRequestResponseModel, Error<PostAdminRequestError>>;
66
67    /// PUT /auth-requests/{id}
68    async fn put<'a>(
69        &self,
70        id: uuid::Uuid,
71        auth_request_update_request_model: Option<models::AuthRequestUpdateRequestModel>,
72    ) -> Result<models::AuthRequestResponseModel, Error<PutError>>;
73}
74
75pub struct AuthRequestsApiClient {
76    configuration: Arc<configuration::Configuration>,
77}
78
79impl AuthRequestsApiClient {
80    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
81        Self { configuration }
82    }
83}
84
85#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
86#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
87impl AuthRequestsApi for AuthRequestsApiClient {
88    async fn get<'a>(
89        &self,
90        id: uuid::Uuid,
91    ) -> Result<models::AuthRequestResponseModel, Error<GetError>> {
92        let local_var_configuration = &self.configuration;
93
94        let local_var_client = &local_var_configuration.client;
95
96        let local_var_uri_str = format!(
97            "{}/auth-requests/{id}",
98            local_var_configuration.base_path,
99            id = id
100        );
101        let mut local_var_req_builder =
102            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
103
104        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
105            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
106        };
107        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
108
109        let local_var_req = local_var_req_builder.build()?;
110        let local_var_resp = local_var_client.execute(local_var_req).await?;
111
112        let local_var_status = local_var_resp.status();
113        let local_var_content_type = local_var_resp
114            .headers()
115            .get("content-type")
116            .and_then(|v| v.to_str().ok())
117            .unwrap_or("application/octet-stream");
118        let local_var_content_type = super::ContentType::from(local_var_content_type);
119        let local_var_content = local_var_resp.text().await?;
120
121        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
122            match local_var_content_type {
123                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
124                ContentType::Text => {
125                    return Err(Error::from(serde_json::Error::custom(
126                        "Received `text/plain` content type response that cannot be converted to `models::AuthRequestResponseModel`",
127                    )));
128                }
129                ContentType::Unsupported(local_var_unknown_type) => {
130                    return Err(Error::from(serde_json::Error::custom(format!(
131                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::AuthRequestResponseModel`"
132                    ))));
133                }
134            }
135        } else {
136            let local_var_entity: Option<GetError> = serde_json::from_str(&local_var_content).ok();
137            let local_var_error = ResponseContent {
138                status: local_var_status,
139                content: local_var_content,
140                entity: local_var_entity,
141            };
142            Err(Error::ResponseError(local_var_error))
143        }
144    }
145
146    async fn get_all(
147        &self,
148    ) -> Result<models::AuthRequestResponseModelListResponseModel, Error<GetAllError>> {
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!("{}/auth-requests", local_var_configuration.base_path);
154        let mut local_var_req_builder =
155            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
156
157        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
158            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
159        };
160        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
161
162        let local_var_req = local_var_req_builder.build()?;
163        let local_var_resp = local_var_client.execute(local_var_req).await?;
164
165        let local_var_status = local_var_resp.status();
166        let local_var_content_type = local_var_resp
167            .headers()
168            .get("content-type")
169            .and_then(|v| v.to_str().ok())
170            .unwrap_or("application/octet-stream");
171        let local_var_content_type = super::ContentType::from(local_var_content_type);
172        let local_var_content = local_var_resp.text().await?;
173
174        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
175            match local_var_content_type {
176                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
177                ContentType::Text => {
178                    return Err(Error::from(serde_json::Error::custom(
179                        "Received `text/plain` content type response that cannot be converted to `models::AuthRequestResponseModelListResponseModel`",
180                    )));
181                }
182                ContentType::Unsupported(local_var_unknown_type) => {
183                    return Err(Error::from(serde_json::Error::custom(format!(
184                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::AuthRequestResponseModelListResponseModel`"
185                    ))));
186                }
187            }
188        } else {
189            let local_var_entity: Option<GetAllError> =
190                serde_json::from_str(&local_var_content).ok();
191            let local_var_error = ResponseContent {
192                status: local_var_status,
193                content: local_var_content,
194                entity: local_var_entity,
195            };
196            Err(Error::ResponseError(local_var_error))
197        }
198    }
199
200    async fn get_pending_auth_requests(
201        &self,
202    ) -> Result<
203        models::PendingAuthRequestResponseModelListResponseModel,
204        Error<GetPendingAuthRequestsError>,
205    > {
206        let local_var_configuration = &self.configuration;
207
208        let local_var_client = &local_var_configuration.client;
209
210        let local_var_uri_str = format!(
211            "{}/auth-requests/pending",
212            local_var_configuration.base_path
213        );
214        let mut local_var_req_builder =
215            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
216
217        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
218            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
219        };
220        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
221
222        let local_var_req = local_var_req_builder.build()?;
223        let local_var_resp = local_var_client.execute(local_var_req).await?;
224
225        let local_var_status = local_var_resp.status();
226        let local_var_content_type = local_var_resp
227            .headers()
228            .get("content-type")
229            .and_then(|v| v.to_str().ok())
230            .unwrap_or("application/octet-stream");
231        let local_var_content_type = super::ContentType::from(local_var_content_type);
232        let local_var_content = local_var_resp.text().await?;
233
234        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
235            match local_var_content_type {
236                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
237                ContentType::Text => {
238                    return Err(Error::from(serde_json::Error::custom(
239                        "Received `text/plain` content type response that cannot be converted to `models::PendingAuthRequestResponseModelListResponseModel`",
240                    )));
241                }
242                ContentType::Unsupported(local_var_unknown_type) => {
243                    return Err(Error::from(serde_json::Error::custom(format!(
244                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::PendingAuthRequestResponseModelListResponseModel`"
245                    ))));
246                }
247            }
248        } else {
249            let local_var_entity: Option<GetPendingAuthRequestsError> =
250                serde_json::from_str(&local_var_content).ok();
251            let local_var_error = ResponseContent {
252                status: local_var_status,
253                content: local_var_content,
254                entity: local_var_entity,
255            };
256            Err(Error::ResponseError(local_var_error))
257        }
258    }
259
260    async fn get_response<'a>(
261        &self,
262        id: uuid::Uuid,
263        code: Option<&'a str>,
264    ) -> Result<models::AuthRequestResponseModel, Error<GetResponseError>> {
265        let local_var_configuration = &self.configuration;
266
267        let local_var_client = &local_var_configuration.client;
268
269        let local_var_uri_str = format!(
270            "{}/auth-requests/{id}/response",
271            local_var_configuration.base_path,
272            id = id
273        );
274        let mut local_var_req_builder =
275            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
276
277        if let Some(ref param_value) = code {
278            local_var_req_builder =
279                local_var_req_builder.query(&[("code", &param_value.to_string())]);
280        }
281        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
282            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
283        };
284        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
285
286        let local_var_req = local_var_req_builder.build()?;
287        let local_var_resp = local_var_client.execute(local_var_req).await?;
288
289        let local_var_status = local_var_resp.status();
290        let local_var_content_type = local_var_resp
291            .headers()
292            .get("content-type")
293            .and_then(|v| v.to_str().ok())
294            .unwrap_or("application/octet-stream");
295        let local_var_content_type = super::ContentType::from(local_var_content_type);
296        let local_var_content = local_var_resp.text().await?;
297
298        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
299            match local_var_content_type {
300                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
301                ContentType::Text => {
302                    return Err(Error::from(serde_json::Error::custom(
303                        "Received `text/plain` content type response that cannot be converted to `models::AuthRequestResponseModel`",
304                    )));
305                }
306                ContentType::Unsupported(local_var_unknown_type) => {
307                    return Err(Error::from(serde_json::Error::custom(format!(
308                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::AuthRequestResponseModel`"
309                    ))));
310                }
311            }
312        } else {
313            let local_var_entity: Option<GetResponseError> =
314                serde_json::from_str(&local_var_content).ok();
315            let local_var_error = ResponseContent {
316                status: local_var_status,
317                content: local_var_content,
318                entity: local_var_entity,
319            };
320            Err(Error::ResponseError(local_var_error))
321        }
322    }
323
324    async fn post<'a>(
325        &self,
326        auth_request_create_request_model: Option<models::AuthRequestCreateRequestModel>,
327    ) -> Result<models::AuthRequestResponseModel, Error<PostError>> {
328        let local_var_configuration = &self.configuration;
329
330        let local_var_client = &local_var_configuration.client;
331
332        let local_var_uri_str = format!("{}/auth-requests", local_var_configuration.base_path);
333        let mut local_var_req_builder =
334            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
335
336        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
337            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
338        };
339        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
340        local_var_req_builder = local_var_req_builder.json(&auth_request_create_request_model);
341
342        let local_var_req = local_var_req_builder.build()?;
343        let local_var_resp = local_var_client.execute(local_var_req).await?;
344
345        let local_var_status = local_var_resp.status();
346        let local_var_content_type = local_var_resp
347            .headers()
348            .get("content-type")
349            .and_then(|v| v.to_str().ok())
350            .unwrap_or("application/octet-stream");
351        let local_var_content_type = super::ContentType::from(local_var_content_type);
352        let local_var_content = local_var_resp.text().await?;
353
354        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
355            match local_var_content_type {
356                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
357                ContentType::Text => {
358                    return Err(Error::from(serde_json::Error::custom(
359                        "Received `text/plain` content type response that cannot be converted to `models::AuthRequestResponseModel`",
360                    )));
361                }
362                ContentType::Unsupported(local_var_unknown_type) => {
363                    return Err(Error::from(serde_json::Error::custom(format!(
364                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::AuthRequestResponseModel`"
365                    ))));
366                }
367            }
368        } else {
369            let local_var_entity: Option<PostError> = serde_json::from_str(&local_var_content).ok();
370            let local_var_error = ResponseContent {
371                status: local_var_status,
372                content: local_var_content,
373                entity: local_var_entity,
374            };
375            Err(Error::ResponseError(local_var_error))
376        }
377    }
378
379    async fn post_admin_request<'a>(
380        &self,
381        auth_request_create_request_model: Option<models::AuthRequestCreateRequestModel>,
382    ) -> Result<models::AuthRequestResponseModel, Error<PostAdminRequestError>> {
383        let local_var_configuration = &self.configuration;
384
385        let local_var_client = &local_var_configuration.client;
386
387        let local_var_uri_str = format!(
388            "{}/auth-requests/admin-request",
389            local_var_configuration.base_path
390        );
391        let mut local_var_req_builder =
392            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
393
394        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
395            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
396        };
397        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
398        local_var_req_builder = local_var_req_builder.json(&auth_request_create_request_model);
399
400        let local_var_req = local_var_req_builder.build()?;
401        let local_var_resp = local_var_client.execute(local_var_req).await?;
402
403        let local_var_status = local_var_resp.status();
404        let local_var_content_type = local_var_resp
405            .headers()
406            .get("content-type")
407            .and_then(|v| v.to_str().ok())
408            .unwrap_or("application/octet-stream");
409        let local_var_content_type = super::ContentType::from(local_var_content_type);
410        let local_var_content = local_var_resp.text().await?;
411
412        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
413            match local_var_content_type {
414                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
415                ContentType::Text => {
416                    return Err(Error::from(serde_json::Error::custom(
417                        "Received `text/plain` content type response that cannot be converted to `models::AuthRequestResponseModel`",
418                    )));
419                }
420                ContentType::Unsupported(local_var_unknown_type) => {
421                    return Err(Error::from(serde_json::Error::custom(format!(
422                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::AuthRequestResponseModel`"
423                    ))));
424                }
425            }
426        } else {
427            let local_var_entity: Option<PostAdminRequestError> =
428                serde_json::from_str(&local_var_content).ok();
429            let local_var_error = ResponseContent {
430                status: local_var_status,
431                content: local_var_content,
432                entity: local_var_entity,
433            };
434            Err(Error::ResponseError(local_var_error))
435        }
436    }
437
438    async fn put<'a>(
439        &self,
440        id: uuid::Uuid,
441        auth_request_update_request_model: Option<models::AuthRequestUpdateRequestModel>,
442    ) -> Result<models::AuthRequestResponseModel, Error<PutError>> {
443        let local_var_configuration = &self.configuration;
444
445        let local_var_client = &local_var_configuration.client;
446
447        let local_var_uri_str = format!(
448            "{}/auth-requests/{id}",
449            local_var_configuration.base_path,
450            id = id
451        );
452        let mut local_var_req_builder =
453            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
454
455        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
456            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
457        };
458        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
459        local_var_req_builder = local_var_req_builder.json(&auth_request_update_request_model);
460
461        let local_var_req = local_var_req_builder.build()?;
462        let local_var_resp = local_var_client.execute(local_var_req).await?;
463
464        let local_var_status = local_var_resp.status();
465        let local_var_content_type = local_var_resp
466            .headers()
467            .get("content-type")
468            .and_then(|v| v.to_str().ok())
469            .unwrap_or("application/octet-stream");
470        let local_var_content_type = super::ContentType::from(local_var_content_type);
471        let local_var_content = local_var_resp.text().await?;
472
473        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
474            match local_var_content_type {
475                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
476                ContentType::Text => {
477                    return Err(Error::from(serde_json::Error::custom(
478                        "Received `text/plain` content type response that cannot be converted to `models::AuthRequestResponseModel`",
479                    )));
480                }
481                ContentType::Unsupported(local_var_unknown_type) => {
482                    return Err(Error::from(serde_json::Error::custom(format!(
483                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::AuthRequestResponseModel`"
484                    ))));
485                }
486            }
487        } else {
488            let local_var_entity: Option<PutError> = serde_json::from_str(&local_var_content).ok();
489            let local_var_error = ResponseContent {
490                status: local_var_status,
491                content: local_var_content,
492                entity: local_var_entity,
493            };
494            Err(Error::ResponseError(local_var_error))
495        }
496    }
497}
498
499/// struct for typed errors of method [`AuthRequestsApi::get`]
500#[derive(Debug, Clone, Serialize, Deserialize)]
501#[serde(untagged)]
502pub enum GetError {
503    UnknownValue(serde_json::Value),
504}
505/// struct for typed errors of method [`AuthRequestsApi::get_all`]
506#[derive(Debug, Clone, Serialize, Deserialize)]
507#[serde(untagged)]
508pub enum GetAllError {
509    UnknownValue(serde_json::Value),
510}
511/// struct for typed errors of method [`AuthRequestsApi::get_pending_auth_requests`]
512#[derive(Debug, Clone, Serialize, Deserialize)]
513#[serde(untagged)]
514pub enum GetPendingAuthRequestsError {
515    UnknownValue(serde_json::Value),
516}
517/// struct for typed errors of method [`AuthRequestsApi::get_response`]
518#[derive(Debug, Clone, Serialize, Deserialize)]
519#[serde(untagged)]
520pub enum GetResponseError {
521    UnknownValue(serde_json::Value),
522}
523/// struct for typed errors of method [`AuthRequestsApi::post`]
524#[derive(Debug, Clone, Serialize, Deserialize)]
525#[serde(untagged)]
526pub enum PostError {
527    UnknownValue(serde_json::Value),
528}
529/// struct for typed errors of method [`AuthRequestsApi::post_admin_request`]
530#[derive(Debug, Clone, Serialize, Deserialize)]
531#[serde(untagged)]
532pub enum PostAdminRequestError {
533    UnknownValue(serde_json::Value),
534}
535/// struct for typed errors of method [`AuthRequestsApi::put`]
536#[derive(Debug, Clone, Serialize, Deserialize)]
537#[serde(untagged)]
538pub enum PutError {
539    UnknownValue(serde_json::Value),
540}