Skip to main content

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