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