datadog_api_client/datadogV1/api/
api_slack_integration.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/// CreateSlackIntegrationChannelError is a struct for typed errors of method [`SlackIntegrationAPI::create_slack_integration_channel`]
14#[derive(Debug, Clone, Serialize, Deserialize)]
15#[serde(untagged)]
16pub enum CreateSlackIntegrationChannelError {
17    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
18    UnknownValue(serde_json::Value),
19}
20
21/// GetSlackIntegrationChannelError is a struct for typed errors of method [`SlackIntegrationAPI::get_slack_integration_channel`]
22#[derive(Debug, Clone, Serialize, Deserialize)]
23#[serde(untagged)]
24pub enum GetSlackIntegrationChannelError {
25    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
26    UnknownValue(serde_json::Value),
27}
28
29/// GetSlackIntegrationChannelsError is a struct for typed errors of method [`SlackIntegrationAPI::get_slack_integration_channels`]
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum GetSlackIntegrationChannelsError {
33    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
34    UnknownValue(serde_json::Value),
35}
36
37/// RemoveSlackIntegrationChannelError is a struct for typed errors of method [`SlackIntegrationAPI::remove_slack_integration_channel`]
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum RemoveSlackIntegrationChannelError {
41    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
42    UnknownValue(serde_json::Value),
43}
44
45/// UpdateSlackIntegrationChannelError is a struct for typed errors of method [`SlackIntegrationAPI::update_slack_integration_channel`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum UpdateSlackIntegrationChannelError {
49    APIErrorResponse(crate::datadogV1::model::APIErrorResponse),
50    UnknownValue(serde_json::Value),
51}
52
53/// Configure your [Datadog-Slack integration](<https://docs.datadoghq.com/integrations/slack>)
54/// directly through the Datadog API.
55#[derive(Debug, Clone)]
56pub struct SlackIntegrationAPI {
57    config: datadog::Configuration,
58    client: reqwest_middleware::ClientWithMiddleware,
59}
60
61impl Default for SlackIntegrationAPI {
62    fn default() -> Self {
63        Self::with_config(datadog::Configuration::default())
64    }
65}
66
67impl SlackIntegrationAPI {
68    pub fn new() -> Self {
69        Self::default()
70    }
71    pub fn with_config(config: datadog::Configuration) -> Self {
72        let mut reqwest_client_builder = reqwest::Client::builder();
73
74        if let Some(proxy_url) = &config.proxy_url {
75            let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
76            reqwest_client_builder = reqwest_client_builder.proxy(proxy);
77        }
78
79        let mut middleware_client_builder =
80            reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
81
82        if config.enable_retry {
83            struct RetryableStatus;
84            impl reqwest_retry::RetryableStrategy for RetryableStatus {
85                fn handle(
86                    &self,
87                    res: &Result<reqwest::Response, reqwest_middleware::Error>,
88                ) -> Option<reqwest_retry::Retryable> {
89                    match res {
90                        Ok(success) => reqwest_retry::default_on_request_success(success),
91                        Err(_) => None,
92                    }
93                }
94            }
95            let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
96                .build_with_max_retries(config.max_retries);
97
98            let retry_middleware =
99                reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
100                    backoff_policy,
101                    RetryableStatus,
102                );
103
104            middleware_client_builder = middleware_client_builder.with(retry_middleware);
105        }
106
107        let client = middleware_client_builder.build();
108
109        Self { config, client }
110    }
111
112    pub fn with_client_and_config(
113        config: datadog::Configuration,
114        client: reqwest_middleware::ClientWithMiddleware,
115    ) -> Self {
116        Self { config, client }
117    }
118
119    /// Add a channel to your Datadog-Slack integration.
120    pub async fn create_slack_integration_channel(
121        &self,
122        account_name: String,
123        body: crate::datadogV1::model::SlackIntegrationChannel,
124    ) -> Result<
125        crate::datadogV1::model::SlackIntegrationChannel,
126        datadog::Error<CreateSlackIntegrationChannelError>,
127    > {
128        match self
129            .create_slack_integration_channel_with_http_info(account_name, body)
130            .await
131        {
132            Ok(response_content) => {
133                if let Some(e) = response_content.entity {
134                    Ok(e)
135                } else {
136                    Err(datadog::Error::Serde(serde::de::Error::custom(
137                        "response content was None",
138                    )))
139                }
140            }
141            Err(err) => Err(err),
142        }
143    }
144
145    /// Add a channel to your Datadog-Slack integration.
146    pub async fn create_slack_integration_channel_with_http_info(
147        &self,
148        account_name: String,
149        body: crate::datadogV1::model::SlackIntegrationChannel,
150    ) -> Result<
151        datadog::ResponseContent<crate::datadogV1::model::SlackIntegrationChannel>,
152        datadog::Error<CreateSlackIntegrationChannelError>,
153    > {
154        let local_configuration = &self.config;
155        let operation_id = "v1.create_slack_integration_channel";
156
157        let local_client = &self.client;
158
159        let local_uri_str = format!(
160            "{}/api/v1/integration/slack/configuration/accounts/{account_name}/channels",
161            local_configuration.get_operation_host(operation_id),
162            account_name = datadog::urlencode(account_name)
163        );
164        let mut local_req_builder =
165            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
166
167        // build headers
168        let mut headers = HeaderMap::new();
169        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
170        headers.insert("Accept", HeaderValue::from_static("application/json"));
171
172        // build user agent
173        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
174            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
175            Err(e) => {
176                log::warn!("Failed to parse user agent header: {e}, falling back to default");
177                headers.insert(
178                    reqwest::header::USER_AGENT,
179                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
180                )
181            }
182        };
183
184        // build auth
185        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
186            headers.insert(
187                "DD-API-KEY",
188                HeaderValue::from_str(local_key.key.as_str())
189                    .expect("failed to parse DD-API-KEY header"),
190            );
191        };
192        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
193            headers.insert(
194                "DD-APPLICATION-KEY",
195                HeaderValue::from_str(local_key.key.as_str())
196                    .expect("failed to parse DD-APPLICATION-KEY header"),
197            );
198        };
199
200        // build body parameters
201        let output = Vec::new();
202        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
203        if body.serialize(&mut ser).is_ok() {
204            if let Some(content_encoding) = headers.get("Content-Encoding") {
205                match content_encoding.to_str().unwrap_or_default() {
206                    "gzip" => {
207                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
208                        let _ = enc.write_all(ser.into_inner().as_slice());
209                        match enc.finish() {
210                            Ok(buf) => {
211                                local_req_builder = local_req_builder.body(buf);
212                            }
213                            Err(e) => return Err(datadog::Error::Io(e)),
214                        }
215                    }
216                    "deflate" => {
217                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
218                        let _ = enc.write_all(ser.into_inner().as_slice());
219                        match enc.finish() {
220                            Ok(buf) => {
221                                local_req_builder = local_req_builder.body(buf);
222                            }
223                            Err(e) => return Err(datadog::Error::Io(e)),
224                        }
225                    }
226                    "zstd1" => {
227                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
228                        let _ = enc.write_all(ser.into_inner().as_slice());
229                        match enc.finish() {
230                            Ok(buf) => {
231                                local_req_builder = local_req_builder.body(buf);
232                            }
233                            Err(e) => return Err(datadog::Error::Io(e)),
234                        }
235                    }
236                    _ => {
237                        local_req_builder = local_req_builder.body(ser.into_inner());
238                    }
239                }
240            } else {
241                local_req_builder = local_req_builder.body(ser.into_inner());
242            }
243        }
244
245        local_req_builder = local_req_builder.headers(headers);
246        let local_req = local_req_builder.build()?;
247        log::debug!("request content: {:?}", local_req.body());
248        let local_resp = local_client.execute(local_req).await?;
249
250        let local_status = local_resp.status();
251        let local_content = local_resp.text().await?;
252        log::debug!("response content: {}", local_content);
253
254        if !local_status.is_client_error() && !local_status.is_server_error() {
255            match serde_json::from_str::<crate::datadogV1::model::SlackIntegrationChannel>(
256                &local_content,
257            ) {
258                Ok(e) => {
259                    return Ok(datadog::ResponseContent {
260                        status: local_status,
261                        content: local_content,
262                        entity: Some(e),
263                    })
264                }
265                Err(e) => return Err(datadog::Error::Serde(e)),
266            };
267        } else {
268            let local_entity: Option<CreateSlackIntegrationChannelError> =
269                serde_json::from_str(&local_content).ok();
270            let local_error = datadog::ResponseContent {
271                status: local_status,
272                content: local_content,
273                entity: local_entity,
274            };
275            Err(datadog::Error::ResponseError(local_error))
276        }
277    }
278
279    /// Get a channel configured for your Datadog-Slack integration.
280    pub async fn get_slack_integration_channel(
281        &self,
282        account_name: String,
283        channel_name: String,
284    ) -> Result<
285        crate::datadogV1::model::SlackIntegrationChannel,
286        datadog::Error<GetSlackIntegrationChannelError>,
287    > {
288        match self
289            .get_slack_integration_channel_with_http_info(account_name, channel_name)
290            .await
291        {
292            Ok(response_content) => {
293                if let Some(e) = response_content.entity {
294                    Ok(e)
295                } else {
296                    Err(datadog::Error::Serde(serde::de::Error::custom(
297                        "response content was None",
298                    )))
299                }
300            }
301            Err(err) => Err(err),
302        }
303    }
304
305    /// Get a channel configured for your Datadog-Slack integration.
306    pub async fn get_slack_integration_channel_with_http_info(
307        &self,
308        account_name: String,
309        channel_name: String,
310    ) -> Result<
311        datadog::ResponseContent<crate::datadogV1::model::SlackIntegrationChannel>,
312        datadog::Error<GetSlackIntegrationChannelError>,
313    > {
314        let local_configuration = &self.config;
315        let operation_id = "v1.get_slack_integration_channel";
316
317        let local_client = &self.client;
318
319        let local_uri_str = format!(
320            "{}/api/v1/integration/slack/configuration/accounts/{account_name}/channels/{channel_name}",
321            local_configuration.get_operation_host(operation_id), account_name=
322            datadog::urlencode(account_name)
323            , channel_name=
324            datadog::urlencode(channel_name)
325            );
326        let mut local_req_builder =
327            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
328
329        // build headers
330        let mut headers = HeaderMap::new();
331        headers.insert("Accept", HeaderValue::from_static("application/json"));
332
333        // build user agent
334        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
335            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
336            Err(e) => {
337                log::warn!("Failed to parse user agent header: {e}, falling back to default");
338                headers.insert(
339                    reqwest::header::USER_AGENT,
340                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
341                )
342            }
343        };
344
345        // build auth
346        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
347            headers.insert(
348                "DD-API-KEY",
349                HeaderValue::from_str(local_key.key.as_str())
350                    .expect("failed to parse DD-API-KEY header"),
351            );
352        };
353        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
354            headers.insert(
355                "DD-APPLICATION-KEY",
356                HeaderValue::from_str(local_key.key.as_str())
357                    .expect("failed to parse DD-APPLICATION-KEY header"),
358            );
359        };
360
361        local_req_builder = local_req_builder.headers(headers);
362        let local_req = local_req_builder.build()?;
363        log::debug!("request content: {:?}", local_req.body());
364        let local_resp = local_client.execute(local_req).await?;
365
366        let local_status = local_resp.status();
367        let local_content = local_resp.text().await?;
368        log::debug!("response content: {}", local_content);
369
370        if !local_status.is_client_error() && !local_status.is_server_error() {
371            match serde_json::from_str::<crate::datadogV1::model::SlackIntegrationChannel>(
372                &local_content,
373            ) {
374                Ok(e) => {
375                    return Ok(datadog::ResponseContent {
376                        status: local_status,
377                        content: local_content,
378                        entity: Some(e),
379                    })
380                }
381                Err(e) => return Err(datadog::Error::Serde(e)),
382            };
383        } else {
384            let local_entity: Option<GetSlackIntegrationChannelError> =
385                serde_json::from_str(&local_content).ok();
386            let local_error = datadog::ResponseContent {
387                status: local_status,
388                content: local_content,
389                entity: local_entity,
390            };
391            Err(datadog::Error::ResponseError(local_error))
392        }
393    }
394
395    /// Get a list of all channels configured for your Datadog-Slack integration.
396    pub async fn get_slack_integration_channels(
397        &self,
398        account_name: String,
399    ) -> Result<
400        Vec<crate::datadogV1::model::SlackIntegrationChannel>,
401        datadog::Error<GetSlackIntegrationChannelsError>,
402    > {
403        match self
404            .get_slack_integration_channels_with_http_info(account_name)
405            .await
406        {
407            Ok(response_content) => {
408                if let Some(e) = response_content.entity {
409                    Ok(e)
410                } else {
411                    Err(datadog::Error::Serde(serde::de::Error::custom(
412                        "response content was None",
413                    )))
414                }
415            }
416            Err(err) => Err(err),
417        }
418    }
419
420    /// Get a list of all channels configured for your Datadog-Slack integration.
421    pub async fn get_slack_integration_channels_with_http_info(
422        &self,
423        account_name: String,
424    ) -> Result<
425        datadog::ResponseContent<Vec<crate::datadogV1::model::SlackIntegrationChannel>>,
426        datadog::Error<GetSlackIntegrationChannelsError>,
427    > {
428        let local_configuration = &self.config;
429        let operation_id = "v1.get_slack_integration_channels";
430
431        let local_client = &self.client;
432
433        let local_uri_str = format!(
434            "{}/api/v1/integration/slack/configuration/accounts/{account_name}/channels",
435            local_configuration.get_operation_host(operation_id),
436            account_name = datadog::urlencode(account_name)
437        );
438        let mut local_req_builder =
439            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
440
441        // build headers
442        let mut headers = HeaderMap::new();
443        headers.insert("Accept", HeaderValue::from_static("application/json"));
444
445        // build user agent
446        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
447            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
448            Err(e) => {
449                log::warn!("Failed to parse user agent header: {e}, falling back to default");
450                headers.insert(
451                    reqwest::header::USER_AGENT,
452                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
453                )
454            }
455        };
456
457        // build auth
458        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
459            headers.insert(
460                "DD-API-KEY",
461                HeaderValue::from_str(local_key.key.as_str())
462                    .expect("failed to parse DD-API-KEY header"),
463            );
464        };
465        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
466            headers.insert(
467                "DD-APPLICATION-KEY",
468                HeaderValue::from_str(local_key.key.as_str())
469                    .expect("failed to parse DD-APPLICATION-KEY header"),
470            );
471        };
472
473        local_req_builder = local_req_builder.headers(headers);
474        let local_req = local_req_builder.build()?;
475        log::debug!("request content: {:?}", local_req.body());
476        let local_resp = local_client.execute(local_req).await?;
477
478        let local_status = local_resp.status();
479        let local_content = local_resp.text().await?;
480        log::debug!("response content: {}", local_content);
481
482        if !local_status.is_client_error() && !local_status.is_server_error() {
483            match serde_json::from_str::<Vec<crate::datadogV1::model::SlackIntegrationChannel>>(
484                &local_content,
485            ) {
486                Ok(e) => {
487                    return Ok(datadog::ResponseContent {
488                        status: local_status,
489                        content: local_content,
490                        entity: Some(e),
491                    })
492                }
493                Err(e) => return Err(datadog::Error::Serde(e)),
494            };
495        } else {
496            let local_entity: Option<GetSlackIntegrationChannelsError> =
497                serde_json::from_str(&local_content).ok();
498            let local_error = datadog::ResponseContent {
499                status: local_status,
500                content: local_content,
501                entity: local_entity,
502            };
503            Err(datadog::Error::ResponseError(local_error))
504        }
505    }
506
507    /// Remove a channel from your Datadog-Slack integration.
508    pub async fn remove_slack_integration_channel(
509        &self,
510        account_name: String,
511        channel_name: String,
512    ) -> Result<(), datadog::Error<RemoveSlackIntegrationChannelError>> {
513        match self
514            .remove_slack_integration_channel_with_http_info(account_name, channel_name)
515            .await
516        {
517            Ok(_) => Ok(()),
518            Err(err) => Err(err),
519        }
520    }
521
522    /// Remove a channel from your Datadog-Slack integration.
523    pub async fn remove_slack_integration_channel_with_http_info(
524        &self,
525        account_name: String,
526        channel_name: String,
527    ) -> Result<datadog::ResponseContent<()>, datadog::Error<RemoveSlackIntegrationChannelError>>
528    {
529        let local_configuration = &self.config;
530        let operation_id = "v1.remove_slack_integration_channel";
531
532        let local_client = &self.client;
533
534        let local_uri_str = format!(
535            "{}/api/v1/integration/slack/configuration/accounts/{account_name}/channels/{channel_name}",
536            local_configuration.get_operation_host(operation_id), account_name=
537            datadog::urlencode(account_name)
538            , channel_name=
539            datadog::urlencode(channel_name)
540            );
541        let mut local_req_builder =
542            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
543
544        // build headers
545        let mut headers = HeaderMap::new();
546        headers.insert("Accept", HeaderValue::from_static("*/*"));
547
548        // build user agent
549        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
550            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
551            Err(e) => {
552                log::warn!("Failed to parse user agent header: {e}, falling back to default");
553                headers.insert(
554                    reqwest::header::USER_AGENT,
555                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
556                )
557            }
558        };
559
560        // build auth
561        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
562            headers.insert(
563                "DD-API-KEY",
564                HeaderValue::from_str(local_key.key.as_str())
565                    .expect("failed to parse DD-API-KEY header"),
566            );
567        };
568        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
569            headers.insert(
570                "DD-APPLICATION-KEY",
571                HeaderValue::from_str(local_key.key.as_str())
572                    .expect("failed to parse DD-APPLICATION-KEY header"),
573            );
574        };
575
576        local_req_builder = local_req_builder.headers(headers);
577        let local_req = local_req_builder.build()?;
578        log::debug!("request content: {:?}", local_req.body());
579        let local_resp = local_client.execute(local_req).await?;
580
581        let local_status = local_resp.status();
582        let local_content = local_resp.text().await?;
583        log::debug!("response content: {}", local_content);
584
585        if !local_status.is_client_error() && !local_status.is_server_error() {
586            Ok(datadog::ResponseContent {
587                status: local_status,
588                content: local_content,
589                entity: None,
590            })
591        } else {
592            let local_entity: Option<RemoveSlackIntegrationChannelError> =
593                serde_json::from_str(&local_content).ok();
594            let local_error = datadog::ResponseContent {
595                status: local_status,
596                content: local_content,
597                entity: local_entity,
598            };
599            Err(datadog::Error::ResponseError(local_error))
600        }
601    }
602
603    /// Update a channel used in your Datadog-Slack integration.
604    pub async fn update_slack_integration_channel(
605        &self,
606        account_name: String,
607        channel_name: String,
608        body: crate::datadogV1::model::SlackIntegrationChannel,
609    ) -> Result<
610        crate::datadogV1::model::SlackIntegrationChannel,
611        datadog::Error<UpdateSlackIntegrationChannelError>,
612    > {
613        match self
614            .update_slack_integration_channel_with_http_info(account_name, channel_name, body)
615            .await
616        {
617            Ok(response_content) => {
618                if let Some(e) = response_content.entity {
619                    Ok(e)
620                } else {
621                    Err(datadog::Error::Serde(serde::de::Error::custom(
622                        "response content was None",
623                    )))
624                }
625            }
626            Err(err) => Err(err),
627        }
628    }
629
630    /// Update a channel used in your Datadog-Slack integration.
631    pub async fn update_slack_integration_channel_with_http_info(
632        &self,
633        account_name: String,
634        channel_name: String,
635        body: crate::datadogV1::model::SlackIntegrationChannel,
636    ) -> Result<
637        datadog::ResponseContent<crate::datadogV1::model::SlackIntegrationChannel>,
638        datadog::Error<UpdateSlackIntegrationChannelError>,
639    > {
640        let local_configuration = &self.config;
641        let operation_id = "v1.update_slack_integration_channel";
642
643        let local_client = &self.client;
644
645        let local_uri_str = format!(
646            "{}/api/v1/integration/slack/configuration/accounts/{account_name}/channels/{channel_name}",
647            local_configuration.get_operation_host(operation_id), account_name=
648            datadog::urlencode(account_name)
649            , channel_name=
650            datadog::urlencode(channel_name)
651            );
652        let mut local_req_builder =
653            local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
654
655        // build headers
656        let mut headers = HeaderMap::new();
657        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
658        headers.insert("Accept", HeaderValue::from_static("application/json"));
659
660        // build user agent
661        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
662            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
663            Err(e) => {
664                log::warn!("Failed to parse user agent header: {e}, falling back to default");
665                headers.insert(
666                    reqwest::header::USER_AGENT,
667                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
668                )
669            }
670        };
671
672        // build auth
673        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
674            headers.insert(
675                "DD-API-KEY",
676                HeaderValue::from_str(local_key.key.as_str())
677                    .expect("failed to parse DD-API-KEY header"),
678            );
679        };
680        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
681            headers.insert(
682                "DD-APPLICATION-KEY",
683                HeaderValue::from_str(local_key.key.as_str())
684                    .expect("failed to parse DD-APPLICATION-KEY header"),
685            );
686        };
687
688        // build body parameters
689        let output = Vec::new();
690        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
691        if body.serialize(&mut ser).is_ok() {
692            if let Some(content_encoding) = headers.get("Content-Encoding") {
693                match content_encoding.to_str().unwrap_or_default() {
694                    "gzip" => {
695                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
696                        let _ = enc.write_all(ser.into_inner().as_slice());
697                        match enc.finish() {
698                            Ok(buf) => {
699                                local_req_builder = local_req_builder.body(buf);
700                            }
701                            Err(e) => return Err(datadog::Error::Io(e)),
702                        }
703                    }
704                    "deflate" => {
705                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
706                        let _ = enc.write_all(ser.into_inner().as_slice());
707                        match enc.finish() {
708                            Ok(buf) => {
709                                local_req_builder = local_req_builder.body(buf);
710                            }
711                            Err(e) => return Err(datadog::Error::Io(e)),
712                        }
713                    }
714                    "zstd1" => {
715                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
716                        let _ = enc.write_all(ser.into_inner().as_slice());
717                        match enc.finish() {
718                            Ok(buf) => {
719                                local_req_builder = local_req_builder.body(buf);
720                            }
721                            Err(e) => return Err(datadog::Error::Io(e)),
722                        }
723                    }
724                    _ => {
725                        local_req_builder = local_req_builder.body(ser.into_inner());
726                    }
727                }
728            } else {
729                local_req_builder = local_req_builder.body(ser.into_inner());
730            }
731        }
732
733        local_req_builder = local_req_builder.headers(headers);
734        let local_req = local_req_builder.build()?;
735        log::debug!("request content: {:?}", local_req.body());
736        let local_resp = local_client.execute(local_req).await?;
737
738        let local_status = local_resp.status();
739        let local_content = local_resp.text().await?;
740        log::debug!("response content: {}", local_content);
741
742        if !local_status.is_client_error() && !local_status.is_server_error() {
743            match serde_json::from_str::<crate::datadogV1::model::SlackIntegrationChannel>(
744                &local_content,
745            ) {
746                Ok(e) => {
747                    return Ok(datadog::ResponseContent {
748                        status: local_status,
749                        content: local_content,
750                        entity: Some(e),
751                    })
752                }
753                Err(e) => return Err(datadog::Error::Serde(e)),
754            };
755        } else {
756            let local_entity: Option<UpdateSlackIntegrationChannelError> =
757                serde_json::from_str(&local_content).ok();
758            let local_error = datadog::ResponseContent {
759                status: local_status,
760                content: local_content,
761                entity: local_entity,
762            };
763            Err(datadog::Error::ResponseError(local_error))
764        }
765    }
766}