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