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::{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 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 async fn get_pending_requests<'a>(
40 &self,
41 org_id: uuid::Uuid,
42 ) -> Result<
43 models::PendingOrganizationAuthRequestResponseModelListResponseModel,
44 Error<GetPendingRequestsError>,
45 >;
46
47 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 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 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
98 local_var_req_builder = local_var_req_builder
99 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
100 }
101 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
102 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
103 };
104 local_var_req_builder =
105 local_var_req_builder.json(&bulk_deny_admin_auth_request_request_model);
106
107 let local_var_req = local_var_req_builder.build()?;
108 let local_var_resp = local_var_client.execute(local_var_req).await?;
109
110 let local_var_status = local_var_resp.status();
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 Ok(())
115 } else {
116 let local_var_entity: Option<BulkDenyRequestsError> =
117 serde_json::from_str(&local_var_content).ok();
118 let local_var_error = ResponseContent {
119 status: local_var_status,
120 content: local_var_content,
121 entity: local_var_entity,
122 };
123 Err(Error::ResponseError(local_var_error))
124 }
125 }
126
127 async fn get_pending_requests<'a>(
128 &self,
129 org_id: uuid::Uuid,
130 ) -> Result<
131 models::PendingOrganizationAuthRequestResponseModelListResponseModel,
132 Error<GetPendingRequestsError>,
133 > {
134 let local_var_configuration = &self.configuration;
135
136 let local_var_client = &local_var_configuration.client;
137
138 let local_var_uri_str = format!(
139 "{}/organizations/{orgId}/auth-requests",
140 local_var_configuration.base_path,
141 orgId = org_id
142 );
143 let mut local_var_req_builder =
144 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
145
146 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
147 local_var_req_builder = local_var_req_builder
148 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
149 }
150 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
151 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
152 };
153
154 let local_var_req = local_var_req_builder.build()?;
155 let local_var_resp = local_var_client.execute(local_var_req).await?;
156
157 let local_var_status = local_var_resp.status();
158 let local_var_content_type = local_var_resp
159 .headers()
160 .get("content-type")
161 .and_then(|v| v.to_str().ok())
162 .unwrap_or("application/octet-stream");
163 let local_var_content_type = super::ContentType::from(local_var_content_type);
164 let local_var_content = local_var_resp.text().await?;
165
166 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
167 match local_var_content_type {
168 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
169 ContentType::Text => {
170 return Err(Error::from(serde_json::Error::custom(
171 "Received `text/plain` content type response that cannot be converted to `models::PendingOrganizationAuthRequestResponseModelListResponseModel`",
172 )));
173 }
174 ContentType::Unsupported(local_var_unknown_type) => {
175 return Err(Error::from(serde_json::Error::custom(format!(
176 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::PendingOrganizationAuthRequestResponseModelListResponseModel`"
177 ))));
178 }
179 }
180 } else {
181 let local_var_entity: Option<GetPendingRequestsError> =
182 serde_json::from_str(&local_var_content).ok();
183 let local_var_error = ResponseContent {
184 status: local_var_status,
185 content: local_var_content,
186 entity: local_var_entity,
187 };
188 Err(Error::ResponseError(local_var_error))
189 }
190 }
191
192 async fn update_auth_request<'a>(
193 &self,
194 org_id: uuid::Uuid,
195 request_id: uuid::Uuid,
196 admin_auth_request_update_request_model: Option<models::AdminAuthRequestUpdateRequestModel>,
197 ) -> Result<(), Error<UpdateAuthRequestError>> {
198 let local_var_configuration = &self.configuration;
199
200 let local_var_client = &local_var_configuration.client;
201
202 let local_var_uri_str = format!(
203 "{}/organizations/{orgId}/auth-requests/{requestId}",
204 local_var_configuration.base_path,
205 orgId = org_id,
206 requestId = request_id
207 );
208 let mut local_var_req_builder =
209 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
210
211 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
212 local_var_req_builder = local_var_req_builder
213 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
214 }
215 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
216 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
217 };
218 local_var_req_builder =
219 local_var_req_builder.json(&admin_auth_request_update_request_model);
220
221 let local_var_req = local_var_req_builder.build()?;
222 let local_var_resp = local_var_client.execute(local_var_req).await?;
223
224 let local_var_status = local_var_resp.status();
225 let local_var_content = local_var_resp.text().await?;
226
227 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
228 Ok(())
229 } else {
230 let local_var_entity: Option<UpdateAuthRequestError> =
231 serde_json::from_str(&local_var_content).ok();
232 let local_var_error = ResponseContent {
233 status: local_var_status,
234 content: local_var_content,
235 entity: local_var_entity,
236 };
237 Err(Error::ResponseError(local_var_error))
238 }
239 }
240
241 async fn update_many_auth_requests<'a>(
242 &self,
243 org_id: uuid::Uuid,
244 organization_auth_request_update_many_request_model: Option<
245 Vec<models::OrganizationAuthRequestUpdateManyRequestModel>,
246 >,
247 ) -> Result<(), Error<UpdateManyAuthRequestsError>> {
248 let local_var_configuration = &self.configuration;
249
250 let local_var_client = &local_var_configuration.client;
251
252 let local_var_uri_str = format!(
253 "{}/organizations/{orgId}/auth-requests",
254 local_var_configuration.base_path,
255 orgId = org_id
256 );
257 let mut local_var_req_builder =
258 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
259
260 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
261 local_var_req_builder = local_var_req_builder
262 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
263 }
264 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
265 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
266 };
267 local_var_req_builder =
268 local_var_req_builder.json(&organization_auth_request_update_many_request_model);
269
270 let local_var_req = local_var_req_builder.build()?;
271 let local_var_resp = local_var_client.execute(local_var_req).await?;
272
273 let local_var_status = local_var_resp.status();
274 let local_var_content = local_var_resp.text().await?;
275
276 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
277 Ok(())
278 } else {
279 let local_var_entity: Option<UpdateManyAuthRequestsError> =
280 serde_json::from_str(&local_var_content).ok();
281 let local_var_error = ResponseContent {
282 status: local_var_status,
283 content: local_var_content,
284 entity: local_var_entity,
285 };
286 Err(Error::ResponseError(local_var_error))
287 }
288 }
289}
290
291#[derive(Debug, Clone, Serialize, Deserialize)]
293#[serde(untagged)]
294pub enum BulkDenyRequestsError {
295 UnknownValue(serde_json::Value),
296}
297#[derive(Debug, Clone, Serialize, Deserialize)]
299#[serde(untagged)]
300pub enum GetPendingRequestsError {
301 UnknownValue(serde_json::Value),
302}
303#[derive(Debug, Clone, Serialize, Deserialize)]
305#[serde(untagged)]
306pub enum UpdateAuthRequestError {
307 UnknownValue(serde_json::Value),
308}
309#[derive(Debug, Clone, Serialize, Deserialize)]
311#[serde(untagged)]
312pub enum UpdateManyAuthRequestsError {
313 UnknownValue(serde_json::Value),
314}