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 ChangeUserPasswordError {
22 Status400(models::Error),
23 Status401(models::Error),
24 Status403(models::Error),
25 UnknownValue(serde_json::Value),
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum CreateUserError {
32 Status400(models::Error),
33 Status401(models::Error),
34 Status403(models::Error),
35 UnknownValue(serde_json::Value),
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum DeleteUserError {
42 Status400(models::Error),
43 Status401(models::Error),
44 Status403(models::Error),
45 Status404(models::Error),
46 UnknownValue(serde_json::Value),
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize)]
51#[serde(untagged)]
52pub enum FindUsersError {
53 Status401(models::Error),
54 Status403(models::Error),
55 UnknownValue(serde_json::Value),
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum FindUsersForOrganizationError {
62 Status401(models::Error),
63 Status403(models::Error),
64 UnknownValue(serde_json::Value),
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum GetCurrentUserError {
71 Status401(models::Error),
72 UnknownValue(serde_json::Value),
73}
74
75#[derive(Debug, Clone, Serialize, Deserialize)]
77#[serde(untagged)]
78pub enum GetUserApiKeyError {
79 Status400(models::Error),
80 Status401(models::Error),
81 Status403(models::Error),
82 Status404(models::Error),
83 UnknownValue(serde_json::Value),
84}
85
86#[derive(Debug, Clone, Serialize, Deserialize)]
88#[serde(untagged)]
89pub enum GetUserByIdError {
90 Status401(models::Error),
91 Status403(models::Error),
92 Status404(models::Error),
93 UnknownValue(serde_json::Value),
94}
95
96#[derive(Debug, Clone, Serialize, Deserialize)]
98#[serde(untagged)]
99pub enum RemoveUserApiKeyError {
100 Status401(models::Error),
101 Status403(models::Error),
102 Status404(models::Error),
103 UnknownValue(serde_json::Value),
104}
105
106#[derive(Debug, Clone, Serialize, Deserialize)]
108#[serde(untagged)]
109pub enum RenewUserApiKeyError {
110 Status401(models::Error),
111 Status403(models::Error),
112 Status404(models::Error),
113 UnknownValue(serde_json::Value),
114}
115
116#[derive(Debug, Clone, Serialize, Deserialize)]
118#[serde(untagged)]
119pub enum SetUserPasswordError {
120 Status400(models::Error),
121 Status401(models::Error),
122 Status403(models::Error),
123 Status404(models::Error),
124 UnknownValue(serde_json::Value),
125}
126
127#[derive(Debug, Clone, Serialize, Deserialize)]
129#[serde(untagged)]
130pub enum UpdateUserError {
131 Status400(models::Error),
132 Status401(models::Error),
133 Status403(models::Error),
134 Status404(models::Error),
135 UnknownValue(serde_json::Value),
136}
137
138
139pub async fn change_user_password(configuration: &configuration::Configuration, user_id: &str, password_change_request: models::PasswordChangeRequest) -> Result<(), Error<ChangeUserPasswordError>> {
140 let p_user_id = user_id;
142 let p_password_change_request = password_change_request;
143
144 let uri_str = format!("{}/user/{userId}/password/change", configuration.base_path, userId=crate::apis::urlencode(p_user_id));
145 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
146
147 if let Some(ref user_agent) = configuration.user_agent {
148 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
149 }
150 if let Some(ref token) = configuration.bearer_access_token {
151 req_builder = req_builder.bearer_auth(token.to_owned());
152 };
153 req_builder = req_builder.json(&p_password_change_request);
154
155 let req = req_builder.build()?;
156 let resp = configuration.client.execute(req).await?;
157
158 let status = resp.status();
159
160 if !status.is_client_error() && !status.is_server_error() {
161 Ok(())
162 } else {
163 let content = resp.text().await?;
164 let entity: Option<ChangeUserPasswordError> = serde_json::from_str(&content).ok();
165 Err(Error::ResponseError(ResponseContent { status, content, entity }))
166 }
167}
168
169pub async fn create_user(configuration: &configuration::Configuration, user_create_request: models::UserCreateRequest) -> Result<models::User, Error<CreateUserError>> {
170 let p_user_create_request = user_create_request;
172
173 let uri_str = format!("{}/user", configuration.base_path);
174 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
175
176 if let Some(ref user_agent) = configuration.user_agent {
177 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
178 }
179 if let Some(ref token) = configuration.bearer_access_token {
180 req_builder = req_builder.bearer_auth(token.to_owned());
181 };
182 req_builder = req_builder.json(&p_user_create_request);
183
184 let req = req_builder.build()?;
185 let resp = configuration.client.execute(req).await?;
186
187 let status = resp.status();
188 let content_type = resp
189 .headers()
190 .get("content-type")
191 .and_then(|v| v.to_str().ok())
192 .unwrap_or("application/octet-stream");
193 let content_type = super::ContentType::from(content_type);
194
195 if !status.is_client_error() && !status.is_server_error() {
196 let content = resp.text().await?;
197 match content_type {
198 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
199 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::User`"))),
200 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::User`")))),
201 }
202 } else {
203 let content = resp.text().await?;
204 let entity: Option<CreateUserError> = serde_json::from_str(&content).ok();
205 Err(Error::ResponseError(ResponseContent { status, content, entity }))
206 }
207}
208
209pub async fn delete_user(configuration: &configuration::Configuration, user_id: &str) -> Result<(), Error<DeleteUserError>> {
210 let p_user_id = user_id;
212
213 let uri_str = format!("{}/user/{userId}", configuration.base_path, userId=crate::apis::urlencode(p_user_id));
214 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
215
216 if let Some(ref user_agent) = configuration.user_agent {
217 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
218 }
219 if let Some(ref token) = configuration.bearer_access_token {
220 req_builder = req_builder.bearer_auth(token.to_owned());
221 };
222
223 let req = req_builder.build()?;
224 let resp = configuration.client.execute(req).await?;
225
226 let status = resp.status();
227
228 if !status.is_client_error() && !status.is_server_error() {
229 Ok(())
230 } else {
231 let content = resp.text().await?;
232 let entity: Option<DeleteUserError> = serde_json::from_str(&content).ok();
233 Err(Error::ResponseError(ResponseContent { status, content, entity }))
234 }
235}
236
237pub async fn find_users(configuration: &configuration::Configuration, analyzer_find_request: Option<models::AnalyzerFindRequest>) -> Result<models::FindUsers200Response, Error<FindUsersError>> {
238 let p_analyzer_find_request = analyzer_find_request;
240
241 let uri_str = format!("{}/user/_search", configuration.base_path);
242 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
243
244 if let Some(ref user_agent) = configuration.user_agent {
245 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
246 }
247 if let Some(ref token) = configuration.bearer_access_token {
248 req_builder = req_builder.bearer_auth(token.to_owned());
249 };
250 req_builder = req_builder.json(&p_analyzer_find_request);
251
252 let req = req_builder.build()?;
253 let resp = configuration.client.execute(req).await?;
254
255 let status = resp.status();
256 let content_type = resp
257 .headers()
258 .get("content-type")
259 .and_then(|v| v.to_str().ok())
260 .unwrap_or("application/octet-stream");
261 let content_type = super::ContentType::from(content_type);
262
263 if !status.is_client_error() && !status.is_server_error() {
264 let content = resp.text().await?;
265 match content_type {
266 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
267 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FindUsers200Response`"))),
268 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::FindUsers200Response`")))),
269 }
270 } else {
271 let content = resp.text().await?;
272 let entity: Option<FindUsersError> = serde_json::from_str(&content).ok();
273 Err(Error::ResponseError(ResponseContent { status, content, entity }))
274 }
275}
276
277pub async fn find_users_for_organization(configuration: &configuration::Configuration, organization_id: &str, analyzer_find_request: Option<models::AnalyzerFindRequest>) -> Result<models::FindUsers200Response, Error<FindUsersForOrganizationError>> {
278 let p_organization_id = organization_id;
280 let p_analyzer_find_request = analyzer_find_request;
281
282 let uri_str = format!("{}/user/organization/{organizationId}/_search", configuration.base_path, organizationId=crate::apis::urlencode(p_organization_id));
283 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
284
285 if let Some(ref user_agent) = configuration.user_agent {
286 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
287 }
288 if let Some(ref token) = configuration.bearer_access_token {
289 req_builder = req_builder.bearer_auth(token.to_owned());
290 };
291 req_builder = req_builder.json(&p_analyzer_find_request);
292
293 let req = req_builder.build()?;
294 let resp = configuration.client.execute(req).await?;
295
296 let status = resp.status();
297 let content_type = resp
298 .headers()
299 .get("content-type")
300 .and_then(|v| v.to_str().ok())
301 .unwrap_or("application/octet-stream");
302 let content_type = super::ContentType::from(content_type);
303
304 if !status.is_client_error() && !status.is_server_error() {
305 let content = resp.text().await?;
306 match content_type {
307 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
308 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FindUsers200Response`"))),
309 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::FindUsers200Response`")))),
310 }
311 } else {
312 let content = resp.text().await?;
313 let entity: Option<FindUsersForOrganizationError> = serde_json::from_str(&content).ok();
314 Err(Error::ResponseError(ResponseContent { status, content, entity }))
315 }
316}
317
318pub async fn get_current_user(configuration: &configuration::Configuration, ) -> Result<models::User, Error<GetCurrentUserError>> {
319
320 let uri_str = format!("{}/user/current", configuration.base_path);
321 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
322
323 if let Some(ref user_agent) = configuration.user_agent {
324 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
325 }
326 if let Some(ref token) = configuration.bearer_access_token {
327 req_builder = req_builder.bearer_auth(token.to_owned());
328 };
329
330 let req = req_builder.build()?;
331 let resp = configuration.client.execute(req).await?;
332
333 let status = resp.status();
334 let content_type = resp
335 .headers()
336 .get("content-type")
337 .and_then(|v| v.to_str().ok())
338 .unwrap_or("application/octet-stream");
339 let content_type = super::ContentType::from(content_type);
340
341 if !status.is_client_error() && !status.is_server_error() {
342 let content = resp.text().await?;
343 match content_type {
344 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
345 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::User`"))),
346 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::User`")))),
347 }
348 } else {
349 let content = resp.text().await?;
350 let entity: Option<GetCurrentUserError> = serde_json::from_str(&content).ok();
351 Err(Error::ResponseError(ResponseContent { status, content, entity }))
352 }
353}
354
355pub async fn get_user_api_key(configuration: &configuration::Configuration, user_id: &str) -> Result<String, Error<GetUserApiKeyError>> {
356 let p_user_id = user_id;
358
359 let uri_str = format!("{}/user/{userId}/key", configuration.base_path, userId=crate::apis::urlencode(p_user_id));
360 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
361
362 if let Some(ref user_agent) = configuration.user_agent {
363 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
364 }
365 if let Some(ref token) = configuration.bearer_access_token {
366 req_builder = req_builder.bearer_auth(token.to_owned());
367 };
368
369 let req = req_builder.build()?;
370 let resp = configuration.client.execute(req).await?;
371
372 let status = resp.status();
373 let content_type = resp
374 .headers()
375 .get("content-type")
376 .and_then(|v| v.to_str().ok())
377 .unwrap_or("application/octet-stream");
378 let content_type = super::ContentType::from(content_type);
379
380 if !status.is_client_error() && !status.is_server_error() {
381 let content = resp.text().await?;
382 match content_type {
383 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
384 ContentType::Text => return Ok(content),
385 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`")))),
386 }
387 } else {
388 let content = resp.text().await?;
389 let entity: Option<GetUserApiKeyError> = serde_json::from_str(&content).ok();
390 Err(Error::ResponseError(ResponseContent { status, content, entity }))
391 }
392}
393
394pub async fn get_user_by_id(configuration: &configuration::Configuration, user_id: &str) -> Result<models::User, Error<GetUserByIdError>> {
395 let p_user_id = user_id;
397
398 let uri_str = format!("{}/user/{userId}", configuration.base_path, userId=crate::apis::urlencode(p_user_id));
399 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
400
401 if let Some(ref user_agent) = configuration.user_agent {
402 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
403 }
404 if let Some(ref token) = configuration.bearer_access_token {
405 req_builder = req_builder.bearer_auth(token.to_owned());
406 };
407
408 let req = req_builder.build()?;
409 let resp = configuration.client.execute(req).await?;
410
411 let status = resp.status();
412 let content_type = resp
413 .headers()
414 .get("content-type")
415 .and_then(|v| v.to_str().ok())
416 .unwrap_or("application/octet-stream");
417 let content_type = super::ContentType::from(content_type);
418
419 if !status.is_client_error() && !status.is_server_error() {
420 let content = resp.text().await?;
421 match content_type {
422 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
423 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::User`"))),
424 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::User`")))),
425 }
426 } else {
427 let content = resp.text().await?;
428 let entity: Option<GetUserByIdError> = serde_json::from_str(&content).ok();
429 Err(Error::ResponseError(ResponseContent { status, content, entity }))
430 }
431}
432
433pub async fn remove_user_api_key(configuration: &configuration::Configuration, user_id: &str) -> Result<(), Error<RemoveUserApiKeyError>> {
434 let p_user_id = user_id;
436
437 let uri_str = format!("{}/user/{userId}/key", configuration.base_path, userId=crate::apis::urlencode(p_user_id));
438 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
439
440 if let Some(ref user_agent) = configuration.user_agent {
441 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
442 }
443 if let Some(ref token) = configuration.bearer_access_token {
444 req_builder = req_builder.bearer_auth(token.to_owned());
445 };
446
447 let req = req_builder.build()?;
448 let resp = configuration.client.execute(req).await?;
449
450 let status = resp.status();
451
452 if !status.is_client_error() && !status.is_server_error() {
453 Ok(())
454 } else {
455 let content = resp.text().await?;
456 let entity: Option<RemoveUserApiKeyError> = serde_json::from_str(&content).ok();
457 Err(Error::ResponseError(ResponseContent { status, content, entity }))
458 }
459}
460
461pub async fn renew_user_api_key(configuration: &configuration::Configuration, user_id: &str) -> Result<String, Error<RenewUserApiKeyError>> {
462 let p_user_id = user_id;
464
465 let uri_str = format!("{}/user/{userId}/key/renew", configuration.base_path, userId=crate::apis::urlencode(p_user_id));
466 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
467
468 if let Some(ref user_agent) = configuration.user_agent {
469 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
470 }
471 if let Some(ref token) = configuration.bearer_access_token {
472 req_builder = req_builder.bearer_auth(token.to_owned());
473 };
474
475 let req = req_builder.build()?;
476 let resp = configuration.client.execute(req).await?;
477
478 let status = resp.status();
479 let content_type = resp
480 .headers()
481 .get("content-type")
482 .and_then(|v| v.to_str().ok())
483 .unwrap_or("application/octet-stream");
484 let content_type = super::ContentType::from(content_type);
485
486 if !status.is_client_error() && !status.is_server_error() {
487 let content = resp.text().await?;
488 match content_type {
489 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
490 ContentType::Text => return Ok(content),
491 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`")))),
492 }
493 } else {
494 let content = resp.text().await?;
495 let entity: Option<RenewUserApiKeyError> = serde_json::from_str(&content).ok();
496 Err(Error::ResponseError(ResponseContent { status, content, entity }))
497 }
498}
499
500pub async fn set_user_password(configuration: &configuration::Configuration, user_id: &str, password_set_request: models::PasswordSetRequest) -> Result<(), Error<SetUserPasswordError>> {
501 let p_user_id = user_id;
503 let p_password_set_request = password_set_request;
504
505 let uri_str = format!("{}/user/{userId}/password/set", configuration.base_path, userId=crate::apis::urlencode(p_user_id));
506 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
507
508 if let Some(ref user_agent) = configuration.user_agent {
509 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
510 }
511 if let Some(ref token) = configuration.bearer_access_token {
512 req_builder = req_builder.bearer_auth(token.to_owned());
513 };
514 req_builder = req_builder.json(&p_password_set_request);
515
516 let req = req_builder.build()?;
517 let resp = configuration.client.execute(req).await?;
518
519 let status = resp.status();
520
521 if !status.is_client_error() && !status.is_server_error() {
522 Ok(())
523 } else {
524 let content = resp.text().await?;
525 let entity: Option<SetUserPasswordError> = serde_json::from_str(&content).ok();
526 Err(Error::ResponseError(ResponseContent { status, content, entity }))
527 }
528}
529
530pub async fn update_user(configuration: &configuration::Configuration, user_id: &str, user_update_request: models::UserUpdateRequest) -> Result<models::User, Error<UpdateUserError>> {
531 let p_user_id = user_id;
533 let p_user_update_request = user_update_request;
534
535 let uri_str = format!("{}/user/{userId}", configuration.base_path, userId=crate::apis::urlencode(p_user_id));
536 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
537
538 if let Some(ref user_agent) = configuration.user_agent {
539 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
540 }
541 if let Some(ref token) = configuration.bearer_access_token {
542 req_builder = req_builder.bearer_auth(token.to_owned());
543 };
544 req_builder = req_builder.json(&p_user_update_request);
545
546 let req = req_builder.build()?;
547 let resp = configuration.client.execute(req).await?;
548
549 let status = resp.status();
550 let content_type = resp
551 .headers()
552 .get("content-type")
553 .and_then(|v| v.to_str().ok())
554 .unwrap_or("application/octet-stream");
555 let content_type = super::ContentType::from(content_type);
556
557 if !status.is_client_error() && !status.is_server_error() {
558 let content = resp.text().await?;
559 match content_type {
560 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
561 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::User`"))),
562 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::User`")))),
563 }
564 } else {
565 let content = resp.text().await?;
566 let entity: Option<UpdateUserError> = serde_json::from_str(&content).ok();
567 Err(Error::ResponseError(ResponseContent { status, content, entity }))
568 }
569}
570