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