datadog_api_client/datadogV1/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/// CreateAPIKeyError is a struct for typed errors of method [`KeyManagementAPI::create_api_key`]
14#[derive(Debug, Clone, Serialize, Deserialize)]
15#[serde(untagged)]
16pub enum CreateAPIKeyError {
17    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
18    UnknownValue(serde_json::Value),
19}
20
21/// CreateApplicationKeyError is a struct for typed errors of method [`KeyManagementAPI::create_application_key`]
22#[derive(Debug, Clone, Serialize, Deserialize)]
23#[serde(untagged)]
24pub enum CreateApplicationKeyError {
25    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
26    UnknownValue(serde_json::Value),
27}
28
29/// DeleteAPIKeyError is a struct for typed errors of method [`KeyManagementAPI::delete_api_key`]
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum DeleteAPIKeyError {
33    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
34    UnknownValue(serde_json::Value),
35}
36
37/// DeleteApplicationKeyError is a struct for typed errors of method [`KeyManagementAPI::delete_application_key`]
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum DeleteApplicationKeyError {
41    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
42    UnknownValue(serde_json::Value),
43}
44
45/// GetAPIKeyError is a struct for typed errors of method [`KeyManagementAPI::get_api_key`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum GetAPIKeyError {
49    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
50    UnknownValue(serde_json::Value),
51}
52
53/// GetApplicationKeyError is a struct for typed errors of method [`KeyManagementAPI::get_application_key`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetApplicationKeyError {
57    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
58    UnknownValue(serde_json::Value),
59}
60
61/// ListAPIKeysError is a struct for typed errors of method [`KeyManagementAPI::list_api_keys`]
62#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum ListAPIKeysError {
65    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
66    UnknownValue(serde_json::Value),
67}
68
69/// ListApplicationKeysError is a struct for typed errors of method [`KeyManagementAPI::list_application_keys`]
70#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum ListApplicationKeysError {
73    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
74    UnknownValue(serde_json::Value),
75}
76
77/// UpdateAPIKeyError is a struct for typed errors of method [`KeyManagementAPI::update_api_key`]
78#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(untagged)]
80pub enum UpdateAPIKeyError {
81    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
82    UnknownValue(serde_json::Value),
83}
84
85/// UpdateApplicationKeyError is a struct for typed errors of method [`KeyManagementAPI::update_application_key`]
86#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(untagged)]
88pub enum UpdateApplicationKeyError {
89    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
90    UnknownValue(serde_json::Value),
91}
92
93/// Manage your Datadog API and application keys. You need an API key and an
94/// application key for a user with the required permissions to interact with these endpoints.
95///
96/// Consult the following pages to view and manage your keys:
97///
98/// - [API Keys](<https://app.datadoghq.com/organization-settings/api-keys>)
99/// - [Application Keys](<https://app.datadoghq.com/personal-settings/application-keys>)
100#[derive(Debug, Clone)]
101pub struct KeyManagementAPI {
102    config: datadog::Configuration,
103    client: reqwest_middleware::ClientWithMiddleware,
104}
105
106impl Default for KeyManagementAPI {
107    fn default() -> Self {
108        Self::with_config(datadog::Configuration::default())
109    }
110}
111
112impl KeyManagementAPI {
113    pub fn new() -> Self {
114        Self::default()
115    }
116    pub fn with_config(config: datadog::Configuration) -> Self {
117        let mut reqwest_client_builder = reqwest::Client::builder();
118
119        if let Some(proxy_url) = &config.proxy_url {
120            let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
121            reqwest_client_builder = reqwest_client_builder.proxy(proxy);
122        }
123
124        let mut middleware_client_builder =
125            reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
126
127        if config.enable_retry {
128            struct RetryableStatus;
129            impl reqwest_retry::RetryableStrategy for RetryableStatus {
130                fn handle(
131                    &self,
132                    res: &Result<reqwest::Response, reqwest_middleware::Error>,
133                ) -> Option<reqwest_retry::Retryable> {
134                    match res {
135                        Ok(success) => reqwest_retry::default_on_request_success(success),
136                        Err(_) => None,
137                    }
138                }
139            }
140            let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
141                .build_with_max_retries(config.max_retries);
142
143            let retry_middleware =
144                reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
145                    backoff_policy,
146                    RetryableStatus,
147                );
148
149            middleware_client_builder = middleware_client_builder.with(retry_middleware);
150        }
151
152        let client = middleware_client_builder.build();
153
154        Self { config, client }
155    }
156
157    pub fn with_client_and_config(
158        config: datadog::Configuration,
159        client: reqwest_middleware::ClientWithMiddleware,
160    ) -> Self {
161        Self { config, client }
162    }
163
164    /// Creates an API key with a given name.
165    pub async fn create_api_key(
166        &self,
167        body: crate::datadogV1::model::ApiKey,
168    ) -> Result<crate::datadogV1::model::ApiKeyResponse, datadog::Error<CreateAPIKeyError>> {
169        match self.create_api_key_with_http_info(body).await {
170            Ok(response_content) => {
171                if let Some(e) = response_content.entity {
172                    Ok(e)
173                } else {
174                    Err(datadog::Error::Serde(serde::de::Error::custom(
175                        "response content was None",
176                    )))
177                }
178            }
179            Err(err) => Err(err),
180        }
181    }
182
183    /// Creates an API key with a given name.
184    pub async fn create_api_key_with_http_info(
185        &self,
186        body: crate::datadogV1::model::ApiKey,
187    ) -> Result<
188        datadog::ResponseContent<crate::datadogV1::model::ApiKeyResponse>,
189        datadog::Error<CreateAPIKeyError>,
190    > {
191        let local_configuration = &self.config;
192        let operation_id = "v1.create_api_key";
193
194        let local_client = &self.client;
195
196        let local_uri_str = format!(
197            "{}/api/v1/api_key",
198            local_configuration.get_operation_host(operation_id)
199        );
200        let mut local_req_builder =
201            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
202
203        // build headers
204        let mut headers = HeaderMap::new();
205        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
206        headers.insert("Accept", HeaderValue::from_static("application/json"));
207
208        // build user agent
209        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
210            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
211            Err(e) => {
212                log::warn!("Failed to parse user agent header: {e}, falling back to default");
213                headers.insert(
214                    reqwest::header::USER_AGENT,
215                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
216                )
217            }
218        };
219
220        // build auth
221        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
222            headers.insert(
223                "DD-API-KEY",
224                HeaderValue::from_str(local_key.key.as_str())
225                    .expect("failed to parse DD-API-KEY header"),
226            );
227        };
228        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
229            headers.insert(
230                "DD-APPLICATION-KEY",
231                HeaderValue::from_str(local_key.key.as_str())
232                    .expect("failed to parse DD-APPLICATION-KEY header"),
233            );
234        };
235
236        // build body parameters
237        let output = Vec::new();
238        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
239        if body.serialize(&mut ser).is_ok() {
240            if let Some(content_encoding) = headers.get("Content-Encoding") {
241                match content_encoding.to_str().unwrap_or_default() {
242                    "gzip" => {
243                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
244                        let _ = enc.write_all(ser.into_inner().as_slice());
245                        match enc.finish() {
246                            Ok(buf) => {
247                                local_req_builder = local_req_builder.body(buf);
248                            }
249                            Err(e) => return Err(datadog::Error::Io(e)),
250                        }
251                    }
252                    "deflate" => {
253                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
254                        let _ = enc.write_all(ser.into_inner().as_slice());
255                        match enc.finish() {
256                            Ok(buf) => {
257                                local_req_builder = local_req_builder.body(buf);
258                            }
259                            Err(e) => return Err(datadog::Error::Io(e)),
260                        }
261                    }
262                    "zstd1" => {
263                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
264                        let _ = enc.write_all(ser.into_inner().as_slice());
265                        match enc.finish() {
266                            Ok(buf) => {
267                                local_req_builder = local_req_builder.body(buf);
268                            }
269                            Err(e) => return Err(datadog::Error::Io(e)),
270                        }
271                    }
272                    _ => {
273                        local_req_builder = local_req_builder.body(ser.into_inner());
274                    }
275                }
276            } else {
277                local_req_builder = local_req_builder.body(ser.into_inner());
278            }
279        }
280
281        local_req_builder = local_req_builder.headers(headers);
282        let local_req = local_req_builder.build()?;
283        log::debug!("request content: {:?}", local_req.body());
284        let local_resp = local_client.execute(local_req).await?;
285
286        let local_status = local_resp.status();
287        let local_content = local_resp.text().await?;
288        log::debug!("response content: {}", local_content);
289
290        if !local_status.is_client_error() && !local_status.is_server_error() {
291            match serde_json::from_str::<crate::datadogV1::model::ApiKeyResponse>(&local_content) {
292                Ok(e) => {
293                    return Ok(datadog::ResponseContent {
294                        status: local_status,
295                        content: local_content,
296                        entity: Some(e),
297                    })
298                }
299                Err(e) => return Err(datadog::Error::Serde(e)),
300            };
301        } else {
302            let local_entity: Option<CreateAPIKeyError> = serde_json::from_str(&local_content).ok();
303            let local_error = datadog::ResponseContent {
304                status: local_status,
305                content: local_content,
306                entity: local_entity,
307            };
308            Err(datadog::Error::ResponseError(local_error))
309        }
310    }
311
312    /// Create an application key with a given name.
313    pub async fn create_application_key(
314        &self,
315        body: crate::datadogV1::model::ApplicationKey,
316    ) -> Result<
317        crate::datadogV1::model::ApplicationKeyResponse,
318        datadog::Error<CreateApplicationKeyError>,
319    > {
320        match self.create_application_key_with_http_info(body).await {
321            Ok(response_content) => {
322                if let Some(e) = response_content.entity {
323                    Ok(e)
324                } else {
325                    Err(datadog::Error::Serde(serde::de::Error::custom(
326                        "response content was None",
327                    )))
328                }
329            }
330            Err(err) => Err(err),
331        }
332    }
333
334    /// Create an application key with a given name.
335    pub async fn create_application_key_with_http_info(
336        &self,
337        body: crate::datadogV1::model::ApplicationKey,
338    ) -> Result<
339        datadog::ResponseContent<crate::datadogV1::model::ApplicationKeyResponse>,
340        datadog::Error<CreateApplicationKeyError>,
341    > {
342        let local_configuration = &self.config;
343        let operation_id = "v1.create_application_key";
344
345        let local_client = &self.client;
346
347        let local_uri_str = format!(
348            "{}/api/v1/application_key",
349            local_configuration.get_operation_host(operation_id)
350        );
351        let mut local_req_builder =
352            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
353
354        // build headers
355        let mut headers = HeaderMap::new();
356        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
357        headers.insert("Accept", HeaderValue::from_static("application/json"));
358
359        // build user agent
360        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
361            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
362            Err(e) => {
363                log::warn!("Failed to parse user agent header: {e}, falling back to default");
364                headers.insert(
365                    reqwest::header::USER_AGENT,
366                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
367                )
368            }
369        };
370
371        // build auth
372        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
373            headers.insert(
374                "DD-API-KEY",
375                HeaderValue::from_str(local_key.key.as_str())
376                    .expect("failed to parse DD-API-KEY header"),
377            );
378        };
379        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
380            headers.insert(
381                "DD-APPLICATION-KEY",
382                HeaderValue::from_str(local_key.key.as_str())
383                    .expect("failed to parse DD-APPLICATION-KEY header"),
384            );
385        };
386
387        // build body parameters
388        let output = Vec::new();
389        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
390        if body.serialize(&mut ser).is_ok() {
391            if let Some(content_encoding) = headers.get("Content-Encoding") {
392                match content_encoding.to_str().unwrap_or_default() {
393                    "gzip" => {
394                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
395                        let _ = enc.write_all(ser.into_inner().as_slice());
396                        match enc.finish() {
397                            Ok(buf) => {
398                                local_req_builder = local_req_builder.body(buf);
399                            }
400                            Err(e) => return Err(datadog::Error::Io(e)),
401                        }
402                    }
403                    "deflate" => {
404                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
405                        let _ = enc.write_all(ser.into_inner().as_slice());
406                        match enc.finish() {
407                            Ok(buf) => {
408                                local_req_builder = local_req_builder.body(buf);
409                            }
410                            Err(e) => return Err(datadog::Error::Io(e)),
411                        }
412                    }
413                    "zstd1" => {
414                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
415                        let _ = enc.write_all(ser.into_inner().as_slice());
416                        match enc.finish() {
417                            Ok(buf) => {
418                                local_req_builder = local_req_builder.body(buf);
419                            }
420                            Err(e) => return Err(datadog::Error::Io(e)),
421                        }
422                    }
423                    _ => {
424                        local_req_builder = local_req_builder.body(ser.into_inner());
425                    }
426                }
427            } else {
428                local_req_builder = local_req_builder.body(ser.into_inner());
429            }
430        }
431
432        local_req_builder = local_req_builder.headers(headers);
433        let local_req = local_req_builder.build()?;
434        log::debug!("request content: {:?}", local_req.body());
435        let local_resp = local_client.execute(local_req).await?;
436
437        let local_status = local_resp.status();
438        let local_content = local_resp.text().await?;
439        log::debug!("response content: {}", local_content);
440
441        if !local_status.is_client_error() && !local_status.is_server_error() {
442            match serde_json::from_str::<crate::datadogV1::model::ApplicationKeyResponse>(
443                &local_content,
444            ) {
445                Ok(e) => {
446                    return Ok(datadog::ResponseContent {
447                        status: local_status,
448                        content: local_content,
449                        entity: Some(e),
450                    })
451                }
452                Err(e) => return Err(datadog::Error::Serde(e)),
453            };
454        } else {
455            let local_entity: Option<CreateApplicationKeyError> =
456                serde_json::from_str(&local_content).ok();
457            let local_error = datadog::ResponseContent {
458                status: local_status,
459                content: local_content,
460                entity: local_entity,
461            };
462            Err(datadog::Error::ResponseError(local_error))
463        }
464    }
465
466    /// Delete a given API key.
467    pub async fn delete_api_key(
468        &self,
469        key: String,
470    ) -> Result<crate::datadogV1::model::ApiKeyResponse, datadog::Error<DeleteAPIKeyError>> {
471        match self.delete_api_key_with_http_info(key).await {
472            Ok(response_content) => {
473                if let Some(e) = response_content.entity {
474                    Ok(e)
475                } else {
476                    Err(datadog::Error::Serde(serde::de::Error::custom(
477                        "response content was None",
478                    )))
479                }
480            }
481            Err(err) => Err(err),
482        }
483    }
484
485    /// Delete a given API key.
486    pub async fn delete_api_key_with_http_info(
487        &self,
488        key: String,
489    ) -> Result<
490        datadog::ResponseContent<crate::datadogV1::model::ApiKeyResponse>,
491        datadog::Error<DeleteAPIKeyError>,
492    > {
493        let local_configuration = &self.config;
494        let operation_id = "v1.delete_api_key";
495
496        let local_client = &self.client;
497
498        let local_uri_str = format!(
499            "{}/api/v1/api_key/{key}",
500            local_configuration.get_operation_host(operation_id),
501            key = datadog::urlencode(key)
502        );
503        let mut local_req_builder =
504            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
505
506        // build headers
507        let mut headers = HeaderMap::new();
508        headers.insert("Accept", HeaderValue::from_static("application/json"));
509
510        // build user agent
511        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
512            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
513            Err(e) => {
514                log::warn!("Failed to parse user agent header: {e}, falling back to default");
515                headers.insert(
516                    reqwest::header::USER_AGENT,
517                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
518                )
519            }
520        };
521
522        // build auth
523        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
524            headers.insert(
525                "DD-API-KEY",
526                HeaderValue::from_str(local_key.key.as_str())
527                    .expect("failed to parse DD-API-KEY header"),
528            );
529        };
530        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
531            headers.insert(
532                "DD-APPLICATION-KEY",
533                HeaderValue::from_str(local_key.key.as_str())
534                    .expect("failed to parse DD-APPLICATION-KEY header"),
535            );
536        };
537
538        local_req_builder = local_req_builder.headers(headers);
539        let local_req = local_req_builder.build()?;
540        log::debug!("request content: {:?}", local_req.body());
541        let local_resp = local_client.execute(local_req).await?;
542
543        let local_status = local_resp.status();
544        let local_content = local_resp.text().await?;
545        log::debug!("response content: {}", local_content);
546
547        if !local_status.is_client_error() && !local_status.is_server_error() {
548            match serde_json::from_str::<crate::datadogV1::model::ApiKeyResponse>(&local_content) {
549                Ok(e) => {
550                    return Ok(datadog::ResponseContent {
551                        status: local_status,
552                        content: local_content,
553                        entity: Some(e),
554                    })
555                }
556                Err(e) => return Err(datadog::Error::Serde(e)),
557            };
558        } else {
559            let local_entity: Option<DeleteAPIKeyError> = serde_json::from_str(&local_content).ok();
560            let local_error = datadog::ResponseContent {
561                status: local_status,
562                content: local_content,
563                entity: local_entity,
564            };
565            Err(datadog::Error::ResponseError(local_error))
566        }
567    }
568
569    /// Delete a given application key.
570    pub async fn delete_application_key(
571        &self,
572        key: String,
573    ) -> Result<
574        crate::datadogV1::model::ApplicationKeyResponse,
575        datadog::Error<DeleteApplicationKeyError>,
576    > {
577        match self.delete_application_key_with_http_info(key).await {
578            Ok(response_content) => {
579                if let Some(e) = response_content.entity {
580                    Ok(e)
581                } else {
582                    Err(datadog::Error::Serde(serde::de::Error::custom(
583                        "response content was None",
584                    )))
585                }
586            }
587            Err(err) => Err(err),
588        }
589    }
590
591    /// Delete a given application key.
592    pub async fn delete_application_key_with_http_info(
593        &self,
594        key: String,
595    ) -> Result<
596        datadog::ResponseContent<crate::datadogV1::model::ApplicationKeyResponse>,
597        datadog::Error<DeleteApplicationKeyError>,
598    > {
599        let local_configuration = &self.config;
600        let operation_id = "v1.delete_application_key";
601
602        let local_client = &self.client;
603
604        let local_uri_str = format!(
605            "{}/api/v1/application_key/{key}",
606            local_configuration.get_operation_host(operation_id),
607            key = datadog::urlencode(key)
608        );
609        let mut local_req_builder =
610            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
611
612        // build headers
613        let mut headers = HeaderMap::new();
614        headers.insert("Accept", HeaderValue::from_static("application/json"));
615
616        // build user agent
617        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
618            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
619            Err(e) => {
620                log::warn!("Failed to parse user agent header: {e}, falling back to default");
621                headers.insert(
622                    reqwest::header::USER_AGENT,
623                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
624                )
625            }
626        };
627
628        // build auth
629        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
630            headers.insert(
631                "DD-API-KEY",
632                HeaderValue::from_str(local_key.key.as_str())
633                    .expect("failed to parse DD-API-KEY header"),
634            );
635        };
636        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
637            headers.insert(
638                "DD-APPLICATION-KEY",
639                HeaderValue::from_str(local_key.key.as_str())
640                    .expect("failed to parse DD-APPLICATION-KEY header"),
641            );
642        };
643
644        local_req_builder = local_req_builder.headers(headers);
645        let local_req = local_req_builder.build()?;
646        log::debug!("request content: {:?}", local_req.body());
647        let local_resp = local_client.execute(local_req).await?;
648
649        let local_status = local_resp.status();
650        let local_content = local_resp.text().await?;
651        log::debug!("response content: {}", local_content);
652
653        if !local_status.is_client_error() && !local_status.is_server_error() {
654            match serde_json::from_str::<crate::datadogV1::model::ApplicationKeyResponse>(
655                &local_content,
656            ) {
657                Ok(e) => {
658                    return Ok(datadog::ResponseContent {
659                        status: local_status,
660                        content: local_content,
661                        entity: Some(e),
662                    })
663                }
664                Err(e) => return Err(datadog::Error::Serde(e)),
665            };
666        } else {
667            let local_entity: Option<DeleteApplicationKeyError> =
668                serde_json::from_str(&local_content).ok();
669            let local_error = datadog::ResponseContent {
670                status: local_status,
671                content: local_content,
672                entity: local_entity,
673            };
674            Err(datadog::Error::ResponseError(local_error))
675        }
676    }
677
678    /// Get a given API key.
679    pub async fn get_api_key(
680        &self,
681        key: String,
682    ) -> Result<crate::datadogV1::model::ApiKeyResponse, datadog::Error<GetAPIKeyError>> {
683        match self.get_api_key_with_http_info(key).await {
684            Ok(response_content) => {
685                if let Some(e) = response_content.entity {
686                    Ok(e)
687                } else {
688                    Err(datadog::Error::Serde(serde::de::Error::custom(
689                        "response content was None",
690                    )))
691                }
692            }
693            Err(err) => Err(err),
694        }
695    }
696
697    /// Get a given API key.
698    pub async fn get_api_key_with_http_info(
699        &self,
700        key: String,
701    ) -> Result<
702        datadog::ResponseContent<crate::datadogV1::model::ApiKeyResponse>,
703        datadog::Error<GetAPIKeyError>,
704    > {
705        let local_configuration = &self.config;
706        let operation_id = "v1.get_api_key";
707
708        let local_client = &self.client;
709
710        let local_uri_str = format!(
711            "{}/api/v1/api_key/{key}",
712            local_configuration.get_operation_host(operation_id),
713            key = datadog::urlencode(key)
714        );
715        let mut local_req_builder =
716            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
717
718        // build headers
719        let mut headers = HeaderMap::new();
720        headers.insert("Accept", HeaderValue::from_static("application/json"));
721
722        // build user agent
723        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
724            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
725            Err(e) => {
726                log::warn!("Failed to parse user agent header: {e}, falling back to default");
727                headers.insert(
728                    reqwest::header::USER_AGENT,
729                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
730                )
731            }
732        };
733
734        // build auth
735        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
736            headers.insert(
737                "DD-API-KEY",
738                HeaderValue::from_str(local_key.key.as_str())
739                    .expect("failed to parse DD-API-KEY header"),
740            );
741        };
742        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
743            headers.insert(
744                "DD-APPLICATION-KEY",
745                HeaderValue::from_str(local_key.key.as_str())
746                    .expect("failed to parse DD-APPLICATION-KEY header"),
747            );
748        };
749
750        local_req_builder = local_req_builder.headers(headers);
751        let local_req = local_req_builder.build()?;
752        log::debug!("request content: {:?}", local_req.body());
753        let local_resp = local_client.execute(local_req).await?;
754
755        let local_status = local_resp.status();
756        let local_content = local_resp.text().await?;
757        log::debug!("response content: {}", local_content);
758
759        if !local_status.is_client_error() && !local_status.is_server_error() {
760            match serde_json::from_str::<crate::datadogV1::model::ApiKeyResponse>(&local_content) {
761                Ok(e) => {
762                    return Ok(datadog::ResponseContent {
763                        status: local_status,
764                        content: local_content,
765                        entity: Some(e),
766                    })
767                }
768                Err(e) => return Err(datadog::Error::Serde(e)),
769            };
770        } else {
771            let local_entity: Option<GetAPIKeyError> = serde_json::from_str(&local_content).ok();
772            let local_error = datadog::ResponseContent {
773                status: local_status,
774                content: local_content,
775                entity: local_entity,
776            };
777            Err(datadog::Error::ResponseError(local_error))
778        }
779    }
780
781    /// Get a given application key.
782    pub async fn get_application_key(
783        &self,
784        key: String,
785    ) -> Result<
786        crate::datadogV1::model::ApplicationKeyResponse,
787        datadog::Error<GetApplicationKeyError>,
788    > {
789        match self.get_application_key_with_http_info(key).await {
790            Ok(response_content) => {
791                if let Some(e) = response_content.entity {
792                    Ok(e)
793                } else {
794                    Err(datadog::Error::Serde(serde::de::Error::custom(
795                        "response content was None",
796                    )))
797                }
798            }
799            Err(err) => Err(err),
800        }
801    }
802
803    /// Get a given application key.
804    pub async fn get_application_key_with_http_info(
805        &self,
806        key: String,
807    ) -> Result<
808        datadog::ResponseContent<crate::datadogV1::model::ApplicationKeyResponse>,
809        datadog::Error<GetApplicationKeyError>,
810    > {
811        let local_configuration = &self.config;
812        let operation_id = "v1.get_application_key";
813
814        let local_client = &self.client;
815
816        let local_uri_str = format!(
817            "{}/api/v1/application_key/{key}",
818            local_configuration.get_operation_host(operation_id),
819            key = datadog::urlencode(key)
820        );
821        let mut local_req_builder =
822            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
823
824        // build headers
825        let mut headers = HeaderMap::new();
826        headers.insert("Accept", HeaderValue::from_static("application/json"));
827
828        // build user agent
829        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
830            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
831            Err(e) => {
832                log::warn!("Failed to parse user agent header: {e}, falling back to default");
833                headers.insert(
834                    reqwest::header::USER_AGENT,
835                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
836                )
837            }
838        };
839
840        // build auth
841        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
842            headers.insert(
843                "DD-API-KEY",
844                HeaderValue::from_str(local_key.key.as_str())
845                    .expect("failed to parse DD-API-KEY header"),
846            );
847        };
848        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
849            headers.insert(
850                "DD-APPLICATION-KEY",
851                HeaderValue::from_str(local_key.key.as_str())
852                    .expect("failed to parse DD-APPLICATION-KEY header"),
853            );
854        };
855
856        local_req_builder = local_req_builder.headers(headers);
857        let local_req = local_req_builder.build()?;
858        log::debug!("request content: {:?}", local_req.body());
859        let local_resp = local_client.execute(local_req).await?;
860
861        let local_status = local_resp.status();
862        let local_content = local_resp.text().await?;
863        log::debug!("response content: {}", local_content);
864
865        if !local_status.is_client_error() && !local_status.is_server_error() {
866            match serde_json::from_str::<crate::datadogV1::model::ApplicationKeyResponse>(
867                &local_content,
868            ) {
869                Ok(e) => {
870                    return Ok(datadog::ResponseContent {
871                        status: local_status,
872                        content: local_content,
873                        entity: Some(e),
874                    })
875                }
876                Err(e) => return Err(datadog::Error::Serde(e)),
877            };
878        } else {
879            let local_entity: Option<GetApplicationKeyError> =
880                serde_json::from_str(&local_content).ok();
881            let local_error = datadog::ResponseContent {
882                status: local_status,
883                content: local_content,
884                entity: local_entity,
885            };
886            Err(datadog::Error::ResponseError(local_error))
887        }
888    }
889
890    /// Get all API keys available for your account.
891    pub async fn list_api_keys(
892        &self,
893    ) -> Result<crate::datadogV1::model::ApiKeyListResponse, datadog::Error<ListAPIKeysError>> {
894        match self.list_api_keys_with_http_info().await {
895            Ok(response_content) => {
896                if let Some(e) = response_content.entity {
897                    Ok(e)
898                } else {
899                    Err(datadog::Error::Serde(serde::de::Error::custom(
900                        "response content was None",
901                    )))
902                }
903            }
904            Err(err) => Err(err),
905        }
906    }
907
908    /// Get all API keys available for your account.
909    pub async fn list_api_keys_with_http_info(
910        &self,
911    ) -> Result<
912        datadog::ResponseContent<crate::datadogV1::model::ApiKeyListResponse>,
913        datadog::Error<ListAPIKeysError>,
914    > {
915        let local_configuration = &self.config;
916        let operation_id = "v1.list_api_keys";
917
918        let local_client = &self.client;
919
920        let local_uri_str = format!(
921            "{}/api/v1/api_key",
922            local_configuration.get_operation_host(operation_id)
923        );
924        let mut local_req_builder =
925            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
926
927        // build headers
928        let mut headers = HeaderMap::new();
929        headers.insert("Accept", HeaderValue::from_static("application/json"));
930
931        // build user agent
932        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
933            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
934            Err(e) => {
935                log::warn!("Failed to parse user agent header: {e}, falling back to default");
936                headers.insert(
937                    reqwest::header::USER_AGENT,
938                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
939                )
940            }
941        };
942
943        // build auth
944        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
945            headers.insert(
946                "DD-API-KEY",
947                HeaderValue::from_str(local_key.key.as_str())
948                    .expect("failed to parse DD-API-KEY header"),
949            );
950        };
951        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
952            headers.insert(
953                "DD-APPLICATION-KEY",
954                HeaderValue::from_str(local_key.key.as_str())
955                    .expect("failed to parse DD-APPLICATION-KEY header"),
956            );
957        };
958
959        local_req_builder = local_req_builder.headers(headers);
960        let local_req = local_req_builder.build()?;
961        log::debug!("request content: {:?}", local_req.body());
962        let local_resp = local_client.execute(local_req).await?;
963
964        let local_status = local_resp.status();
965        let local_content = local_resp.text().await?;
966        log::debug!("response content: {}", local_content);
967
968        if !local_status.is_client_error() && !local_status.is_server_error() {
969            match serde_json::from_str::<crate::datadogV1::model::ApiKeyListResponse>(
970                &local_content,
971            ) {
972                Ok(e) => {
973                    return Ok(datadog::ResponseContent {
974                        status: local_status,
975                        content: local_content,
976                        entity: Some(e),
977                    })
978                }
979                Err(e) => return Err(datadog::Error::Serde(e)),
980            };
981        } else {
982            let local_entity: Option<ListAPIKeysError> = serde_json::from_str(&local_content).ok();
983            let local_error = datadog::ResponseContent {
984                status: local_status,
985                content: local_content,
986                entity: local_entity,
987            };
988            Err(datadog::Error::ResponseError(local_error))
989        }
990    }
991
992    /// Get all application keys available for your Datadog account.
993    pub async fn list_application_keys(
994        &self,
995    ) -> Result<
996        crate::datadogV1::model::ApplicationKeyListResponse,
997        datadog::Error<ListApplicationKeysError>,
998    > {
999        match self.list_application_keys_with_http_info().await {
1000            Ok(response_content) => {
1001                if let Some(e) = response_content.entity {
1002                    Ok(e)
1003                } else {
1004                    Err(datadog::Error::Serde(serde::de::Error::custom(
1005                        "response content was None",
1006                    )))
1007                }
1008            }
1009            Err(err) => Err(err),
1010        }
1011    }
1012
1013    /// Get all application keys available for your Datadog account.
1014    pub async fn list_application_keys_with_http_info(
1015        &self,
1016    ) -> Result<
1017        datadog::ResponseContent<crate::datadogV1::model::ApplicationKeyListResponse>,
1018        datadog::Error<ListApplicationKeysError>,
1019    > {
1020        let local_configuration = &self.config;
1021        let operation_id = "v1.list_application_keys";
1022
1023        let local_client = &self.client;
1024
1025        let local_uri_str = format!(
1026            "{}/api/v1/application_key",
1027            local_configuration.get_operation_host(operation_id)
1028        );
1029        let mut local_req_builder =
1030            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1031
1032        // build headers
1033        let mut headers = HeaderMap::new();
1034        headers.insert("Accept", HeaderValue::from_static("application/json"));
1035
1036        // build user agent
1037        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1038            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1039            Err(e) => {
1040                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1041                headers.insert(
1042                    reqwest::header::USER_AGENT,
1043                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1044                )
1045            }
1046        };
1047
1048        // build auth
1049        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1050            headers.insert(
1051                "DD-API-KEY",
1052                HeaderValue::from_str(local_key.key.as_str())
1053                    .expect("failed to parse DD-API-KEY header"),
1054            );
1055        };
1056        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1057            headers.insert(
1058                "DD-APPLICATION-KEY",
1059                HeaderValue::from_str(local_key.key.as_str())
1060                    .expect("failed to parse DD-APPLICATION-KEY header"),
1061            );
1062        };
1063
1064        local_req_builder = local_req_builder.headers(headers);
1065        let local_req = local_req_builder.build()?;
1066        log::debug!("request content: {:?}", local_req.body());
1067        let local_resp = local_client.execute(local_req).await?;
1068
1069        let local_status = local_resp.status();
1070        let local_content = local_resp.text().await?;
1071        log::debug!("response content: {}", local_content);
1072
1073        if !local_status.is_client_error() && !local_status.is_server_error() {
1074            match serde_json::from_str::<crate::datadogV1::model::ApplicationKeyListResponse>(
1075                &local_content,
1076            ) {
1077                Ok(e) => {
1078                    return Ok(datadog::ResponseContent {
1079                        status: local_status,
1080                        content: local_content,
1081                        entity: Some(e),
1082                    })
1083                }
1084                Err(e) => return Err(datadog::Error::Serde(e)),
1085            };
1086        } else {
1087            let local_entity: Option<ListApplicationKeysError> =
1088                serde_json::from_str(&local_content).ok();
1089            let local_error = datadog::ResponseContent {
1090                status: local_status,
1091                content: local_content,
1092                entity: local_entity,
1093            };
1094            Err(datadog::Error::ResponseError(local_error))
1095        }
1096    }
1097
1098    /// Edit an API key name.
1099    pub async fn update_api_key(
1100        &self,
1101        key: String,
1102        body: crate::datadogV1::model::ApiKey,
1103    ) -> Result<crate::datadogV1::model::ApiKeyResponse, datadog::Error<UpdateAPIKeyError>> {
1104        match self.update_api_key_with_http_info(key, body).await {
1105            Ok(response_content) => {
1106                if let Some(e) = response_content.entity {
1107                    Ok(e)
1108                } else {
1109                    Err(datadog::Error::Serde(serde::de::Error::custom(
1110                        "response content was None",
1111                    )))
1112                }
1113            }
1114            Err(err) => Err(err),
1115        }
1116    }
1117
1118    /// Edit an API key name.
1119    pub async fn update_api_key_with_http_info(
1120        &self,
1121        key: String,
1122        body: crate::datadogV1::model::ApiKey,
1123    ) -> Result<
1124        datadog::ResponseContent<crate::datadogV1::model::ApiKeyResponse>,
1125        datadog::Error<UpdateAPIKeyError>,
1126    > {
1127        let local_configuration = &self.config;
1128        let operation_id = "v1.update_api_key";
1129
1130        let local_client = &self.client;
1131
1132        let local_uri_str = format!(
1133            "{}/api/v1/api_key/{key}",
1134            local_configuration.get_operation_host(operation_id),
1135            key = datadog::urlencode(key)
1136        );
1137        let mut local_req_builder =
1138            local_client.request(reqwest::Method::PUT, local_uri_str.as_str());
1139
1140        // build headers
1141        let mut headers = HeaderMap::new();
1142        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1143        headers.insert("Accept", HeaderValue::from_static("application/json"));
1144
1145        // build user agent
1146        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1147            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1148            Err(e) => {
1149                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1150                headers.insert(
1151                    reqwest::header::USER_AGENT,
1152                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1153                )
1154            }
1155        };
1156
1157        // build auth
1158        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1159            headers.insert(
1160                "DD-API-KEY",
1161                HeaderValue::from_str(local_key.key.as_str())
1162                    .expect("failed to parse DD-API-KEY header"),
1163            );
1164        };
1165        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1166            headers.insert(
1167                "DD-APPLICATION-KEY",
1168                HeaderValue::from_str(local_key.key.as_str())
1169                    .expect("failed to parse DD-APPLICATION-KEY header"),
1170            );
1171        };
1172
1173        // build body parameters
1174        let output = Vec::new();
1175        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1176        if body.serialize(&mut ser).is_ok() {
1177            if let Some(content_encoding) = headers.get("Content-Encoding") {
1178                match content_encoding.to_str().unwrap_or_default() {
1179                    "gzip" => {
1180                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1181                        let _ = enc.write_all(ser.into_inner().as_slice());
1182                        match enc.finish() {
1183                            Ok(buf) => {
1184                                local_req_builder = local_req_builder.body(buf);
1185                            }
1186                            Err(e) => return Err(datadog::Error::Io(e)),
1187                        }
1188                    }
1189                    "deflate" => {
1190                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1191                        let _ = enc.write_all(ser.into_inner().as_slice());
1192                        match enc.finish() {
1193                            Ok(buf) => {
1194                                local_req_builder = local_req_builder.body(buf);
1195                            }
1196                            Err(e) => return Err(datadog::Error::Io(e)),
1197                        }
1198                    }
1199                    "zstd1" => {
1200                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1201                        let _ = enc.write_all(ser.into_inner().as_slice());
1202                        match enc.finish() {
1203                            Ok(buf) => {
1204                                local_req_builder = local_req_builder.body(buf);
1205                            }
1206                            Err(e) => return Err(datadog::Error::Io(e)),
1207                        }
1208                    }
1209                    _ => {
1210                        local_req_builder = local_req_builder.body(ser.into_inner());
1211                    }
1212                }
1213            } else {
1214                local_req_builder = local_req_builder.body(ser.into_inner());
1215            }
1216        }
1217
1218        local_req_builder = local_req_builder.headers(headers);
1219        let local_req = local_req_builder.build()?;
1220        log::debug!("request content: {:?}", local_req.body());
1221        let local_resp = local_client.execute(local_req).await?;
1222
1223        let local_status = local_resp.status();
1224        let local_content = local_resp.text().await?;
1225        log::debug!("response content: {}", local_content);
1226
1227        if !local_status.is_client_error() && !local_status.is_server_error() {
1228            match serde_json::from_str::<crate::datadogV1::model::ApiKeyResponse>(&local_content) {
1229                Ok(e) => {
1230                    return Ok(datadog::ResponseContent {
1231                        status: local_status,
1232                        content: local_content,
1233                        entity: Some(e),
1234                    })
1235                }
1236                Err(e) => return Err(datadog::Error::Serde(e)),
1237            };
1238        } else {
1239            let local_entity: Option<UpdateAPIKeyError> = serde_json::from_str(&local_content).ok();
1240            let local_error = datadog::ResponseContent {
1241                status: local_status,
1242                content: local_content,
1243                entity: local_entity,
1244            };
1245            Err(datadog::Error::ResponseError(local_error))
1246        }
1247    }
1248
1249    /// Edit an application key name.
1250    pub async fn update_application_key(
1251        &self,
1252        key: String,
1253        body: crate::datadogV1::model::ApplicationKey,
1254    ) -> Result<
1255        crate::datadogV1::model::ApplicationKeyResponse,
1256        datadog::Error<UpdateApplicationKeyError>,
1257    > {
1258        match self.update_application_key_with_http_info(key, body).await {
1259            Ok(response_content) => {
1260                if let Some(e) = response_content.entity {
1261                    Ok(e)
1262                } else {
1263                    Err(datadog::Error::Serde(serde::de::Error::custom(
1264                        "response content was None",
1265                    )))
1266                }
1267            }
1268            Err(err) => Err(err),
1269        }
1270    }
1271
1272    /// Edit an application key name.
1273    pub async fn update_application_key_with_http_info(
1274        &self,
1275        key: String,
1276        body: crate::datadogV1::model::ApplicationKey,
1277    ) -> Result<
1278        datadog::ResponseContent<crate::datadogV1::model::ApplicationKeyResponse>,
1279        datadog::Error<UpdateApplicationKeyError>,
1280    > {
1281        let local_configuration = &self.config;
1282        let operation_id = "v1.update_application_key";
1283
1284        let local_client = &self.client;
1285
1286        let local_uri_str = format!(
1287            "{}/api/v1/application_key/{key}",
1288            local_configuration.get_operation_host(operation_id),
1289            key = datadog::urlencode(key)
1290        );
1291        let mut local_req_builder =
1292            local_client.request(reqwest::Method::PUT, local_uri_str.as_str());
1293
1294        // build headers
1295        let mut headers = HeaderMap::new();
1296        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1297        headers.insert("Accept", HeaderValue::from_static("application/json"));
1298
1299        // build user agent
1300        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1301            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1302            Err(e) => {
1303                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1304                headers.insert(
1305                    reqwest::header::USER_AGENT,
1306                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1307                )
1308            }
1309        };
1310
1311        // build auth
1312        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1313            headers.insert(
1314                "DD-API-KEY",
1315                HeaderValue::from_str(local_key.key.as_str())
1316                    .expect("failed to parse DD-API-KEY header"),
1317            );
1318        };
1319        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1320            headers.insert(
1321                "DD-APPLICATION-KEY",
1322                HeaderValue::from_str(local_key.key.as_str())
1323                    .expect("failed to parse DD-APPLICATION-KEY header"),
1324            );
1325        };
1326
1327        // build body parameters
1328        let output = Vec::new();
1329        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1330        if body.serialize(&mut ser).is_ok() {
1331            if let Some(content_encoding) = headers.get("Content-Encoding") {
1332                match content_encoding.to_str().unwrap_or_default() {
1333                    "gzip" => {
1334                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1335                        let _ = enc.write_all(ser.into_inner().as_slice());
1336                        match enc.finish() {
1337                            Ok(buf) => {
1338                                local_req_builder = local_req_builder.body(buf);
1339                            }
1340                            Err(e) => return Err(datadog::Error::Io(e)),
1341                        }
1342                    }
1343                    "deflate" => {
1344                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
1345                        let _ = enc.write_all(ser.into_inner().as_slice());
1346                        match enc.finish() {
1347                            Ok(buf) => {
1348                                local_req_builder = local_req_builder.body(buf);
1349                            }
1350                            Err(e) => return Err(datadog::Error::Io(e)),
1351                        }
1352                    }
1353                    "zstd1" => {
1354                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
1355                        let _ = enc.write_all(ser.into_inner().as_slice());
1356                        match enc.finish() {
1357                            Ok(buf) => {
1358                                local_req_builder = local_req_builder.body(buf);
1359                            }
1360                            Err(e) => return Err(datadog::Error::Io(e)),
1361                        }
1362                    }
1363                    _ => {
1364                        local_req_builder = local_req_builder.body(ser.into_inner());
1365                    }
1366                }
1367            } else {
1368                local_req_builder = local_req_builder.body(ser.into_inner());
1369            }
1370        }
1371
1372        local_req_builder = local_req_builder.headers(headers);
1373        let local_req = local_req_builder.build()?;
1374        log::debug!("request content: {:?}", local_req.body());
1375        let local_resp = local_client.execute(local_req).await?;
1376
1377        let local_status = local_resp.status();
1378        let local_content = local_resp.text().await?;
1379        log::debug!("response content: {}", local_content);
1380
1381        if !local_status.is_client_error() && !local_status.is_server_error() {
1382            match serde_json::from_str::<crate::datadogV1::model::ApplicationKeyResponse>(
1383                &local_content,
1384            ) {
1385                Ok(e) => {
1386                    return Ok(datadog::ResponseContent {
1387                        status: local_status,
1388                        content: local_content,
1389                        entity: Some(e),
1390                    })
1391                }
1392                Err(e) => return Err(datadog::Error::Serde(e)),
1393            };
1394        } else {
1395            let local_entity: Option<UpdateApplicationKeyError> =
1396                serde_json::from_str(&local_content).ok();
1397            let local_error = datadog::ResponseContent {
1398                status: local_status,
1399                content: local_content,
1400                entity: local_entity,
1401            };
1402            Err(datadog::Error::ResponseError(local_error))
1403        }
1404    }
1405}