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