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