1use 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#[derive(Debug, Clone, Serialize, Deserialize)]
15#[serde(untagged)]
16pub enum CheckAWSLogsLambdaAsyncError {
17    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
18    UnknownValue(serde_json::Value),
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
23#[serde(untagged)]
24pub enum CheckAWSLogsServicesAsyncError {
25    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
26    UnknownValue(serde_json::Value),
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum CreateAWSLambdaARNError {
33    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
34    UnknownValue(serde_json::Value),
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum DeleteAWSLambdaARNError {
41    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
42    UnknownValue(serde_json::Value),
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum EnableAWSLogServicesError {
49    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
50    UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum ListAWSLogsIntegrationsError {
57    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
58    UnknownValue(serde_json::Value),
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum ListAWSLogsServicesError {
65    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
66    UnknownValue(serde_json::Value),
67}
68
69#[derive(Debug, Clone)]
72pub struct AWSLogsIntegrationAPI {
73    config: datadog::Configuration,
74    client: reqwest_middleware::ClientWithMiddleware,
75}
76
77impl Default for AWSLogsIntegrationAPI {
78    fn default() -> Self {
79        Self::with_config(datadog::Configuration::default())
80    }
81}
82
83impl AWSLogsIntegrationAPI {
84    pub fn new() -> Self {
85        Self::default()
86    }
87    pub fn with_config(config: datadog::Configuration) -> Self {
88        let mut reqwest_client_builder = reqwest::Client::builder();
89
90        if let Some(proxy_url) = &config.proxy_url {
91            let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
92            reqwest_client_builder = reqwest_client_builder.proxy(proxy);
93        }
94
95        let mut middleware_client_builder =
96            reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
97
98        if config.enable_retry {
99            struct RetryableStatus;
100            impl reqwest_retry::RetryableStrategy for RetryableStatus {
101                fn handle(
102                    &self,
103                    res: &Result<reqwest::Response, reqwest_middleware::Error>,
104                ) -> Option<reqwest_retry::Retryable> {
105                    match res {
106                        Ok(success) => reqwest_retry::default_on_request_success(success),
107                        Err(_) => None,
108                    }
109                }
110            }
111            let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
112                .build_with_max_retries(config.max_retries);
113
114            let retry_middleware =
115                reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
116                    backoff_policy,
117                    RetryableStatus,
118                );
119
120            middleware_client_builder = middleware_client_builder.with(retry_middleware);
121        }
122
123        let client = middleware_client_builder.build();
124
125        Self { config, client }
126    }
127
128    pub fn with_client_and_config(
129        config: datadog::Configuration,
130        client: reqwest_middleware::ClientWithMiddleware,
131    ) -> Self {
132        Self { config, client }
133    }
134
135    pub async fn check_aws_logs_lambda_async(
144        &self,
145        body: crate::datadogV1::model::AWSAccountAndLambdaRequest,
146    ) -> Result<
147        crate::datadogV1::model::AWSLogsAsyncResponse,
148        datadog::Error<CheckAWSLogsLambdaAsyncError>,
149    > {
150        match self.check_aws_logs_lambda_async_with_http_info(body).await {
151            Ok(response_content) => {
152                if let Some(e) = response_content.entity {
153                    Ok(e)
154                } else {
155                    Err(datadog::Error::Serde(serde::de::Error::custom(
156                        "response content was None",
157                    )))
158                }
159            }
160            Err(err) => Err(err),
161        }
162    }
163
164    pub async fn check_aws_logs_lambda_async_with_http_info(
173        &self,
174        body: crate::datadogV1::model::AWSAccountAndLambdaRequest,
175    ) -> Result<
176        datadog::ResponseContent<crate::datadogV1::model::AWSLogsAsyncResponse>,
177        datadog::Error<CheckAWSLogsLambdaAsyncError>,
178    > {
179        let local_configuration = &self.config;
180        let operation_id = "v1.check_aws_logs_lambda_async";
181
182        let local_client = &self.client;
183
184        let local_uri_str = format!(
185            "{}/api/v1/integration/aws/logs/check_async",
186            local_configuration.get_operation_host(operation_id)
187        );
188        let mut local_req_builder =
189            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
190
191        let mut headers = HeaderMap::new();
193        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
194        headers.insert("Accept", HeaderValue::from_static("application/json"));
195
196        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
198            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
199            Err(e) => {
200                log::warn!("Failed to parse user agent header: {e}, falling back to default");
201                headers.insert(
202                    reqwest::header::USER_AGENT,
203                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
204                )
205            }
206        };
207
208        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
210            headers.insert(
211                "DD-API-KEY",
212                HeaderValue::from_str(local_key.key.as_str())
213                    .expect("failed to parse DD-API-KEY header"),
214            );
215        };
216        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
217            headers.insert(
218                "DD-APPLICATION-KEY",
219                HeaderValue::from_str(local_key.key.as_str())
220                    .expect("failed to parse DD-APPLICATION-KEY header"),
221            );
222        };
223
224        let output = Vec::new();
226        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
227        if body.serialize(&mut ser).is_ok() {
228            if let Some(content_encoding) = headers.get("Content-Encoding") {
229                match content_encoding.to_str().unwrap_or_default() {
230                    "gzip" => {
231                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
232                        let _ = enc.write_all(ser.into_inner().as_slice());
233                        match enc.finish() {
234                            Ok(buf) => {
235                                local_req_builder = local_req_builder.body(buf);
236                            }
237                            Err(e) => return Err(datadog::Error::Io(e)),
238                        }
239                    }
240                    "deflate" => {
241                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
242                        let _ = enc.write_all(ser.into_inner().as_slice());
243                        match enc.finish() {
244                            Ok(buf) => {
245                                local_req_builder = local_req_builder.body(buf);
246                            }
247                            Err(e) => return Err(datadog::Error::Io(e)),
248                        }
249                    }
250                    "zstd1" => {
251                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
252                        let _ = enc.write_all(ser.into_inner().as_slice());
253                        match enc.finish() {
254                            Ok(buf) => {
255                                local_req_builder = local_req_builder.body(buf);
256                            }
257                            Err(e) => return Err(datadog::Error::Io(e)),
258                        }
259                    }
260                    _ => {
261                        local_req_builder = local_req_builder.body(ser.into_inner());
262                    }
263                }
264            } else {
265                local_req_builder = local_req_builder.body(ser.into_inner());
266            }
267        }
268
269        local_req_builder = local_req_builder.headers(headers);
270        let local_req = local_req_builder.build()?;
271        log::debug!("request content: {:?}", local_req.body());
272        let local_resp = local_client.execute(local_req).await?;
273
274        let local_status = local_resp.status();
275        let local_content = local_resp.text().await?;
276        log::debug!("response content: {}", local_content);
277
278        if !local_status.is_client_error() && !local_status.is_server_error() {
279            match serde_json::from_str::<crate::datadogV1::model::AWSLogsAsyncResponse>(
280                &local_content,
281            ) {
282                Ok(e) => {
283                    return Ok(datadog::ResponseContent {
284                        status: local_status,
285                        content: local_content,
286                        entity: Some(e),
287                    })
288                }
289                Err(e) => return Err(datadog::Error::Serde(e)),
290            };
291        } else {
292            let local_entity: Option<CheckAWSLogsLambdaAsyncError> =
293                serde_json::from_str(&local_content).ok();
294            let local_error = datadog::ResponseContent {
295                status: local_status,
296                content: local_content,
297                entity: local_entity,
298            };
299            Err(datadog::Error::ResponseError(local_error))
300        }
301    }
302
303    pub async fn check_aws_logs_services_async(
314        &self,
315        body: crate::datadogV1::model::AWSLogsServicesRequest,
316    ) -> Result<
317        crate::datadogV1::model::AWSLogsAsyncResponse,
318        datadog::Error<CheckAWSLogsServicesAsyncError>,
319    > {
320        match self
321            .check_aws_logs_services_async_with_http_info(body)
322            .await
323        {
324            Ok(response_content) => {
325                if let Some(e) = response_content.entity {
326                    Ok(e)
327                } else {
328                    Err(datadog::Error::Serde(serde::de::Error::custom(
329                        "response content was None",
330                    )))
331                }
332            }
333            Err(err) => Err(err),
334        }
335    }
336
337    pub async fn check_aws_logs_services_async_with_http_info(
348        &self,
349        body: crate::datadogV1::model::AWSLogsServicesRequest,
350    ) -> Result<
351        datadog::ResponseContent<crate::datadogV1::model::AWSLogsAsyncResponse>,
352        datadog::Error<CheckAWSLogsServicesAsyncError>,
353    > {
354        let local_configuration = &self.config;
355        let operation_id = "v1.check_aws_logs_services_async";
356
357        let local_client = &self.client;
358
359        let local_uri_str = format!(
360            "{}/api/v1/integration/aws/logs/services_async",
361            local_configuration.get_operation_host(operation_id)
362        );
363        let mut local_req_builder =
364            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
365
366        let mut headers = HeaderMap::new();
368        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
369        headers.insert("Accept", HeaderValue::from_static("application/json"));
370
371        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
373            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
374            Err(e) => {
375                log::warn!("Failed to parse user agent header: {e}, falling back to default");
376                headers.insert(
377                    reqwest::header::USER_AGENT,
378                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
379                )
380            }
381        };
382
383        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
385            headers.insert(
386                "DD-API-KEY",
387                HeaderValue::from_str(local_key.key.as_str())
388                    .expect("failed to parse DD-API-KEY header"),
389            );
390        };
391        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
392            headers.insert(
393                "DD-APPLICATION-KEY",
394                HeaderValue::from_str(local_key.key.as_str())
395                    .expect("failed to parse DD-APPLICATION-KEY header"),
396            );
397        };
398
399        let output = Vec::new();
401        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
402        if body.serialize(&mut ser).is_ok() {
403            if let Some(content_encoding) = headers.get("Content-Encoding") {
404                match content_encoding.to_str().unwrap_or_default() {
405                    "gzip" => {
406                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
407                        let _ = enc.write_all(ser.into_inner().as_slice());
408                        match enc.finish() {
409                            Ok(buf) => {
410                                local_req_builder = local_req_builder.body(buf);
411                            }
412                            Err(e) => return Err(datadog::Error::Io(e)),
413                        }
414                    }
415                    "deflate" => {
416                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
417                        let _ = enc.write_all(ser.into_inner().as_slice());
418                        match enc.finish() {
419                            Ok(buf) => {
420                                local_req_builder = local_req_builder.body(buf);
421                            }
422                            Err(e) => return Err(datadog::Error::Io(e)),
423                        }
424                    }
425                    "zstd1" => {
426                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
427                        let _ = enc.write_all(ser.into_inner().as_slice());
428                        match enc.finish() {
429                            Ok(buf) => {
430                                local_req_builder = local_req_builder.body(buf);
431                            }
432                            Err(e) => return Err(datadog::Error::Io(e)),
433                        }
434                    }
435                    _ => {
436                        local_req_builder = local_req_builder.body(ser.into_inner());
437                    }
438                }
439            } else {
440                local_req_builder = local_req_builder.body(ser.into_inner());
441            }
442        }
443
444        local_req_builder = local_req_builder.headers(headers);
445        let local_req = local_req_builder.build()?;
446        log::debug!("request content: {:?}", local_req.body());
447        let local_resp = local_client.execute(local_req).await?;
448
449        let local_status = local_resp.status();
450        let local_content = local_resp.text().await?;
451        log::debug!("response content: {}", local_content);
452
453        if !local_status.is_client_error() && !local_status.is_server_error() {
454            match serde_json::from_str::<crate::datadogV1::model::AWSLogsAsyncResponse>(
455                &local_content,
456            ) {
457                Ok(e) => {
458                    return Ok(datadog::ResponseContent {
459                        status: local_status,
460                        content: local_content,
461                        entity: Some(e),
462                    })
463                }
464                Err(e) => return Err(datadog::Error::Serde(e)),
465            };
466        } else {
467            let local_entity: Option<CheckAWSLogsServicesAsyncError> =
468                serde_json::from_str(&local_content).ok();
469            let local_error = datadog::ResponseContent {
470                status: local_status,
471                content: local_content,
472                entity: local_entity,
473            };
474            Err(datadog::Error::ResponseError(local_error))
475        }
476    }
477
478    pub async fn create_aws_lambda_arn(
480        &self,
481        body: crate::datadogV1::model::AWSAccountAndLambdaRequest,
482    ) -> Result<
483        std::collections::BTreeMap<String, serde_json::Value>,
484        datadog::Error<CreateAWSLambdaARNError>,
485    > {
486        match self.create_aws_lambda_arn_with_http_info(body).await {
487            Ok(response_content) => {
488                if let Some(e) = response_content.entity {
489                    Ok(e)
490                } else {
491                    Err(datadog::Error::Serde(serde::de::Error::custom(
492                        "response content was None",
493                    )))
494                }
495            }
496            Err(err) => Err(err),
497        }
498    }
499
500    pub async fn create_aws_lambda_arn_with_http_info(
502        &self,
503        body: crate::datadogV1::model::AWSAccountAndLambdaRequest,
504    ) -> Result<
505        datadog::ResponseContent<std::collections::BTreeMap<String, serde_json::Value>>,
506        datadog::Error<CreateAWSLambdaARNError>,
507    > {
508        let local_configuration = &self.config;
509        let operation_id = "v1.create_aws_lambda_arn";
510
511        let local_client = &self.client;
512
513        let local_uri_str = format!(
514            "{}/api/v1/integration/aws/logs",
515            local_configuration.get_operation_host(operation_id)
516        );
517        let mut local_req_builder =
518            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
519
520        let mut headers = HeaderMap::new();
522        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
523        headers.insert("Accept", HeaderValue::from_static("application/json"));
524
525        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
527            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
528            Err(e) => {
529                log::warn!("Failed to parse user agent header: {e}, falling back to default");
530                headers.insert(
531                    reqwest::header::USER_AGENT,
532                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
533                )
534            }
535        };
536
537        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
539            headers.insert(
540                "DD-API-KEY",
541                HeaderValue::from_str(local_key.key.as_str())
542                    .expect("failed to parse DD-API-KEY header"),
543            );
544        };
545        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
546            headers.insert(
547                "DD-APPLICATION-KEY",
548                HeaderValue::from_str(local_key.key.as_str())
549                    .expect("failed to parse DD-APPLICATION-KEY header"),
550            );
551        };
552
553        let output = Vec::new();
555        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
556        if body.serialize(&mut ser).is_ok() {
557            if let Some(content_encoding) = headers.get("Content-Encoding") {
558                match content_encoding.to_str().unwrap_or_default() {
559                    "gzip" => {
560                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
561                        let _ = enc.write_all(ser.into_inner().as_slice());
562                        match enc.finish() {
563                            Ok(buf) => {
564                                local_req_builder = local_req_builder.body(buf);
565                            }
566                            Err(e) => return Err(datadog::Error::Io(e)),
567                        }
568                    }
569                    "deflate" => {
570                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
571                        let _ = enc.write_all(ser.into_inner().as_slice());
572                        match enc.finish() {
573                            Ok(buf) => {
574                                local_req_builder = local_req_builder.body(buf);
575                            }
576                            Err(e) => return Err(datadog::Error::Io(e)),
577                        }
578                    }
579                    "zstd1" => {
580                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
581                        let _ = enc.write_all(ser.into_inner().as_slice());
582                        match enc.finish() {
583                            Ok(buf) => {
584                                local_req_builder = local_req_builder.body(buf);
585                            }
586                            Err(e) => return Err(datadog::Error::Io(e)),
587                        }
588                    }
589                    _ => {
590                        local_req_builder = local_req_builder.body(ser.into_inner());
591                    }
592                }
593            } else {
594                local_req_builder = local_req_builder.body(ser.into_inner());
595            }
596        }
597
598        local_req_builder = local_req_builder.headers(headers);
599        let local_req = local_req_builder.build()?;
600        log::debug!("request content: {:?}", local_req.body());
601        let local_resp = local_client.execute(local_req).await?;
602
603        let local_status = local_resp.status();
604        let local_content = local_resp.text().await?;
605        log::debug!("response content: {}", local_content);
606
607        if !local_status.is_client_error() && !local_status.is_server_error() {
608            match serde_json::from_str::<std::collections::BTreeMap<String, serde_json::Value>>(
609                &local_content,
610            ) {
611                Ok(e) => {
612                    return Ok(datadog::ResponseContent {
613                        status: local_status,
614                        content: local_content,
615                        entity: Some(e),
616                    })
617                }
618                Err(e) => return Err(datadog::Error::Serde(e)),
619            };
620        } else {
621            let local_entity: Option<CreateAWSLambdaARNError> =
622                serde_json::from_str(&local_content).ok();
623            let local_error = datadog::ResponseContent {
624                status: local_status,
625                content: local_content,
626                entity: local_entity,
627            };
628            Err(datadog::Error::ResponseError(local_error))
629        }
630    }
631
632    pub async fn delete_aws_lambda_arn(
634        &self,
635        body: crate::datadogV1::model::AWSAccountAndLambdaRequest,
636    ) -> Result<
637        std::collections::BTreeMap<String, serde_json::Value>,
638        datadog::Error<DeleteAWSLambdaARNError>,
639    > {
640        match self.delete_aws_lambda_arn_with_http_info(body).await {
641            Ok(response_content) => {
642                if let Some(e) = response_content.entity {
643                    Ok(e)
644                } else {
645                    Err(datadog::Error::Serde(serde::de::Error::custom(
646                        "response content was None",
647                    )))
648                }
649            }
650            Err(err) => Err(err),
651        }
652    }
653
654    pub async fn delete_aws_lambda_arn_with_http_info(
656        &self,
657        body: crate::datadogV1::model::AWSAccountAndLambdaRequest,
658    ) -> Result<
659        datadog::ResponseContent<std::collections::BTreeMap<String, serde_json::Value>>,
660        datadog::Error<DeleteAWSLambdaARNError>,
661    > {
662        let local_configuration = &self.config;
663        let operation_id = "v1.delete_aws_lambda_arn";
664
665        let local_client = &self.client;
666
667        let local_uri_str = format!(
668            "{}/api/v1/integration/aws/logs",
669            local_configuration.get_operation_host(operation_id)
670        );
671        let mut local_req_builder =
672            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
673
674        let mut headers = HeaderMap::new();
676        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
677        headers.insert("Accept", HeaderValue::from_static("application/json"));
678
679        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
681            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
682            Err(e) => {
683                log::warn!("Failed to parse user agent header: {e}, falling back to default");
684                headers.insert(
685                    reqwest::header::USER_AGENT,
686                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
687                )
688            }
689        };
690
691        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
693            headers.insert(
694                "DD-API-KEY",
695                HeaderValue::from_str(local_key.key.as_str())
696                    .expect("failed to parse DD-API-KEY header"),
697            );
698        };
699        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
700            headers.insert(
701                "DD-APPLICATION-KEY",
702                HeaderValue::from_str(local_key.key.as_str())
703                    .expect("failed to parse DD-APPLICATION-KEY header"),
704            );
705        };
706
707        let output = Vec::new();
709        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
710        if body.serialize(&mut ser).is_ok() {
711            if let Some(content_encoding) = headers.get("Content-Encoding") {
712                match content_encoding.to_str().unwrap_or_default() {
713                    "gzip" => {
714                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
715                        let _ = enc.write_all(ser.into_inner().as_slice());
716                        match enc.finish() {
717                            Ok(buf) => {
718                                local_req_builder = local_req_builder.body(buf);
719                            }
720                            Err(e) => return Err(datadog::Error::Io(e)),
721                        }
722                    }
723                    "deflate" => {
724                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
725                        let _ = enc.write_all(ser.into_inner().as_slice());
726                        match enc.finish() {
727                            Ok(buf) => {
728                                local_req_builder = local_req_builder.body(buf);
729                            }
730                            Err(e) => return Err(datadog::Error::Io(e)),
731                        }
732                    }
733                    "zstd1" => {
734                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
735                        let _ = enc.write_all(ser.into_inner().as_slice());
736                        match enc.finish() {
737                            Ok(buf) => {
738                                local_req_builder = local_req_builder.body(buf);
739                            }
740                            Err(e) => return Err(datadog::Error::Io(e)),
741                        }
742                    }
743                    _ => {
744                        local_req_builder = local_req_builder.body(ser.into_inner());
745                    }
746                }
747            } else {
748                local_req_builder = local_req_builder.body(ser.into_inner());
749            }
750        }
751
752        local_req_builder = local_req_builder.headers(headers);
753        let local_req = local_req_builder.build()?;
754        log::debug!("request content: {:?}", local_req.body());
755        let local_resp = local_client.execute(local_req).await?;
756
757        let local_status = local_resp.status();
758        let local_content = local_resp.text().await?;
759        log::debug!("response content: {}", local_content);
760
761        if !local_status.is_client_error() && !local_status.is_server_error() {
762            match serde_json::from_str::<std::collections::BTreeMap<String, serde_json::Value>>(
763                &local_content,
764            ) {
765                Ok(e) => {
766                    return Ok(datadog::ResponseContent {
767                        status: local_status,
768                        content: local_content,
769                        entity: Some(e),
770                    })
771                }
772                Err(e) => return Err(datadog::Error::Serde(e)),
773            };
774        } else {
775            let local_entity: Option<DeleteAWSLambdaARNError> =
776                serde_json::from_str(&local_content).ok();
777            let local_error = datadog::ResponseContent {
778                status: local_status,
779                content: local_content,
780                entity: local_entity,
781            };
782            Err(datadog::Error::ResponseError(local_error))
783        }
784    }
785
786    pub async fn enable_aws_log_services(
788        &self,
789        body: crate::datadogV1::model::AWSLogsServicesRequest,
790    ) -> Result<
791        std::collections::BTreeMap<String, serde_json::Value>,
792        datadog::Error<EnableAWSLogServicesError>,
793    > {
794        match self.enable_aws_log_services_with_http_info(body).await {
795            Ok(response_content) => {
796                if let Some(e) = response_content.entity {
797                    Ok(e)
798                } else {
799                    Err(datadog::Error::Serde(serde::de::Error::custom(
800                        "response content was None",
801                    )))
802                }
803            }
804            Err(err) => Err(err),
805        }
806    }
807
808    pub async fn enable_aws_log_services_with_http_info(
810        &self,
811        body: crate::datadogV1::model::AWSLogsServicesRequest,
812    ) -> Result<
813        datadog::ResponseContent<std::collections::BTreeMap<String, serde_json::Value>>,
814        datadog::Error<EnableAWSLogServicesError>,
815    > {
816        let local_configuration = &self.config;
817        let operation_id = "v1.enable_aws_log_services";
818
819        let local_client = &self.client;
820
821        let local_uri_str = format!(
822            "{}/api/v1/integration/aws/logs/services",
823            local_configuration.get_operation_host(operation_id)
824        );
825        let mut local_req_builder =
826            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
827
828        let mut headers = HeaderMap::new();
830        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
831        headers.insert("Accept", HeaderValue::from_static("application/json"));
832
833        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
835            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
836            Err(e) => {
837                log::warn!("Failed to parse user agent header: {e}, falling back to default");
838                headers.insert(
839                    reqwest::header::USER_AGENT,
840                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
841                )
842            }
843        };
844
845        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
847            headers.insert(
848                "DD-API-KEY",
849                HeaderValue::from_str(local_key.key.as_str())
850                    .expect("failed to parse DD-API-KEY header"),
851            );
852        };
853        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
854            headers.insert(
855                "DD-APPLICATION-KEY",
856                HeaderValue::from_str(local_key.key.as_str())
857                    .expect("failed to parse DD-APPLICATION-KEY header"),
858            );
859        };
860
861        let output = Vec::new();
863        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
864        if body.serialize(&mut ser).is_ok() {
865            if let Some(content_encoding) = headers.get("Content-Encoding") {
866                match content_encoding.to_str().unwrap_or_default() {
867                    "gzip" => {
868                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
869                        let _ = enc.write_all(ser.into_inner().as_slice());
870                        match enc.finish() {
871                            Ok(buf) => {
872                                local_req_builder = local_req_builder.body(buf);
873                            }
874                            Err(e) => return Err(datadog::Error::Io(e)),
875                        }
876                    }
877                    "deflate" => {
878                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
879                        let _ = enc.write_all(ser.into_inner().as_slice());
880                        match enc.finish() {
881                            Ok(buf) => {
882                                local_req_builder = local_req_builder.body(buf);
883                            }
884                            Err(e) => return Err(datadog::Error::Io(e)),
885                        }
886                    }
887                    "zstd1" => {
888                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
889                        let _ = enc.write_all(ser.into_inner().as_slice());
890                        match enc.finish() {
891                            Ok(buf) => {
892                                local_req_builder = local_req_builder.body(buf);
893                            }
894                            Err(e) => return Err(datadog::Error::Io(e)),
895                        }
896                    }
897                    _ => {
898                        local_req_builder = local_req_builder.body(ser.into_inner());
899                    }
900                }
901            } else {
902                local_req_builder = local_req_builder.body(ser.into_inner());
903            }
904        }
905
906        local_req_builder = local_req_builder.headers(headers);
907        let local_req = local_req_builder.build()?;
908        log::debug!("request content: {:?}", local_req.body());
909        let local_resp = local_client.execute(local_req).await?;
910
911        let local_status = local_resp.status();
912        let local_content = local_resp.text().await?;
913        log::debug!("response content: {}", local_content);
914
915        if !local_status.is_client_error() && !local_status.is_server_error() {
916            match serde_json::from_str::<std::collections::BTreeMap<String, serde_json::Value>>(
917                &local_content,
918            ) {
919                Ok(e) => {
920                    return Ok(datadog::ResponseContent {
921                        status: local_status,
922                        content: local_content,
923                        entity: Some(e),
924                    })
925                }
926                Err(e) => return Err(datadog::Error::Serde(e)),
927            };
928        } else {
929            let local_entity: Option<EnableAWSLogServicesError> =
930                serde_json::from_str(&local_content).ok();
931            let local_error = datadog::ResponseContent {
932                status: local_status,
933                content: local_content,
934                entity: local_entity,
935            };
936            Err(datadog::Error::ResponseError(local_error))
937        }
938    }
939
940    pub async fn list_aws_logs_integrations(
942        &self,
943    ) -> Result<
944        Vec<crate::datadogV1::model::AWSLogsListResponse>,
945        datadog::Error<ListAWSLogsIntegrationsError>,
946    > {
947        match self.list_aws_logs_integrations_with_http_info().await {
948            Ok(response_content) => {
949                if let Some(e) = response_content.entity {
950                    Ok(e)
951                } else {
952                    Err(datadog::Error::Serde(serde::de::Error::custom(
953                        "response content was None",
954                    )))
955                }
956            }
957            Err(err) => Err(err),
958        }
959    }
960
961    pub async fn list_aws_logs_integrations_with_http_info(
963        &self,
964    ) -> Result<
965        datadog::ResponseContent<Vec<crate::datadogV1::model::AWSLogsListResponse>>,
966        datadog::Error<ListAWSLogsIntegrationsError>,
967    > {
968        let local_configuration = &self.config;
969        let operation_id = "v1.list_aws_logs_integrations";
970
971        let local_client = &self.client;
972
973        let local_uri_str = format!(
974            "{}/api/v1/integration/aws/logs",
975            local_configuration.get_operation_host(operation_id)
976        );
977        let mut local_req_builder =
978            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
979
980        let mut headers = HeaderMap::new();
982        headers.insert("Accept", HeaderValue::from_static("application/json"));
983
984        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
986            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
987            Err(e) => {
988                log::warn!("Failed to parse user agent header: {e}, falling back to default");
989                headers.insert(
990                    reqwest::header::USER_AGENT,
991                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
992                )
993            }
994        };
995
996        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
998            headers.insert(
999                "DD-API-KEY",
1000                HeaderValue::from_str(local_key.key.as_str())
1001                    .expect("failed to parse DD-API-KEY header"),
1002            );
1003        };
1004        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1005            headers.insert(
1006                "DD-APPLICATION-KEY",
1007                HeaderValue::from_str(local_key.key.as_str())
1008                    .expect("failed to parse DD-APPLICATION-KEY header"),
1009            );
1010        };
1011
1012        local_req_builder = local_req_builder.headers(headers);
1013        let local_req = local_req_builder.build()?;
1014        log::debug!("request content: {:?}", local_req.body());
1015        let local_resp = local_client.execute(local_req).await?;
1016
1017        let local_status = local_resp.status();
1018        let local_content = local_resp.text().await?;
1019        log::debug!("response content: {}", local_content);
1020
1021        if !local_status.is_client_error() && !local_status.is_server_error() {
1022            match serde_json::from_str::<Vec<crate::datadogV1::model::AWSLogsListResponse>>(
1023                &local_content,
1024            ) {
1025                Ok(e) => {
1026                    return Ok(datadog::ResponseContent {
1027                        status: local_status,
1028                        content: local_content,
1029                        entity: Some(e),
1030                    })
1031                }
1032                Err(e) => return Err(datadog::Error::Serde(e)),
1033            };
1034        } else {
1035            let local_entity: Option<ListAWSLogsIntegrationsError> =
1036                serde_json::from_str(&local_content).ok();
1037            let local_error = datadog::ResponseContent {
1038                status: local_status,
1039                content: local_content,
1040                entity: local_entity,
1041            };
1042            Err(datadog::Error::ResponseError(local_error))
1043        }
1044    }
1045
1046    pub async fn list_aws_logs_services(
1048        &self,
1049    ) -> Result<
1050        Vec<crate::datadogV1::model::AWSLogsListServicesResponse>,
1051        datadog::Error<ListAWSLogsServicesError>,
1052    > {
1053        match self.list_aws_logs_services_with_http_info().await {
1054            Ok(response_content) => {
1055                if let Some(e) = response_content.entity {
1056                    Ok(e)
1057                } else {
1058                    Err(datadog::Error::Serde(serde::de::Error::custom(
1059                        "response content was None",
1060                    )))
1061                }
1062            }
1063            Err(err) => Err(err),
1064        }
1065    }
1066
1067    pub async fn list_aws_logs_services_with_http_info(
1069        &self,
1070    ) -> Result<
1071        datadog::ResponseContent<Vec<crate::datadogV1::model::AWSLogsListServicesResponse>>,
1072        datadog::Error<ListAWSLogsServicesError>,
1073    > {
1074        let local_configuration = &self.config;
1075        let operation_id = "v1.list_aws_logs_services";
1076
1077        let local_client = &self.client;
1078
1079        let local_uri_str = format!(
1080            "{}/api/v1/integration/aws/logs/services",
1081            local_configuration.get_operation_host(operation_id)
1082        );
1083        let mut local_req_builder =
1084            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1085
1086        let mut headers = HeaderMap::new();
1088        headers.insert("Accept", HeaderValue::from_static("application/json"));
1089
1090        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1092            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1093            Err(e) => {
1094                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1095                headers.insert(
1096                    reqwest::header::USER_AGENT,
1097                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1098                )
1099            }
1100        };
1101
1102        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1104            headers.insert(
1105                "DD-API-KEY",
1106                HeaderValue::from_str(local_key.key.as_str())
1107                    .expect("failed to parse DD-API-KEY header"),
1108            );
1109        };
1110        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1111            headers.insert(
1112                "DD-APPLICATION-KEY",
1113                HeaderValue::from_str(local_key.key.as_str())
1114                    .expect("failed to parse DD-APPLICATION-KEY header"),
1115            );
1116        };
1117
1118        local_req_builder = local_req_builder.headers(headers);
1119        let local_req = local_req_builder.build()?;
1120        log::debug!("request content: {:?}", local_req.body());
1121        let local_resp = local_client.execute(local_req).await?;
1122
1123        let local_status = local_resp.status();
1124        let local_content = local_resp.text().await?;
1125        log::debug!("response content: {}", local_content);
1126
1127        if !local_status.is_client_error() && !local_status.is_server_error() {
1128            match serde_json::from_str::<Vec<crate::datadogV1::model::AWSLogsListServicesResponse>>(
1129                &local_content,
1130            ) {
1131                Ok(e) => {
1132                    return Ok(datadog::ResponseContent {
1133                        status: local_status,
1134                        content: local_content,
1135                        entity: Some(e),
1136                    })
1137                }
1138                Err(e) => return Err(datadog::Error::Serde(e)),
1139            };
1140        } else {
1141            let local_entity: Option<ListAWSLogsServicesError> =
1142                serde_json::from_str(&local_content).ok();
1143            let local_error = datadog::ResponseContent {
1144                status: local_status,
1145                content: local_content,
1146                entity: local_entity,
1147            };
1148            Err(datadog::Error::ResponseError(local_error))
1149        }
1150    }
1151}