1use crate::datadog;
5use flate2::{
6 write::{GzEncoder, ZlibEncoder},
7 Compression,
8};
9use log::warn;
10use reqwest::header::{HeaderMap, HeaderValue};
11use serde::{Deserialize, Serialize};
12use std::io::Write;
13
14#[non_exhaustive]
16#[derive(Clone, Default, Debug)]
17pub struct ListRoleUsersOptionalParams {
18 pub page_size: Option<i64>,
20 pub page_number: Option<i64>,
22 pub sort: Option<String>,
26 pub filter: Option<String>,
28}
29
30impl ListRoleUsersOptionalParams {
31 pub fn page_size(mut self, value: i64) -> Self {
33 self.page_size = Some(value);
34 self
35 }
36 pub fn page_number(mut self, value: i64) -> Self {
38 self.page_number = Some(value);
39 self
40 }
41 pub fn sort(mut self, value: String) -> Self {
45 self.sort = Some(value);
46 self
47 }
48 pub fn filter(mut self, value: String) -> Self {
50 self.filter = Some(value);
51 self
52 }
53}
54
55#[non_exhaustive]
57#[derive(Clone, Default, Debug)]
58pub struct ListRolesOptionalParams {
59 pub page_size: Option<i64>,
61 pub page_number: Option<i64>,
63 pub sort: Option<crate::datadogV2::model::RolesSort>,
67 pub filter: Option<String>,
69 pub filter_id: Option<String>,
71}
72
73impl ListRolesOptionalParams {
74 pub fn page_size(mut self, value: i64) -> Self {
76 self.page_size = Some(value);
77 self
78 }
79 pub fn page_number(mut self, value: i64) -> Self {
81 self.page_number = Some(value);
82 self
83 }
84 pub fn sort(mut self, value: crate::datadogV2::model::RolesSort) -> Self {
88 self.sort = Some(value);
89 self
90 }
91 pub fn filter(mut self, value: String) -> Self {
93 self.filter = Some(value);
94 self
95 }
96 pub fn filter_id(mut self, value: String) -> Self {
98 self.filter_id = Some(value);
99 self
100 }
101}
102
103#[derive(Debug, Clone, Serialize, Deserialize)]
105#[serde(untagged)]
106pub enum AddPermissionToRoleError {
107 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
108 UnknownValue(serde_json::Value),
109}
110
111#[derive(Debug, Clone, Serialize, Deserialize)]
113#[serde(untagged)]
114pub enum AddUserToRoleError {
115 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
116 UnknownValue(serde_json::Value),
117}
118
119#[derive(Debug, Clone, Serialize, Deserialize)]
121#[serde(untagged)]
122pub enum CloneRoleError {
123 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
124 UnknownValue(serde_json::Value),
125}
126
127#[derive(Debug, Clone, Serialize, Deserialize)]
129#[serde(untagged)]
130pub enum CreateRoleError {
131 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
132 UnknownValue(serde_json::Value),
133}
134
135#[derive(Debug, Clone, Serialize, Deserialize)]
137#[serde(untagged)]
138pub enum DeleteRoleError {
139 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
140 UnknownValue(serde_json::Value),
141}
142
143#[derive(Debug, Clone, Serialize, Deserialize)]
145#[serde(untagged)]
146pub enum GetRoleError {
147 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
148 UnknownValue(serde_json::Value),
149}
150
151#[derive(Debug, Clone, Serialize, Deserialize)]
153#[serde(untagged)]
154pub enum ListPermissionsError {
155 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
156 UnknownValue(serde_json::Value),
157}
158
159#[derive(Debug, Clone, Serialize, Deserialize)]
161#[serde(untagged)]
162pub enum ListRolePermissionsError {
163 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
164 UnknownValue(serde_json::Value),
165}
166
167#[derive(Debug, Clone, Serialize, Deserialize)]
169#[serde(untagged)]
170pub enum ListRoleTemplatesError {
171 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
172 UnknownValue(serde_json::Value),
173}
174
175#[derive(Debug, Clone, Serialize, Deserialize)]
177#[serde(untagged)]
178pub enum ListRoleUsersError {
179 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
180 UnknownValue(serde_json::Value),
181}
182
183#[derive(Debug, Clone, Serialize, Deserialize)]
185#[serde(untagged)]
186pub enum ListRolesError {
187 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
188 UnknownValue(serde_json::Value),
189}
190
191#[derive(Debug, Clone, Serialize, Deserialize)]
193#[serde(untagged)]
194pub enum RemovePermissionFromRoleError {
195 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
196 UnknownValue(serde_json::Value),
197}
198
199#[derive(Debug, Clone, Serialize, Deserialize)]
201#[serde(untagged)]
202pub enum RemoveUserFromRoleError {
203 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
204 UnknownValue(serde_json::Value),
205}
206
207#[derive(Debug, Clone, Serialize, Deserialize)]
209#[serde(untagged)]
210pub enum UpdateRoleError {
211 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
212 UnknownValue(serde_json::Value),
213}
214
215#[derive(Debug, Clone)]
224pub struct RolesAPI {
225 config: datadog::Configuration,
226 client: reqwest_middleware::ClientWithMiddleware,
227}
228
229impl Default for RolesAPI {
230 fn default() -> Self {
231 Self::with_config(datadog::Configuration::default())
232 }
233}
234
235impl RolesAPI {
236 pub fn new() -> Self {
237 Self::default()
238 }
239 pub fn with_config(config: datadog::Configuration) -> Self {
240 let mut reqwest_client_builder = reqwest::Client::builder();
241
242 if let Some(proxy_url) = &config.proxy_url {
243 let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
244 reqwest_client_builder = reqwest_client_builder.proxy(proxy);
245 }
246
247 let mut middleware_client_builder =
248 reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
249
250 if config.enable_retry {
251 struct RetryableStatus;
252 impl reqwest_retry::RetryableStrategy for RetryableStatus {
253 fn handle(
254 &self,
255 res: &Result<reqwest::Response, reqwest_middleware::Error>,
256 ) -> Option<reqwest_retry::Retryable> {
257 match res {
258 Ok(success) => reqwest_retry::default_on_request_success(success),
259 Err(_) => None,
260 }
261 }
262 }
263 let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
264 .build_with_max_retries(config.max_retries);
265
266 let retry_middleware =
267 reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
268 backoff_policy,
269 RetryableStatus,
270 );
271
272 middleware_client_builder = middleware_client_builder.with(retry_middleware);
273 }
274
275 let client = middleware_client_builder.build();
276
277 Self { config, client }
278 }
279
280 pub fn with_client_and_config(
281 config: datadog::Configuration,
282 client: reqwest_middleware::ClientWithMiddleware,
283 ) -> Self {
284 Self { config, client }
285 }
286
287 pub async fn add_permission_to_role(
289 &self,
290 role_id: String,
291 body: crate::datadogV2::model::RelationshipToPermission,
292 ) -> Result<
293 crate::datadogV2::model::PermissionsResponse,
294 datadog::Error<AddPermissionToRoleError>,
295 > {
296 match self
297 .add_permission_to_role_with_http_info(role_id, body)
298 .await
299 {
300 Ok(response_content) => {
301 if let Some(e) = response_content.entity {
302 Ok(e)
303 } else {
304 Err(datadog::Error::Serde(serde::de::Error::custom(
305 "response content was None",
306 )))
307 }
308 }
309 Err(err) => Err(err),
310 }
311 }
312
313 pub async fn add_permission_to_role_with_http_info(
315 &self,
316 role_id: String,
317 body: crate::datadogV2::model::RelationshipToPermission,
318 ) -> Result<
319 datadog::ResponseContent<crate::datadogV2::model::PermissionsResponse>,
320 datadog::Error<AddPermissionToRoleError>,
321 > {
322 let local_configuration = &self.config;
323 let operation_id = "v2.add_permission_to_role";
324
325 let local_client = &self.client;
326
327 let local_uri_str = format!(
328 "{}/api/v2/roles/{role_id}/permissions",
329 local_configuration.get_operation_host(operation_id),
330 role_id = datadog::urlencode(role_id)
331 );
332 let mut local_req_builder =
333 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
334
335 let mut headers = HeaderMap::new();
337 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
338 headers.insert("Accept", HeaderValue::from_static("application/json"));
339
340 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
342 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
343 Err(e) => {
344 log::warn!("Failed to parse user agent header: {e}, falling back to default");
345 headers.insert(
346 reqwest::header::USER_AGENT,
347 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
348 )
349 }
350 };
351
352 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
354 headers.insert(
355 "DD-API-KEY",
356 HeaderValue::from_str(local_key.key.as_str())
357 .expect("failed to parse DD-API-KEY header"),
358 );
359 };
360 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
361 headers.insert(
362 "DD-APPLICATION-KEY",
363 HeaderValue::from_str(local_key.key.as_str())
364 .expect("failed to parse DD-APPLICATION-KEY header"),
365 );
366 };
367
368 let output = Vec::new();
370 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
371 if body.serialize(&mut ser).is_ok() {
372 if let Some(content_encoding) = headers.get("Content-Encoding") {
373 match content_encoding.to_str().unwrap_or_default() {
374 "gzip" => {
375 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
376 let _ = enc.write_all(ser.into_inner().as_slice());
377 match enc.finish() {
378 Ok(buf) => {
379 local_req_builder = local_req_builder.body(buf);
380 }
381 Err(e) => return Err(datadog::Error::Io(e)),
382 }
383 }
384 "deflate" => {
385 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
386 let _ = enc.write_all(ser.into_inner().as_slice());
387 match enc.finish() {
388 Ok(buf) => {
389 local_req_builder = local_req_builder.body(buf);
390 }
391 Err(e) => return Err(datadog::Error::Io(e)),
392 }
393 }
394 "zstd1" => {
395 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
396 let _ = enc.write_all(ser.into_inner().as_slice());
397 match enc.finish() {
398 Ok(buf) => {
399 local_req_builder = local_req_builder.body(buf);
400 }
401 Err(e) => return Err(datadog::Error::Io(e)),
402 }
403 }
404 _ => {
405 local_req_builder = local_req_builder.body(ser.into_inner());
406 }
407 }
408 } else {
409 local_req_builder = local_req_builder.body(ser.into_inner());
410 }
411 }
412
413 local_req_builder = local_req_builder.headers(headers);
414 let local_req = local_req_builder.build()?;
415 log::debug!("request content: {:?}", local_req.body());
416 let local_resp = local_client.execute(local_req).await?;
417
418 let local_status = local_resp.status();
419 let local_content = local_resp.text().await?;
420 log::debug!("response content: {}", local_content);
421
422 if !local_status.is_client_error() && !local_status.is_server_error() {
423 match serde_json::from_str::<crate::datadogV2::model::PermissionsResponse>(
424 &local_content,
425 ) {
426 Ok(e) => {
427 return Ok(datadog::ResponseContent {
428 status: local_status,
429 content: local_content,
430 entity: Some(e),
431 })
432 }
433 Err(e) => return Err(datadog::Error::Serde(e)),
434 };
435 } else {
436 let local_entity: Option<AddPermissionToRoleError> =
437 serde_json::from_str(&local_content).ok();
438 let local_error = datadog::ResponseContent {
439 status: local_status,
440 content: local_content,
441 entity: local_entity,
442 };
443 Err(datadog::Error::ResponseError(local_error))
444 }
445 }
446
447 pub async fn add_user_to_role(
449 &self,
450 role_id: String,
451 body: crate::datadogV2::model::RelationshipToUser,
452 ) -> Result<crate::datadogV2::model::UsersResponse, datadog::Error<AddUserToRoleError>> {
453 match self.add_user_to_role_with_http_info(role_id, body).await {
454 Ok(response_content) => {
455 if let Some(e) = response_content.entity {
456 Ok(e)
457 } else {
458 Err(datadog::Error::Serde(serde::de::Error::custom(
459 "response content was None",
460 )))
461 }
462 }
463 Err(err) => Err(err),
464 }
465 }
466
467 pub async fn add_user_to_role_with_http_info(
469 &self,
470 role_id: String,
471 body: crate::datadogV2::model::RelationshipToUser,
472 ) -> Result<
473 datadog::ResponseContent<crate::datadogV2::model::UsersResponse>,
474 datadog::Error<AddUserToRoleError>,
475 > {
476 let local_configuration = &self.config;
477 let operation_id = "v2.add_user_to_role";
478
479 let local_client = &self.client;
480
481 let local_uri_str = format!(
482 "{}/api/v2/roles/{role_id}/users",
483 local_configuration.get_operation_host(operation_id),
484 role_id = datadog::urlencode(role_id)
485 );
486 let mut local_req_builder =
487 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
488
489 let mut headers = HeaderMap::new();
491 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
492 headers.insert("Accept", HeaderValue::from_static("application/json"));
493
494 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
496 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
497 Err(e) => {
498 log::warn!("Failed to parse user agent header: {e}, falling back to default");
499 headers.insert(
500 reqwest::header::USER_AGENT,
501 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
502 )
503 }
504 };
505
506 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
508 headers.insert(
509 "DD-API-KEY",
510 HeaderValue::from_str(local_key.key.as_str())
511 .expect("failed to parse DD-API-KEY header"),
512 );
513 };
514 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
515 headers.insert(
516 "DD-APPLICATION-KEY",
517 HeaderValue::from_str(local_key.key.as_str())
518 .expect("failed to parse DD-APPLICATION-KEY header"),
519 );
520 };
521
522 let output = Vec::new();
524 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
525 if body.serialize(&mut ser).is_ok() {
526 if let Some(content_encoding) = headers.get("Content-Encoding") {
527 match content_encoding.to_str().unwrap_or_default() {
528 "gzip" => {
529 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
530 let _ = enc.write_all(ser.into_inner().as_slice());
531 match enc.finish() {
532 Ok(buf) => {
533 local_req_builder = local_req_builder.body(buf);
534 }
535 Err(e) => return Err(datadog::Error::Io(e)),
536 }
537 }
538 "deflate" => {
539 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
540 let _ = enc.write_all(ser.into_inner().as_slice());
541 match enc.finish() {
542 Ok(buf) => {
543 local_req_builder = local_req_builder.body(buf);
544 }
545 Err(e) => return Err(datadog::Error::Io(e)),
546 }
547 }
548 "zstd1" => {
549 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
550 let _ = enc.write_all(ser.into_inner().as_slice());
551 match enc.finish() {
552 Ok(buf) => {
553 local_req_builder = local_req_builder.body(buf);
554 }
555 Err(e) => return Err(datadog::Error::Io(e)),
556 }
557 }
558 _ => {
559 local_req_builder = local_req_builder.body(ser.into_inner());
560 }
561 }
562 } else {
563 local_req_builder = local_req_builder.body(ser.into_inner());
564 }
565 }
566
567 local_req_builder = local_req_builder.headers(headers);
568 let local_req = local_req_builder.build()?;
569 log::debug!("request content: {:?}", local_req.body());
570 let local_resp = local_client.execute(local_req).await?;
571
572 let local_status = local_resp.status();
573 let local_content = local_resp.text().await?;
574 log::debug!("response content: {}", local_content);
575
576 if !local_status.is_client_error() && !local_status.is_server_error() {
577 match serde_json::from_str::<crate::datadogV2::model::UsersResponse>(&local_content) {
578 Ok(e) => {
579 return Ok(datadog::ResponseContent {
580 status: local_status,
581 content: local_content,
582 entity: Some(e),
583 })
584 }
585 Err(e) => return Err(datadog::Error::Serde(e)),
586 };
587 } else {
588 let local_entity: Option<AddUserToRoleError> =
589 serde_json::from_str(&local_content).ok();
590 let local_error = datadog::ResponseContent {
591 status: local_status,
592 content: local_content,
593 entity: local_entity,
594 };
595 Err(datadog::Error::ResponseError(local_error))
596 }
597 }
598
599 pub async fn clone_role(
601 &self,
602 role_id: String,
603 body: crate::datadogV2::model::RoleCloneRequest,
604 ) -> Result<crate::datadogV2::model::RoleResponse, datadog::Error<CloneRoleError>> {
605 match self.clone_role_with_http_info(role_id, body).await {
606 Ok(response_content) => {
607 if let Some(e) = response_content.entity {
608 Ok(e)
609 } else {
610 Err(datadog::Error::Serde(serde::de::Error::custom(
611 "response content was None",
612 )))
613 }
614 }
615 Err(err) => Err(err),
616 }
617 }
618
619 pub async fn clone_role_with_http_info(
621 &self,
622 role_id: String,
623 body: crate::datadogV2::model::RoleCloneRequest,
624 ) -> Result<
625 datadog::ResponseContent<crate::datadogV2::model::RoleResponse>,
626 datadog::Error<CloneRoleError>,
627 > {
628 let local_configuration = &self.config;
629 let operation_id = "v2.clone_role";
630
631 let local_client = &self.client;
632
633 let local_uri_str = format!(
634 "{}/api/v2/roles/{role_id}/clone",
635 local_configuration.get_operation_host(operation_id),
636 role_id = datadog::urlencode(role_id)
637 );
638 let mut local_req_builder =
639 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
640
641 let mut headers = HeaderMap::new();
643 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
644 headers.insert("Accept", HeaderValue::from_static("application/json"));
645
646 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
648 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
649 Err(e) => {
650 log::warn!("Failed to parse user agent header: {e}, falling back to default");
651 headers.insert(
652 reqwest::header::USER_AGENT,
653 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
654 )
655 }
656 };
657
658 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
660 headers.insert(
661 "DD-API-KEY",
662 HeaderValue::from_str(local_key.key.as_str())
663 .expect("failed to parse DD-API-KEY header"),
664 );
665 };
666 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
667 headers.insert(
668 "DD-APPLICATION-KEY",
669 HeaderValue::from_str(local_key.key.as_str())
670 .expect("failed to parse DD-APPLICATION-KEY header"),
671 );
672 };
673
674 let output = Vec::new();
676 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
677 if body.serialize(&mut ser).is_ok() {
678 if let Some(content_encoding) = headers.get("Content-Encoding") {
679 match content_encoding.to_str().unwrap_or_default() {
680 "gzip" => {
681 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
682 let _ = enc.write_all(ser.into_inner().as_slice());
683 match enc.finish() {
684 Ok(buf) => {
685 local_req_builder = local_req_builder.body(buf);
686 }
687 Err(e) => return Err(datadog::Error::Io(e)),
688 }
689 }
690 "deflate" => {
691 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
692 let _ = enc.write_all(ser.into_inner().as_slice());
693 match enc.finish() {
694 Ok(buf) => {
695 local_req_builder = local_req_builder.body(buf);
696 }
697 Err(e) => return Err(datadog::Error::Io(e)),
698 }
699 }
700 "zstd1" => {
701 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
702 let _ = enc.write_all(ser.into_inner().as_slice());
703 match enc.finish() {
704 Ok(buf) => {
705 local_req_builder = local_req_builder.body(buf);
706 }
707 Err(e) => return Err(datadog::Error::Io(e)),
708 }
709 }
710 _ => {
711 local_req_builder = local_req_builder.body(ser.into_inner());
712 }
713 }
714 } else {
715 local_req_builder = local_req_builder.body(ser.into_inner());
716 }
717 }
718
719 local_req_builder = local_req_builder.headers(headers);
720 let local_req = local_req_builder.build()?;
721 log::debug!("request content: {:?}", local_req.body());
722 let local_resp = local_client.execute(local_req).await?;
723
724 let local_status = local_resp.status();
725 let local_content = local_resp.text().await?;
726 log::debug!("response content: {}", local_content);
727
728 if !local_status.is_client_error() && !local_status.is_server_error() {
729 match serde_json::from_str::<crate::datadogV2::model::RoleResponse>(&local_content) {
730 Ok(e) => {
731 return Ok(datadog::ResponseContent {
732 status: local_status,
733 content: local_content,
734 entity: Some(e),
735 })
736 }
737 Err(e) => return Err(datadog::Error::Serde(e)),
738 };
739 } else {
740 let local_entity: Option<CloneRoleError> = serde_json::from_str(&local_content).ok();
741 let local_error = datadog::ResponseContent {
742 status: local_status,
743 content: local_content,
744 entity: local_entity,
745 };
746 Err(datadog::Error::ResponseError(local_error))
747 }
748 }
749
750 pub async fn create_role(
752 &self,
753 body: crate::datadogV2::model::RoleCreateRequest,
754 ) -> Result<crate::datadogV2::model::RoleCreateResponse, datadog::Error<CreateRoleError>> {
755 match self.create_role_with_http_info(body).await {
756 Ok(response_content) => {
757 if let Some(e) = response_content.entity {
758 Ok(e)
759 } else {
760 Err(datadog::Error::Serde(serde::de::Error::custom(
761 "response content was None",
762 )))
763 }
764 }
765 Err(err) => Err(err),
766 }
767 }
768
769 pub async fn create_role_with_http_info(
771 &self,
772 body: crate::datadogV2::model::RoleCreateRequest,
773 ) -> Result<
774 datadog::ResponseContent<crate::datadogV2::model::RoleCreateResponse>,
775 datadog::Error<CreateRoleError>,
776 > {
777 let local_configuration = &self.config;
778 let operation_id = "v2.create_role";
779
780 let local_client = &self.client;
781
782 let local_uri_str = format!(
783 "{}/api/v2/roles",
784 local_configuration.get_operation_host(operation_id)
785 );
786 let mut local_req_builder =
787 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
788
789 let mut headers = HeaderMap::new();
791 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
792 headers.insert("Accept", HeaderValue::from_static("application/json"));
793
794 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
796 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
797 Err(e) => {
798 log::warn!("Failed to parse user agent header: {e}, falling back to default");
799 headers.insert(
800 reqwest::header::USER_AGENT,
801 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
802 )
803 }
804 };
805
806 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
808 headers.insert(
809 "DD-API-KEY",
810 HeaderValue::from_str(local_key.key.as_str())
811 .expect("failed to parse DD-API-KEY header"),
812 );
813 };
814 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
815 headers.insert(
816 "DD-APPLICATION-KEY",
817 HeaderValue::from_str(local_key.key.as_str())
818 .expect("failed to parse DD-APPLICATION-KEY header"),
819 );
820 };
821
822 let output = Vec::new();
824 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
825 if body.serialize(&mut ser).is_ok() {
826 if let Some(content_encoding) = headers.get("Content-Encoding") {
827 match content_encoding.to_str().unwrap_or_default() {
828 "gzip" => {
829 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
830 let _ = enc.write_all(ser.into_inner().as_slice());
831 match enc.finish() {
832 Ok(buf) => {
833 local_req_builder = local_req_builder.body(buf);
834 }
835 Err(e) => return Err(datadog::Error::Io(e)),
836 }
837 }
838 "deflate" => {
839 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
840 let _ = enc.write_all(ser.into_inner().as_slice());
841 match enc.finish() {
842 Ok(buf) => {
843 local_req_builder = local_req_builder.body(buf);
844 }
845 Err(e) => return Err(datadog::Error::Io(e)),
846 }
847 }
848 "zstd1" => {
849 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
850 let _ = enc.write_all(ser.into_inner().as_slice());
851 match enc.finish() {
852 Ok(buf) => {
853 local_req_builder = local_req_builder.body(buf);
854 }
855 Err(e) => return Err(datadog::Error::Io(e)),
856 }
857 }
858 _ => {
859 local_req_builder = local_req_builder.body(ser.into_inner());
860 }
861 }
862 } else {
863 local_req_builder = local_req_builder.body(ser.into_inner());
864 }
865 }
866
867 local_req_builder = local_req_builder.headers(headers);
868 let local_req = local_req_builder.build()?;
869 log::debug!("request content: {:?}", local_req.body());
870 let local_resp = local_client.execute(local_req).await?;
871
872 let local_status = local_resp.status();
873 let local_content = local_resp.text().await?;
874 log::debug!("response content: {}", local_content);
875
876 if !local_status.is_client_error() && !local_status.is_server_error() {
877 match serde_json::from_str::<crate::datadogV2::model::RoleCreateResponse>(
878 &local_content,
879 ) {
880 Ok(e) => {
881 return Ok(datadog::ResponseContent {
882 status: local_status,
883 content: local_content,
884 entity: Some(e),
885 })
886 }
887 Err(e) => return Err(datadog::Error::Serde(e)),
888 };
889 } else {
890 let local_entity: Option<CreateRoleError> = serde_json::from_str(&local_content).ok();
891 let local_error = datadog::ResponseContent {
892 status: local_status,
893 content: local_content,
894 entity: local_entity,
895 };
896 Err(datadog::Error::ResponseError(local_error))
897 }
898 }
899
900 pub async fn delete_role(
902 &self,
903 role_id: String,
904 ) -> Result<(), datadog::Error<DeleteRoleError>> {
905 match self.delete_role_with_http_info(role_id).await {
906 Ok(_) => Ok(()),
907 Err(err) => Err(err),
908 }
909 }
910
911 pub async fn delete_role_with_http_info(
913 &self,
914 role_id: String,
915 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteRoleError>> {
916 let local_configuration = &self.config;
917 let operation_id = "v2.delete_role";
918
919 let local_client = &self.client;
920
921 let local_uri_str = format!(
922 "{}/api/v2/roles/{role_id}",
923 local_configuration.get_operation_host(operation_id),
924 role_id = datadog::urlencode(role_id)
925 );
926 let mut local_req_builder =
927 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
928
929 let mut headers = HeaderMap::new();
931 headers.insert("Accept", HeaderValue::from_static("*/*"));
932
933 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
935 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
936 Err(e) => {
937 log::warn!("Failed to parse user agent header: {e}, falling back to default");
938 headers.insert(
939 reqwest::header::USER_AGENT,
940 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
941 )
942 }
943 };
944
945 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
947 headers.insert(
948 "DD-API-KEY",
949 HeaderValue::from_str(local_key.key.as_str())
950 .expect("failed to parse DD-API-KEY header"),
951 );
952 };
953 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
954 headers.insert(
955 "DD-APPLICATION-KEY",
956 HeaderValue::from_str(local_key.key.as_str())
957 .expect("failed to parse DD-APPLICATION-KEY header"),
958 );
959 };
960
961 local_req_builder = local_req_builder.headers(headers);
962 let local_req = local_req_builder.build()?;
963 log::debug!("request content: {:?}", local_req.body());
964 let local_resp = local_client.execute(local_req).await?;
965
966 let local_status = local_resp.status();
967 let local_content = local_resp.text().await?;
968 log::debug!("response content: {}", local_content);
969
970 if !local_status.is_client_error() && !local_status.is_server_error() {
971 Ok(datadog::ResponseContent {
972 status: local_status,
973 content: local_content,
974 entity: None,
975 })
976 } else {
977 let local_entity: Option<DeleteRoleError> = serde_json::from_str(&local_content).ok();
978 let local_error = datadog::ResponseContent {
979 status: local_status,
980 content: local_content,
981 entity: local_entity,
982 };
983 Err(datadog::Error::ResponseError(local_error))
984 }
985 }
986
987 pub async fn get_role(
989 &self,
990 role_id: String,
991 ) -> Result<crate::datadogV2::model::RoleResponse, datadog::Error<GetRoleError>> {
992 match self.get_role_with_http_info(role_id).await {
993 Ok(response_content) => {
994 if let Some(e) = response_content.entity {
995 Ok(e)
996 } else {
997 Err(datadog::Error::Serde(serde::de::Error::custom(
998 "response content was None",
999 )))
1000 }
1001 }
1002 Err(err) => Err(err),
1003 }
1004 }
1005
1006 pub async fn get_role_with_http_info(
1008 &self,
1009 role_id: String,
1010 ) -> Result<
1011 datadog::ResponseContent<crate::datadogV2::model::RoleResponse>,
1012 datadog::Error<GetRoleError>,
1013 > {
1014 let local_configuration = &self.config;
1015 let operation_id = "v2.get_role";
1016
1017 let local_client = &self.client;
1018
1019 let local_uri_str = format!(
1020 "{}/api/v2/roles/{role_id}",
1021 local_configuration.get_operation_host(operation_id),
1022 role_id = datadog::urlencode(role_id)
1023 );
1024 let mut local_req_builder =
1025 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1026
1027 let mut headers = HeaderMap::new();
1029 headers.insert("Accept", HeaderValue::from_static("application/json"));
1030
1031 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1033 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1034 Err(e) => {
1035 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1036 headers.insert(
1037 reqwest::header::USER_AGENT,
1038 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1039 )
1040 }
1041 };
1042
1043 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1045 headers.insert(
1046 "DD-API-KEY",
1047 HeaderValue::from_str(local_key.key.as_str())
1048 .expect("failed to parse DD-API-KEY header"),
1049 );
1050 };
1051 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1052 headers.insert(
1053 "DD-APPLICATION-KEY",
1054 HeaderValue::from_str(local_key.key.as_str())
1055 .expect("failed to parse DD-APPLICATION-KEY header"),
1056 );
1057 };
1058
1059 local_req_builder = local_req_builder.headers(headers);
1060 let local_req = local_req_builder.build()?;
1061 log::debug!("request content: {:?}", local_req.body());
1062 let local_resp = local_client.execute(local_req).await?;
1063
1064 let local_status = local_resp.status();
1065 let local_content = local_resp.text().await?;
1066 log::debug!("response content: {}", local_content);
1067
1068 if !local_status.is_client_error() && !local_status.is_server_error() {
1069 match serde_json::from_str::<crate::datadogV2::model::RoleResponse>(&local_content) {
1070 Ok(e) => {
1071 return Ok(datadog::ResponseContent {
1072 status: local_status,
1073 content: local_content,
1074 entity: Some(e),
1075 })
1076 }
1077 Err(e) => return Err(datadog::Error::Serde(e)),
1078 };
1079 } else {
1080 let local_entity: Option<GetRoleError> = serde_json::from_str(&local_content).ok();
1081 let local_error = datadog::ResponseContent {
1082 status: local_status,
1083 content: local_content,
1084 entity: local_entity,
1085 };
1086 Err(datadog::Error::ResponseError(local_error))
1087 }
1088 }
1089
1090 pub async fn list_permissions(
1092 &self,
1093 ) -> Result<crate::datadogV2::model::PermissionsResponse, datadog::Error<ListPermissionsError>>
1094 {
1095 match self.list_permissions_with_http_info().await {
1096 Ok(response_content) => {
1097 if let Some(e) = response_content.entity {
1098 Ok(e)
1099 } else {
1100 Err(datadog::Error::Serde(serde::de::Error::custom(
1101 "response content was None",
1102 )))
1103 }
1104 }
1105 Err(err) => Err(err),
1106 }
1107 }
1108
1109 pub async fn list_permissions_with_http_info(
1111 &self,
1112 ) -> Result<
1113 datadog::ResponseContent<crate::datadogV2::model::PermissionsResponse>,
1114 datadog::Error<ListPermissionsError>,
1115 > {
1116 let local_configuration = &self.config;
1117 let operation_id = "v2.list_permissions";
1118
1119 let local_client = &self.client;
1120
1121 let local_uri_str = format!(
1122 "{}/api/v2/permissions",
1123 local_configuration.get_operation_host(operation_id)
1124 );
1125 let mut local_req_builder =
1126 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1127
1128 let mut headers = HeaderMap::new();
1130 headers.insert("Accept", HeaderValue::from_static("application/json"));
1131
1132 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1134 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1135 Err(e) => {
1136 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1137 headers.insert(
1138 reqwest::header::USER_AGENT,
1139 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1140 )
1141 }
1142 };
1143
1144 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1146 headers.insert(
1147 "DD-API-KEY",
1148 HeaderValue::from_str(local_key.key.as_str())
1149 .expect("failed to parse DD-API-KEY header"),
1150 );
1151 };
1152 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1153 headers.insert(
1154 "DD-APPLICATION-KEY",
1155 HeaderValue::from_str(local_key.key.as_str())
1156 .expect("failed to parse DD-APPLICATION-KEY header"),
1157 );
1158 };
1159
1160 local_req_builder = local_req_builder.headers(headers);
1161 let local_req = local_req_builder.build()?;
1162 log::debug!("request content: {:?}", local_req.body());
1163 let local_resp = local_client.execute(local_req).await?;
1164
1165 let local_status = local_resp.status();
1166 let local_content = local_resp.text().await?;
1167 log::debug!("response content: {}", local_content);
1168
1169 if !local_status.is_client_error() && !local_status.is_server_error() {
1170 match serde_json::from_str::<crate::datadogV2::model::PermissionsResponse>(
1171 &local_content,
1172 ) {
1173 Ok(e) => {
1174 return Ok(datadog::ResponseContent {
1175 status: local_status,
1176 content: local_content,
1177 entity: Some(e),
1178 })
1179 }
1180 Err(e) => return Err(datadog::Error::Serde(e)),
1181 };
1182 } else {
1183 let local_entity: Option<ListPermissionsError> =
1184 serde_json::from_str(&local_content).ok();
1185 let local_error = datadog::ResponseContent {
1186 status: local_status,
1187 content: local_content,
1188 entity: local_entity,
1189 };
1190 Err(datadog::Error::ResponseError(local_error))
1191 }
1192 }
1193
1194 pub async fn list_role_permissions(
1196 &self,
1197 role_id: String,
1198 ) -> Result<
1199 crate::datadogV2::model::PermissionsResponse,
1200 datadog::Error<ListRolePermissionsError>,
1201 > {
1202 match self.list_role_permissions_with_http_info(role_id).await {
1203 Ok(response_content) => {
1204 if let Some(e) = response_content.entity {
1205 Ok(e)
1206 } else {
1207 Err(datadog::Error::Serde(serde::de::Error::custom(
1208 "response content was None",
1209 )))
1210 }
1211 }
1212 Err(err) => Err(err),
1213 }
1214 }
1215
1216 pub async fn list_role_permissions_with_http_info(
1218 &self,
1219 role_id: String,
1220 ) -> Result<
1221 datadog::ResponseContent<crate::datadogV2::model::PermissionsResponse>,
1222 datadog::Error<ListRolePermissionsError>,
1223 > {
1224 let local_configuration = &self.config;
1225 let operation_id = "v2.list_role_permissions";
1226
1227 let local_client = &self.client;
1228
1229 let local_uri_str = format!(
1230 "{}/api/v2/roles/{role_id}/permissions",
1231 local_configuration.get_operation_host(operation_id),
1232 role_id = datadog::urlencode(role_id)
1233 );
1234 let mut local_req_builder =
1235 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1236
1237 let mut headers = HeaderMap::new();
1239 headers.insert("Accept", HeaderValue::from_static("application/json"));
1240
1241 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1243 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1244 Err(e) => {
1245 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1246 headers.insert(
1247 reqwest::header::USER_AGENT,
1248 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1249 )
1250 }
1251 };
1252
1253 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1255 headers.insert(
1256 "DD-API-KEY",
1257 HeaderValue::from_str(local_key.key.as_str())
1258 .expect("failed to parse DD-API-KEY header"),
1259 );
1260 };
1261 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1262 headers.insert(
1263 "DD-APPLICATION-KEY",
1264 HeaderValue::from_str(local_key.key.as_str())
1265 .expect("failed to parse DD-APPLICATION-KEY header"),
1266 );
1267 };
1268
1269 local_req_builder = local_req_builder.headers(headers);
1270 let local_req = local_req_builder.build()?;
1271 log::debug!("request content: {:?}", local_req.body());
1272 let local_resp = local_client.execute(local_req).await?;
1273
1274 let local_status = local_resp.status();
1275 let local_content = local_resp.text().await?;
1276 log::debug!("response content: {}", local_content);
1277
1278 if !local_status.is_client_error() && !local_status.is_server_error() {
1279 match serde_json::from_str::<crate::datadogV2::model::PermissionsResponse>(
1280 &local_content,
1281 ) {
1282 Ok(e) => {
1283 return Ok(datadog::ResponseContent {
1284 status: local_status,
1285 content: local_content,
1286 entity: Some(e),
1287 })
1288 }
1289 Err(e) => return Err(datadog::Error::Serde(e)),
1290 };
1291 } else {
1292 let local_entity: Option<ListRolePermissionsError> =
1293 serde_json::from_str(&local_content).ok();
1294 let local_error = datadog::ResponseContent {
1295 status: local_status,
1296 content: local_content,
1297 entity: local_entity,
1298 };
1299 Err(datadog::Error::ResponseError(local_error))
1300 }
1301 }
1302
1303 pub async fn list_role_templates(
1305 &self,
1306 ) -> Result<crate::datadogV2::model::RoleTemplateArray, datadog::Error<ListRoleTemplatesError>>
1307 {
1308 match self.list_role_templates_with_http_info().await {
1309 Ok(response_content) => {
1310 if let Some(e) = response_content.entity {
1311 Ok(e)
1312 } else {
1313 Err(datadog::Error::Serde(serde::de::Error::custom(
1314 "response content was None",
1315 )))
1316 }
1317 }
1318 Err(err) => Err(err),
1319 }
1320 }
1321
1322 pub async fn list_role_templates_with_http_info(
1324 &self,
1325 ) -> Result<
1326 datadog::ResponseContent<crate::datadogV2::model::RoleTemplateArray>,
1327 datadog::Error<ListRoleTemplatesError>,
1328 > {
1329 let local_configuration = &self.config;
1330 let operation_id = "v2.list_role_templates";
1331 if local_configuration.is_unstable_operation_enabled(operation_id) {
1332 warn!("Using unstable operation {operation_id}");
1333 } else {
1334 let local_error = datadog::UnstableOperationDisabledError {
1335 msg: "Operation 'v2.list_role_templates' is not enabled".to_string(),
1336 };
1337 return Err(datadog::Error::UnstableOperationDisabledError(local_error));
1338 }
1339
1340 let local_client = &self.client;
1341
1342 let local_uri_str = format!(
1343 "{}/api/v2/roles/templates",
1344 local_configuration.get_operation_host(operation_id)
1345 );
1346 let mut local_req_builder =
1347 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1348
1349 let mut headers = HeaderMap::new();
1351 headers.insert("Accept", HeaderValue::from_static("application/json"));
1352
1353 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1355 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1356 Err(e) => {
1357 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1358 headers.insert(
1359 reqwest::header::USER_AGENT,
1360 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1361 )
1362 }
1363 };
1364
1365 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1367 headers.insert(
1368 "DD-API-KEY",
1369 HeaderValue::from_str(local_key.key.as_str())
1370 .expect("failed to parse DD-API-KEY header"),
1371 );
1372 };
1373 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1374 headers.insert(
1375 "DD-APPLICATION-KEY",
1376 HeaderValue::from_str(local_key.key.as_str())
1377 .expect("failed to parse DD-APPLICATION-KEY header"),
1378 );
1379 };
1380
1381 local_req_builder = local_req_builder.headers(headers);
1382 let local_req = local_req_builder.build()?;
1383 log::debug!("request content: {:?}", local_req.body());
1384 let local_resp = local_client.execute(local_req).await?;
1385
1386 let local_status = local_resp.status();
1387 let local_content = local_resp.text().await?;
1388 log::debug!("response content: {}", local_content);
1389
1390 if !local_status.is_client_error() && !local_status.is_server_error() {
1391 match serde_json::from_str::<crate::datadogV2::model::RoleTemplateArray>(&local_content)
1392 {
1393 Ok(e) => {
1394 return Ok(datadog::ResponseContent {
1395 status: local_status,
1396 content: local_content,
1397 entity: Some(e),
1398 })
1399 }
1400 Err(e) => return Err(datadog::Error::Serde(e)),
1401 };
1402 } else {
1403 let local_entity: Option<ListRoleTemplatesError> =
1404 serde_json::from_str(&local_content).ok();
1405 let local_error = datadog::ResponseContent {
1406 status: local_status,
1407 content: local_content,
1408 entity: local_entity,
1409 };
1410 Err(datadog::Error::ResponseError(local_error))
1411 }
1412 }
1413
1414 pub async fn list_role_users(
1416 &self,
1417 role_id: String,
1418 params: ListRoleUsersOptionalParams,
1419 ) -> Result<crate::datadogV2::model::UsersResponse, datadog::Error<ListRoleUsersError>> {
1420 match self.list_role_users_with_http_info(role_id, params).await {
1421 Ok(response_content) => {
1422 if let Some(e) = response_content.entity {
1423 Ok(e)
1424 } else {
1425 Err(datadog::Error::Serde(serde::de::Error::custom(
1426 "response content was None",
1427 )))
1428 }
1429 }
1430 Err(err) => Err(err),
1431 }
1432 }
1433
1434 pub async fn list_role_users_with_http_info(
1436 &self,
1437 role_id: String,
1438 params: ListRoleUsersOptionalParams,
1439 ) -> Result<
1440 datadog::ResponseContent<crate::datadogV2::model::UsersResponse>,
1441 datadog::Error<ListRoleUsersError>,
1442 > {
1443 let local_configuration = &self.config;
1444 let operation_id = "v2.list_role_users";
1445
1446 let page_size = params.page_size;
1448 let page_number = params.page_number;
1449 let sort = params.sort;
1450 let filter = params.filter;
1451
1452 let local_client = &self.client;
1453
1454 let local_uri_str = format!(
1455 "{}/api/v2/roles/{role_id}/users",
1456 local_configuration.get_operation_host(operation_id),
1457 role_id = datadog::urlencode(role_id)
1458 );
1459 let mut local_req_builder =
1460 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1461
1462 if let Some(ref local_query_param) = page_size {
1463 local_req_builder =
1464 local_req_builder.query(&[("page[size]", &local_query_param.to_string())]);
1465 };
1466 if let Some(ref local_query_param) = page_number {
1467 local_req_builder =
1468 local_req_builder.query(&[("page[number]", &local_query_param.to_string())]);
1469 };
1470 if let Some(ref local_query_param) = sort {
1471 local_req_builder =
1472 local_req_builder.query(&[("sort", &local_query_param.to_string())]);
1473 };
1474 if let Some(ref local_query_param) = filter {
1475 local_req_builder =
1476 local_req_builder.query(&[("filter", &local_query_param.to_string())]);
1477 };
1478
1479 let mut headers = HeaderMap::new();
1481 headers.insert("Accept", HeaderValue::from_static("application/json"));
1482
1483 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1485 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1486 Err(e) => {
1487 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1488 headers.insert(
1489 reqwest::header::USER_AGENT,
1490 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1491 )
1492 }
1493 };
1494
1495 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1497 headers.insert(
1498 "DD-API-KEY",
1499 HeaderValue::from_str(local_key.key.as_str())
1500 .expect("failed to parse DD-API-KEY header"),
1501 );
1502 };
1503 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1504 headers.insert(
1505 "DD-APPLICATION-KEY",
1506 HeaderValue::from_str(local_key.key.as_str())
1507 .expect("failed to parse DD-APPLICATION-KEY header"),
1508 );
1509 };
1510
1511 local_req_builder = local_req_builder.headers(headers);
1512 let local_req = local_req_builder.build()?;
1513 log::debug!("request content: {:?}", local_req.body());
1514 let local_resp = local_client.execute(local_req).await?;
1515
1516 let local_status = local_resp.status();
1517 let local_content = local_resp.text().await?;
1518 log::debug!("response content: {}", local_content);
1519
1520 if !local_status.is_client_error() && !local_status.is_server_error() {
1521 match serde_json::from_str::<crate::datadogV2::model::UsersResponse>(&local_content) {
1522 Ok(e) => {
1523 return Ok(datadog::ResponseContent {
1524 status: local_status,
1525 content: local_content,
1526 entity: Some(e),
1527 })
1528 }
1529 Err(e) => return Err(datadog::Error::Serde(e)),
1530 };
1531 } else {
1532 let local_entity: Option<ListRoleUsersError> =
1533 serde_json::from_str(&local_content).ok();
1534 let local_error = datadog::ResponseContent {
1535 status: local_status,
1536 content: local_content,
1537 entity: local_entity,
1538 };
1539 Err(datadog::Error::ResponseError(local_error))
1540 }
1541 }
1542
1543 pub async fn list_roles(
1545 &self,
1546 params: ListRolesOptionalParams,
1547 ) -> Result<crate::datadogV2::model::RolesResponse, datadog::Error<ListRolesError>> {
1548 match self.list_roles_with_http_info(params).await {
1549 Ok(response_content) => {
1550 if let Some(e) = response_content.entity {
1551 Ok(e)
1552 } else {
1553 Err(datadog::Error::Serde(serde::de::Error::custom(
1554 "response content was None",
1555 )))
1556 }
1557 }
1558 Err(err) => Err(err),
1559 }
1560 }
1561
1562 pub async fn list_roles_with_http_info(
1564 &self,
1565 params: ListRolesOptionalParams,
1566 ) -> Result<
1567 datadog::ResponseContent<crate::datadogV2::model::RolesResponse>,
1568 datadog::Error<ListRolesError>,
1569 > {
1570 let local_configuration = &self.config;
1571 let operation_id = "v2.list_roles";
1572
1573 let page_size = params.page_size;
1575 let page_number = params.page_number;
1576 let sort = params.sort;
1577 let filter = params.filter;
1578 let filter_id = params.filter_id;
1579
1580 let local_client = &self.client;
1581
1582 let local_uri_str = format!(
1583 "{}/api/v2/roles",
1584 local_configuration.get_operation_host(operation_id)
1585 );
1586 let mut local_req_builder =
1587 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1588
1589 if let Some(ref local_query_param) = page_size {
1590 local_req_builder =
1591 local_req_builder.query(&[("page[size]", &local_query_param.to_string())]);
1592 };
1593 if let Some(ref local_query_param) = page_number {
1594 local_req_builder =
1595 local_req_builder.query(&[("page[number]", &local_query_param.to_string())]);
1596 };
1597 if let Some(ref local_query_param) = sort {
1598 local_req_builder =
1599 local_req_builder.query(&[("sort", &local_query_param.to_string())]);
1600 };
1601 if let Some(ref local_query_param) = filter {
1602 local_req_builder =
1603 local_req_builder.query(&[("filter", &local_query_param.to_string())]);
1604 };
1605 if let Some(ref local_query_param) = filter_id {
1606 local_req_builder =
1607 local_req_builder.query(&[("filter[id]", &local_query_param.to_string())]);
1608 };
1609
1610 let mut headers = HeaderMap::new();
1612 headers.insert("Accept", HeaderValue::from_static("application/json"));
1613
1614 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1616 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1617 Err(e) => {
1618 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1619 headers.insert(
1620 reqwest::header::USER_AGENT,
1621 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1622 )
1623 }
1624 };
1625
1626 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1628 headers.insert(
1629 "DD-API-KEY",
1630 HeaderValue::from_str(local_key.key.as_str())
1631 .expect("failed to parse DD-API-KEY header"),
1632 );
1633 };
1634 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1635 headers.insert(
1636 "DD-APPLICATION-KEY",
1637 HeaderValue::from_str(local_key.key.as_str())
1638 .expect("failed to parse DD-APPLICATION-KEY header"),
1639 );
1640 };
1641
1642 local_req_builder = local_req_builder.headers(headers);
1643 let local_req = local_req_builder.build()?;
1644 log::debug!("request content: {:?}", local_req.body());
1645 let local_resp = local_client.execute(local_req).await?;
1646
1647 let local_status = local_resp.status();
1648 let local_content = local_resp.text().await?;
1649 log::debug!("response content: {}", local_content);
1650
1651 if !local_status.is_client_error() && !local_status.is_server_error() {
1652 match serde_json::from_str::<crate::datadogV2::model::RolesResponse>(&local_content) {
1653 Ok(e) => {
1654 return Ok(datadog::ResponseContent {
1655 status: local_status,
1656 content: local_content,
1657 entity: Some(e),
1658 })
1659 }
1660 Err(e) => return Err(datadog::Error::Serde(e)),
1661 };
1662 } else {
1663 let local_entity: Option<ListRolesError> = serde_json::from_str(&local_content).ok();
1664 let local_error = datadog::ResponseContent {
1665 status: local_status,
1666 content: local_content,
1667 entity: local_entity,
1668 };
1669 Err(datadog::Error::ResponseError(local_error))
1670 }
1671 }
1672
1673 pub async fn remove_permission_from_role(
1675 &self,
1676 role_id: String,
1677 body: crate::datadogV2::model::RelationshipToPermission,
1678 ) -> Result<
1679 crate::datadogV2::model::PermissionsResponse,
1680 datadog::Error<RemovePermissionFromRoleError>,
1681 > {
1682 match self
1683 .remove_permission_from_role_with_http_info(role_id, body)
1684 .await
1685 {
1686 Ok(response_content) => {
1687 if let Some(e) = response_content.entity {
1688 Ok(e)
1689 } else {
1690 Err(datadog::Error::Serde(serde::de::Error::custom(
1691 "response content was None",
1692 )))
1693 }
1694 }
1695 Err(err) => Err(err),
1696 }
1697 }
1698
1699 pub async fn remove_permission_from_role_with_http_info(
1701 &self,
1702 role_id: String,
1703 body: crate::datadogV2::model::RelationshipToPermission,
1704 ) -> Result<
1705 datadog::ResponseContent<crate::datadogV2::model::PermissionsResponse>,
1706 datadog::Error<RemovePermissionFromRoleError>,
1707 > {
1708 let local_configuration = &self.config;
1709 let operation_id = "v2.remove_permission_from_role";
1710
1711 let local_client = &self.client;
1712
1713 let local_uri_str = format!(
1714 "{}/api/v2/roles/{role_id}/permissions",
1715 local_configuration.get_operation_host(operation_id),
1716 role_id = datadog::urlencode(role_id)
1717 );
1718 let mut local_req_builder =
1719 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
1720
1721 let mut headers = HeaderMap::new();
1723 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1724 headers.insert("Accept", HeaderValue::from_static("application/json"));
1725
1726 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1728 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1729 Err(e) => {
1730 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1731 headers.insert(
1732 reqwest::header::USER_AGENT,
1733 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1734 )
1735 }
1736 };
1737
1738 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1740 headers.insert(
1741 "DD-API-KEY",
1742 HeaderValue::from_str(local_key.key.as_str())
1743 .expect("failed to parse DD-API-KEY header"),
1744 );
1745 };
1746 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1747 headers.insert(
1748 "DD-APPLICATION-KEY",
1749 HeaderValue::from_str(local_key.key.as_str())
1750 .expect("failed to parse DD-APPLICATION-KEY header"),
1751 );
1752 };
1753
1754 let output = Vec::new();
1756 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1757 if body.serialize(&mut ser).is_ok() {
1758 if let Some(content_encoding) = headers.get("Content-Encoding") {
1759 match content_encoding.to_str().unwrap_or_default() {
1760 "gzip" => {
1761 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1762 let _ = enc.write_all(ser.into_inner().as_slice());
1763 match enc.finish() {
1764 Ok(buf) => {
1765 local_req_builder = local_req_builder.body(buf);
1766 }
1767 Err(e) => return Err(datadog::Error::Io(e)),
1768 }
1769 }
1770 "deflate" => {
1771 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1772 let _ = enc.write_all(ser.into_inner().as_slice());
1773 match enc.finish() {
1774 Ok(buf) => {
1775 local_req_builder = local_req_builder.body(buf);
1776 }
1777 Err(e) => return Err(datadog::Error::Io(e)),
1778 }
1779 }
1780 "zstd1" => {
1781 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1782 let _ = enc.write_all(ser.into_inner().as_slice());
1783 match enc.finish() {
1784 Ok(buf) => {
1785 local_req_builder = local_req_builder.body(buf);
1786 }
1787 Err(e) => return Err(datadog::Error::Io(e)),
1788 }
1789 }
1790 _ => {
1791 local_req_builder = local_req_builder.body(ser.into_inner());
1792 }
1793 }
1794 } else {
1795 local_req_builder = local_req_builder.body(ser.into_inner());
1796 }
1797 }
1798
1799 local_req_builder = local_req_builder.headers(headers);
1800 let local_req = local_req_builder.build()?;
1801 log::debug!("request content: {:?}", local_req.body());
1802 let local_resp = local_client.execute(local_req).await?;
1803
1804 let local_status = local_resp.status();
1805 let local_content = local_resp.text().await?;
1806 log::debug!("response content: {}", local_content);
1807
1808 if !local_status.is_client_error() && !local_status.is_server_error() {
1809 match serde_json::from_str::<crate::datadogV2::model::PermissionsResponse>(
1810 &local_content,
1811 ) {
1812 Ok(e) => {
1813 return Ok(datadog::ResponseContent {
1814 status: local_status,
1815 content: local_content,
1816 entity: Some(e),
1817 })
1818 }
1819 Err(e) => return Err(datadog::Error::Serde(e)),
1820 };
1821 } else {
1822 let local_entity: Option<RemovePermissionFromRoleError> =
1823 serde_json::from_str(&local_content).ok();
1824 let local_error = datadog::ResponseContent {
1825 status: local_status,
1826 content: local_content,
1827 entity: local_entity,
1828 };
1829 Err(datadog::Error::ResponseError(local_error))
1830 }
1831 }
1832
1833 pub async fn remove_user_from_role(
1835 &self,
1836 role_id: String,
1837 body: crate::datadogV2::model::RelationshipToUser,
1838 ) -> Result<crate::datadogV2::model::UsersResponse, datadog::Error<RemoveUserFromRoleError>>
1839 {
1840 match self
1841 .remove_user_from_role_with_http_info(role_id, body)
1842 .await
1843 {
1844 Ok(response_content) => {
1845 if let Some(e) = response_content.entity {
1846 Ok(e)
1847 } else {
1848 Err(datadog::Error::Serde(serde::de::Error::custom(
1849 "response content was None",
1850 )))
1851 }
1852 }
1853 Err(err) => Err(err),
1854 }
1855 }
1856
1857 pub async fn remove_user_from_role_with_http_info(
1859 &self,
1860 role_id: String,
1861 body: crate::datadogV2::model::RelationshipToUser,
1862 ) -> Result<
1863 datadog::ResponseContent<crate::datadogV2::model::UsersResponse>,
1864 datadog::Error<RemoveUserFromRoleError>,
1865 > {
1866 let local_configuration = &self.config;
1867 let operation_id = "v2.remove_user_from_role";
1868
1869 let local_client = &self.client;
1870
1871 let local_uri_str = format!(
1872 "{}/api/v2/roles/{role_id}/users",
1873 local_configuration.get_operation_host(operation_id),
1874 role_id = datadog::urlencode(role_id)
1875 );
1876 let mut local_req_builder =
1877 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
1878
1879 let mut headers = HeaderMap::new();
1881 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1882 headers.insert("Accept", HeaderValue::from_static("application/json"));
1883
1884 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1886 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1887 Err(e) => {
1888 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1889 headers.insert(
1890 reqwest::header::USER_AGENT,
1891 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1892 )
1893 }
1894 };
1895
1896 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1898 headers.insert(
1899 "DD-API-KEY",
1900 HeaderValue::from_str(local_key.key.as_str())
1901 .expect("failed to parse DD-API-KEY header"),
1902 );
1903 };
1904 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1905 headers.insert(
1906 "DD-APPLICATION-KEY",
1907 HeaderValue::from_str(local_key.key.as_str())
1908 .expect("failed to parse DD-APPLICATION-KEY header"),
1909 );
1910 };
1911
1912 let output = Vec::new();
1914 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1915 if body.serialize(&mut ser).is_ok() {
1916 if let Some(content_encoding) = headers.get("Content-Encoding") {
1917 match content_encoding.to_str().unwrap_or_default() {
1918 "gzip" => {
1919 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1920 let _ = enc.write_all(ser.into_inner().as_slice());
1921 match enc.finish() {
1922 Ok(buf) => {
1923 local_req_builder = local_req_builder.body(buf);
1924 }
1925 Err(e) => return Err(datadog::Error::Io(e)),
1926 }
1927 }
1928 "deflate" => {
1929 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1930 let _ = enc.write_all(ser.into_inner().as_slice());
1931 match enc.finish() {
1932 Ok(buf) => {
1933 local_req_builder = local_req_builder.body(buf);
1934 }
1935 Err(e) => return Err(datadog::Error::Io(e)),
1936 }
1937 }
1938 "zstd1" => {
1939 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1940 let _ = enc.write_all(ser.into_inner().as_slice());
1941 match enc.finish() {
1942 Ok(buf) => {
1943 local_req_builder = local_req_builder.body(buf);
1944 }
1945 Err(e) => return Err(datadog::Error::Io(e)),
1946 }
1947 }
1948 _ => {
1949 local_req_builder = local_req_builder.body(ser.into_inner());
1950 }
1951 }
1952 } else {
1953 local_req_builder = local_req_builder.body(ser.into_inner());
1954 }
1955 }
1956
1957 local_req_builder = local_req_builder.headers(headers);
1958 let local_req = local_req_builder.build()?;
1959 log::debug!("request content: {:?}", local_req.body());
1960 let local_resp = local_client.execute(local_req).await?;
1961
1962 let local_status = local_resp.status();
1963 let local_content = local_resp.text().await?;
1964 log::debug!("response content: {}", local_content);
1965
1966 if !local_status.is_client_error() && !local_status.is_server_error() {
1967 match serde_json::from_str::<crate::datadogV2::model::UsersResponse>(&local_content) {
1968 Ok(e) => {
1969 return Ok(datadog::ResponseContent {
1970 status: local_status,
1971 content: local_content,
1972 entity: Some(e),
1973 })
1974 }
1975 Err(e) => return Err(datadog::Error::Serde(e)),
1976 };
1977 } else {
1978 let local_entity: Option<RemoveUserFromRoleError> =
1979 serde_json::from_str(&local_content).ok();
1980 let local_error = datadog::ResponseContent {
1981 status: local_status,
1982 content: local_content,
1983 entity: local_entity,
1984 };
1985 Err(datadog::Error::ResponseError(local_error))
1986 }
1987 }
1988
1989 pub async fn update_role(
1991 &self,
1992 role_id: String,
1993 body: crate::datadogV2::model::RoleUpdateRequest,
1994 ) -> Result<crate::datadogV2::model::RoleUpdateResponse, datadog::Error<UpdateRoleError>> {
1995 match self.update_role_with_http_info(role_id, body).await {
1996 Ok(response_content) => {
1997 if let Some(e) = response_content.entity {
1998 Ok(e)
1999 } else {
2000 Err(datadog::Error::Serde(serde::de::Error::custom(
2001 "response content was None",
2002 )))
2003 }
2004 }
2005 Err(err) => Err(err),
2006 }
2007 }
2008
2009 pub async fn update_role_with_http_info(
2011 &self,
2012 role_id: String,
2013 body: crate::datadogV2::model::RoleUpdateRequest,
2014 ) -> Result<
2015 datadog::ResponseContent<crate::datadogV2::model::RoleUpdateResponse>,
2016 datadog::Error<UpdateRoleError>,
2017 > {
2018 let local_configuration = &self.config;
2019 let operation_id = "v2.update_role";
2020
2021 let local_client = &self.client;
2022
2023 let local_uri_str = format!(
2024 "{}/api/v2/roles/{role_id}",
2025 local_configuration.get_operation_host(operation_id),
2026 role_id = datadog::urlencode(role_id)
2027 );
2028 let mut local_req_builder =
2029 local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
2030
2031 let mut headers = HeaderMap::new();
2033 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
2034 headers.insert("Accept", HeaderValue::from_static("application/json"));
2035
2036 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2038 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2039 Err(e) => {
2040 log::warn!("Failed to parse user agent header: {e}, falling back to default");
2041 headers.insert(
2042 reqwest::header::USER_AGENT,
2043 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2044 )
2045 }
2046 };
2047
2048 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2050 headers.insert(
2051 "DD-API-KEY",
2052 HeaderValue::from_str(local_key.key.as_str())
2053 .expect("failed to parse DD-API-KEY header"),
2054 );
2055 };
2056 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2057 headers.insert(
2058 "DD-APPLICATION-KEY",
2059 HeaderValue::from_str(local_key.key.as_str())
2060 .expect("failed to parse DD-APPLICATION-KEY header"),
2061 );
2062 };
2063
2064 let output = Vec::new();
2066 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2067 if body.serialize(&mut ser).is_ok() {
2068 if let Some(content_encoding) = headers.get("Content-Encoding") {
2069 match content_encoding.to_str().unwrap_or_default() {
2070 "gzip" => {
2071 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2072 let _ = enc.write_all(ser.into_inner().as_slice());
2073 match enc.finish() {
2074 Ok(buf) => {
2075 local_req_builder = local_req_builder.body(buf);
2076 }
2077 Err(e) => return Err(datadog::Error::Io(e)),
2078 }
2079 }
2080 "deflate" => {
2081 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2082 let _ = enc.write_all(ser.into_inner().as_slice());
2083 match enc.finish() {
2084 Ok(buf) => {
2085 local_req_builder = local_req_builder.body(buf);
2086 }
2087 Err(e) => return Err(datadog::Error::Io(e)),
2088 }
2089 }
2090 "zstd1" => {
2091 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2092 let _ = enc.write_all(ser.into_inner().as_slice());
2093 match enc.finish() {
2094 Ok(buf) => {
2095 local_req_builder = local_req_builder.body(buf);
2096 }
2097 Err(e) => return Err(datadog::Error::Io(e)),
2098 }
2099 }
2100 _ => {
2101 local_req_builder = local_req_builder.body(ser.into_inner());
2102 }
2103 }
2104 } else {
2105 local_req_builder = local_req_builder.body(ser.into_inner());
2106 }
2107 }
2108
2109 local_req_builder = local_req_builder.headers(headers);
2110 let local_req = local_req_builder.build()?;
2111 log::debug!("request content: {:?}", local_req.body());
2112 let local_resp = local_client.execute(local_req).await?;
2113
2114 let local_status = local_resp.status();
2115 let local_content = local_resp.text().await?;
2116 log::debug!("response content: {}", local_content);
2117
2118 if !local_status.is_client_error() && !local_status.is_server_error() {
2119 match serde_json::from_str::<crate::datadogV2::model::RoleUpdateResponse>(
2120 &local_content,
2121 ) {
2122 Ok(e) => {
2123 return Ok(datadog::ResponseContent {
2124 status: local_status,
2125 content: local_content,
2126 entity: Some(e),
2127 })
2128 }
2129 Err(e) => return Err(datadog::Error::Serde(e)),
2130 };
2131 } else {
2132 let local_entity: Option<UpdateRoleError> = serde_json::from_str(&local_content).ok();
2133 let local_error = datadog::ResponseContent {
2134 status: local_status,
2135 content: local_content,
2136 entity: local_entity,
2137 };
2138 Err(datadog::Error::ResponseError(local_error))
2139 }
2140 }
2141}