1use 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 AccountsKeyManagementApi: Send + Sync {
29 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 async fn post_convert_to_key_connector(
40 &self,
41 ) -> Result<(), Error<PostConvertToKeyConnectorError>>;
42
43 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 async fn regenerate_keys<'a>(
51 &self,
52 key_regeneration_request_model: Option<models::KeyRegenerationRequestModel>,
53 ) -> Result<(), Error<RegenerateKeysError>>;
54
55 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_token) = local_var_configuration.oauth_access_token {
97 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
98 };
99 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
100
101 let local_var_req = local_var_req_builder.build()?;
102 let local_var_resp = local_var_client.execute(local_var_req).await?;
103
104 let local_var_status = local_var_resp.status();
105 let local_var_content_type = local_var_resp
106 .headers()
107 .get("content-type")
108 .and_then(|v| v.to_str().ok())
109 .unwrap_or("application/octet-stream");
110 let local_var_content_type = super::ContentType::from(local_var_content_type);
111 let local_var_content = local_var_resp.text().await?;
112
113 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
114 match local_var_content_type {
115 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
116 ContentType::Text => {
117 return Err(Error::from(serde_json::Error::custom(
118 "Received `text/plain` content type response that cannot be converted to `models::KeyConnectorConfirmationDetailsResponseModel`",
119 )));
120 }
121 ContentType::Unsupported(local_var_unknown_type) => {
122 return Err(Error::from(serde_json::Error::custom(format!(
123 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::KeyConnectorConfirmationDetailsResponseModel`"
124 ))));
125 }
126 }
127 } else {
128 let local_var_entity: Option<GetKeyConnectorConfirmationDetailsError> =
129 serde_json::from_str(&local_var_content).ok();
130 let local_var_error = ResponseContent {
131 status: local_var_status,
132 content: local_var_content,
133 entity: local_var_entity,
134 };
135 Err(Error::ResponseError(local_var_error))
136 }
137 }
138
139 async fn post_convert_to_key_connector(
140 &self,
141 ) -> Result<(), Error<PostConvertToKeyConnectorError>> {
142 let local_var_configuration = &self.configuration;
143
144 let local_var_client = &local_var_configuration.client;
145
146 let local_var_uri_str = format!(
147 "{}/accounts/convert-to-key-connector",
148 local_var_configuration.base_path
149 );
150 let mut local_var_req_builder =
151 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
152
153 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
154 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
155 };
156 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
157
158 let local_var_req = local_var_req_builder.build()?;
159 let local_var_resp = local_var_client.execute(local_var_req).await?;
160
161 let local_var_status = local_var_resp.status();
162 let local_var_content = local_var_resp.text().await?;
163
164 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
165 Ok(())
166 } else {
167 let local_var_entity: Option<PostConvertToKeyConnectorError> =
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 post_set_key_connector_key<'a>(
179 &self,
180 set_key_connector_key_request_model: Option<models::SetKeyConnectorKeyRequestModel>,
181 ) -> Result<(), Error<PostSetKeyConnectorKeyError>> {
182 let local_var_configuration = &self.configuration;
183
184 let local_var_client = &local_var_configuration.client;
185
186 let local_var_uri_str = format!(
187 "{}/accounts/set-key-connector-key",
188 local_var_configuration.base_path
189 );
190 let mut local_var_req_builder =
191 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
192
193 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
194 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
195 };
196 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
197 local_var_req_builder = local_var_req_builder.json(&set_key_connector_key_request_model);
198
199 let local_var_req = local_var_req_builder.build()?;
200 let local_var_resp = local_var_client.execute(local_var_req).await?;
201
202 let local_var_status = local_var_resp.status();
203 let local_var_content = local_var_resp.text().await?;
204
205 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
206 Ok(())
207 } else {
208 let local_var_entity: Option<PostSetKeyConnectorKeyError> =
209 serde_json::from_str(&local_var_content).ok();
210 let local_var_error = ResponseContent {
211 status: local_var_status,
212 content: local_var_content,
213 entity: local_var_entity,
214 };
215 Err(Error::ResponseError(local_var_error))
216 }
217 }
218
219 async fn regenerate_keys<'a>(
220 &self,
221 key_regeneration_request_model: Option<models::KeyRegenerationRequestModel>,
222 ) -> Result<(), Error<RegenerateKeysError>> {
223 let local_var_configuration = &self.configuration;
224
225 let local_var_client = &local_var_configuration.client;
226
227 let local_var_uri_str = format!(
228 "{}/accounts/key-management/regenerate-keys",
229 local_var_configuration.base_path
230 );
231 let mut local_var_req_builder =
232 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
233
234 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
235 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
236 };
237 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
238 local_var_req_builder = local_var_req_builder.json(&key_regeneration_request_model);
239
240 let local_var_req = local_var_req_builder.build()?;
241 let local_var_resp = local_var_client.execute(local_var_req).await?;
242
243 let local_var_status = local_var_resp.status();
244 let local_var_content = local_var_resp.text().await?;
245
246 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
247 Ok(())
248 } else {
249 let local_var_entity: Option<RegenerateKeysError> =
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 rotate_user_account_keys<'a>(
261 &self,
262 rotate_user_account_keys_and_data_request_model: Option<
263 models::RotateUserAccountKeysAndDataRequestModel,
264 >,
265 ) -> Result<(), Error<RotateUserAccountKeysError>> {
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 "{}/accounts/key-management/rotate-user-account-keys",
272 local_var_configuration.base_path
273 );
274 let mut local_var_req_builder =
275 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
276
277 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
278 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
279 };
280 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
281 local_var_req_builder =
282 local_var_req_builder.json(&rotate_user_account_keys_and_data_request_model);
283
284 let local_var_req = local_var_req_builder.build()?;
285 let local_var_resp = local_var_client.execute(local_var_req).await?;
286
287 let local_var_status = local_var_resp.status();
288 let local_var_content = local_var_resp.text().await?;
289
290 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
291 Ok(())
292 } else {
293 let local_var_entity: Option<RotateUserAccountKeysError> =
294 serde_json::from_str(&local_var_content).ok();
295 let local_var_error = ResponseContent {
296 status: local_var_status,
297 content: local_var_content,
298 entity: local_var_entity,
299 };
300 Err(Error::ResponseError(local_var_error))
301 }
302 }
303}
304
305#[derive(Debug, Clone, Serialize, Deserialize)]
308#[serde(untagged)]
309pub enum GetKeyConnectorConfirmationDetailsError {
310 UnknownValue(serde_json::Value),
311}
312#[derive(Debug, Clone, Serialize, Deserialize)]
314#[serde(untagged)]
315pub enum PostConvertToKeyConnectorError {
316 UnknownValue(serde_json::Value),
317}
318#[derive(Debug, Clone, Serialize, Deserialize)]
320#[serde(untagged)]
321pub enum PostSetKeyConnectorKeyError {
322 UnknownValue(serde_json::Value),
323}
324#[derive(Debug, Clone, Serialize, Deserialize)]
326#[serde(untagged)]
327pub enum RegenerateKeysError {
328 UnknownValue(serde_json::Value),
329}
330#[derive(Debug, Clone, Serialize, Deserialize)]
332#[serde(untagged)]
333pub enum RotateUserAccountKeysError {
334 UnknownValue(serde_json::Value),
335}