datadog_api_client/datadogV2/api/
api_roles.rs

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