bitwarden_api_api/apis/
accounts_key_management_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 AccountsKeyManagementApi: Send + Sync {
29    /// GET /accounts/key-connector/confirmation-details/{orgSsoIdentifier}
30    async fn get_key_connector_confirmation_details<'a>(
31        &self,
32        org_sso_identifier: &'a str,
33    ) -> Result<
34        models::KeyConnectorConfirmationDetailsResponseModel,
35        Error<GetKeyConnectorConfirmationDetailsError>,
36    >;
37
38    /// POST /accounts/convert-to-key-connector
39    async fn post_convert_to_key_connector(
40        &self,
41    ) -> Result<(), Error<PostConvertToKeyConnectorError>>;
42
43    /// POST /accounts/set-key-connector-key
44    async fn post_set_key_connector_key<'a>(
45        &self,
46        set_key_connector_key_request_model: Option<models::SetKeyConnectorKeyRequestModel>,
47    ) -> Result<(), Error<PostSetKeyConnectorKeyError>>;
48
49    /// POST /accounts/key-management/regenerate-keys
50    async fn regenerate_keys<'a>(
51        &self,
52        key_regeneration_request_model: Option<models::KeyRegenerationRequestModel>,
53    ) -> Result<(), Error<RegenerateKeysError>>;
54
55    /// POST /accounts/key-management/rotate-user-account-keys
56    async fn rotate_user_account_keys<'a>(
57        &self,
58        rotate_user_account_keys_and_data_request_model: Option<
59            models::RotateUserAccountKeysAndDataRequestModel,
60        >,
61    ) -> Result<(), Error<RotateUserAccountKeysError>>;
62}
63
64pub struct AccountsKeyManagementApiClient {
65    configuration: Arc<configuration::Configuration>,
66}
67
68impl AccountsKeyManagementApiClient {
69    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
70        Self { configuration }
71    }
72}
73
74#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
75#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
76impl AccountsKeyManagementApi for AccountsKeyManagementApiClient {
77    async fn get_key_connector_confirmation_details<'a>(
78        &self,
79        org_sso_identifier: &'a str,
80    ) -> Result<
81        models::KeyConnectorConfirmationDetailsResponseModel,
82        Error<GetKeyConnectorConfirmationDetailsError>,
83    > {
84        let local_var_configuration = &self.configuration;
85
86        let local_var_client = &local_var_configuration.client;
87
88        let local_var_uri_str = format!(
89            "{}/accounts/key-connector/confirmation-details/{orgSsoIdentifier}",
90            local_var_configuration.base_path,
91            orgSsoIdentifier = crate::apis::urlencode(org_sso_identifier)
92        );
93        let mut local_var_req_builder =
94            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
95
96        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
97            local_var_req_builder = local_var_req_builder
98                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
99        }
100        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
101            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
102        };
103
104        let local_var_req = local_var_req_builder.build()?;
105        let local_var_resp = local_var_client.execute(local_var_req).await?;
106
107        let local_var_status = local_var_resp.status();
108        let local_var_content_type = local_var_resp
109            .headers()
110            .get("content-type")
111            .and_then(|v| v.to_str().ok())
112            .unwrap_or("application/octet-stream");
113        let local_var_content_type = super::ContentType::from(local_var_content_type);
114        let local_var_content = local_var_resp.text().await?;
115
116        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
117            match local_var_content_type {
118                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
119                ContentType::Text => {
120                    return Err(Error::from(serde_json::Error::custom(
121                        "Received `text/plain` content type response that cannot be converted to `models::KeyConnectorConfirmationDetailsResponseModel`",
122                    )));
123                }
124                ContentType::Unsupported(local_var_unknown_type) => {
125                    return Err(Error::from(serde_json::Error::custom(format!(
126                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::KeyConnectorConfirmationDetailsResponseModel`"
127                    ))));
128                }
129            }
130        } else {
131            let local_var_entity: Option<GetKeyConnectorConfirmationDetailsError> =
132                serde_json::from_str(&local_var_content).ok();
133            let local_var_error = ResponseContent {
134                status: local_var_status,
135                content: local_var_content,
136                entity: local_var_entity,
137            };
138            Err(Error::ResponseError(local_var_error))
139        }
140    }
141
142    async fn post_convert_to_key_connector(
143        &self,
144    ) -> Result<(), Error<PostConvertToKeyConnectorError>> {
145        let local_var_configuration = &self.configuration;
146
147        let local_var_client = &local_var_configuration.client;
148
149        let local_var_uri_str = format!(
150            "{}/accounts/convert-to-key-connector",
151            local_var_configuration.base_path
152        );
153        let mut local_var_req_builder =
154            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
155
156        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
157            local_var_req_builder = local_var_req_builder
158                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
159        }
160        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
161            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
162        };
163
164        let local_var_req = local_var_req_builder.build()?;
165        let local_var_resp = local_var_client.execute(local_var_req).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<PostConvertToKeyConnectorError> =
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 post_set_key_connector_key<'a>(
185        &self,
186        set_key_connector_key_request_model: Option<models::SetKeyConnectorKeyRequestModel>,
187    ) -> Result<(), Error<PostSetKeyConnectorKeyError>> {
188        let local_var_configuration = &self.configuration;
189
190        let local_var_client = &local_var_configuration.client;
191
192        let local_var_uri_str = format!(
193            "{}/accounts/set-key-connector-key",
194            local_var_configuration.base_path
195        );
196        let mut local_var_req_builder =
197            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
198
199        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
200            local_var_req_builder = local_var_req_builder
201                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
202        }
203        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
204            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
205        };
206        local_var_req_builder = local_var_req_builder.json(&set_key_connector_key_request_model);
207
208        let local_var_req = local_var_req_builder.build()?;
209        let local_var_resp = local_var_client.execute(local_var_req).await?;
210
211        let local_var_status = local_var_resp.status();
212        let local_var_content = local_var_resp.text().await?;
213
214        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
215            Ok(())
216        } else {
217            let local_var_entity: Option<PostSetKeyConnectorKeyError> =
218                serde_json::from_str(&local_var_content).ok();
219            let local_var_error = ResponseContent {
220                status: local_var_status,
221                content: local_var_content,
222                entity: local_var_entity,
223            };
224            Err(Error::ResponseError(local_var_error))
225        }
226    }
227
228    async fn regenerate_keys<'a>(
229        &self,
230        key_regeneration_request_model: Option<models::KeyRegenerationRequestModel>,
231    ) -> Result<(), Error<RegenerateKeysError>> {
232        let local_var_configuration = &self.configuration;
233
234        let local_var_client = &local_var_configuration.client;
235
236        let local_var_uri_str = format!(
237            "{}/accounts/key-management/regenerate-keys",
238            local_var_configuration.base_path
239        );
240        let mut local_var_req_builder =
241            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
242
243        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
244            local_var_req_builder = local_var_req_builder
245                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
246        }
247        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
248            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
249        };
250        local_var_req_builder = local_var_req_builder.json(&key_regeneration_request_model);
251
252        let local_var_req = local_var_req_builder.build()?;
253        let local_var_resp = local_var_client.execute(local_var_req).await?;
254
255        let local_var_status = local_var_resp.status();
256        let local_var_content = local_var_resp.text().await?;
257
258        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
259            Ok(())
260        } else {
261            let local_var_entity: Option<RegenerateKeysError> =
262                serde_json::from_str(&local_var_content).ok();
263            let local_var_error = ResponseContent {
264                status: local_var_status,
265                content: local_var_content,
266                entity: local_var_entity,
267            };
268            Err(Error::ResponseError(local_var_error))
269        }
270    }
271
272    async fn rotate_user_account_keys<'a>(
273        &self,
274        rotate_user_account_keys_and_data_request_model: Option<
275            models::RotateUserAccountKeysAndDataRequestModel,
276        >,
277    ) -> Result<(), Error<RotateUserAccountKeysError>> {
278        let local_var_configuration = &self.configuration;
279
280        let local_var_client = &local_var_configuration.client;
281
282        let local_var_uri_str = format!(
283            "{}/accounts/key-management/rotate-user-account-keys",
284            local_var_configuration.base_path
285        );
286        let mut local_var_req_builder =
287            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
288
289        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
290            local_var_req_builder = local_var_req_builder
291                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
292        }
293        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
294            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
295        };
296        local_var_req_builder =
297            local_var_req_builder.json(&rotate_user_account_keys_and_data_request_model);
298
299        let local_var_req = local_var_req_builder.build()?;
300        let local_var_resp = local_var_client.execute(local_var_req).await?;
301
302        let local_var_status = local_var_resp.status();
303        let local_var_content = local_var_resp.text().await?;
304
305        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
306            Ok(())
307        } else {
308            let local_var_entity: Option<RotateUserAccountKeysError> =
309                serde_json::from_str(&local_var_content).ok();
310            let local_var_error = ResponseContent {
311                status: local_var_status,
312                content: local_var_content,
313                entity: local_var_entity,
314            };
315            Err(Error::ResponseError(local_var_error))
316        }
317    }
318}
319
320/// struct for typed errors of method
321/// [`AccountsKeyManagementApi::get_key_connector_confirmation_details`]
322#[derive(Debug, Clone, Serialize, Deserialize)]
323#[serde(untagged)]
324pub enum GetKeyConnectorConfirmationDetailsError {
325    UnknownValue(serde_json::Value),
326}
327/// struct for typed errors of method [`AccountsKeyManagementApi::post_convert_to_key_connector`]
328#[derive(Debug, Clone, Serialize, Deserialize)]
329#[serde(untagged)]
330pub enum PostConvertToKeyConnectorError {
331    UnknownValue(serde_json::Value),
332}
333/// struct for typed errors of method [`AccountsKeyManagementApi::post_set_key_connector_key`]
334#[derive(Debug, Clone, Serialize, Deserialize)]
335#[serde(untagged)]
336pub enum PostSetKeyConnectorKeyError {
337    UnknownValue(serde_json::Value),
338}
339/// struct for typed errors of method [`AccountsKeyManagementApi::regenerate_keys`]
340#[derive(Debug, Clone, Serialize, Deserialize)]
341#[serde(untagged)]
342pub enum RegenerateKeysError {
343    UnknownValue(serde_json::Value),
344}
345/// struct for typed errors of method [`AccountsKeyManagementApi::rotate_user_account_keys`]
346#[derive(Debug, Clone, Serialize, Deserialize)]
347#[serde(untagged)]
348pub enum RotateUserAccountKeysError {
349    UnknownValue(serde_json::Value),
350}