datadog_api_client/datadogV2/api/
api_key_management.rs

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