datadog_api_client/datadogV2/api/
api_teams.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 async_stream::try_stream;
6use flate2::{
7    write::{GzEncoder, ZlibEncoder},
8    Compression,
9};
10use futures_core::stream::Stream;
11use reqwest::header::{HeaderMap, HeaderValue};
12use serde::{Deserialize, Serialize};
13use std::io::Write;
14
15/// GetTeamMembershipsOptionalParams is a struct for passing parameters to the method [`TeamsAPI::get_team_memberships`]
16#[non_exhaustive]
17#[derive(Clone, Default, Debug)]
18pub struct GetTeamMembershipsOptionalParams {
19    /// Size for a given page. The maximum allowed value is 100.
20    pub page_size: Option<i64>,
21    /// Specific page number to return.
22    pub page_number: Option<i64>,
23    /// Specifies the order of returned team memberships
24    pub sort: Option<crate::datadogV2::model::GetTeamMembershipsSort>,
25    /// Search query, can be user email or name
26    pub filter_keyword: Option<String>,
27}
28
29impl GetTeamMembershipsOptionalParams {
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    /// Specifies the order of returned team memberships
41    pub fn sort(mut self, value: crate::datadogV2::model::GetTeamMembershipsSort) -> Self {
42        self.sort = Some(value);
43        self
44    }
45    /// Search query, can be user email or name
46    pub fn filter_keyword(mut self, value: String) -> Self {
47        self.filter_keyword = Some(value);
48        self
49    }
50}
51
52/// ListTeamsOptionalParams is a struct for passing parameters to the method [`TeamsAPI::list_teams`]
53#[non_exhaustive]
54#[derive(Clone, Default, Debug)]
55pub struct ListTeamsOptionalParams {
56    /// Specific page number to return.
57    pub page_number: Option<i64>,
58    /// Size for a given page. The maximum allowed value is 100.
59    pub page_size: Option<i64>,
60    /// Specifies the order of the returned teams
61    pub sort: Option<crate::datadogV2::model::ListTeamsSort>,
62    /// Included related resources optionally requested. Allowed enum values: `team_links, user_team_permissions`
63    pub include: Option<Vec<crate::datadogV2::model::ListTeamsInclude>>,
64    /// Search query. Can be team name, team handle, or email of team member
65    pub filter_keyword: Option<String>,
66    /// When true, only returns teams the current user belongs to
67    pub filter_me: Option<bool>,
68    /// List of fields that need to be fetched.
69    pub fields_team: Option<Vec<crate::datadogV2::model::TeamsField>>,
70}
71
72impl ListTeamsOptionalParams {
73    /// Specific page number to return.
74    pub fn page_number(mut self, value: i64) -> Self {
75        self.page_number = Some(value);
76        self
77    }
78    /// Size for a given page. The maximum allowed value is 100.
79    pub fn page_size(mut self, value: i64) -> Self {
80        self.page_size = Some(value);
81        self
82    }
83    /// Specifies the order of the returned teams
84    pub fn sort(mut self, value: crate::datadogV2::model::ListTeamsSort) -> Self {
85        self.sort = Some(value);
86        self
87    }
88    /// Included related resources optionally requested. Allowed enum values: `team_links, user_team_permissions`
89    pub fn include(mut self, value: Vec<crate::datadogV2::model::ListTeamsInclude>) -> Self {
90        self.include = Some(value);
91        self
92    }
93    /// Search query. Can be team name, team handle, or email of team member
94    pub fn filter_keyword(mut self, value: String) -> Self {
95        self.filter_keyword = Some(value);
96        self
97    }
98    /// When true, only returns teams the current user belongs to
99    pub fn filter_me(mut self, value: bool) -> Self {
100        self.filter_me = Some(value);
101        self
102    }
103    /// List of fields that need to be fetched.
104    pub fn fields_team(mut self, value: Vec<crate::datadogV2::model::TeamsField>) -> Self {
105        self.fields_team = Some(value);
106        self
107    }
108}
109
110/// CreateTeamError is a struct for typed errors of method [`TeamsAPI::create_team`]
111#[derive(Debug, Clone, Serialize, Deserialize)]
112#[serde(untagged)]
113pub enum CreateTeamError {
114    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
115    UnknownValue(serde_json::Value),
116}
117
118/// CreateTeamLinkError is a struct for typed errors of method [`TeamsAPI::create_team_link`]
119#[derive(Debug, Clone, Serialize, Deserialize)]
120#[serde(untagged)]
121pub enum CreateTeamLinkError {
122    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
123    UnknownValue(serde_json::Value),
124}
125
126/// CreateTeamMembershipError is a struct for typed errors of method [`TeamsAPI::create_team_membership`]
127#[derive(Debug, Clone, Serialize, Deserialize)]
128#[serde(untagged)]
129pub enum CreateTeamMembershipError {
130    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
131    UnknownValue(serde_json::Value),
132}
133
134/// DeleteTeamError is a struct for typed errors of method [`TeamsAPI::delete_team`]
135#[derive(Debug, Clone, Serialize, Deserialize)]
136#[serde(untagged)]
137pub enum DeleteTeamError {
138    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
139    UnknownValue(serde_json::Value),
140}
141
142/// DeleteTeamLinkError is a struct for typed errors of method [`TeamsAPI::delete_team_link`]
143#[derive(Debug, Clone, Serialize, Deserialize)]
144#[serde(untagged)]
145pub enum DeleteTeamLinkError {
146    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
147    UnknownValue(serde_json::Value),
148}
149
150/// DeleteTeamMembershipError is a struct for typed errors of method [`TeamsAPI::delete_team_membership`]
151#[derive(Debug, Clone, Serialize, Deserialize)]
152#[serde(untagged)]
153pub enum DeleteTeamMembershipError {
154    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
155    UnknownValue(serde_json::Value),
156}
157
158/// GetTeamError is a struct for typed errors of method [`TeamsAPI::get_team`]
159#[derive(Debug, Clone, Serialize, Deserialize)]
160#[serde(untagged)]
161pub enum GetTeamError {
162    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
163    UnknownValue(serde_json::Value),
164}
165
166/// GetTeamLinkError is a struct for typed errors of method [`TeamsAPI::get_team_link`]
167#[derive(Debug, Clone, Serialize, Deserialize)]
168#[serde(untagged)]
169pub enum GetTeamLinkError {
170    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
171    UnknownValue(serde_json::Value),
172}
173
174/// GetTeamLinksError is a struct for typed errors of method [`TeamsAPI::get_team_links`]
175#[derive(Debug, Clone, Serialize, Deserialize)]
176#[serde(untagged)]
177pub enum GetTeamLinksError {
178    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
179    UnknownValue(serde_json::Value),
180}
181
182/// GetTeamMembershipsError is a struct for typed errors of method [`TeamsAPI::get_team_memberships`]
183#[derive(Debug, Clone, Serialize, Deserialize)]
184#[serde(untagged)]
185pub enum GetTeamMembershipsError {
186    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
187    UnknownValue(serde_json::Value),
188}
189
190/// GetTeamPermissionSettingsError is a struct for typed errors of method [`TeamsAPI::get_team_permission_settings`]
191#[derive(Debug, Clone, Serialize, Deserialize)]
192#[serde(untagged)]
193pub enum GetTeamPermissionSettingsError {
194    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
195    UnknownValue(serde_json::Value),
196}
197
198/// GetUserMembershipsError is a struct for typed errors of method [`TeamsAPI::get_user_memberships`]
199#[derive(Debug, Clone, Serialize, Deserialize)]
200#[serde(untagged)]
201pub enum GetUserMembershipsError {
202    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
203    UnknownValue(serde_json::Value),
204}
205
206/// ListTeamsError is a struct for typed errors of method [`TeamsAPI::list_teams`]
207#[derive(Debug, Clone, Serialize, Deserialize)]
208#[serde(untagged)]
209pub enum ListTeamsError {
210    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
211    UnknownValue(serde_json::Value),
212}
213
214/// UpdateTeamError is a struct for typed errors of method [`TeamsAPI::update_team`]
215#[derive(Debug, Clone, Serialize, Deserialize)]
216#[serde(untagged)]
217pub enum UpdateTeamError {
218    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
219    UnknownValue(serde_json::Value),
220}
221
222/// UpdateTeamLinkError is a struct for typed errors of method [`TeamsAPI::update_team_link`]
223#[derive(Debug, Clone, Serialize, Deserialize)]
224#[serde(untagged)]
225pub enum UpdateTeamLinkError {
226    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
227    UnknownValue(serde_json::Value),
228}
229
230/// UpdateTeamMembershipError is a struct for typed errors of method [`TeamsAPI::update_team_membership`]
231#[derive(Debug, Clone, Serialize, Deserialize)]
232#[serde(untagged)]
233pub enum UpdateTeamMembershipError {
234    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
235    UnknownValue(serde_json::Value),
236}
237
238/// UpdateTeamPermissionSettingError is a struct for typed errors of method [`TeamsAPI::update_team_permission_setting`]
239#[derive(Debug, Clone, Serialize, Deserialize)]
240#[serde(untagged)]
241pub enum UpdateTeamPermissionSettingError {
242    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
243    UnknownValue(serde_json::Value),
244}
245
246/// View and manage teams within Datadog. See the [Teams page](<https://docs.datadoghq.com/account_management/teams/>) for more information.
247#[derive(Debug, Clone)]
248pub struct TeamsAPI {
249    config: datadog::Configuration,
250    client: reqwest_middleware::ClientWithMiddleware,
251}
252
253impl Default for TeamsAPI {
254    fn default() -> Self {
255        Self::with_config(datadog::Configuration::default())
256    }
257}
258
259impl TeamsAPI {
260    pub fn new() -> Self {
261        Self::default()
262    }
263    pub fn with_config(config: datadog::Configuration) -> Self {
264        let mut reqwest_client_builder = reqwest::Client::builder();
265
266        if let Some(proxy_url) = &config.proxy_url {
267            let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
268            reqwest_client_builder = reqwest_client_builder.proxy(proxy);
269        }
270
271        let mut middleware_client_builder =
272            reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
273
274        if config.enable_retry {
275            struct RetryableStatus;
276            impl reqwest_retry::RetryableStrategy for RetryableStatus {
277                fn handle(
278                    &self,
279                    res: &Result<reqwest::Response, reqwest_middleware::Error>,
280                ) -> Option<reqwest_retry::Retryable> {
281                    match res {
282                        Ok(success) => reqwest_retry::default_on_request_success(success),
283                        Err(_) => None,
284                    }
285                }
286            }
287            let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
288                .build_with_max_retries(config.max_retries);
289
290            let retry_middleware =
291                reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
292                    backoff_policy,
293                    RetryableStatus,
294                );
295
296            middleware_client_builder = middleware_client_builder.with(retry_middleware);
297        }
298
299        let client = middleware_client_builder.build();
300
301        Self { config, client }
302    }
303
304    pub fn with_client_and_config(
305        config: datadog::Configuration,
306        client: reqwest_middleware::ClientWithMiddleware,
307    ) -> Self {
308        Self { config, client }
309    }
310
311    /// Create a new team.
312    /// User IDs passed through the `users` relationship field are added to the team.
313    pub async fn create_team(
314        &self,
315        body: crate::datadogV2::model::TeamCreateRequest,
316    ) -> Result<crate::datadogV2::model::TeamResponse, datadog::Error<CreateTeamError>> {
317        match self.create_team_with_http_info(body).await {
318            Ok(response_content) => {
319                if let Some(e) = response_content.entity {
320                    Ok(e)
321                } else {
322                    Err(datadog::Error::Serde(serde::de::Error::custom(
323                        "response content was None",
324                    )))
325                }
326            }
327            Err(err) => Err(err),
328        }
329    }
330
331    /// Create a new team.
332    /// User IDs passed through the `users` relationship field are added to the team.
333    pub async fn create_team_with_http_info(
334        &self,
335        body: crate::datadogV2::model::TeamCreateRequest,
336    ) -> Result<
337        datadog::ResponseContent<crate::datadogV2::model::TeamResponse>,
338        datadog::Error<CreateTeamError>,
339    > {
340        let local_configuration = &self.config;
341        let operation_id = "v2.create_team";
342
343        let local_client = &self.client;
344
345        let local_uri_str = format!(
346            "{}/api/v2/team",
347            local_configuration.get_operation_host(operation_id)
348        );
349        let mut local_req_builder =
350            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
351
352        // build headers
353        let mut headers = HeaderMap::new();
354        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
355        headers.insert("Accept", HeaderValue::from_static("application/json"));
356
357        // build user agent
358        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
359            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
360            Err(e) => {
361                log::warn!("Failed to parse user agent header: {e}, falling back to default");
362                headers.insert(
363                    reqwest::header::USER_AGENT,
364                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
365                )
366            }
367        };
368
369        // build auth
370        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
371            headers.insert(
372                "DD-API-KEY",
373                HeaderValue::from_str(local_key.key.as_str())
374                    .expect("failed to parse DD-API-KEY header"),
375            );
376        };
377        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
378            headers.insert(
379                "DD-APPLICATION-KEY",
380                HeaderValue::from_str(local_key.key.as_str())
381                    .expect("failed to parse DD-APPLICATION-KEY header"),
382            );
383        };
384
385        // build body parameters
386        let output = Vec::new();
387        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
388        if body.serialize(&mut ser).is_ok() {
389            if let Some(content_encoding) = headers.get("Content-Encoding") {
390                match content_encoding.to_str().unwrap_or_default() {
391                    "gzip" => {
392                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
393                        let _ = enc.write_all(ser.into_inner().as_slice());
394                        match enc.finish() {
395                            Ok(buf) => {
396                                local_req_builder = local_req_builder.body(buf);
397                            }
398                            Err(e) => return Err(datadog::Error::Io(e)),
399                        }
400                    }
401                    "deflate" => {
402                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
403                        let _ = enc.write_all(ser.into_inner().as_slice());
404                        match enc.finish() {
405                            Ok(buf) => {
406                                local_req_builder = local_req_builder.body(buf);
407                            }
408                            Err(e) => return Err(datadog::Error::Io(e)),
409                        }
410                    }
411                    "zstd1" => {
412                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
413                        let _ = enc.write_all(ser.into_inner().as_slice());
414                        match enc.finish() {
415                            Ok(buf) => {
416                                local_req_builder = local_req_builder.body(buf);
417                            }
418                            Err(e) => return Err(datadog::Error::Io(e)),
419                        }
420                    }
421                    _ => {
422                        local_req_builder = local_req_builder.body(ser.into_inner());
423                    }
424                }
425            } else {
426                local_req_builder = local_req_builder.body(ser.into_inner());
427            }
428        }
429
430        local_req_builder = local_req_builder.headers(headers);
431        let local_req = local_req_builder.build()?;
432        log::debug!("request content: {:?}", local_req.body());
433        let local_resp = local_client.execute(local_req).await?;
434
435        let local_status = local_resp.status();
436        let local_content = local_resp.text().await?;
437        log::debug!("response content: {}", local_content);
438
439        if !local_status.is_client_error() && !local_status.is_server_error() {
440            match serde_json::from_str::<crate::datadogV2::model::TeamResponse>(&local_content) {
441                Ok(e) => {
442                    return Ok(datadog::ResponseContent {
443                        status: local_status,
444                        content: local_content,
445                        entity: Some(e),
446                    })
447                }
448                Err(e) => return Err(datadog::Error::Serde(e)),
449            };
450        } else {
451            let local_entity: Option<CreateTeamError> = serde_json::from_str(&local_content).ok();
452            let local_error = datadog::ResponseContent {
453                status: local_status,
454                content: local_content,
455                entity: local_entity,
456            };
457            Err(datadog::Error::ResponseError(local_error))
458        }
459    }
460
461    /// Add a new link to a team.
462    pub async fn create_team_link(
463        &self,
464        team_id: String,
465        body: crate::datadogV2::model::TeamLinkCreateRequest,
466    ) -> Result<crate::datadogV2::model::TeamLinkResponse, datadog::Error<CreateTeamLinkError>>
467    {
468        match self.create_team_link_with_http_info(team_id, body).await {
469            Ok(response_content) => {
470                if let Some(e) = response_content.entity {
471                    Ok(e)
472                } else {
473                    Err(datadog::Error::Serde(serde::de::Error::custom(
474                        "response content was None",
475                    )))
476                }
477            }
478            Err(err) => Err(err),
479        }
480    }
481
482    /// Add a new link to a team.
483    pub async fn create_team_link_with_http_info(
484        &self,
485        team_id: String,
486        body: crate::datadogV2::model::TeamLinkCreateRequest,
487    ) -> Result<
488        datadog::ResponseContent<crate::datadogV2::model::TeamLinkResponse>,
489        datadog::Error<CreateTeamLinkError>,
490    > {
491        let local_configuration = &self.config;
492        let operation_id = "v2.create_team_link";
493
494        let local_client = &self.client;
495
496        let local_uri_str = format!(
497            "{}/api/v2/team/{team_id}/links",
498            local_configuration.get_operation_host(operation_id),
499            team_id = datadog::urlencode(team_id)
500        );
501        let mut local_req_builder =
502            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
503
504        // build headers
505        let mut headers = HeaderMap::new();
506        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
507        headers.insert("Accept", HeaderValue::from_static("application/json"));
508
509        // build user agent
510        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
511            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
512            Err(e) => {
513                log::warn!("Failed to parse user agent header: {e}, falling back to default");
514                headers.insert(
515                    reqwest::header::USER_AGENT,
516                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
517                )
518            }
519        };
520
521        // build auth
522        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
523            headers.insert(
524                "DD-API-KEY",
525                HeaderValue::from_str(local_key.key.as_str())
526                    .expect("failed to parse DD-API-KEY header"),
527            );
528        };
529        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
530            headers.insert(
531                "DD-APPLICATION-KEY",
532                HeaderValue::from_str(local_key.key.as_str())
533                    .expect("failed to parse DD-APPLICATION-KEY header"),
534            );
535        };
536
537        // build body parameters
538        let output = Vec::new();
539        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
540        if body.serialize(&mut ser).is_ok() {
541            if let Some(content_encoding) = headers.get("Content-Encoding") {
542                match content_encoding.to_str().unwrap_or_default() {
543                    "gzip" => {
544                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
545                        let _ = enc.write_all(ser.into_inner().as_slice());
546                        match enc.finish() {
547                            Ok(buf) => {
548                                local_req_builder = local_req_builder.body(buf);
549                            }
550                            Err(e) => return Err(datadog::Error::Io(e)),
551                        }
552                    }
553                    "deflate" => {
554                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
555                        let _ = enc.write_all(ser.into_inner().as_slice());
556                        match enc.finish() {
557                            Ok(buf) => {
558                                local_req_builder = local_req_builder.body(buf);
559                            }
560                            Err(e) => return Err(datadog::Error::Io(e)),
561                        }
562                    }
563                    "zstd1" => {
564                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
565                        let _ = enc.write_all(ser.into_inner().as_slice());
566                        match enc.finish() {
567                            Ok(buf) => {
568                                local_req_builder = local_req_builder.body(buf);
569                            }
570                            Err(e) => return Err(datadog::Error::Io(e)),
571                        }
572                    }
573                    _ => {
574                        local_req_builder = local_req_builder.body(ser.into_inner());
575                    }
576                }
577            } else {
578                local_req_builder = local_req_builder.body(ser.into_inner());
579            }
580        }
581
582        local_req_builder = local_req_builder.headers(headers);
583        let local_req = local_req_builder.build()?;
584        log::debug!("request content: {:?}", local_req.body());
585        let local_resp = local_client.execute(local_req).await?;
586
587        let local_status = local_resp.status();
588        let local_content = local_resp.text().await?;
589        log::debug!("response content: {}", local_content);
590
591        if !local_status.is_client_error() && !local_status.is_server_error() {
592            match serde_json::from_str::<crate::datadogV2::model::TeamLinkResponse>(&local_content)
593            {
594                Ok(e) => {
595                    return Ok(datadog::ResponseContent {
596                        status: local_status,
597                        content: local_content,
598                        entity: Some(e),
599                    })
600                }
601                Err(e) => return Err(datadog::Error::Serde(e)),
602            };
603        } else {
604            let local_entity: Option<CreateTeamLinkError> =
605                serde_json::from_str(&local_content).ok();
606            let local_error = datadog::ResponseContent {
607                status: local_status,
608                content: local_content,
609                entity: local_entity,
610            };
611            Err(datadog::Error::ResponseError(local_error))
612        }
613    }
614
615    /// Add a user to a team.
616    pub async fn create_team_membership(
617        &self,
618        team_id: String,
619        body: crate::datadogV2::model::UserTeamRequest,
620    ) -> Result<crate::datadogV2::model::UserTeamResponse, datadog::Error<CreateTeamMembershipError>>
621    {
622        match self
623            .create_team_membership_with_http_info(team_id, body)
624            .await
625        {
626            Ok(response_content) => {
627                if let Some(e) = response_content.entity {
628                    Ok(e)
629                } else {
630                    Err(datadog::Error::Serde(serde::de::Error::custom(
631                        "response content was None",
632                    )))
633                }
634            }
635            Err(err) => Err(err),
636        }
637    }
638
639    /// Add a user to a team.
640    pub async fn create_team_membership_with_http_info(
641        &self,
642        team_id: String,
643        body: crate::datadogV2::model::UserTeamRequest,
644    ) -> Result<
645        datadog::ResponseContent<crate::datadogV2::model::UserTeamResponse>,
646        datadog::Error<CreateTeamMembershipError>,
647    > {
648        let local_configuration = &self.config;
649        let operation_id = "v2.create_team_membership";
650
651        let local_client = &self.client;
652
653        let local_uri_str = format!(
654            "{}/api/v2/team/{team_id}/memberships",
655            local_configuration.get_operation_host(operation_id),
656            team_id = datadog::urlencode(team_id)
657        );
658        let mut local_req_builder =
659            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
660
661        // build headers
662        let mut headers = HeaderMap::new();
663        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
664        headers.insert("Accept", HeaderValue::from_static("application/json"));
665
666        // build user agent
667        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
668            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
669            Err(e) => {
670                log::warn!("Failed to parse user agent header: {e}, falling back to default");
671                headers.insert(
672                    reqwest::header::USER_AGENT,
673                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
674                )
675            }
676        };
677
678        // build auth
679        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
680            headers.insert(
681                "DD-API-KEY",
682                HeaderValue::from_str(local_key.key.as_str())
683                    .expect("failed to parse DD-API-KEY header"),
684            );
685        };
686        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
687            headers.insert(
688                "DD-APPLICATION-KEY",
689                HeaderValue::from_str(local_key.key.as_str())
690                    .expect("failed to parse DD-APPLICATION-KEY header"),
691            );
692        };
693
694        // build body parameters
695        let output = Vec::new();
696        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
697        if body.serialize(&mut ser).is_ok() {
698            if let Some(content_encoding) = headers.get("Content-Encoding") {
699                match content_encoding.to_str().unwrap_or_default() {
700                    "gzip" => {
701                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
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                    "deflate" => {
711                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
712                        let _ = enc.write_all(ser.into_inner().as_slice());
713                        match enc.finish() {
714                            Ok(buf) => {
715                                local_req_builder = local_req_builder.body(buf);
716                            }
717                            Err(e) => return Err(datadog::Error::Io(e)),
718                        }
719                    }
720                    "zstd1" => {
721                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
722                        let _ = enc.write_all(ser.into_inner().as_slice());
723                        match enc.finish() {
724                            Ok(buf) => {
725                                local_req_builder = local_req_builder.body(buf);
726                            }
727                            Err(e) => return Err(datadog::Error::Io(e)),
728                        }
729                    }
730                    _ => {
731                        local_req_builder = local_req_builder.body(ser.into_inner());
732                    }
733                }
734            } else {
735                local_req_builder = local_req_builder.body(ser.into_inner());
736            }
737        }
738
739        local_req_builder = local_req_builder.headers(headers);
740        let local_req = local_req_builder.build()?;
741        log::debug!("request content: {:?}", local_req.body());
742        let local_resp = local_client.execute(local_req).await?;
743
744        let local_status = local_resp.status();
745        let local_content = local_resp.text().await?;
746        log::debug!("response content: {}", local_content);
747
748        if !local_status.is_client_error() && !local_status.is_server_error() {
749            match serde_json::from_str::<crate::datadogV2::model::UserTeamResponse>(&local_content)
750            {
751                Ok(e) => {
752                    return Ok(datadog::ResponseContent {
753                        status: local_status,
754                        content: local_content,
755                        entity: Some(e),
756                    })
757                }
758                Err(e) => return Err(datadog::Error::Serde(e)),
759            };
760        } else {
761            let local_entity: Option<CreateTeamMembershipError> =
762                serde_json::from_str(&local_content).ok();
763            let local_error = datadog::ResponseContent {
764                status: local_status,
765                content: local_content,
766                entity: local_entity,
767            };
768            Err(datadog::Error::ResponseError(local_error))
769        }
770    }
771
772    /// Remove a team using the team's `id`.
773    pub async fn delete_team(
774        &self,
775        team_id: String,
776    ) -> Result<(), datadog::Error<DeleteTeamError>> {
777        match self.delete_team_with_http_info(team_id).await {
778            Ok(_) => Ok(()),
779            Err(err) => Err(err),
780        }
781    }
782
783    /// Remove a team using the team's `id`.
784    pub async fn delete_team_with_http_info(
785        &self,
786        team_id: String,
787    ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteTeamError>> {
788        let local_configuration = &self.config;
789        let operation_id = "v2.delete_team";
790
791        let local_client = &self.client;
792
793        let local_uri_str = format!(
794            "{}/api/v2/team/{team_id}",
795            local_configuration.get_operation_host(operation_id),
796            team_id = datadog::urlencode(team_id)
797        );
798        let mut local_req_builder =
799            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
800
801        // build headers
802        let mut headers = HeaderMap::new();
803        headers.insert("Accept", HeaderValue::from_static("*/*"));
804
805        // build user agent
806        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
807            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
808            Err(e) => {
809                log::warn!("Failed to parse user agent header: {e}, falling back to default");
810                headers.insert(
811                    reqwest::header::USER_AGENT,
812                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
813                )
814            }
815        };
816
817        // build auth
818        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
819            headers.insert(
820                "DD-API-KEY",
821                HeaderValue::from_str(local_key.key.as_str())
822                    .expect("failed to parse DD-API-KEY header"),
823            );
824        };
825        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
826            headers.insert(
827                "DD-APPLICATION-KEY",
828                HeaderValue::from_str(local_key.key.as_str())
829                    .expect("failed to parse DD-APPLICATION-KEY header"),
830            );
831        };
832
833        local_req_builder = local_req_builder.headers(headers);
834        let local_req = local_req_builder.build()?;
835        log::debug!("request content: {:?}", local_req.body());
836        let local_resp = local_client.execute(local_req).await?;
837
838        let local_status = local_resp.status();
839        let local_content = local_resp.text().await?;
840        log::debug!("response content: {}", local_content);
841
842        if !local_status.is_client_error() && !local_status.is_server_error() {
843            Ok(datadog::ResponseContent {
844                status: local_status,
845                content: local_content,
846                entity: None,
847            })
848        } else {
849            let local_entity: Option<DeleteTeamError> = serde_json::from_str(&local_content).ok();
850            let local_error = datadog::ResponseContent {
851                status: local_status,
852                content: local_content,
853                entity: local_entity,
854            };
855            Err(datadog::Error::ResponseError(local_error))
856        }
857    }
858
859    /// Remove a link from a team.
860    pub async fn delete_team_link(
861        &self,
862        team_id: String,
863        link_id: String,
864    ) -> Result<(), datadog::Error<DeleteTeamLinkError>> {
865        match self.delete_team_link_with_http_info(team_id, link_id).await {
866            Ok(_) => Ok(()),
867            Err(err) => Err(err),
868        }
869    }
870
871    /// Remove a link from a team.
872    pub async fn delete_team_link_with_http_info(
873        &self,
874        team_id: String,
875        link_id: String,
876    ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteTeamLinkError>> {
877        let local_configuration = &self.config;
878        let operation_id = "v2.delete_team_link";
879
880        let local_client = &self.client;
881
882        let local_uri_str = format!(
883            "{}/api/v2/team/{team_id}/links/{link_id}",
884            local_configuration.get_operation_host(operation_id),
885            team_id = datadog::urlencode(team_id),
886            link_id = datadog::urlencode(link_id)
887        );
888        let mut local_req_builder =
889            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
890
891        // build headers
892        let mut headers = HeaderMap::new();
893        headers.insert("Accept", HeaderValue::from_static("*/*"));
894
895        // build user agent
896        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
897            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
898            Err(e) => {
899                log::warn!("Failed to parse user agent header: {e}, falling back to default");
900                headers.insert(
901                    reqwest::header::USER_AGENT,
902                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
903                )
904            }
905        };
906
907        // build auth
908        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
909            headers.insert(
910                "DD-API-KEY",
911                HeaderValue::from_str(local_key.key.as_str())
912                    .expect("failed to parse DD-API-KEY header"),
913            );
914        };
915        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
916            headers.insert(
917                "DD-APPLICATION-KEY",
918                HeaderValue::from_str(local_key.key.as_str())
919                    .expect("failed to parse DD-APPLICATION-KEY header"),
920            );
921        };
922
923        local_req_builder = local_req_builder.headers(headers);
924        let local_req = local_req_builder.build()?;
925        log::debug!("request content: {:?}", local_req.body());
926        let local_resp = local_client.execute(local_req).await?;
927
928        let local_status = local_resp.status();
929        let local_content = local_resp.text().await?;
930        log::debug!("response content: {}", local_content);
931
932        if !local_status.is_client_error() && !local_status.is_server_error() {
933            Ok(datadog::ResponseContent {
934                status: local_status,
935                content: local_content,
936                entity: None,
937            })
938        } else {
939            let local_entity: Option<DeleteTeamLinkError> =
940                serde_json::from_str(&local_content).ok();
941            let local_error = datadog::ResponseContent {
942                status: local_status,
943                content: local_content,
944                entity: local_entity,
945            };
946            Err(datadog::Error::ResponseError(local_error))
947        }
948    }
949
950    /// Remove a user from a team.
951    pub async fn delete_team_membership(
952        &self,
953        team_id: String,
954        user_id: String,
955    ) -> Result<(), datadog::Error<DeleteTeamMembershipError>> {
956        match self
957            .delete_team_membership_with_http_info(team_id, user_id)
958            .await
959        {
960            Ok(_) => Ok(()),
961            Err(err) => Err(err),
962        }
963    }
964
965    /// Remove a user from a team.
966    pub async fn delete_team_membership_with_http_info(
967        &self,
968        team_id: String,
969        user_id: String,
970    ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteTeamMembershipError>> {
971        let local_configuration = &self.config;
972        let operation_id = "v2.delete_team_membership";
973
974        let local_client = &self.client;
975
976        let local_uri_str = format!(
977            "{}/api/v2/team/{team_id}/memberships/{user_id}",
978            local_configuration.get_operation_host(operation_id),
979            team_id = datadog::urlencode(team_id),
980            user_id = datadog::urlencode(user_id)
981        );
982        let mut local_req_builder =
983            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
984
985        // build headers
986        let mut headers = HeaderMap::new();
987        headers.insert("Accept", HeaderValue::from_static("*/*"));
988
989        // build user agent
990        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
991            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
992            Err(e) => {
993                log::warn!("Failed to parse user agent header: {e}, falling back to default");
994                headers.insert(
995                    reqwest::header::USER_AGENT,
996                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
997                )
998            }
999        };
1000
1001        // build auth
1002        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1003            headers.insert(
1004                "DD-API-KEY",
1005                HeaderValue::from_str(local_key.key.as_str())
1006                    .expect("failed to parse DD-API-KEY header"),
1007            );
1008        };
1009        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1010            headers.insert(
1011                "DD-APPLICATION-KEY",
1012                HeaderValue::from_str(local_key.key.as_str())
1013                    .expect("failed to parse DD-APPLICATION-KEY header"),
1014            );
1015        };
1016
1017        local_req_builder = local_req_builder.headers(headers);
1018        let local_req = local_req_builder.build()?;
1019        log::debug!("request content: {:?}", local_req.body());
1020        let local_resp = local_client.execute(local_req).await?;
1021
1022        let local_status = local_resp.status();
1023        let local_content = local_resp.text().await?;
1024        log::debug!("response content: {}", local_content);
1025
1026        if !local_status.is_client_error() && !local_status.is_server_error() {
1027            Ok(datadog::ResponseContent {
1028                status: local_status,
1029                content: local_content,
1030                entity: None,
1031            })
1032        } else {
1033            let local_entity: Option<DeleteTeamMembershipError> =
1034                serde_json::from_str(&local_content).ok();
1035            let local_error = datadog::ResponseContent {
1036                status: local_status,
1037                content: local_content,
1038                entity: local_entity,
1039            };
1040            Err(datadog::Error::ResponseError(local_error))
1041        }
1042    }
1043
1044    /// Get a single team using the team's `id`.
1045    pub async fn get_team(
1046        &self,
1047        team_id: String,
1048    ) -> Result<crate::datadogV2::model::TeamResponse, datadog::Error<GetTeamError>> {
1049        match self.get_team_with_http_info(team_id).await {
1050            Ok(response_content) => {
1051                if let Some(e) = response_content.entity {
1052                    Ok(e)
1053                } else {
1054                    Err(datadog::Error::Serde(serde::de::Error::custom(
1055                        "response content was None",
1056                    )))
1057                }
1058            }
1059            Err(err) => Err(err),
1060        }
1061    }
1062
1063    /// Get a single team using the team's `id`.
1064    pub async fn get_team_with_http_info(
1065        &self,
1066        team_id: String,
1067    ) -> Result<
1068        datadog::ResponseContent<crate::datadogV2::model::TeamResponse>,
1069        datadog::Error<GetTeamError>,
1070    > {
1071        let local_configuration = &self.config;
1072        let operation_id = "v2.get_team";
1073
1074        let local_client = &self.client;
1075
1076        let local_uri_str = format!(
1077            "{}/api/v2/team/{team_id}",
1078            local_configuration.get_operation_host(operation_id),
1079            team_id = datadog::urlencode(team_id)
1080        );
1081        let mut local_req_builder =
1082            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1083
1084        // build headers
1085        let mut headers = HeaderMap::new();
1086        headers.insert("Accept", HeaderValue::from_static("application/json"));
1087
1088        // build user agent
1089        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1090            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1091            Err(e) => {
1092                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1093                headers.insert(
1094                    reqwest::header::USER_AGENT,
1095                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1096                )
1097            }
1098        };
1099
1100        // build auth
1101        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1102            headers.insert(
1103                "DD-API-KEY",
1104                HeaderValue::from_str(local_key.key.as_str())
1105                    .expect("failed to parse DD-API-KEY header"),
1106            );
1107        };
1108        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1109            headers.insert(
1110                "DD-APPLICATION-KEY",
1111                HeaderValue::from_str(local_key.key.as_str())
1112                    .expect("failed to parse DD-APPLICATION-KEY header"),
1113            );
1114        };
1115
1116        local_req_builder = local_req_builder.headers(headers);
1117        let local_req = local_req_builder.build()?;
1118        log::debug!("request content: {:?}", local_req.body());
1119        let local_resp = local_client.execute(local_req).await?;
1120
1121        let local_status = local_resp.status();
1122        let local_content = local_resp.text().await?;
1123        log::debug!("response content: {}", local_content);
1124
1125        if !local_status.is_client_error() && !local_status.is_server_error() {
1126            match serde_json::from_str::<crate::datadogV2::model::TeamResponse>(&local_content) {
1127                Ok(e) => {
1128                    return Ok(datadog::ResponseContent {
1129                        status: local_status,
1130                        content: local_content,
1131                        entity: Some(e),
1132                    })
1133                }
1134                Err(e) => return Err(datadog::Error::Serde(e)),
1135            };
1136        } else {
1137            let local_entity: Option<GetTeamError> = serde_json::from_str(&local_content).ok();
1138            let local_error = datadog::ResponseContent {
1139                status: local_status,
1140                content: local_content,
1141                entity: local_entity,
1142            };
1143            Err(datadog::Error::ResponseError(local_error))
1144        }
1145    }
1146
1147    /// Get a single link for a team.
1148    pub async fn get_team_link(
1149        &self,
1150        team_id: String,
1151        link_id: String,
1152    ) -> Result<crate::datadogV2::model::TeamLinkResponse, datadog::Error<GetTeamLinkError>> {
1153        match self.get_team_link_with_http_info(team_id, link_id).await {
1154            Ok(response_content) => {
1155                if let Some(e) = response_content.entity {
1156                    Ok(e)
1157                } else {
1158                    Err(datadog::Error::Serde(serde::de::Error::custom(
1159                        "response content was None",
1160                    )))
1161                }
1162            }
1163            Err(err) => Err(err),
1164        }
1165    }
1166
1167    /// Get a single link for a team.
1168    pub async fn get_team_link_with_http_info(
1169        &self,
1170        team_id: String,
1171        link_id: String,
1172    ) -> Result<
1173        datadog::ResponseContent<crate::datadogV2::model::TeamLinkResponse>,
1174        datadog::Error<GetTeamLinkError>,
1175    > {
1176        let local_configuration = &self.config;
1177        let operation_id = "v2.get_team_link";
1178
1179        let local_client = &self.client;
1180
1181        let local_uri_str = format!(
1182            "{}/api/v2/team/{team_id}/links/{link_id}",
1183            local_configuration.get_operation_host(operation_id),
1184            team_id = datadog::urlencode(team_id),
1185            link_id = datadog::urlencode(link_id)
1186        );
1187        let mut local_req_builder =
1188            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1189
1190        // build headers
1191        let mut headers = HeaderMap::new();
1192        headers.insert("Accept", HeaderValue::from_static("application/json"));
1193
1194        // build user agent
1195        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1196            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1197            Err(e) => {
1198                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1199                headers.insert(
1200                    reqwest::header::USER_AGENT,
1201                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1202                )
1203            }
1204        };
1205
1206        // build auth
1207        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1208            headers.insert(
1209                "DD-API-KEY",
1210                HeaderValue::from_str(local_key.key.as_str())
1211                    .expect("failed to parse DD-API-KEY header"),
1212            );
1213        };
1214        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1215            headers.insert(
1216                "DD-APPLICATION-KEY",
1217                HeaderValue::from_str(local_key.key.as_str())
1218                    .expect("failed to parse DD-APPLICATION-KEY header"),
1219            );
1220        };
1221
1222        local_req_builder = local_req_builder.headers(headers);
1223        let local_req = local_req_builder.build()?;
1224        log::debug!("request content: {:?}", local_req.body());
1225        let local_resp = local_client.execute(local_req).await?;
1226
1227        let local_status = local_resp.status();
1228        let local_content = local_resp.text().await?;
1229        log::debug!("response content: {}", local_content);
1230
1231        if !local_status.is_client_error() && !local_status.is_server_error() {
1232            match serde_json::from_str::<crate::datadogV2::model::TeamLinkResponse>(&local_content)
1233            {
1234                Ok(e) => {
1235                    return Ok(datadog::ResponseContent {
1236                        status: local_status,
1237                        content: local_content,
1238                        entity: Some(e),
1239                    })
1240                }
1241                Err(e) => return Err(datadog::Error::Serde(e)),
1242            };
1243        } else {
1244            let local_entity: Option<GetTeamLinkError> = serde_json::from_str(&local_content).ok();
1245            let local_error = datadog::ResponseContent {
1246                status: local_status,
1247                content: local_content,
1248                entity: local_entity,
1249            };
1250            Err(datadog::Error::ResponseError(local_error))
1251        }
1252    }
1253
1254    /// Get all links for a given team.
1255    pub async fn get_team_links(
1256        &self,
1257        team_id: String,
1258    ) -> Result<crate::datadogV2::model::TeamLinksResponse, datadog::Error<GetTeamLinksError>> {
1259        match self.get_team_links_with_http_info(team_id).await {
1260            Ok(response_content) => {
1261                if let Some(e) = response_content.entity {
1262                    Ok(e)
1263                } else {
1264                    Err(datadog::Error::Serde(serde::de::Error::custom(
1265                        "response content was None",
1266                    )))
1267                }
1268            }
1269            Err(err) => Err(err),
1270        }
1271    }
1272
1273    /// Get all links for a given team.
1274    pub async fn get_team_links_with_http_info(
1275        &self,
1276        team_id: String,
1277    ) -> Result<
1278        datadog::ResponseContent<crate::datadogV2::model::TeamLinksResponse>,
1279        datadog::Error<GetTeamLinksError>,
1280    > {
1281        let local_configuration = &self.config;
1282        let operation_id = "v2.get_team_links";
1283
1284        let local_client = &self.client;
1285
1286        let local_uri_str = format!(
1287            "{}/api/v2/team/{team_id}/links",
1288            local_configuration.get_operation_host(operation_id),
1289            team_id = datadog::urlencode(team_id)
1290        );
1291        let mut local_req_builder =
1292            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1293
1294        // build headers
1295        let mut headers = HeaderMap::new();
1296        headers.insert("Accept", HeaderValue::from_static("application/json"));
1297
1298        // build user agent
1299        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1300            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1301            Err(e) => {
1302                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1303                headers.insert(
1304                    reqwest::header::USER_AGENT,
1305                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1306                )
1307            }
1308        };
1309
1310        // build auth
1311        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1312            headers.insert(
1313                "DD-API-KEY",
1314                HeaderValue::from_str(local_key.key.as_str())
1315                    .expect("failed to parse DD-API-KEY header"),
1316            );
1317        };
1318        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1319            headers.insert(
1320                "DD-APPLICATION-KEY",
1321                HeaderValue::from_str(local_key.key.as_str())
1322                    .expect("failed to parse DD-APPLICATION-KEY header"),
1323            );
1324        };
1325
1326        local_req_builder = local_req_builder.headers(headers);
1327        let local_req = local_req_builder.build()?;
1328        log::debug!("request content: {:?}", local_req.body());
1329        let local_resp = local_client.execute(local_req).await?;
1330
1331        let local_status = local_resp.status();
1332        let local_content = local_resp.text().await?;
1333        log::debug!("response content: {}", local_content);
1334
1335        if !local_status.is_client_error() && !local_status.is_server_error() {
1336            match serde_json::from_str::<crate::datadogV2::model::TeamLinksResponse>(&local_content)
1337            {
1338                Ok(e) => {
1339                    return Ok(datadog::ResponseContent {
1340                        status: local_status,
1341                        content: local_content,
1342                        entity: Some(e),
1343                    })
1344                }
1345                Err(e) => return Err(datadog::Error::Serde(e)),
1346            };
1347        } else {
1348            let local_entity: Option<GetTeamLinksError> = serde_json::from_str(&local_content).ok();
1349            let local_error = datadog::ResponseContent {
1350                status: local_status,
1351                content: local_content,
1352                entity: local_entity,
1353            };
1354            Err(datadog::Error::ResponseError(local_error))
1355        }
1356    }
1357
1358    /// Get a paginated list of members for a team
1359    pub async fn get_team_memberships(
1360        &self,
1361        team_id: String,
1362        params: GetTeamMembershipsOptionalParams,
1363    ) -> Result<crate::datadogV2::model::UserTeamsResponse, datadog::Error<GetTeamMembershipsError>>
1364    {
1365        match self
1366            .get_team_memberships_with_http_info(team_id, params)
1367            .await
1368        {
1369            Ok(response_content) => {
1370                if let Some(e) = response_content.entity {
1371                    Ok(e)
1372                } else {
1373                    Err(datadog::Error::Serde(serde::de::Error::custom(
1374                        "response content was None",
1375                    )))
1376                }
1377            }
1378            Err(err) => Err(err),
1379        }
1380    }
1381
1382    pub fn get_team_memberships_with_pagination(
1383        &self,
1384        team_id: String,
1385        mut params: GetTeamMembershipsOptionalParams,
1386    ) -> impl Stream<
1387        Item = Result<crate::datadogV2::model::UserTeam, datadog::Error<GetTeamMembershipsError>>,
1388    > + '_ {
1389        try_stream! {
1390            let mut page_size: i64 = 10;
1391            if params.page_size.is_none() {
1392                params.page_size = Some(page_size);
1393            } else {
1394                page_size = params.page_size.unwrap().clone();
1395            }
1396            if params.page_number.is_none() {
1397                params.page_number = Some(0);
1398            }
1399            loop {
1400                let resp = self.get_team_memberships( team_id.clone(),params.clone()).await?;
1401                let Some(data) = resp.data else { break };
1402
1403                let r = data;
1404                let count = r.len();
1405                for team in r {
1406                    yield team;
1407                }
1408
1409                if count < page_size as usize {
1410                    break;
1411                }
1412                params.page_number = Some(params.page_number.unwrap() + 1);
1413            }
1414        }
1415    }
1416
1417    /// Get a paginated list of members for a team
1418    pub async fn get_team_memberships_with_http_info(
1419        &self,
1420        team_id: String,
1421        params: GetTeamMembershipsOptionalParams,
1422    ) -> Result<
1423        datadog::ResponseContent<crate::datadogV2::model::UserTeamsResponse>,
1424        datadog::Error<GetTeamMembershipsError>,
1425    > {
1426        let local_configuration = &self.config;
1427        let operation_id = "v2.get_team_memberships";
1428
1429        // unbox and build optional parameters
1430        let page_size = params.page_size;
1431        let page_number = params.page_number;
1432        let sort = params.sort;
1433        let filter_keyword = params.filter_keyword;
1434
1435        let local_client = &self.client;
1436
1437        let local_uri_str = format!(
1438            "{}/api/v2/team/{team_id}/memberships",
1439            local_configuration.get_operation_host(operation_id),
1440            team_id = datadog::urlencode(team_id)
1441        );
1442        let mut local_req_builder =
1443            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1444
1445        if let Some(ref local_query_param) = page_size {
1446            local_req_builder =
1447                local_req_builder.query(&[("page[size]", &local_query_param.to_string())]);
1448        };
1449        if let Some(ref local_query_param) = page_number {
1450            local_req_builder =
1451                local_req_builder.query(&[("page[number]", &local_query_param.to_string())]);
1452        };
1453        if let Some(ref local_query_param) = sort {
1454            local_req_builder =
1455                local_req_builder.query(&[("sort", &local_query_param.to_string())]);
1456        };
1457        if let Some(ref local_query_param) = filter_keyword {
1458            local_req_builder =
1459                local_req_builder.query(&[("filter[keyword]", &local_query_param.to_string())]);
1460        };
1461
1462        // build headers
1463        let mut headers = HeaderMap::new();
1464        headers.insert("Accept", HeaderValue::from_static("application/json"));
1465
1466        // build user agent
1467        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1468            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1469            Err(e) => {
1470                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1471                headers.insert(
1472                    reqwest::header::USER_AGENT,
1473                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1474                )
1475            }
1476        };
1477
1478        // build auth
1479        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1480            headers.insert(
1481                "DD-API-KEY",
1482                HeaderValue::from_str(local_key.key.as_str())
1483                    .expect("failed to parse DD-API-KEY header"),
1484            );
1485        };
1486        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1487            headers.insert(
1488                "DD-APPLICATION-KEY",
1489                HeaderValue::from_str(local_key.key.as_str())
1490                    .expect("failed to parse DD-APPLICATION-KEY header"),
1491            );
1492        };
1493
1494        local_req_builder = local_req_builder.headers(headers);
1495        let local_req = local_req_builder.build()?;
1496        log::debug!("request content: {:?}", local_req.body());
1497        let local_resp = local_client.execute(local_req).await?;
1498
1499        let local_status = local_resp.status();
1500        let local_content = local_resp.text().await?;
1501        log::debug!("response content: {}", local_content);
1502
1503        if !local_status.is_client_error() && !local_status.is_server_error() {
1504            match serde_json::from_str::<crate::datadogV2::model::UserTeamsResponse>(&local_content)
1505            {
1506                Ok(e) => {
1507                    return Ok(datadog::ResponseContent {
1508                        status: local_status,
1509                        content: local_content,
1510                        entity: Some(e),
1511                    })
1512                }
1513                Err(e) => return Err(datadog::Error::Serde(e)),
1514            };
1515        } else {
1516            let local_entity: Option<GetTeamMembershipsError> =
1517                serde_json::from_str(&local_content).ok();
1518            let local_error = datadog::ResponseContent {
1519                status: local_status,
1520                content: local_content,
1521                entity: local_entity,
1522            };
1523            Err(datadog::Error::ResponseError(local_error))
1524        }
1525    }
1526
1527    /// Get all permission settings for a given team.
1528    pub async fn get_team_permission_settings(
1529        &self,
1530        team_id: String,
1531    ) -> Result<
1532        crate::datadogV2::model::TeamPermissionSettingsResponse,
1533        datadog::Error<GetTeamPermissionSettingsError>,
1534    > {
1535        match self
1536            .get_team_permission_settings_with_http_info(team_id)
1537            .await
1538        {
1539            Ok(response_content) => {
1540                if let Some(e) = response_content.entity {
1541                    Ok(e)
1542                } else {
1543                    Err(datadog::Error::Serde(serde::de::Error::custom(
1544                        "response content was None",
1545                    )))
1546                }
1547            }
1548            Err(err) => Err(err),
1549        }
1550    }
1551
1552    /// Get all permission settings for a given team.
1553    pub async fn get_team_permission_settings_with_http_info(
1554        &self,
1555        team_id: String,
1556    ) -> Result<
1557        datadog::ResponseContent<crate::datadogV2::model::TeamPermissionSettingsResponse>,
1558        datadog::Error<GetTeamPermissionSettingsError>,
1559    > {
1560        let local_configuration = &self.config;
1561        let operation_id = "v2.get_team_permission_settings";
1562
1563        let local_client = &self.client;
1564
1565        let local_uri_str = format!(
1566            "{}/api/v2/team/{team_id}/permission-settings",
1567            local_configuration.get_operation_host(operation_id),
1568            team_id = datadog::urlencode(team_id)
1569        );
1570        let mut local_req_builder =
1571            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1572
1573        // build headers
1574        let mut headers = HeaderMap::new();
1575        headers.insert("Accept", HeaderValue::from_static("application/json"));
1576
1577        // build user agent
1578        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1579            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1580            Err(e) => {
1581                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1582                headers.insert(
1583                    reqwest::header::USER_AGENT,
1584                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1585                )
1586            }
1587        };
1588
1589        // build auth
1590        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1591            headers.insert(
1592                "DD-API-KEY",
1593                HeaderValue::from_str(local_key.key.as_str())
1594                    .expect("failed to parse DD-API-KEY header"),
1595            );
1596        };
1597        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1598            headers.insert(
1599                "DD-APPLICATION-KEY",
1600                HeaderValue::from_str(local_key.key.as_str())
1601                    .expect("failed to parse DD-APPLICATION-KEY header"),
1602            );
1603        };
1604
1605        local_req_builder = local_req_builder.headers(headers);
1606        let local_req = local_req_builder.build()?;
1607        log::debug!("request content: {:?}", local_req.body());
1608        let local_resp = local_client.execute(local_req).await?;
1609
1610        let local_status = local_resp.status();
1611        let local_content = local_resp.text().await?;
1612        log::debug!("response content: {}", local_content);
1613
1614        if !local_status.is_client_error() && !local_status.is_server_error() {
1615            match serde_json::from_str::<crate::datadogV2::model::TeamPermissionSettingsResponse>(
1616                &local_content,
1617            ) {
1618                Ok(e) => {
1619                    return Ok(datadog::ResponseContent {
1620                        status: local_status,
1621                        content: local_content,
1622                        entity: Some(e),
1623                    })
1624                }
1625                Err(e) => return Err(datadog::Error::Serde(e)),
1626            };
1627        } else {
1628            let local_entity: Option<GetTeamPermissionSettingsError> =
1629                serde_json::from_str(&local_content).ok();
1630            let local_error = datadog::ResponseContent {
1631                status: local_status,
1632                content: local_content,
1633                entity: local_entity,
1634            };
1635            Err(datadog::Error::ResponseError(local_error))
1636        }
1637    }
1638
1639    /// Get a list of memberships for a user
1640    pub async fn get_user_memberships(
1641        &self,
1642        user_uuid: String,
1643    ) -> Result<crate::datadogV2::model::UserTeamsResponse, datadog::Error<GetUserMembershipsError>>
1644    {
1645        match self.get_user_memberships_with_http_info(user_uuid).await {
1646            Ok(response_content) => {
1647                if let Some(e) = response_content.entity {
1648                    Ok(e)
1649                } else {
1650                    Err(datadog::Error::Serde(serde::de::Error::custom(
1651                        "response content was None",
1652                    )))
1653                }
1654            }
1655            Err(err) => Err(err),
1656        }
1657    }
1658
1659    /// Get a list of memberships for a user
1660    pub async fn get_user_memberships_with_http_info(
1661        &self,
1662        user_uuid: String,
1663    ) -> Result<
1664        datadog::ResponseContent<crate::datadogV2::model::UserTeamsResponse>,
1665        datadog::Error<GetUserMembershipsError>,
1666    > {
1667        let local_configuration = &self.config;
1668        let operation_id = "v2.get_user_memberships";
1669
1670        let local_client = &self.client;
1671
1672        let local_uri_str = format!(
1673            "{}/api/v2/users/{user_uuid}/memberships",
1674            local_configuration.get_operation_host(operation_id),
1675            user_uuid = datadog::urlencode(user_uuid)
1676        );
1677        let mut local_req_builder =
1678            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1679
1680        // build headers
1681        let mut headers = HeaderMap::new();
1682        headers.insert("Accept", HeaderValue::from_static("application/json"));
1683
1684        // build user agent
1685        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1686            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1687            Err(e) => {
1688                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1689                headers.insert(
1690                    reqwest::header::USER_AGENT,
1691                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1692                )
1693            }
1694        };
1695
1696        // build auth
1697        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1698            headers.insert(
1699                "DD-API-KEY",
1700                HeaderValue::from_str(local_key.key.as_str())
1701                    .expect("failed to parse DD-API-KEY header"),
1702            );
1703        };
1704        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1705            headers.insert(
1706                "DD-APPLICATION-KEY",
1707                HeaderValue::from_str(local_key.key.as_str())
1708                    .expect("failed to parse DD-APPLICATION-KEY header"),
1709            );
1710        };
1711
1712        local_req_builder = local_req_builder.headers(headers);
1713        let local_req = local_req_builder.build()?;
1714        log::debug!("request content: {:?}", local_req.body());
1715        let local_resp = local_client.execute(local_req).await?;
1716
1717        let local_status = local_resp.status();
1718        let local_content = local_resp.text().await?;
1719        log::debug!("response content: {}", local_content);
1720
1721        if !local_status.is_client_error() && !local_status.is_server_error() {
1722            match serde_json::from_str::<crate::datadogV2::model::UserTeamsResponse>(&local_content)
1723            {
1724                Ok(e) => {
1725                    return Ok(datadog::ResponseContent {
1726                        status: local_status,
1727                        content: local_content,
1728                        entity: Some(e),
1729                    })
1730                }
1731                Err(e) => return Err(datadog::Error::Serde(e)),
1732            };
1733        } else {
1734            let local_entity: Option<GetUserMembershipsError> =
1735                serde_json::from_str(&local_content).ok();
1736            let local_error = datadog::ResponseContent {
1737                status: local_status,
1738                content: local_content,
1739                entity: local_entity,
1740            };
1741            Err(datadog::Error::ResponseError(local_error))
1742        }
1743    }
1744
1745    /// Get all teams.
1746    /// Can be used to search for teams using the `filter[keyword]` and `filter[me]` query parameters.
1747    pub async fn list_teams(
1748        &self,
1749        params: ListTeamsOptionalParams,
1750    ) -> Result<crate::datadogV2::model::TeamsResponse, datadog::Error<ListTeamsError>> {
1751        match self.list_teams_with_http_info(params).await {
1752            Ok(response_content) => {
1753                if let Some(e) = response_content.entity {
1754                    Ok(e)
1755                } else {
1756                    Err(datadog::Error::Serde(serde::de::Error::custom(
1757                        "response content was None",
1758                    )))
1759                }
1760            }
1761            Err(err) => Err(err),
1762        }
1763    }
1764
1765    pub fn list_teams_with_pagination(
1766        &self,
1767        mut params: ListTeamsOptionalParams,
1768    ) -> impl Stream<Item = Result<crate::datadogV2::model::Team, datadog::Error<ListTeamsError>>> + '_
1769    {
1770        try_stream! {
1771            let mut page_size: i64 = 10;
1772            if params.page_size.is_none() {
1773                params.page_size = Some(page_size);
1774            } else {
1775                page_size = params.page_size.unwrap().clone();
1776            }
1777            if params.page_number.is_none() {
1778                params.page_number = Some(0);
1779            }
1780            loop {
1781                let resp = self.list_teams(params.clone()).await?;
1782                let Some(data) = resp.data else { break };
1783
1784                let r = data;
1785                let count = r.len();
1786                for team in r {
1787                    yield team;
1788                }
1789
1790                if count < page_size as usize {
1791                    break;
1792                }
1793                params.page_number = Some(params.page_number.unwrap() + 1);
1794            }
1795        }
1796    }
1797
1798    /// Get all teams.
1799    /// Can be used to search for teams using the `filter[keyword]` and `filter[me]` query parameters.
1800    pub async fn list_teams_with_http_info(
1801        &self,
1802        params: ListTeamsOptionalParams,
1803    ) -> Result<
1804        datadog::ResponseContent<crate::datadogV2::model::TeamsResponse>,
1805        datadog::Error<ListTeamsError>,
1806    > {
1807        let local_configuration = &self.config;
1808        let operation_id = "v2.list_teams";
1809
1810        // unbox and build optional parameters
1811        let page_number = params.page_number;
1812        let page_size = params.page_size;
1813        let sort = params.sort;
1814        let include = params.include;
1815        let filter_keyword = params.filter_keyword;
1816        let filter_me = params.filter_me;
1817        let fields_team = params.fields_team;
1818
1819        let local_client = &self.client;
1820
1821        let local_uri_str = format!(
1822            "{}/api/v2/team",
1823            local_configuration.get_operation_host(operation_id)
1824        );
1825        let mut local_req_builder =
1826            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1827
1828        if let Some(ref local_query_param) = page_number {
1829            local_req_builder =
1830                local_req_builder.query(&[("page[number]", &local_query_param.to_string())]);
1831        };
1832        if let Some(ref local_query_param) = page_size {
1833            local_req_builder =
1834                local_req_builder.query(&[("page[size]", &local_query_param.to_string())]);
1835        };
1836        if let Some(ref local_query_param) = sort {
1837            local_req_builder =
1838                local_req_builder.query(&[("sort", &local_query_param.to_string())]);
1839        };
1840        if let Some(ref local) = include {
1841            for param in local {
1842                local_req_builder = local_req_builder.query(&[("include", &param.to_string())]);
1843            }
1844        };
1845        if let Some(ref local_query_param) = filter_keyword {
1846            local_req_builder =
1847                local_req_builder.query(&[("filter[keyword]", &local_query_param.to_string())]);
1848        };
1849        if let Some(ref local_query_param) = filter_me {
1850            local_req_builder =
1851                local_req_builder.query(&[("filter[me]", &local_query_param.to_string())]);
1852        };
1853        if let Some(ref local) = fields_team {
1854            local_req_builder = local_req_builder.query(&[(
1855                "fields[team]",
1856                &local
1857                    .iter()
1858                    .map(|p| p.to_string())
1859                    .collect::<Vec<String>>()
1860                    .join(",")
1861                    .to_string(),
1862            )]);
1863        };
1864
1865        // build headers
1866        let mut headers = HeaderMap::new();
1867        headers.insert("Accept", HeaderValue::from_static("application/json"));
1868
1869        // build user agent
1870        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1871            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1872            Err(e) => {
1873                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1874                headers.insert(
1875                    reqwest::header::USER_AGENT,
1876                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1877                )
1878            }
1879        };
1880
1881        // build auth
1882        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1883            headers.insert(
1884                "DD-API-KEY",
1885                HeaderValue::from_str(local_key.key.as_str())
1886                    .expect("failed to parse DD-API-KEY header"),
1887            );
1888        };
1889        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1890            headers.insert(
1891                "DD-APPLICATION-KEY",
1892                HeaderValue::from_str(local_key.key.as_str())
1893                    .expect("failed to parse DD-APPLICATION-KEY header"),
1894            );
1895        };
1896
1897        local_req_builder = local_req_builder.headers(headers);
1898        let local_req = local_req_builder.build()?;
1899        log::debug!("request content: {:?}", local_req.body());
1900        let local_resp = local_client.execute(local_req).await?;
1901
1902        let local_status = local_resp.status();
1903        let local_content = local_resp.text().await?;
1904        log::debug!("response content: {}", local_content);
1905
1906        if !local_status.is_client_error() && !local_status.is_server_error() {
1907            match serde_json::from_str::<crate::datadogV2::model::TeamsResponse>(&local_content) {
1908                Ok(e) => {
1909                    return Ok(datadog::ResponseContent {
1910                        status: local_status,
1911                        content: local_content,
1912                        entity: Some(e),
1913                    })
1914                }
1915                Err(e) => return Err(datadog::Error::Serde(e)),
1916            };
1917        } else {
1918            let local_entity: Option<ListTeamsError> = serde_json::from_str(&local_content).ok();
1919            let local_error = datadog::ResponseContent {
1920                status: local_status,
1921                content: local_content,
1922                entity: local_entity,
1923            };
1924            Err(datadog::Error::ResponseError(local_error))
1925        }
1926    }
1927
1928    /// Update a team using the team's `id`.
1929    /// If the `team_links` relationship is present, the associated links are updated to be in the order they appear in the array, and any existing team links not present are removed.
1930    pub async fn update_team(
1931        &self,
1932        team_id: String,
1933        body: crate::datadogV2::model::TeamUpdateRequest,
1934    ) -> Result<crate::datadogV2::model::TeamResponse, datadog::Error<UpdateTeamError>> {
1935        match self.update_team_with_http_info(team_id, body).await {
1936            Ok(response_content) => {
1937                if let Some(e) = response_content.entity {
1938                    Ok(e)
1939                } else {
1940                    Err(datadog::Error::Serde(serde::de::Error::custom(
1941                        "response content was None",
1942                    )))
1943                }
1944            }
1945            Err(err) => Err(err),
1946        }
1947    }
1948
1949    /// Update a team using the team's `id`.
1950    /// If the `team_links` relationship is present, the associated links are updated to be in the order they appear in the array, and any existing team links not present are removed.
1951    pub async fn update_team_with_http_info(
1952        &self,
1953        team_id: String,
1954        body: crate::datadogV2::model::TeamUpdateRequest,
1955    ) -> Result<
1956        datadog::ResponseContent<crate::datadogV2::model::TeamResponse>,
1957        datadog::Error<UpdateTeamError>,
1958    > {
1959        let local_configuration = &self.config;
1960        let operation_id = "v2.update_team";
1961
1962        let local_client = &self.client;
1963
1964        let local_uri_str = format!(
1965            "{}/api/v2/team/{team_id}",
1966            local_configuration.get_operation_host(operation_id),
1967            team_id = datadog::urlencode(team_id)
1968        );
1969        let mut local_req_builder =
1970            local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
1971
1972        // build headers
1973        let mut headers = HeaderMap::new();
1974        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1975        headers.insert("Accept", HeaderValue::from_static("application/json"));
1976
1977        // build user agent
1978        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1979            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1980            Err(e) => {
1981                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1982                headers.insert(
1983                    reqwest::header::USER_AGENT,
1984                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1985                )
1986            }
1987        };
1988
1989        // build auth
1990        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1991            headers.insert(
1992                "DD-API-KEY",
1993                HeaderValue::from_str(local_key.key.as_str())
1994                    .expect("failed to parse DD-API-KEY header"),
1995            );
1996        };
1997        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1998            headers.insert(
1999                "DD-APPLICATION-KEY",
2000                HeaderValue::from_str(local_key.key.as_str())
2001                    .expect("failed to parse DD-APPLICATION-KEY header"),
2002            );
2003        };
2004
2005        // build body parameters
2006        let output = Vec::new();
2007        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2008        if body.serialize(&mut ser).is_ok() {
2009            if let Some(content_encoding) = headers.get("Content-Encoding") {
2010                match content_encoding.to_str().unwrap_or_default() {
2011                    "gzip" => {
2012                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2013                        let _ = enc.write_all(ser.into_inner().as_slice());
2014                        match enc.finish() {
2015                            Ok(buf) => {
2016                                local_req_builder = local_req_builder.body(buf);
2017                            }
2018                            Err(e) => return Err(datadog::Error::Io(e)),
2019                        }
2020                    }
2021                    "deflate" => {
2022                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2023                        let _ = enc.write_all(ser.into_inner().as_slice());
2024                        match enc.finish() {
2025                            Ok(buf) => {
2026                                local_req_builder = local_req_builder.body(buf);
2027                            }
2028                            Err(e) => return Err(datadog::Error::Io(e)),
2029                        }
2030                    }
2031                    "zstd1" => {
2032                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2033                        let _ = enc.write_all(ser.into_inner().as_slice());
2034                        match enc.finish() {
2035                            Ok(buf) => {
2036                                local_req_builder = local_req_builder.body(buf);
2037                            }
2038                            Err(e) => return Err(datadog::Error::Io(e)),
2039                        }
2040                    }
2041                    _ => {
2042                        local_req_builder = local_req_builder.body(ser.into_inner());
2043                    }
2044                }
2045            } else {
2046                local_req_builder = local_req_builder.body(ser.into_inner());
2047            }
2048        }
2049
2050        local_req_builder = local_req_builder.headers(headers);
2051        let local_req = local_req_builder.build()?;
2052        log::debug!("request content: {:?}", local_req.body());
2053        let local_resp = local_client.execute(local_req).await?;
2054
2055        let local_status = local_resp.status();
2056        let local_content = local_resp.text().await?;
2057        log::debug!("response content: {}", local_content);
2058
2059        if !local_status.is_client_error() && !local_status.is_server_error() {
2060            match serde_json::from_str::<crate::datadogV2::model::TeamResponse>(&local_content) {
2061                Ok(e) => {
2062                    return Ok(datadog::ResponseContent {
2063                        status: local_status,
2064                        content: local_content,
2065                        entity: Some(e),
2066                    })
2067                }
2068                Err(e) => return Err(datadog::Error::Serde(e)),
2069            };
2070        } else {
2071            let local_entity: Option<UpdateTeamError> = serde_json::from_str(&local_content).ok();
2072            let local_error = datadog::ResponseContent {
2073                status: local_status,
2074                content: local_content,
2075                entity: local_entity,
2076            };
2077            Err(datadog::Error::ResponseError(local_error))
2078        }
2079    }
2080
2081    /// Update a team link.
2082    pub async fn update_team_link(
2083        &self,
2084        team_id: String,
2085        link_id: String,
2086        body: crate::datadogV2::model::TeamLinkCreateRequest,
2087    ) -> Result<crate::datadogV2::model::TeamLinkResponse, datadog::Error<UpdateTeamLinkError>>
2088    {
2089        match self
2090            .update_team_link_with_http_info(team_id, link_id, body)
2091            .await
2092        {
2093            Ok(response_content) => {
2094                if let Some(e) = response_content.entity {
2095                    Ok(e)
2096                } else {
2097                    Err(datadog::Error::Serde(serde::de::Error::custom(
2098                        "response content was None",
2099                    )))
2100                }
2101            }
2102            Err(err) => Err(err),
2103        }
2104    }
2105
2106    /// Update a team link.
2107    pub async fn update_team_link_with_http_info(
2108        &self,
2109        team_id: String,
2110        link_id: String,
2111        body: crate::datadogV2::model::TeamLinkCreateRequest,
2112    ) -> Result<
2113        datadog::ResponseContent<crate::datadogV2::model::TeamLinkResponse>,
2114        datadog::Error<UpdateTeamLinkError>,
2115    > {
2116        let local_configuration = &self.config;
2117        let operation_id = "v2.update_team_link";
2118
2119        let local_client = &self.client;
2120
2121        let local_uri_str = format!(
2122            "{}/api/v2/team/{team_id}/links/{link_id}",
2123            local_configuration.get_operation_host(operation_id),
2124            team_id = datadog::urlencode(team_id),
2125            link_id = datadog::urlencode(link_id)
2126        );
2127        let mut local_req_builder =
2128            local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
2129
2130        // build headers
2131        let mut headers = HeaderMap::new();
2132        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
2133        headers.insert("Accept", HeaderValue::from_static("application/json"));
2134
2135        // build user agent
2136        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2137            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2138            Err(e) => {
2139                log::warn!("Failed to parse user agent header: {e}, falling back to default");
2140                headers.insert(
2141                    reqwest::header::USER_AGENT,
2142                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2143                )
2144            }
2145        };
2146
2147        // build auth
2148        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2149            headers.insert(
2150                "DD-API-KEY",
2151                HeaderValue::from_str(local_key.key.as_str())
2152                    .expect("failed to parse DD-API-KEY header"),
2153            );
2154        };
2155        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2156            headers.insert(
2157                "DD-APPLICATION-KEY",
2158                HeaderValue::from_str(local_key.key.as_str())
2159                    .expect("failed to parse DD-APPLICATION-KEY header"),
2160            );
2161        };
2162
2163        // build body parameters
2164        let output = Vec::new();
2165        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2166        if body.serialize(&mut ser).is_ok() {
2167            if let Some(content_encoding) = headers.get("Content-Encoding") {
2168                match content_encoding.to_str().unwrap_or_default() {
2169                    "gzip" => {
2170                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2171                        let _ = enc.write_all(ser.into_inner().as_slice());
2172                        match enc.finish() {
2173                            Ok(buf) => {
2174                                local_req_builder = local_req_builder.body(buf);
2175                            }
2176                            Err(e) => return Err(datadog::Error::Io(e)),
2177                        }
2178                    }
2179                    "deflate" => {
2180                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2181                        let _ = enc.write_all(ser.into_inner().as_slice());
2182                        match enc.finish() {
2183                            Ok(buf) => {
2184                                local_req_builder = local_req_builder.body(buf);
2185                            }
2186                            Err(e) => return Err(datadog::Error::Io(e)),
2187                        }
2188                    }
2189                    "zstd1" => {
2190                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2191                        let _ = enc.write_all(ser.into_inner().as_slice());
2192                        match enc.finish() {
2193                            Ok(buf) => {
2194                                local_req_builder = local_req_builder.body(buf);
2195                            }
2196                            Err(e) => return Err(datadog::Error::Io(e)),
2197                        }
2198                    }
2199                    _ => {
2200                        local_req_builder = local_req_builder.body(ser.into_inner());
2201                    }
2202                }
2203            } else {
2204                local_req_builder = local_req_builder.body(ser.into_inner());
2205            }
2206        }
2207
2208        local_req_builder = local_req_builder.headers(headers);
2209        let local_req = local_req_builder.build()?;
2210        log::debug!("request content: {:?}", local_req.body());
2211        let local_resp = local_client.execute(local_req).await?;
2212
2213        let local_status = local_resp.status();
2214        let local_content = local_resp.text().await?;
2215        log::debug!("response content: {}", local_content);
2216
2217        if !local_status.is_client_error() && !local_status.is_server_error() {
2218            match serde_json::from_str::<crate::datadogV2::model::TeamLinkResponse>(&local_content)
2219            {
2220                Ok(e) => {
2221                    return Ok(datadog::ResponseContent {
2222                        status: local_status,
2223                        content: local_content,
2224                        entity: Some(e),
2225                    })
2226                }
2227                Err(e) => return Err(datadog::Error::Serde(e)),
2228            };
2229        } else {
2230            let local_entity: Option<UpdateTeamLinkError> =
2231                serde_json::from_str(&local_content).ok();
2232            let local_error = datadog::ResponseContent {
2233                status: local_status,
2234                content: local_content,
2235                entity: local_entity,
2236            };
2237            Err(datadog::Error::ResponseError(local_error))
2238        }
2239    }
2240
2241    /// Update a user's membership attributes on a team.
2242    pub async fn update_team_membership(
2243        &self,
2244        team_id: String,
2245        user_id: String,
2246        body: crate::datadogV2::model::UserTeamUpdateRequest,
2247    ) -> Result<crate::datadogV2::model::UserTeamResponse, datadog::Error<UpdateTeamMembershipError>>
2248    {
2249        match self
2250            .update_team_membership_with_http_info(team_id, user_id, body)
2251            .await
2252        {
2253            Ok(response_content) => {
2254                if let Some(e) = response_content.entity {
2255                    Ok(e)
2256                } else {
2257                    Err(datadog::Error::Serde(serde::de::Error::custom(
2258                        "response content was None",
2259                    )))
2260                }
2261            }
2262            Err(err) => Err(err),
2263        }
2264    }
2265
2266    /// Update a user's membership attributes on a team.
2267    pub async fn update_team_membership_with_http_info(
2268        &self,
2269        team_id: String,
2270        user_id: String,
2271        body: crate::datadogV2::model::UserTeamUpdateRequest,
2272    ) -> Result<
2273        datadog::ResponseContent<crate::datadogV2::model::UserTeamResponse>,
2274        datadog::Error<UpdateTeamMembershipError>,
2275    > {
2276        let local_configuration = &self.config;
2277        let operation_id = "v2.update_team_membership";
2278
2279        let local_client = &self.client;
2280
2281        let local_uri_str = format!(
2282            "{}/api/v2/team/{team_id}/memberships/{user_id}",
2283            local_configuration.get_operation_host(operation_id),
2284            team_id = datadog::urlencode(team_id),
2285            user_id = datadog::urlencode(user_id)
2286        );
2287        let mut local_req_builder =
2288            local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
2289
2290        // build headers
2291        let mut headers = HeaderMap::new();
2292        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
2293        headers.insert("Accept", HeaderValue::from_static("application/json"));
2294
2295        // build user agent
2296        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2297            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2298            Err(e) => {
2299                log::warn!("Failed to parse user agent header: {e}, falling back to default");
2300                headers.insert(
2301                    reqwest::header::USER_AGENT,
2302                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2303                )
2304            }
2305        };
2306
2307        // build auth
2308        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2309            headers.insert(
2310                "DD-API-KEY",
2311                HeaderValue::from_str(local_key.key.as_str())
2312                    .expect("failed to parse DD-API-KEY header"),
2313            );
2314        };
2315        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2316            headers.insert(
2317                "DD-APPLICATION-KEY",
2318                HeaderValue::from_str(local_key.key.as_str())
2319                    .expect("failed to parse DD-APPLICATION-KEY header"),
2320            );
2321        };
2322
2323        // build body parameters
2324        let output = Vec::new();
2325        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2326        if body.serialize(&mut ser).is_ok() {
2327            if let Some(content_encoding) = headers.get("Content-Encoding") {
2328                match content_encoding.to_str().unwrap_or_default() {
2329                    "gzip" => {
2330                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2331                        let _ = enc.write_all(ser.into_inner().as_slice());
2332                        match enc.finish() {
2333                            Ok(buf) => {
2334                                local_req_builder = local_req_builder.body(buf);
2335                            }
2336                            Err(e) => return Err(datadog::Error::Io(e)),
2337                        }
2338                    }
2339                    "deflate" => {
2340                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2341                        let _ = enc.write_all(ser.into_inner().as_slice());
2342                        match enc.finish() {
2343                            Ok(buf) => {
2344                                local_req_builder = local_req_builder.body(buf);
2345                            }
2346                            Err(e) => return Err(datadog::Error::Io(e)),
2347                        }
2348                    }
2349                    "zstd1" => {
2350                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2351                        let _ = enc.write_all(ser.into_inner().as_slice());
2352                        match enc.finish() {
2353                            Ok(buf) => {
2354                                local_req_builder = local_req_builder.body(buf);
2355                            }
2356                            Err(e) => return Err(datadog::Error::Io(e)),
2357                        }
2358                    }
2359                    _ => {
2360                        local_req_builder = local_req_builder.body(ser.into_inner());
2361                    }
2362                }
2363            } else {
2364                local_req_builder = local_req_builder.body(ser.into_inner());
2365            }
2366        }
2367
2368        local_req_builder = local_req_builder.headers(headers);
2369        let local_req = local_req_builder.build()?;
2370        log::debug!("request content: {:?}", local_req.body());
2371        let local_resp = local_client.execute(local_req).await?;
2372
2373        let local_status = local_resp.status();
2374        let local_content = local_resp.text().await?;
2375        log::debug!("response content: {}", local_content);
2376
2377        if !local_status.is_client_error() && !local_status.is_server_error() {
2378            match serde_json::from_str::<crate::datadogV2::model::UserTeamResponse>(&local_content)
2379            {
2380                Ok(e) => {
2381                    return Ok(datadog::ResponseContent {
2382                        status: local_status,
2383                        content: local_content,
2384                        entity: Some(e),
2385                    })
2386                }
2387                Err(e) => return Err(datadog::Error::Serde(e)),
2388            };
2389        } else {
2390            let local_entity: Option<UpdateTeamMembershipError> =
2391                serde_json::from_str(&local_content).ok();
2392            let local_error = datadog::ResponseContent {
2393                status: local_status,
2394                content: local_content,
2395                entity: local_entity,
2396            };
2397            Err(datadog::Error::ResponseError(local_error))
2398        }
2399    }
2400
2401    /// Update a team permission setting for a given team.
2402    pub async fn update_team_permission_setting(
2403        &self,
2404        team_id: String,
2405        action: String,
2406        body: crate::datadogV2::model::TeamPermissionSettingUpdateRequest,
2407    ) -> Result<
2408        crate::datadogV2::model::TeamPermissionSettingResponse,
2409        datadog::Error<UpdateTeamPermissionSettingError>,
2410    > {
2411        match self
2412            .update_team_permission_setting_with_http_info(team_id, action, body)
2413            .await
2414        {
2415            Ok(response_content) => {
2416                if let Some(e) = response_content.entity {
2417                    Ok(e)
2418                } else {
2419                    Err(datadog::Error::Serde(serde::de::Error::custom(
2420                        "response content was None",
2421                    )))
2422                }
2423            }
2424            Err(err) => Err(err),
2425        }
2426    }
2427
2428    /// Update a team permission setting for a given team.
2429    pub async fn update_team_permission_setting_with_http_info(
2430        &self,
2431        team_id: String,
2432        action: String,
2433        body: crate::datadogV2::model::TeamPermissionSettingUpdateRequest,
2434    ) -> Result<
2435        datadog::ResponseContent<crate::datadogV2::model::TeamPermissionSettingResponse>,
2436        datadog::Error<UpdateTeamPermissionSettingError>,
2437    > {
2438        let local_configuration = &self.config;
2439        let operation_id = "v2.update_team_permission_setting";
2440
2441        let local_client = &self.client;
2442
2443        let local_uri_str = format!(
2444            "{}/api/v2/team/{team_id}/permission-settings/{action}",
2445            local_configuration.get_operation_host(operation_id),
2446            team_id = datadog::urlencode(team_id),
2447            action = datadog::urlencode(action)
2448        );
2449        let mut local_req_builder =
2450            local_client.request(reqwest::Method::PUT, local_uri_str.as_str());
2451
2452        // build headers
2453        let mut headers = HeaderMap::new();
2454        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
2455        headers.insert("Accept", HeaderValue::from_static("application/json"));
2456
2457        // build user agent
2458        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2459            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2460            Err(e) => {
2461                log::warn!("Failed to parse user agent header: {e}, falling back to default");
2462                headers.insert(
2463                    reqwest::header::USER_AGENT,
2464                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2465                )
2466            }
2467        };
2468
2469        // build auth
2470        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2471            headers.insert(
2472                "DD-API-KEY",
2473                HeaderValue::from_str(local_key.key.as_str())
2474                    .expect("failed to parse DD-API-KEY header"),
2475            );
2476        };
2477        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2478            headers.insert(
2479                "DD-APPLICATION-KEY",
2480                HeaderValue::from_str(local_key.key.as_str())
2481                    .expect("failed to parse DD-APPLICATION-KEY header"),
2482            );
2483        };
2484
2485        // build body parameters
2486        let output = Vec::new();
2487        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2488        if body.serialize(&mut ser).is_ok() {
2489            if let Some(content_encoding) = headers.get("Content-Encoding") {
2490                match content_encoding.to_str().unwrap_or_default() {
2491                    "gzip" => {
2492                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2493                        let _ = enc.write_all(ser.into_inner().as_slice());
2494                        match enc.finish() {
2495                            Ok(buf) => {
2496                                local_req_builder = local_req_builder.body(buf);
2497                            }
2498                            Err(e) => return Err(datadog::Error::Io(e)),
2499                        }
2500                    }
2501                    "deflate" => {
2502                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2503                        let _ = enc.write_all(ser.into_inner().as_slice());
2504                        match enc.finish() {
2505                            Ok(buf) => {
2506                                local_req_builder = local_req_builder.body(buf);
2507                            }
2508                            Err(e) => return Err(datadog::Error::Io(e)),
2509                        }
2510                    }
2511                    "zstd1" => {
2512                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2513                        let _ = enc.write_all(ser.into_inner().as_slice());
2514                        match enc.finish() {
2515                            Ok(buf) => {
2516                                local_req_builder = local_req_builder.body(buf);
2517                            }
2518                            Err(e) => return Err(datadog::Error::Io(e)),
2519                        }
2520                    }
2521                    _ => {
2522                        local_req_builder = local_req_builder.body(ser.into_inner());
2523                    }
2524                }
2525            } else {
2526                local_req_builder = local_req_builder.body(ser.into_inner());
2527            }
2528        }
2529
2530        local_req_builder = local_req_builder.headers(headers);
2531        let local_req = local_req_builder.build()?;
2532        log::debug!("request content: {:?}", local_req.body());
2533        let local_resp = local_client.execute(local_req).await?;
2534
2535        let local_status = local_resp.status();
2536        let local_content = local_resp.text().await?;
2537        log::debug!("response content: {}", local_content);
2538
2539        if !local_status.is_client_error() && !local_status.is_server_error() {
2540            match serde_json::from_str::<crate::datadogV2::model::TeamPermissionSettingResponse>(
2541                &local_content,
2542            ) {
2543                Ok(e) => {
2544                    return Ok(datadog::ResponseContent {
2545                        status: local_status,
2546                        content: local_content,
2547                        entity: Some(e),
2548                    })
2549                }
2550                Err(e) => return Err(datadog::Error::Serde(e)),
2551            };
2552        } else {
2553            let local_entity: Option<UpdateTeamPermissionSettingError> =
2554                serde_json::from_str(&local_content).ok();
2555            let local_error = datadog::ResponseContent {
2556                status: local_status,
2557                content: local_content,
2558                entity: local_entity,
2559            };
2560            Err(datadog::Error::ResponseError(local_error))
2561        }
2562    }
2563}