1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateUserError {
22 Status400(models::ErrorResponse),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum DeleteUserError {
30 Status404(models::ErrorResponse),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetCurrentUserError {
38 Status401(models::ErrorResponse),
39 UnknownValue(serde_json::Value),
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum GetUserApiKeyError {
46 Status404(models::ErrorResponse),
47 UnknownValue(serde_json::Value),
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum GetUserByIdError {
54 Status404(models::ErrorResponse),
55 UnknownValue(serde_json::Value),
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum RemoveUserApiKeyError {
62 Status404(models::ErrorResponse),
63 UnknownValue(serde_json::Value),
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum RenewUserApiKeyError {
70 Status404(models::ErrorResponse),
71 UnknownValue(serde_json::Value),
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum SetUserOrganisationsError {
78 Status400(models::ErrorResponse),
79 UnknownValue(serde_json::Value),
80}
81
82#[derive(Debug, Clone, Serialize, Deserialize)]
84#[serde(untagged)]
85pub enum SetUserPasswordError {
86 Status400(models::ErrorResponse),
87 UnknownValue(serde_json::Value),
88}
89
90#[derive(Debug, Clone, Serialize, Deserialize)]
92#[serde(untagged)]
93pub enum UpdateUserError {
94 Status400(models::ErrorResponse),
95 UnknownValue(serde_json::Value),
96}
97
98
99pub async fn create_user(configuration: &configuration::Configuration, input_user: models::InputUser, x_organisation: Option<&str>) -> Result<models::OutputUser, Error<CreateUserError>> {
100 let p_input_user = input_user;
102 let p_x_organisation = x_organisation;
103
104 let uri_str = format!("{}/v1/user", configuration.base_path);
105 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
106
107 if let Some(ref user_agent) = configuration.user_agent {
108 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
109 }
110 if let Some(param_value) = p_x_organisation {
111 req_builder = req_builder.header("X-Organisation", param_value.to_string());
112 }
113 if let Some(ref auth_conf) = configuration.basic_auth {
114 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
115 };
116 if let Some(ref token) = configuration.bearer_access_token {
117 req_builder = req_builder.bearer_auth(token.to_owned());
118 };
119 req_builder = req_builder.json(&p_input_user);
120
121 let req = req_builder.build()?;
122 let resp = configuration.client.execute(req).await?;
123
124 let status = resp.status();
125 let content_type = resp
126 .headers()
127 .get("content-type")
128 .and_then(|v| v.to_str().ok())
129 .unwrap_or("application/octet-stream");
130 let content_type = super::ContentType::from(content_type);
131
132 if !status.is_client_error() && !status.is_server_error() {
133 let content = resp.text().await?;
134 match content_type {
135 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
136 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OutputUser`"))),
137 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::OutputUser`")))),
138 }
139 } else {
140 let content = resp.text().await?;
141 let entity: Option<CreateUserError> = serde_json::from_str(&content).ok();
142 Err(Error::ResponseError(ResponseContent { status, content, entity }))
143 }
144}
145
146pub async fn delete_user(configuration: &configuration::Configuration, user_id: &str, organisation: Option<&str>, x_organisation: Option<&str>) -> Result<(), Error<DeleteUserError>> {
147 let p_user_id = user_id;
149 let p_organisation = organisation;
150 let p_x_organisation = x_organisation;
151
152 let uri_str = format!("{}/v1/user/{user_id}/force", configuration.base_path, user_id=crate::apis::urlencode(p_user_id));
153 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
154
155 if let Some(ref param_value) = p_organisation {
156 req_builder = req_builder.query(&[("organisation", ¶m_value.to_string())]);
157 }
158 if let Some(ref user_agent) = configuration.user_agent {
159 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
160 }
161 if let Some(param_value) = p_x_organisation {
162 req_builder = req_builder.header("X-Organisation", param_value.to_string());
163 }
164 if let Some(ref auth_conf) = configuration.basic_auth {
165 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
166 };
167 if let Some(ref token) = configuration.bearer_access_token {
168 req_builder = req_builder.bearer_auth(token.to_owned());
169 };
170
171 let req = req_builder.build()?;
172 let resp = configuration.client.execute(req).await?;
173
174 let status = resp.status();
175
176 if !status.is_client_error() && !status.is_server_error() {
177 Ok(())
178 } else {
179 let content = resp.text().await?;
180 let entity: Option<DeleteUserError> = serde_json::from_str(&content).ok();
181 Err(Error::ResponseError(ResponseContent { status, content, entity }))
182 }
183}
184
185pub async fn get_current_user(configuration: &configuration::Configuration, x_organisation: Option<&str>) -> Result<models::OutputUser, Error<GetCurrentUserError>> {
186 let p_x_organisation = x_organisation;
188
189 let uri_str = format!("{}/v1/user/current", configuration.base_path);
190 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
191
192 if let Some(ref user_agent) = configuration.user_agent {
193 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
194 }
195 if let Some(param_value) = p_x_organisation {
196 req_builder = req_builder.header("X-Organisation", param_value.to_string());
197 }
198 if let Some(ref auth_conf) = configuration.basic_auth {
199 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
200 };
201 if let Some(ref token) = configuration.bearer_access_token {
202 req_builder = req_builder.bearer_auth(token.to_owned());
203 };
204
205 let req = req_builder.build()?;
206 let resp = configuration.client.execute(req).await?;
207
208 let status = resp.status();
209 let content_type = resp
210 .headers()
211 .get("content-type")
212 .and_then(|v| v.to_str().ok())
213 .unwrap_or("application/octet-stream");
214 let content_type = super::ContentType::from(content_type);
215
216 if !status.is_client_error() && !status.is_server_error() {
217 let content = resp.text().await?;
218 match content_type {
219 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
220 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OutputUser`"))),
221 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::OutputUser`")))),
222 }
223 } else {
224 let content = resp.text().await?;
225 let entity: Option<GetCurrentUserError> = serde_json::from_str(&content).ok();
226 Err(Error::ResponseError(ResponseContent { status, content, entity }))
227 }
228}
229
230pub async fn get_user_api_key(configuration: &configuration::Configuration, user_id: &str, x_organisation: Option<&str>) -> Result<String, Error<GetUserApiKeyError>> {
231 let p_user_id = user_id;
233 let p_x_organisation = x_organisation;
234
235 let uri_str = format!("{}/v1/user/{user_id}/key", configuration.base_path, user_id=crate::apis::urlencode(p_user_id));
236 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
237
238 if let Some(ref user_agent) = configuration.user_agent {
239 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
240 }
241 if let Some(param_value) = p_x_organisation {
242 req_builder = req_builder.header("X-Organisation", param_value.to_string());
243 }
244 if let Some(ref auth_conf) = configuration.basic_auth {
245 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
246 };
247 if let Some(ref token) = configuration.bearer_access_token {
248 req_builder = req_builder.bearer_auth(token.to_owned());
249 };
250
251 let req = req_builder.build()?;
252 let resp = configuration.client.execute(req).await?;
253
254 let status = resp.status();
255 let content_type = resp
256 .headers()
257 .get("content-type")
258 .and_then(|v| v.to_str().ok())
259 .unwrap_or("application/octet-stream");
260 let content_type = super::ContentType::from(content_type);
261
262 if !status.is_client_error() && !status.is_server_error() {
263 let content = resp.text().await?;
264 match content_type {
265 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
266 ContentType::Text => return Ok(content),
267 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))),
268 }
269 } else {
270 let content = resp.text().await?;
271 let entity: Option<GetUserApiKeyError> = serde_json::from_str(&content).ok();
272 Err(Error::ResponseError(ResponseContent { status, content, entity }))
273 }
274}
275
276pub async fn get_user_by_id(configuration: &configuration::Configuration, user_id: &str, x_organisation: Option<&str>) -> Result<models::OutputUser, Error<GetUserByIdError>> {
277 let p_user_id = user_id;
279 let p_x_organisation = x_organisation;
280
281 let uri_str = format!("{}/v1/user/{user_id}", configuration.base_path, user_id=crate::apis::urlencode(p_user_id));
282 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
283
284 if let Some(ref user_agent) = configuration.user_agent {
285 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
286 }
287 if let Some(param_value) = p_x_organisation {
288 req_builder = req_builder.header("X-Organisation", param_value.to_string());
289 }
290 if let Some(ref auth_conf) = configuration.basic_auth {
291 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
292 };
293 if let Some(ref token) = configuration.bearer_access_token {
294 req_builder = req_builder.bearer_auth(token.to_owned());
295 };
296
297 let req = req_builder.build()?;
298 let resp = configuration.client.execute(req).await?;
299
300 let status = resp.status();
301 let content_type = resp
302 .headers()
303 .get("content-type")
304 .and_then(|v| v.to_str().ok())
305 .unwrap_or("application/octet-stream");
306 let content_type = super::ContentType::from(content_type);
307
308 if !status.is_client_error() && !status.is_server_error() {
309 let content = resp.text().await?;
310 match content_type {
311 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
312 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OutputUser`"))),
313 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::OutputUser`")))),
314 }
315 } else {
316 let content = resp.text().await?;
317 let entity: Option<GetUserByIdError> = serde_json::from_str(&content).ok();
318 Err(Error::ResponseError(ResponseContent { status, content, entity }))
319 }
320}
321
322pub async fn remove_user_api_key(configuration: &configuration::Configuration, user_id: &str, x_organisation: Option<&str>) -> Result<(), Error<RemoveUserApiKeyError>> {
323 let p_user_id = user_id;
325 let p_x_organisation = x_organisation;
326
327 let uri_str = format!("{}/v1/user/{user_id}/key", configuration.base_path, user_id=crate::apis::urlencode(p_user_id));
328 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
329
330 if let Some(ref user_agent) = configuration.user_agent {
331 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
332 }
333 if let Some(param_value) = p_x_organisation {
334 req_builder = req_builder.header("X-Organisation", param_value.to_string());
335 }
336 if let Some(ref auth_conf) = configuration.basic_auth {
337 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
338 };
339 if let Some(ref token) = configuration.bearer_access_token {
340 req_builder = req_builder.bearer_auth(token.to_owned());
341 };
342
343 let req = req_builder.build()?;
344 let resp = configuration.client.execute(req).await?;
345
346 let status = resp.status();
347
348 if !status.is_client_error() && !status.is_server_error() {
349 Ok(())
350 } else {
351 let content = resp.text().await?;
352 let entity: Option<RemoveUserApiKeyError> = serde_json::from_str(&content).ok();
353 Err(Error::ResponseError(ResponseContent { status, content, entity }))
354 }
355}
356
357pub async fn renew_user_api_key(configuration: &configuration::Configuration, user_id: &str, x_organisation: Option<&str>) -> Result<String, Error<RenewUserApiKeyError>> {
358 let p_user_id = user_id;
360 let p_x_organisation = x_organisation;
361
362 let uri_str = format!("{}/v1/user/{user_id}/key/renew", configuration.base_path, user_id=crate::apis::urlencode(p_user_id));
363 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
364
365 if let Some(ref user_agent) = configuration.user_agent {
366 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
367 }
368 if let Some(param_value) = p_x_organisation {
369 req_builder = req_builder.header("X-Organisation", param_value.to_string());
370 }
371 if let Some(ref auth_conf) = configuration.basic_auth {
372 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
373 };
374 if let Some(ref token) = configuration.bearer_access_token {
375 req_builder = req_builder.bearer_auth(token.to_owned());
376 };
377
378 let req = req_builder.build()?;
379 let resp = configuration.client.execute(req).await?;
380
381 let status = resp.status();
382 let content_type = resp
383 .headers()
384 .get("content-type")
385 .and_then(|v| v.to_str().ok())
386 .unwrap_or("application/octet-stream");
387 let content_type = super::ContentType::from(content_type);
388
389 if !status.is_client_error() && !status.is_server_error() {
390 let content = resp.text().await?;
391 match content_type {
392 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
393 ContentType::Text => return Ok(content),
394 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))),
395 }
396 } else {
397 let content = resp.text().await?;
398 let entity: Option<RenewUserApiKeyError> = serde_json::from_str(&content).ok();
399 Err(Error::ResponseError(ResponseContent { status, content, entity }))
400 }
401}
402
403pub async fn set_user_organisations(configuration: &configuration::Configuration, user_id: &str, set_user_organisations_request: models::SetUserOrganisationsRequest, x_organisation: Option<&str>) -> Result<models::SetUserOrganisations200Response, Error<SetUserOrganisationsError>> {
404 let p_user_id = user_id;
406 let p_set_user_organisations_request = set_user_organisations_request;
407 let p_x_organisation = x_organisation;
408
409 let uri_str = format!("{}/v1/user/{user_id}/organisations", configuration.base_path, user_id=crate::apis::urlencode(p_user_id));
410 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
411
412 if let Some(ref user_agent) = configuration.user_agent {
413 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
414 }
415 if let Some(param_value) = p_x_organisation {
416 req_builder = req_builder.header("X-Organisation", param_value.to_string());
417 }
418 if let Some(ref auth_conf) = configuration.basic_auth {
419 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
420 };
421 if let Some(ref token) = configuration.bearer_access_token {
422 req_builder = req_builder.bearer_auth(token.to_owned());
423 };
424 req_builder = req_builder.json(&p_set_user_organisations_request);
425
426 let req = req_builder.build()?;
427 let resp = configuration.client.execute(req).await?;
428
429 let status = resp.status();
430 let content_type = resp
431 .headers()
432 .get("content-type")
433 .and_then(|v| v.to_str().ok())
434 .unwrap_or("application/octet-stream");
435 let content_type = super::ContentType::from(content_type);
436
437 if !status.is_client_error() && !status.is_server_error() {
438 let content = resp.text().await?;
439 match content_type {
440 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
441 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SetUserOrganisations200Response`"))),
442 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SetUserOrganisations200Response`")))),
443 }
444 } else {
445 let content = resp.text().await?;
446 let entity: Option<SetUserOrganisationsError> = serde_json::from_str(&content).ok();
447 Err(Error::ResponseError(ResponseContent { status, content, entity }))
448 }
449}
450
451pub async fn set_user_password(configuration: &configuration::Configuration, user_id: &str, set_user_password_request: models::SetUserPasswordRequest, x_organisation: Option<&str>) -> Result<(), Error<SetUserPasswordError>> {
452 let p_user_id = user_id;
454 let p_set_user_password_request = set_user_password_request;
455 let p_x_organisation = x_organisation;
456
457 let uri_str = format!("{}/v1/user/{user_id}/password/set", configuration.base_path, user_id=crate::apis::urlencode(p_user_id));
458 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
459
460 if let Some(ref user_agent) = configuration.user_agent {
461 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
462 }
463 if let Some(param_value) = p_x_organisation {
464 req_builder = req_builder.header("X-Organisation", param_value.to_string());
465 }
466 if let Some(ref auth_conf) = configuration.basic_auth {
467 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
468 };
469 if let Some(ref token) = configuration.bearer_access_token {
470 req_builder = req_builder.bearer_auth(token.to_owned());
471 };
472 req_builder = req_builder.json(&p_set_user_password_request);
473
474 let req = req_builder.build()?;
475 let resp = configuration.client.execute(req).await?;
476
477 let status = resp.status();
478
479 if !status.is_client_error() && !status.is_server_error() {
480 Ok(())
481 } else {
482 let content = resp.text().await?;
483 let entity: Option<SetUserPasswordError> = serde_json::from_str(&content).ok();
484 Err(Error::ResponseError(ResponseContent { status, content, entity }))
485 }
486}
487
488pub async fn update_user(configuration: &configuration::Configuration, user_id: &str, input_update_user: models::InputUpdateUser, x_organisation: Option<&str>) -> Result<(), Error<UpdateUserError>> {
489 let p_user_id = user_id;
491 let p_input_update_user = input_update_user;
492 let p_x_organisation = x_organisation;
493
494 let uri_str = format!("{}/v1/user/{user_id}", configuration.base_path, user_id=crate::apis::urlencode(p_user_id));
495 let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
496
497 if let Some(ref user_agent) = configuration.user_agent {
498 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
499 }
500 if let Some(param_value) = p_x_organisation {
501 req_builder = req_builder.header("X-Organisation", param_value.to_string());
502 }
503 if let Some(ref auth_conf) = configuration.basic_auth {
504 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
505 };
506 if let Some(ref token) = configuration.bearer_access_token {
507 req_builder = req_builder.bearer_auth(token.to_owned());
508 };
509 req_builder = req_builder.json(&p_input_update_user);
510
511 let req = req_builder.build()?;
512 let resp = configuration.client.execute(req).await?;
513
514 let status = resp.status();
515
516 if !status.is_client_error() && !status.is_server_error() {
517 Ok(())
518 } else {
519 let content = resp.text().await?;
520 let entity: Option<UpdateUserError> = serde_json::from_str(&content).ok();
521 Err(Error::ResponseError(ResponseContent { status, content, entity }))
522 }
523}
524