datadog_api_client/datadogV2/api/
api_csm_threats.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/// DeleteCSMThreatsAgentRuleOptionalParams is a struct for passing parameters to the method [`CSMThreatsAPI::delete_csm_threats_agent_rule`]
14#[non_exhaustive]
15#[derive(Clone, Default, Debug)]
16pub struct DeleteCSMThreatsAgentRuleOptionalParams {
17    /// The ID of the Agent policy
18    pub policy_id: Option<String>,
19}
20
21impl DeleteCSMThreatsAgentRuleOptionalParams {
22    /// The ID of the Agent policy
23    pub fn policy_id(mut self, value: String) -> Self {
24        self.policy_id = Some(value);
25        self
26    }
27}
28
29/// GetCSMThreatsAgentRuleOptionalParams is a struct for passing parameters to the method [`CSMThreatsAPI::get_csm_threats_agent_rule`]
30#[non_exhaustive]
31#[derive(Clone, Default, Debug)]
32pub struct GetCSMThreatsAgentRuleOptionalParams {
33    /// The ID of the Agent policy
34    pub policy_id: Option<String>,
35}
36
37impl GetCSMThreatsAgentRuleOptionalParams {
38    /// The ID of the Agent policy
39    pub fn policy_id(mut self, value: String) -> Self {
40        self.policy_id = Some(value);
41        self
42    }
43}
44
45/// ListCSMThreatsAgentRulesOptionalParams is a struct for passing parameters to the method [`CSMThreatsAPI::list_csm_threats_agent_rules`]
46#[non_exhaustive]
47#[derive(Clone, Default, Debug)]
48pub struct ListCSMThreatsAgentRulesOptionalParams {
49    /// The ID of the Agent policy
50    pub policy_id: Option<String>,
51}
52
53impl ListCSMThreatsAgentRulesOptionalParams {
54    /// The ID of the Agent policy
55    pub fn policy_id(mut self, value: String) -> Self {
56        self.policy_id = Some(value);
57        self
58    }
59}
60
61/// UpdateCSMThreatsAgentRuleOptionalParams is a struct for passing parameters to the method [`CSMThreatsAPI::update_csm_threats_agent_rule`]
62#[non_exhaustive]
63#[derive(Clone, Default, Debug)]
64pub struct UpdateCSMThreatsAgentRuleOptionalParams {
65    /// The ID of the Agent policy
66    pub policy_id: Option<String>,
67}
68
69impl UpdateCSMThreatsAgentRuleOptionalParams {
70    /// The ID of the Agent policy
71    pub fn policy_id(mut self, value: String) -> Self {
72        self.policy_id = Some(value);
73        self
74    }
75}
76
77/// CreateCSMThreatsAgentPolicyError is a struct for typed errors of method [`CSMThreatsAPI::create_csm_threats_agent_policy`]
78#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(untagged)]
80pub enum CreateCSMThreatsAgentPolicyError {
81    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
82    UnknownValue(serde_json::Value),
83}
84
85/// CreateCSMThreatsAgentRuleError is a struct for typed errors of method [`CSMThreatsAPI::create_csm_threats_agent_rule`]
86#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(untagged)]
88pub enum CreateCSMThreatsAgentRuleError {
89    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
90    UnknownValue(serde_json::Value),
91}
92
93/// CreateCloudWorkloadSecurityAgentRuleError is a struct for typed errors of method [`CSMThreatsAPI::create_cloud_workload_security_agent_rule`]
94#[derive(Debug, Clone, Serialize, Deserialize)]
95#[serde(untagged)]
96pub enum CreateCloudWorkloadSecurityAgentRuleError {
97    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
98    UnknownValue(serde_json::Value),
99}
100
101/// DeleteCSMThreatsAgentPolicyError is a struct for typed errors of method [`CSMThreatsAPI::delete_csm_threats_agent_policy`]
102#[derive(Debug, Clone, Serialize, Deserialize)]
103#[serde(untagged)]
104pub enum DeleteCSMThreatsAgentPolicyError {
105    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
106    UnknownValue(serde_json::Value),
107}
108
109/// DeleteCSMThreatsAgentRuleError is a struct for typed errors of method [`CSMThreatsAPI::delete_csm_threats_agent_rule`]
110#[derive(Debug, Clone, Serialize, Deserialize)]
111#[serde(untagged)]
112pub enum DeleteCSMThreatsAgentRuleError {
113    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
114    UnknownValue(serde_json::Value),
115}
116
117/// DeleteCloudWorkloadSecurityAgentRuleError is a struct for typed errors of method [`CSMThreatsAPI::delete_cloud_workload_security_agent_rule`]
118#[derive(Debug, Clone, Serialize, Deserialize)]
119#[serde(untagged)]
120pub enum DeleteCloudWorkloadSecurityAgentRuleError {
121    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
122    UnknownValue(serde_json::Value),
123}
124
125/// DownloadCSMThreatsPolicyError is a struct for typed errors of method [`CSMThreatsAPI::download_csm_threats_policy`]
126#[derive(Debug, Clone, Serialize, Deserialize)]
127#[serde(untagged)]
128pub enum DownloadCSMThreatsPolicyError {
129    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
130    UnknownValue(serde_json::Value),
131}
132
133/// DownloadCloudWorkloadPolicyFileError is a struct for typed errors of method [`CSMThreatsAPI::download_cloud_workload_policy_file`]
134#[derive(Debug, Clone, Serialize, Deserialize)]
135#[serde(untagged)]
136pub enum DownloadCloudWorkloadPolicyFileError {
137    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
138    UnknownValue(serde_json::Value),
139}
140
141/// GetCSMThreatsAgentPolicyError is a struct for typed errors of method [`CSMThreatsAPI::get_csm_threats_agent_policy`]
142#[derive(Debug, Clone, Serialize, Deserialize)]
143#[serde(untagged)]
144pub enum GetCSMThreatsAgentPolicyError {
145    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
146    UnknownValue(serde_json::Value),
147}
148
149/// GetCSMThreatsAgentRuleError is a struct for typed errors of method [`CSMThreatsAPI::get_csm_threats_agent_rule`]
150#[derive(Debug, Clone, Serialize, Deserialize)]
151#[serde(untagged)]
152pub enum GetCSMThreatsAgentRuleError {
153    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
154    UnknownValue(serde_json::Value),
155}
156
157/// GetCloudWorkloadSecurityAgentRuleError is a struct for typed errors of method [`CSMThreatsAPI::get_cloud_workload_security_agent_rule`]
158#[derive(Debug, Clone, Serialize, Deserialize)]
159#[serde(untagged)]
160pub enum GetCloudWorkloadSecurityAgentRuleError {
161    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
162    UnknownValue(serde_json::Value),
163}
164
165/// ListCSMThreatsAgentPoliciesError is a struct for typed errors of method [`CSMThreatsAPI::list_csm_threats_agent_policies`]
166#[derive(Debug, Clone, Serialize, Deserialize)]
167#[serde(untagged)]
168pub enum ListCSMThreatsAgentPoliciesError {
169    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
170    UnknownValue(serde_json::Value),
171}
172
173/// ListCSMThreatsAgentRulesError is a struct for typed errors of method [`CSMThreatsAPI::list_csm_threats_agent_rules`]
174#[derive(Debug, Clone, Serialize, Deserialize)]
175#[serde(untagged)]
176pub enum ListCSMThreatsAgentRulesError {
177    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
178    UnknownValue(serde_json::Value),
179}
180
181/// ListCloudWorkloadSecurityAgentRulesError is a struct for typed errors of method [`CSMThreatsAPI::list_cloud_workload_security_agent_rules`]
182#[derive(Debug, Clone, Serialize, Deserialize)]
183#[serde(untagged)]
184pub enum ListCloudWorkloadSecurityAgentRulesError {
185    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
186    UnknownValue(serde_json::Value),
187}
188
189/// UpdateCSMThreatsAgentPolicyError is a struct for typed errors of method [`CSMThreatsAPI::update_csm_threats_agent_policy`]
190#[derive(Debug, Clone, Serialize, Deserialize)]
191#[serde(untagged)]
192pub enum UpdateCSMThreatsAgentPolicyError {
193    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
194    UnknownValue(serde_json::Value),
195}
196
197/// UpdateCSMThreatsAgentRuleError is a struct for typed errors of method [`CSMThreatsAPI::update_csm_threats_agent_rule`]
198#[derive(Debug, Clone, Serialize, Deserialize)]
199#[serde(untagged)]
200pub enum UpdateCSMThreatsAgentRuleError {
201    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
202    UnknownValue(serde_json::Value),
203}
204
205/// UpdateCloudWorkloadSecurityAgentRuleError is a struct for typed errors of method [`CSMThreatsAPI::update_cloud_workload_security_agent_rule`]
206#[derive(Debug, Clone, Serialize, Deserialize)]
207#[serde(untagged)]
208pub enum UpdateCloudWorkloadSecurityAgentRuleError {
209    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
210    UnknownValue(serde_json::Value),
211}
212
213/// Workload Protection monitors file, network, and process activity across your environment to detect real-time threats to your infrastructure. See [Workload Protection](<https://docs.datadoghq.com/security/workload_protection/>) for more information on setting up Workload Protection.
214///
215/// **Note**: These endpoints are split based on whether you are using the US1-FED site or not. Please reference the specific resource for the site you are using.
216#[derive(Debug, Clone)]
217pub struct CSMThreatsAPI {
218    config: datadog::Configuration,
219    client: reqwest_middleware::ClientWithMiddleware,
220}
221
222impl Default for CSMThreatsAPI {
223    fn default() -> Self {
224        Self::with_config(datadog::Configuration::default())
225    }
226}
227
228impl CSMThreatsAPI {
229    pub fn new() -> Self {
230        Self::default()
231    }
232    pub fn with_config(config: datadog::Configuration) -> Self {
233        let mut reqwest_client_builder = reqwest::Client::builder();
234
235        if let Some(proxy_url) = &config.proxy_url {
236            let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
237            reqwest_client_builder = reqwest_client_builder.proxy(proxy);
238        }
239
240        let mut middleware_client_builder =
241            reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
242
243        if config.enable_retry {
244            struct RetryableStatus;
245            impl reqwest_retry::RetryableStrategy for RetryableStatus {
246                fn handle(
247                    &self,
248                    res: &Result<reqwest::Response, reqwest_middleware::Error>,
249                ) -> Option<reqwest_retry::Retryable> {
250                    match res {
251                        Ok(success) => reqwest_retry::default_on_request_success(success),
252                        Err(_) => None,
253                    }
254                }
255            }
256            let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
257                .build_with_max_retries(config.max_retries);
258
259            let retry_middleware =
260                reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
261                    backoff_policy,
262                    RetryableStatus,
263                );
264
265            middleware_client_builder = middleware_client_builder.with(retry_middleware);
266        }
267
268        let client = middleware_client_builder.build();
269
270        Self { config, client }
271    }
272
273    pub fn with_client_and_config(
274        config: datadog::Configuration,
275        client: reqwest_middleware::ClientWithMiddleware,
276    ) -> Self {
277        Self { config, client }
278    }
279
280    /// Create a new Workload Protection policy with the given parameters.
281    ///
282    /// **Note**: This endpoint is not available for the Government (US1-FED) site. Please reference the (US1-FED) specific resource below.
283    pub async fn create_csm_threats_agent_policy(
284        &self,
285        body: crate::datadogV2::model::CloudWorkloadSecurityAgentPolicyCreateRequest,
286    ) -> Result<
287        crate::datadogV2::model::CloudWorkloadSecurityAgentPolicyResponse,
288        datadog::Error<CreateCSMThreatsAgentPolicyError>,
289    > {
290        match self
291            .create_csm_threats_agent_policy_with_http_info(body)
292            .await
293        {
294            Ok(response_content) => {
295                if let Some(e) = response_content.entity {
296                    Ok(e)
297                } else {
298                    Err(datadog::Error::Serde(serde::de::Error::custom(
299                        "response content was None",
300                    )))
301                }
302            }
303            Err(err) => Err(err),
304        }
305    }
306
307    /// Create a new Workload Protection policy with the given parameters.
308    ///
309    /// **Note**: This endpoint is not available for the Government (US1-FED) site. Please reference the (US1-FED) specific resource below.
310    pub async fn create_csm_threats_agent_policy_with_http_info(
311        &self,
312        body: crate::datadogV2::model::CloudWorkloadSecurityAgentPolicyCreateRequest,
313    ) -> Result<
314        datadog::ResponseContent<crate::datadogV2::model::CloudWorkloadSecurityAgentPolicyResponse>,
315        datadog::Error<CreateCSMThreatsAgentPolicyError>,
316    > {
317        let local_configuration = &self.config;
318        let operation_id = "v2.create_csm_threats_agent_policy";
319
320        let local_client = &self.client;
321
322        let local_uri_str = format!(
323            "{}/api/v2/remote_config/products/cws/policy",
324            local_configuration.get_operation_host(operation_id)
325        );
326        let mut local_req_builder =
327            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
328
329        // build headers
330        let mut headers = HeaderMap::new();
331        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
332        headers.insert("Accept", HeaderValue::from_static("application/json"));
333
334        // build user agent
335        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
336            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
337            Err(e) => {
338                log::warn!("Failed to parse user agent header: {e}, falling back to default");
339                headers.insert(
340                    reqwest::header::USER_AGENT,
341                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
342                )
343            }
344        };
345
346        // build auth
347        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
348            headers.insert(
349                "DD-API-KEY",
350                HeaderValue::from_str(local_key.key.as_str())
351                    .expect("failed to parse DD-API-KEY header"),
352            );
353        };
354        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
355            headers.insert(
356                "DD-APPLICATION-KEY",
357                HeaderValue::from_str(local_key.key.as_str())
358                    .expect("failed to parse DD-APPLICATION-KEY header"),
359            );
360        };
361
362        // build body parameters
363        let output = Vec::new();
364        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
365        if body.serialize(&mut ser).is_ok() {
366            if let Some(content_encoding) = headers.get("Content-Encoding") {
367                match content_encoding.to_str().unwrap_or_default() {
368                    "gzip" => {
369                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
370                        let _ = enc.write_all(ser.into_inner().as_slice());
371                        match enc.finish() {
372                            Ok(buf) => {
373                                local_req_builder = local_req_builder.body(buf);
374                            }
375                            Err(e) => return Err(datadog::Error::Io(e)),
376                        }
377                    }
378                    "deflate" => {
379                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
380                        let _ = enc.write_all(ser.into_inner().as_slice());
381                        match enc.finish() {
382                            Ok(buf) => {
383                                local_req_builder = local_req_builder.body(buf);
384                            }
385                            Err(e) => return Err(datadog::Error::Io(e)),
386                        }
387                    }
388                    "zstd1" => {
389                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
390                        let _ = enc.write_all(ser.into_inner().as_slice());
391                        match enc.finish() {
392                            Ok(buf) => {
393                                local_req_builder = local_req_builder.body(buf);
394                            }
395                            Err(e) => return Err(datadog::Error::Io(e)),
396                        }
397                    }
398                    _ => {
399                        local_req_builder = local_req_builder.body(ser.into_inner());
400                    }
401                }
402            } else {
403                local_req_builder = local_req_builder.body(ser.into_inner());
404            }
405        }
406
407        local_req_builder = local_req_builder.headers(headers);
408        let local_req = local_req_builder.build()?;
409        log::debug!("request content: {:?}", local_req.body());
410        let local_resp = local_client.execute(local_req).await?;
411
412        let local_status = local_resp.status();
413        let local_content = local_resp.text().await?;
414        log::debug!("response content: {}", local_content);
415
416        if !local_status.is_client_error() && !local_status.is_server_error() {
417            match serde_json::from_str::<
418                crate::datadogV2::model::CloudWorkloadSecurityAgentPolicyResponse,
419            >(&local_content)
420            {
421                Ok(e) => {
422                    return Ok(datadog::ResponseContent {
423                        status: local_status,
424                        content: local_content,
425                        entity: Some(e),
426                    })
427                }
428                Err(e) => return Err(datadog::Error::Serde(e)),
429            };
430        } else {
431            let local_entity: Option<CreateCSMThreatsAgentPolicyError> =
432                serde_json::from_str(&local_content).ok();
433            let local_error = datadog::ResponseContent {
434                status: local_status,
435                content: local_content,
436                entity: local_entity,
437            };
438            Err(datadog::Error::ResponseError(local_error))
439        }
440    }
441
442    /// Create a new Workload Protection agent rule with the given parameters.
443    ///
444    /// **Note**: This endpoint is not available for the Government (US1-FED) site. Please reference the (US1-FED) specific resource below.
445    pub async fn create_csm_threats_agent_rule(
446        &self,
447        body: crate::datadogV2::model::CloudWorkloadSecurityAgentRuleCreateRequest,
448    ) -> Result<
449        crate::datadogV2::model::CloudWorkloadSecurityAgentRuleResponse,
450        datadog::Error<CreateCSMThreatsAgentRuleError>,
451    > {
452        match self
453            .create_csm_threats_agent_rule_with_http_info(body)
454            .await
455        {
456            Ok(response_content) => {
457                if let Some(e) = response_content.entity {
458                    Ok(e)
459                } else {
460                    Err(datadog::Error::Serde(serde::de::Error::custom(
461                        "response content was None",
462                    )))
463                }
464            }
465            Err(err) => Err(err),
466        }
467    }
468
469    /// Create a new Workload Protection agent rule with the given parameters.
470    ///
471    /// **Note**: This endpoint is not available for the Government (US1-FED) site. Please reference the (US1-FED) specific resource below.
472    pub async fn create_csm_threats_agent_rule_with_http_info(
473        &self,
474        body: crate::datadogV2::model::CloudWorkloadSecurityAgentRuleCreateRequest,
475    ) -> Result<
476        datadog::ResponseContent<crate::datadogV2::model::CloudWorkloadSecurityAgentRuleResponse>,
477        datadog::Error<CreateCSMThreatsAgentRuleError>,
478    > {
479        let local_configuration = &self.config;
480        let operation_id = "v2.create_csm_threats_agent_rule";
481
482        let local_client = &self.client;
483
484        let local_uri_str = format!(
485            "{}/api/v2/remote_config/products/cws/agent_rules",
486            local_configuration.get_operation_host(operation_id)
487        );
488        let mut local_req_builder =
489            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
490
491        // build headers
492        let mut headers = HeaderMap::new();
493        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
494        headers.insert("Accept", HeaderValue::from_static("application/json"));
495
496        // build user agent
497        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
498            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
499            Err(e) => {
500                log::warn!("Failed to parse user agent header: {e}, falling back to default");
501                headers.insert(
502                    reqwest::header::USER_AGENT,
503                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
504                )
505            }
506        };
507
508        // build auth
509        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
510            headers.insert(
511                "DD-API-KEY",
512                HeaderValue::from_str(local_key.key.as_str())
513                    .expect("failed to parse DD-API-KEY header"),
514            );
515        };
516        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
517            headers.insert(
518                "DD-APPLICATION-KEY",
519                HeaderValue::from_str(local_key.key.as_str())
520                    .expect("failed to parse DD-APPLICATION-KEY header"),
521            );
522        };
523
524        // build body parameters
525        let output = Vec::new();
526        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
527        if body.serialize(&mut ser).is_ok() {
528            if let Some(content_encoding) = headers.get("Content-Encoding") {
529                match content_encoding.to_str().unwrap_or_default() {
530                    "gzip" => {
531                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
532                        let _ = enc.write_all(ser.into_inner().as_slice());
533                        match enc.finish() {
534                            Ok(buf) => {
535                                local_req_builder = local_req_builder.body(buf);
536                            }
537                            Err(e) => return Err(datadog::Error::Io(e)),
538                        }
539                    }
540                    "deflate" => {
541                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
542                        let _ = enc.write_all(ser.into_inner().as_slice());
543                        match enc.finish() {
544                            Ok(buf) => {
545                                local_req_builder = local_req_builder.body(buf);
546                            }
547                            Err(e) => return Err(datadog::Error::Io(e)),
548                        }
549                    }
550                    "zstd1" => {
551                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
552                        let _ = enc.write_all(ser.into_inner().as_slice());
553                        match enc.finish() {
554                            Ok(buf) => {
555                                local_req_builder = local_req_builder.body(buf);
556                            }
557                            Err(e) => return Err(datadog::Error::Io(e)),
558                        }
559                    }
560                    _ => {
561                        local_req_builder = local_req_builder.body(ser.into_inner());
562                    }
563                }
564            } else {
565                local_req_builder = local_req_builder.body(ser.into_inner());
566            }
567        }
568
569        local_req_builder = local_req_builder.headers(headers);
570        let local_req = local_req_builder.build()?;
571        log::debug!("request content: {:?}", local_req.body());
572        let local_resp = local_client.execute(local_req).await?;
573
574        let local_status = local_resp.status();
575        let local_content = local_resp.text().await?;
576        log::debug!("response content: {}", local_content);
577
578        if !local_status.is_client_error() && !local_status.is_server_error() {
579            match serde_json::from_str::<
580                crate::datadogV2::model::CloudWorkloadSecurityAgentRuleResponse,
581            >(&local_content)
582            {
583                Ok(e) => {
584                    return Ok(datadog::ResponseContent {
585                        status: local_status,
586                        content: local_content,
587                        entity: Some(e),
588                    })
589                }
590                Err(e) => return Err(datadog::Error::Serde(e)),
591            };
592        } else {
593            let local_entity: Option<CreateCSMThreatsAgentRuleError> =
594                serde_json::from_str(&local_content).ok();
595            let local_error = datadog::ResponseContent {
596                status: local_status,
597                content: local_content,
598                entity: local_entity,
599            };
600            Err(datadog::Error::ResponseError(local_error))
601        }
602    }
603
604    /// Create a new agent rule with the given parameters.
605    ///
606    /// **Note**: This endpoint should only be used for the Government (US1-FED) site.
607    pub async fn create_cloud_workload_security_agent_rule(
608        &self,
609        body: crate::datadogV2::model::CloudWorkloadSecurityAgentRuleCreateRequest,
610    ) -> Result<
611        crate::datadogV2::model::CloudWorkloadSecurityAgentRuleResponse,
612        datadog::Error<CreateCloudWorkloadSecurityAgentRuleError>,
613    > {
614        match self
615            .create_cloud_workload_security_agent_rule_with_http_info(body)
616            .await
617        {
618            Ok(response_content) => {
619                if let Some(e) = response_content.entity {
620                    Ok(e)
621                } else {
622                    Err(datadog::Error::Serde(serde::de::Error::custom(
623                        "response content was None",
624                    )))
625                }
626            }
627            Err(err) => Err(err),
628        }
629    }
630
631    /// Create a new agent rule with the given parameters.
632    ///
633    /// **Note**: This endpoint should only be used for the Government (US1-FED) site.
634    pub async fn create_cloud_workload_security_agent_rule_with_http_info(
635        &self,
636        body: crate::datadogV2::model::CloudWorkloadSecurityAgentRuleCreateRequest,
637    ) -> Result<
638        datadog::ResponseContent<crate::datadogV2::model::CloudWorkloadSecurityAgentRuleResponse>,
639        datadog::Error<CreateCloudWorkloadSecurityAgentRuleError>,
640    > {
641        let local_configuration = &self.config;
642        let operation_id = "v2.create_cloud_workload_security_agent_rule";
643
644        let local_client = &self.client;
645
646        let local_uri_str = format!(
647            "{}/api/v2/security_monitoring/cloud_workload_security/agent_rules",
648            local_configuration.get_operation_host(operation_id)
649        );
650        let mut local_req_builder =
651            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
652
653        // build headers
654        let mut headers = HeaderMap::new();
655        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
656        headers.insert("Accept", HeaderValue::from_static("application/json"));
657
658        // build user agent
659        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
660            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
661            Err(e) => {
662                log::warn!("Failed to parse user agent header: {e}, falling back to default");
663                headers.insert(
664                    reqwest::header::USER_AGENT,
665                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
666                )
667            }
668        };
669
670        // build auth
671        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
672            headers.insert(
673                "DD-API-KEY",
674                HeaderValue::from_str(local_key.key.as_str())
675                    .expect("failed to parse DD-API-KEY header"),
676            );
677        };
678        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
679            headers.insert(
680                "DD-APPLICATION-KEY",
681                HeaderValue::from_str(local_key.key.as_str())
682                    .expect("failed to parse DD-APPLICATION-KEY header"),
683            );
684        };
685
686        // build body parameters
687        let output = Vec::new();
688        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
689        if body.serialize(&mut ser).is_ok() {
690            if let Some(content_encoding) = headers.get("Content-Encoding") {
691                match content_encoding.to_str().unwrap_or_default() {
692                    "gzip" => {
693                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
694                        let _ = enc.write_all(ser.into_inner().as_slice());
695                        match enc.finish() {
696                            Ok(buf) => {
697                                local_req_builder = local_req_builder.body(buf);
698                            }
699                            Err(e) => return Err(datadog::Error::Io(e)),
700                        }
701                    }
702                    "deflate" => {
703                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
704                        let _ = enc.write_all(ser.into_inner().as_slice());
705                        match enc.finish() {
706                            Ok(buf) => {
707                                local_req_builder = local_req_builder.body(buf);
708                            }
709                            Err(e) => return Err(datadog::Error::Io(e)),
710                        }
711                    }
712                    "zstd1" => {
713                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
714                        let _ = enc.write_all(ser.into_inner().as_slice());
715                        match enc.finish() {
716                            Ok(buf) => {
717                                local_req_builder = local_req_builder.body(buf);
718                            }
719                            Err(e) => return Err(datadog::Error::Io(e)),
720                        }
721                    }
722                    _ => {
723                        local_req_builder = local_req_builder.body(ser.into_inner());
724                    }
725                }
726            } else {
727                local_req_builder = local_req_builder.body(ser.into_inner());
728            }
729        }
730
731        local_req_builder = local_req_builder.headers(headers);
732        let local_req = local_req_builder.build()?;
733        log::debug!("request content: {:?}", local_req.body());
734        let local_resp = local_client.execute(local_req).await?;
735
736        let local_status = local_resp.status();
737        let local_content = local_resp.text().await?;
738        log::debug!("response content: {}", local_content);
739
740        if !local_status.is_client_error() && !local_status.is_server_error() {
741            match serde_json::from_str::<
742                crate::datadogV2::model::CloudWorkloadSecurityAgentRuleResponse,
743            >(&local_content)
744            {
745                Ok(e) => {
746                    return Ok(datadog::ResponseContent {
747                        status: local_status,
748                        content: local_content,
749                        entity: Some(e),
750                    })
751                }
752                Err(e) => return Err(datadog::Error::Serde(e)),
753            };
754        } else {
755            let local_entity: Option<CreateCloudWorkloadSecurityAgentRuleError> =
756                serde_json::from_str(&local_content).ok();
757            let local_error = datadog::ResponseContent {
758                status: local_status,
759                content: local_content,
760                entity: local_entity,
761            };
762            Err(datadog::Error::ResponseError(local_error))
763        }
764    }
765
766    /// Delete a specific Workload Protection policy.
767    ///
768    /// **Note**: This endpoint is not available for the Government (US1-FED) site. Please reference the (US1-FED) specific resource below.
769    pub async fn delete_csm_threats_agent_policy(
770        &self,
771        policy_id: String,
772    ) -> Result<(), datadog::Error<DeleteCSMThreatsAgentPolicyError>> {
773        match self
774            .delete_csm_threats_agent_policy_with_http_info(policy_id)
775            .await
776        {
777            Ok(_) => Ok(()),
778            Err(err) => Err(err),
779        }
780    }
781
782    /// Delete a specific Workload Protection policy.
783    ///
784    /// **Note**: This endpoint is not available for the Government (US1-FED) site. Please reference the (US1-FED) specific resource below.
785    pub async fn delete_csm_threats_agent_policy_with_http_info(
786        &self,
787        policy_id: String,
788    ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteCSMThreatsAgentPolicyError>>
789    {
790        let local_configuration = &self.config;
791        let operation_id = "v2.delete_csm_threats_agent_policy";
792
793        let local_client = &self.client;
794
795        let local_uri_str = format!(
796            "{}/api/v2/remote_config/products/cws/policy/{policy_id}",
797            local_configuration.get_operation_host(operation_id),
798            policy_id = datadog::urlencode(policy_id)
799        );
800        let mut local_req_builder =
801            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
802
803        // build headers
804        let mut headers = HeaderMap::new();
805        headers.insert("Accept", HeaderValue::from_static("*/*"));
806
807        // build user agent
808        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
809            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
810            Err(e) => {
811                log::warn!("Failed to parse user agent header: {e}, falling back to default");
812                headers.insert(
813                    reqwest::header::USER_AGENT,
814                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
815                )
816            }
817        };
818
819        // build auth
820        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
821            headers.insert(
822                "DD-API-KEY",
823                HeaderValue::from_str(local_key.key.as_str())
824                    .expect("failed to parse DD-API-KEY header"),
825            );
826        };
827        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
828            headers.insert(
829                "DD-APPLICATION-KEY",
830                HeaderValue::from_str(local_key.key.as_str())
831                    .expect("failed to parse DD-APPLICATION-KEY header"),
832            );
833        };
834
835        local_req_builder = local_req_builder.headers(headers);
836        let local_req = local_req_builder.build()?;
837        log::debug!("request content: {:?}", local_req.body());
838        let local_resp = local_client.execute(local_req).await?;
839
840        let local_status = local_resp.status();
841        let local_content = local_resp.text().await?;
842        log::debug!("response content: {}", local_content);
843
844        if !local_status.is_client_error() && !local_status.is_server_error() {
845            Ok(datadog::ResponseContent {
846                status: local_status,
847                content: local_content,
848                entity: None,
849            })
850        } else {
851            let local_entity: Option<DeleteCSMThreatsAgentPolicyError> =
852                serde_json::from_str(&local_content).ok();
853            let local_error = datadog::ResponseContent {
854                status: local_status,
855                content: local_content,
856                entity: local_entity,
857            };
858            Err(datadog::Error::ResponseError(local_error))
859        }
860    }
861
862    /// Delete a specific Workload Protection agent rule.
863    ///
864    /// **Note**: This endpoint is not available for the Government (US1-FED) site. Please reference the (US1-FED) specific resource below.
865    pub async fn delete_csm_threats_agent_rule(
866        &self,
867        agent_rule_id: String,
868        params: DeleteCSMThreatsAgentRuleOptionalParams,
869    ) -> Result<(), datadog::Error<DeleteCSMThreatsAgentRuleError>> {
870        match self
871            .delete_csm_threats_agent_rule_with_http_info(agent_rule_id, params)
872            .await
873        {
874            Ok(_) => Ok(()),
875            Err(err) => Err(err),
876        }
877    }
878
879    /// Delete a specific Workload Protection agent rule.
880    ///
881    /// **Note**: This endpoint is not available for the Government (US1-FED) site. Please reference the (US1-FED) specific resource below.
882    pub async fn delete_csm_threats_agent_rule_with_http_info(
883        &self,
884        agent_rule_id: String,
885        params: DeleteCSMThreatsAgentRuleOptionalParams,
886    ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteCSMThreatsAgentRuleError>> {
887        let local_configuration = &self.config;
888        let operation_id = "v2.delete_csm_threats_agent_rule";
889
890        // unbox and build optional parameters
891        let policy_id = params.policy_id;
892
893        let local_client = &self.client;
894
895        let local_uri_str = format!(
896            "{}/api/v2/remote_config/products/cws/agent_rules/{agent_rule_id}",
897            local_configuration.get_operation_host(operation_id),
898            agent_rule_id = datadog::urlencode(agent_rule_id)
899        );
900        let mut local_req_builder =
901            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
902
903        if let Some(ref local_query_param) = policy_id {
904            local_req_builder =
905                local_req_builder.query(&[("policy_id", &local_query_param.to_string())]);
906        };
907
908        // build headers
909        let mut headers = HeaderMap::new();
910        headers.insert("Accept", HeaderValue::from_static("*/*"));
911
912        // build user agent
913        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
914            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
915            Err(e) => {
916                log::warn!("Failed to parse user agent header: {e}, falling back to default");
917                headers.insert(
918                    reqwest::header::USER_AGENT,
919                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
920                )
921            }
922        };
923
924        // build auth
925        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
926            headers.insert(
927                "DD-API-KEY",
928                HeaderValue::from_str(local_key.key.as_str())
929                    .expect("failed to parse DD-API-KEY header"),
930            );
931        };
932        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
933            headers.insert(
934                "DD-APPLICATION-KEY",
935                HeaderValue::from_str(local_key.key.as_str())
936                    .expect("failed to parse DD-APPLICATION-KEY header"),
937            );
938        };
939
940        local_req_builder = local_req_builder.headers(headers);
941        let local_req = local_req_builder.build()?;
942        log::debug!("request content: {:?}", local_req.body());
943        let local_resp = local_client.execute(local_req).await?;
944
945        let local_status = local_resp.status();
946        let local_content = local_resp.text().await?;
947        log::debug!("response content: {}", local_content);
948
949        if !local_status.is_client_error() && !local_status.is_server_error() {
950            Ok(datadog::ResponseContent {
951                status: local_status,
952                content: local_content,
953                entity: None,
954            })
955        } else {
956            let local_entity: Option<DeleteCSMThreatsAgentRuleError> =
957                serde_json::from_str(&local_content).ok();
958            let local_error = datadog::ResponseContent {
959                status: local_status,
960                content: local_content,
961                entity: local_entity,
962            };
963            Err(datadog::Error::ResponseError(local_error))
964        }
965    }
966
967    /// Delete a specific agent rule.
968    ///
969    /// **Note**: This endpoint should only be used for the Government (US1-FED) site.
970    pub async fn delete_cloud_workload_security_agent_rule(
971        &self,
972        agent_rule_id: String,
973    ) -> Result<(), datadog::Error<DeleteCloudWorkloadSecurityAgentRuleError>> {
974        match self
975            .delete_cloud_workload_security_agent_rule_with_http_info(agent_rule_id)
976            .await
977        {
978            Ok(_) => Ok(()),
979            Err(err) => Err(err),
980        }
981    }
982
983    /// Delete a specific agent rule.
984    ///
985    /// **Note**: This endpoint should only be used for the Government (US1-FED) site.
986    pub async fn delete_cloud_workload_security_agent_rule_with_http_info(
987        &self,
988        agent_rule_id: String,
989    ) -> Result<
990        datadog::ResponseContent<()>,
991        datadog::Error<DeleteCloudWorkloadSecurityAgentRuleError>,
992    > {
993        let local_configuration = &self.config;
994        let operation_id = "v2.delete_cloud_workload_security_agent_rule";
995
996        let local_client = &self.client;
997
998        let local_uri_str = format!(
999            "{}/api/v2/security_monitoring/cloud_workload_security/agent_rules/{agent_rule_id}",
1000            local_configuration.get_operation_host(operation_id),
1001            agent_rule_id = datadog::urlencode(agent_rule_id)
1002        );
1003        let mut local_req_builder =
1004            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
1005
1006        // build headers
1007        let mut headers = HeaderMap::new();
1008        headers.insert("Accept", HeaderValue::from_static("*/*"));
1009
1010        // build user agent
1011        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1012            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1013            Err(e) => {
1014                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1015                headers.insert(
1016                    reqwest::header::USER_AGENT,
1017                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1018                )
1019            }
1020        };
1021
1022        // build auth
1023        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1024            headers.insert(
1025                "DD-API-KEY",
1026                HeaderValue::from_str(local_key.key.as_str())
1027                    .expect("failed to parse DD-API-KEY header"),
1028            );
1029        };
1030        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1031            headers.insert(
1032                "DD-APPLICATION-KEY",
1033                HeaderValue::from_str(local_key.key.as_str())
1034                    .expect("failed to parse DD-APPLICATION-KEY header"),
1035            );
1036        };
1037
1038        local_req_builder = local_req_builder.headers(headers);
1039        let local_req = local_req_builder.build()?;
1040        log::debug!("request content: {:?}", local_req.body());
1041        let local_resp = local_client.execute(local_req).await?;
1042
1043        let local_status = local_resp.status();
1044        let local_content = local_resp.text().await?;
1045        log::debug!("response content: {}", local_content);
1046
1047        if !local_status.is_client_error() && !local_status.is_server_error() {
1048            Ok(datadog::ResponseContent {
1049                status: local_status,
1050                content: local_content,
1051                entity: None,
1052            })
1053        } else {
1054            let local_entity: Option<DeleteCloudWorkloadSecurityAgentRuleError> =
1055                serde_json::from_str(&local_content).ok();
1056            let local_error = datadog::ResponseContent {
1057                status: local_status,
1058                content: local_content,
1059                entity: local_entity,
1060            };
1061            Err(datadog::Error::ResponseError(local_error))
1062        }
1063    }
1064
1065    /// The download endpoint generates a Workload Protection policy file from your currently active
1066    /// Workload Protection agent rules, and downloads them as a `.policy` file. This file can then be deployed to
1067    /// your agents to update the policy running in your environment.
1068    ///
1069    /// **Note**: This endpoint is not available for the Government (US1-FED) site. Please reference the (US1-FED) specific resource below.
1070    pub async fn download_csm_threats_policy(
1071        &self,
1072    ) -> Result<Vec<u8>, datadog::Error<DownloadCSMThreatsPolicyError>> {
1073        match self.download_csm_threats_policy_with_http_info().await {
1074            Ok(response_content) => {
1075                if let Some(e) = response_content.entity {
1076                    Ok(e)
1077                } else {
1078                    Err(datadog::Error::Serde(serde::de::Error::custom(
1079                        "response content was None",
1080                    )))
1081                }
1082            }
1083            Err(err) => Err(err),
1084        }
1085    }
1086
1087    /// The download endpoint generates a Workload Protection policy file from your currently active
1088    /// Workload Protection agent rules, and downloads them as a `.policy` file. This file can then be deployed to
1089    /// your agents to update the policy running in your environment.
1090    ///
1091    /// **Note**: This endpoint is not available for the Government (US1-FED) site. Please reference the (US1-FED) specific resource below.
1092    pub async fn download_csm_threats_policy_with_http_info(
1093        &self,
1094    ) -> Result<datadog::ResponseContent<Vec<u8>>, datadog::Error<DownloadCSMThreatsPolicyError>>
1095    {
1096        let local_configuration = &self.config;
1097        let operation_id = "v2.download_csm_threats_policy";
1098
1099        let local_client = &self.client;
1100
1101        let local_uri_str = format!(
1102            "{}/api/v2/remote_config/products/cws/policy/download",
1103            local_configuration.get_operation_host(operation_id)
1104        );
1105        let mut local_req_builder =
1106            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1107
1108        // build headers
1109        let mut headers = HeaderMap::new();
1110        headers.insert("Accept", HeaderValue::from_static("application/json"));
1111
1112        // build user agent
1113        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1114            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1115            Err(e) => {
1116                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1117                headers.insert(
1118                    reqwest::header::USER_AGENT,
1119                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1120                )
1121            }
1122        };
1123
1124        // build auth
1125        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1126            headers.insert(
1127                "DD-API-KEY",
1128                HeaderValue::from_str(local_key.key.as_str())
1129                    .expect("failed to parse DD-API-KEY header"),
1130            );
1131        };
1132        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1133            headers.insert(
1134                "DD-APPLICATION-KEY",
1135                HeaderValue::from_str(local_key.key.as_str())
1136                    .expect("failed to parse DD-APPLICATION-KEY header"),
1137            );
1138        };
1139
1140        local_req_builder = local_req_builder.headers(headers);
1141        let local_req = local_req_builder.build()?;
1142        log::debug!("request content: {:?}", local_req.body());
1143        let local_resp = local_client.execute(local_req).await?;
1144
1145        let local_status = local_resp.status();
1146        let local_content = local_resp.text().await?;
1147        log::debug!("response content: {}", local_content);
1148
1149        if !local_status.is_client_error() && !local_status.is_server_error() {
1150            Ok(datadog::ResponseContent {
1151                status: local_status,
1152                content: local_content.clone(),
1153                entity: Some(local_content.into_bytes()),
1154            })
1155        } else {
1156            let local_entity: Option<DownloadCSMThreatsPolicyError> =
1157                serde_json::from_str(&local_content).ok();
1158            let local_error = datadog::ResponseContent {
1159                status: local_status,
1160                content: local_content,
1161                entity: local_entity,
1162            };
1163            Err(datadog::Error::ResponseError(local_error))
1164        }
1165    }
1166
1167    /// The download endpoint generates a Workload Protection policy file from your currently active
1168    /// Workload Protection agent rules, and downloads them as a `.policy` file. This file can then be deployed to
1169    /// your agents to update the policy running in your environment.
1170    ///
1171    /// **Note**: This endpoint should only be used for the Government (US1-FED) site.
1172    pub async fn download_cloud_workload_policy_file(
1173        &self,
1174    ) -> Result<Vec<u8>, datadog::Error<DownloadCloudWorkloadPolicyFileError>> {
1175        match self
1176            .download_cloud_workload_policy_file_with_http_info()
1177            .await
1178        {
1179            Ok(response_content) => {
1180                if let Some(e) = response_content.entity {
1181                    Ok(e)
1182                } else {
1183                    Err(datadog::Error::Serde(serde::de::Error::custom(
1184                        "response content was None",
1185                    )))
1186                }
1187            }
1188            Err(err) => Err(err),
1189        }
1190    }
1191
1192    /// The download endpoint generates a Workload Protection policy file from your currently active
1193    /// Workload Protection agent rules, and downloads them as a `.policy` file. This file can then be deployed to
1194    /// your agents to update the policy running in your environment.
1195    ///
1196    /// **Note**: This endpoint should only be used for the Government (US1-FED) site.
1197    pub async fn download_cloud_workload_policy_file_with_http_info(
1198        &self,
1199    ) -> Result<
1200        datadog::ResponseContent<Vec<u8>>,
1201        datadog::Error<DownloadCloudWorkloadPolicyFileError>,
1202    > {
1203        let local_configuration = &self.config;
1204        let operation_id = "v2.download_cloud_workload_policy_file";
1205
1206        let local_client = &self.client;
1207
1208        let local_uri_str = format!(
1209            "{}/api/v2/security/cloud_workload/policy/download",
1210            local_configuration.get_operation_host(operation_id)
1211        );
1212        let mut local_req_builder =
1213            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1214
1215        // build headers
1216        let mut headers = HeaderMap::new();
1217        headers.insert("Accept", HeaderValue::from_static("application/json"));
1218
1219        // build user agent
1220        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1221            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1222            Err(e) => {
1223                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1224                headers.insert(
1225                    reqwest::header::USER_AGENT,
1226                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1227                )
1228            }
1229        };
1230
1231        // build auth
1232        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1233            headers.insert(
1234                "DD-API-KEY",
1235                HeaderValue::from_str(local_key.key.as_str())
1236                    .expect("failed to parse DD-API-KEY header"),
1237            );
1238        };
1239        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1240            headers.insert(
1241                "DD-APPLICATION-KEY",
1242                HeaderValue::from_str(local_key.key.as_str())
1243                    .expect("failed to parse DD-APPLICATION-KEY header"),
1244            );
1245        };
1246
1247        local_req_builder = local_req_builder.headers(headers);
1248        let local_req = local_req_builder.build()?;
1249        log::debug!("request content: {:?}", local_req.body());
1250        let local_resp = local_client.execute(local_req).await?;
1251
1252        let local_status = local_resp.status();
1253        let local_content = local_resp.text().await?;
1254        log::debug!("response content: {}", local_content);
1255
1256        if !local_status.is_client_error() && !local_status.is_server_error() {
1257            Ok(datadog::ResponseContent {
1258                status: local_status,
1259                content: local_content.clone(),
1260                entity: Some(local_content.into_bytes()),
1261            })
1262        } else {
1263            let local_entity: Option<DownloadCloudWorkloadPolicyFileError> =
1264                serde_json::from_str(&local_content).ok();
1265            let local_error = datadog::ResponseContent {
1266                status: local_status,
1267                content: local_content,
1268                entity: local_entity,
1269            };
1270            Err(datadog::Error::ResponseError(local_error))
1271        }
1272    }
1273
1274    /// Get the details of a specific Workload Protection policy.
1275    ///
1276    /// **Note**: This endpoint is not available for the Government (US1-FED) site. Please reference the (US1-FED) specific resource below.
1277    pub async fn get_csm_threats_agent_policy(
1278        &self,
1279        policy_id: String,
1280    ) -> Result<
1281        crate::datadogV2::model::CloudWorkloadSecurityAgentPolicyResponse,
1282        datadog::Error<GetCSMThreatsAgentPolicyError>,
1283    > {
1284        match self
1285            .get_csm_threats_agent_policy_with_http_info(policy_id)
1286            .await
1287        {
1288            Ok(response_content) => {
1289                if let Some(e) = response_content.entity {
1290                    Ok(e)
1291                } else {
1292                    Err(datadog::Error::Serde(serde::de::Error::custom(
1293                        "response content was None",
1294                    )))
1295                }
1296            }
1297            Err(err) => Err(err),
1298        }
1299    }
1300
1301    /// Get the details of a specific Workload Protection policy.
1302    ///
1303    /// **Note**: This endpoint is not available for the Government (US1-FED) site. Please reference the (US1-FED) specific resource below.
1304    pub async fn get_csm_threats_agent_policy_with_http_info(
1305        &self,
1306        policy_id: String,
1307    ) -> Result<
1308        datadog::ResponseContent<crate::datadogV2::model::CloudWorkloadSecurityAgentPolicyResponse>,
1309        datadog::Error<GetCSMThreatsAgentPolicyError>,
1310    > {
1311        let local_configuration = &self.config;
1312        let operation_id = "v2.get_csm_threats_agent_policy";
1313
1314        let local_client = &self.client;
1315
1316        let local_uri_str = format!(
1317            "{}/api/v2/remote_config/products/cws/policy/{policy_id}",
1318            local_configuration.get_operation_host(operation_id),
1319            policy_id = datadog::urlencode(policy_id)
1320        );
1321        let mut local_req_builder =
1322            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1323
1324        // build headers
1325        let mut headers = HeaderMap::new();
1326        headers.insert("Accept", HeaderValue::from_static("application/json"));
1327
1328        // build user agent
1329        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1330            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1331            Err(e) => {
1332                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1333                headers.insert(
1334                    reqwest::header::USER_AGENT,
1335                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1336                )
1337            }
1338        };
1339
1340        // build auth
1341        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1342            headers.insert(
1343                "DD-API-KEY",
1344                HeaderValue::from_str(local_key.key.as_str())
1345                    .expect("failed to parse DD-API-KEY header"),
1346            );
1347        };
1348        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1349            headers.insert(
1350                "DD-APPLICATION-KEY",
1351                HeaderValue::from_str(local_key.key.as_str())
1352                    .expect("failed to parse DD-APPLICATION-KEY header"),
1353            );
1354        };
1355
1356        local_req_builder = local_req_builder.headers(headers);
1357        let local_req = local_req_builder.build()?;
1358        log::debug!("request content: {:?}", local_req.body());
1359        let local_resp = local_client.execute(local_req).await?;
1360
1361        let local_status = local_resp.status();
1362        let local_content = local_resp.text().await?;
1363        log::debug!("response content: {}", local_content);
1364
1365        if !local_status.is_client_error() && !local_status.is_server_error() {
1366            match serde_json::from_str::<
1367                crate::datadogV2::model::CloudWorkloadSecurityAgentPolicyResponse,
1368            >(&local_content)
1369            {
1370                Ok(e) => {
1371                    return Ok(datadog::ResponseContent {
1372                        status: local_status,
1373                        content: local_content,
1374                        entity: Some(e),
1375                    })
1376                }
1377                Err(e) => return Err(datadog::Error::Serde(e)),
1378            };
1379        } else {
1380            let local_entity: Option<GetCSMThreatsAgentPolicyError> =
1381                serde_json::from_str(&local_content).ok();
1382            let local_error = datadog::ResponseContent {
1383                status: local_status,
1384                content: local_content,
1385                entity: local_entity,
1386            };
1387            Err(datadog::Error::ResponseError(local_error))
1388        }
1389    }
1390
1391    /// Get the details of a specific Workload Protection agent rule.
1392    ///
1393    /// **Note**: This endpoint is not available for the Government (US1-FED) site. Please reference the (US1-FED) specific resource below.
1394    pub async fn get_csm_threats_agent_rule(
1395        &self,
1396        agent_rule_id: String,
1397        params: GetCSMThreatsAgentRuleOptionalParams,
1398    ) -> Result<
1399        crate::datadogV2::model::CloudWorkloadSecurityAgentRuleResponse,
1400        datadog::Error<GetCSMThreatsAgentRuleError>,
1401    > {
1402        match self
1403            .get_csm_threats_agent_rule_with_http_info(agent_rule_id, params)
1404            .await
1405        {
1406            Ok(response_content) => {
1407                if let Some(e) = response_content.entity {
1408                    Ok(e)
1409                } else {
1410                    Err(datadog::Error::Serde(serde::de::Error::custom(
1411                        "response content was None",
1412                    )))
1413                }
1414            }
1415            Err(err) => Err(err),
1416        }
1417    }
1418
1419    /// Get the details of a specific Workload Protection agent rule.
1420    ///
1421    /// **Note**: This endpoint is not available for the Government (US1-FED) site. Please reference the (US1-FED) specific resource below.
1422    pub async fn get_csm_threats_agent_rule_with_http_info(
1423        &self,
1424        agent_rule_id: String,
1425        params: GetCSMThreatsAgentRuleOptionalParams,
1426    ) -> Result<
1427        datadog::ResponseContent<crate::datadogV2::model::CloudWorkloadSecurityAgentRuleResponse>,
1428        datadog::Error<GetCSMThreatsAgentRuleError>,
1429    > {
1430        let local_configuration = &self.config;
1431        let operation_id = "v2.get_csm_threats_agent_rule";
1432
1433        // unbox and build optional parameters
1434        let policy_id = params.policy_id;
1435
1436        let local_client = &self.client;
1437
1438        let local_uri_str = format!(
1439            "{}/api/v2/remote_config/products/cws/agent_rules/{agent_rule_id}",
1440            local_configuration.get_operation_host(operation_id),
1441            agent_rule_id = datadog::urlencode(agent_rule_id)
1442        );
1443        let mut local_req_builder =
1444            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1445
1446        if let Some(ref local_query_param) = policy_id {
1447            local_req_builder =
1448                local_req_builder.query(&[("policy_id", &local_query_param.to_string())]);
1449        };
1450
1451        // build headers
1452        let mut headers = HeaderMap::new();
1453        headers.insert("Accept", HeaderValue::from_static("application/json"));
1454
1455        // build user agent
1456        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1457            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1458            Err(e) => {
1459                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1460                headers.insert(
1461                    reqwest::header::USER_AGENT,
1462                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1463                )
1464            }
1465        };
1466
1467        // build auth
1468        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1469            headers.insert(
1470                "DD-API-KEY",
1471                HeaderValue::from_str(local_key.key.as_str())
1472                    .expect("failed to parse DD-API-KEY header"),
1473            );
1474        };
1475        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1476            headers.insert(
1477                "DD-APPLICATION-KEY",
1478                HeaderValue::from_str(local_key.key.as_str())
1479                    .expect("failed to parse DD-APPLICATION-KEY header"),
1480            );
1481        };
1482
1483        local_req_builder = local_req_builder.headers(headers);
1484        let local_req = local_req_builder.build()?;
1485        log::debug!("request content: {:?}", local_req.body());
1486        let local_resp = local_client.execute(local_req).await?;
1487
1488        let local_status = local_resp.status();
1489        let local_content = local_resp.text().await?;
1490        log::debug!("response content: {}", local_content);
1491
1492        if !local_status.is_client_error() && !local_status.is_server_error() {
1493            match serde_json::from_str::<
1494                crate::datadogV2::model::CloudWorkloadSecurityAgentRuleResponse,
1495            >(&local_content)
1496            {
1497                Ok(e) => {
1498                    return Ok(datadog::ResponseContent {
1499                        status: local_status,
1500                        content: local_content,
1501                        entity: Some(e),
1502                    })
1503                }
1504                Err(e) => return Err(datadog::Error::Serde(e)),
1505            };
1506        } else {
1507            let local_entity: Option<GetCSMThreatsAgentRuleError> =
1508                serde_json::from_str(&local_content).ok();
1509            let local_error = datadog::ResponseContent {
1510                status: local_status,
1511                content: local_content,
1512                entity: local_entity,
1513            };
1514            Err(datadog::Error::ResponseError(local_error))
1515        }
1516    }
1517
1518    /// Get the details of a specific agent rule.
1519    ///
1520    /// **Note**: This endpoint should only be used for the Government (US1-FED) site.
1521    pub async fn get_cloud_workload_security_agent_rule(
1522        &self,
1523        agent_rule_id: String,
1524    ) -> Result<
1525        crate::datadogV2::model::CloudWorkloadSecurityAgentRuleResponse,
1526        datadog::Error<GetCloudWorkloadSecurityAgentRuleError>,
1527    > {
1528        match self
1529            .get_cloud_workload_security_agent_rule_with_http_info(agent_rule_id)
1530            .await
1531        {
1532            Ok(response_content) => {
1533                if let Some(e) = response_content.entity {
1534                    Ok(e)
1535                } else {
1536                    Err(datadog::Error::Serde(serde::de::Error::custom(
1537                        "response content was None",
1538                    )))
1539                }
1540            }
1541            Err(err) => Err(err),
1542        }
1543    }
1544
1545    /// Get the details of a specific agent rule.
1546    ///
1547    /// **Note**: This endpoint should only be used for the Government (US1-FED) site.
1548    pub async fn get_cloud_workload_security_agent_rule_with_http_info(
1549        &self,
1550        agent_rule_id: String,
1551    ) -> Result<
1552        datadog::ResponseContent<crate::datadogV2::model::CloudWorkloadSecurityAgentRuleResponse>,
1553        datadog::Error<GetCloudWorkloadSecurityAgentRuleError>,
1554    > {
1555        let local_configuration = &self.config;
1556        let operation_id = "v2.get_cloud_workload_security_agent_rule";
1557
1558        let local_client = &self.client;
1559
1560        let local_uri_str = format!(
1561            "{}/api/v2/security_monitoring/cloud_workload_security/agent_rules/{agent_rule_id}",
1562            local_configuration.get_operation_host(operation_id),
1563            agent_rule_id = datadog::urlencode(agent_rule_id)
1564        );
1565        let mut local_req_builder =
1566            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1567
1568        // build headers
1569        let mut headers = HeaderMap::new();
1570        headers.insert("Accept", HeaderValue::from_static("application/json"));
1571
1572        // build user agent
1573        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1574            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1575            Err(e) => {
1576                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1577                headers.insert(
1578                    reqwest::header::USER_AGENT,
1579                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1580                )
1581            }
1582        };
1583
1584        // build auth
1585        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1586            headers.insert(
1587                "DD-API-KEY",
1588                HeaderValue::from_str(local_key.key.as_str())
1589                    .expect("failed to parse DD-API-KEY header"),
1590            );
1591        };
1592        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1593            headers.insert(
1594                "DD-APPLICATION-KEY",
1595                HeaderValue::from_str(local_key.key.as_str())
1596                    .expect("failed to parse DD-APPLICATION-KEY header"),
1597            );
1598        };
1599
1600        local_req_builder = local_req_builder.headers(headers);
1601        let local_req = local_req_builder.build()?;
1602        log::debug!("request content: {:?}", local_req.body());
1603        let local_resp = local_client.execute(local_req).await?;
1604
1605        let local_status = local_resp.status();
1606        let local_content = local_resp.text().await?;
1607        log::debug!("response content: {}", local_content);
1608
1609        if !local_status.is_client_error() && !local_status.is_server_error() {
1610            match serde_json::from_str::<
1611                crate::datadogV2::model::CloudWorkloadSecurityAgentRuleResponse,
1612            >(&local_content)
1613            {
1614                Ok(e) => {
1615                    return Ok(datadog::ResponseContent {
1616                        status: local_status,
1617                        content: local_content,
1618                        entity: Some(e),
1619                    })
1620                }
1621                Err(e) => return Err(datadog::Error::Serde(e)),
1622            };
1623        } else {
1624            let local_entity: Option<GetCloudWorkloadSecurityAgentRuleError> =
1625                serde_json::from_str(&local_content).ok();
1626            let local_error = datadog::ResponseContent {
1627                status: local_status,
1628                content: local_content,
1629                entity: local_entity,
1630            };
1631            Err(datadog::Error::ResponseError(local_error))
1632        }
1633    }
1634
1635    /// Get the list of Workload Protection policies.
1636    ///
1637    /// **Note**: This endpoint is not available for the Government (US1-FED) site. Please reference the (US1-FED) specific resource below.
1638    pub async fn list_csm_threats_agent_policies(
1639        &self,
1640    ) -> Result<
1641        crate::datadogV2::model::CloudWorkloadSecurityAgentPoliciesListResponse,
1642        datadog::Error<ListCSMThreatsAgentPoliciesError>,
1643    > {
1644        match self.list_csm_threats_agent_policies_with_http_info().await {
1645            Ok(response_content) => {
1646                if let Some(e) = response_content.entity {
1647                    Ok(e)
1648                } else {
1649                    Err(datadog::Error::Serde(serde::de::Error::custom(
1650                        "response content was None",
1651                    )))
1652                }
1653            }
1654            Err(err) => Err(err),
1655        }
1656    }
1657
1658    /// Get the list of Workload Protection policies.
1659    ///
1660    /// **Note**: This endpoint is not available for the Government (US1-FED) site. Please reference the (US1-FED) specific resource below.
1661    pub async fn list_csm_threats_agent_policies_with_http_info(
1662        &self,
1663    ) -> Result<
1664        datadog::ResponseContent<
1665            crate::datadogV2::model::CloudWorkloadSecurityAgentPoliciesListResponse,
1666        >,
1667        datadog::Error<ListCSMThreatsAgentPoliciesError>,
1668    > {
1669        let local_configuration = &self.config;
1670        let operation_id = "v2.list_csm_threats_agent_policies";
1671
1672        let local_client = &self.client;
1673
1674        let local_uri_str = format!(
1675            "{}/api/v2/remote_config/products/cws/policy",
1676            local_configuration.get_operation_host(operation_id)
1677        );
1678        let mut local_req_builder =
1679            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1680
1681        // build headers
1682        let mut headers = HeaderMap::new();
1683        headers.insert("Accept", HeaderValue::from_static("application/json"));
1684
1685        // build user agent
1686        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1687            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1688            Err(e) => {
1689                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1690                headers.insert(
1691                    reqwest::header::USER_AGENT,
1692                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1693                )
1694            }
1695        };
1696
1697        // build auth
1698        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1699            headers.insert(
1700                "DD-API-KEY",
1701                HeaderValue::from_str(local_key.key.as_str())
1702                    .expect("failed to parse DD-API-KEY header"),
1703            );
1704        };
1705        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1706            headers.insert(
1707                "DD-APPLICATION-KEY",
1708                HeaderValue::from_str(local_key.key.as_str())
1709                    .expect("failed to parse DD-APPLICATION-KEY header"),
1710            );
1711        };
1712
1713        local_req_builder = local_req_builder.headers(headers);
1714        let local_req = local_req_builder.build()?;
1715        log::debug!("request content: {:?}", local_req.body());
1716        let local_resp = local_client.execute(local_req).await?;
1717
1718        let local_status = local_resp.status();
1719        let local_content = local_resp.text().await?;
1720        log::debug!("response content: {}", local_content);
1721
1722        if !local_status.is_client_error() && !local_status.is_server_error() {
1723            match serde_json::from_str::<
1724                crate::datadogV2::model::CloudWorkloadSecurityAgentPoliciesListResponse,
1725            >(&local_content)
1726            {
1727                Ok(e) => {
1728                    return Ok(datadog::ResponseContent {
1729                        status: local_status,
1730                        content: local_content,
1731                        entity: Some(e),
1732                    })
1733                }
1734                Err(e) => return Err(datadog::Error::Serde(e)),
1735            };
1736        } else {
1737            let local_entity: Option<ListCSMThreatsAgentPoliciesError> =
1738                serde_json::from_str(&local_content).ok();
1739            let local_error = datadog::ResponseContent {
1740                status: local_status,
1741                content: local_content,
1742                entity: local_entity,
1743            };
1744            Err(datadog::Error::ResponseError(local_error))
1745        }
1746    }
1747
1748    /// Get the list of Workload Protection agent rules.
1749    ///
1750    /// **Note**: This endpoint is not available for the Government (US1-FED) site. Please reference the (US1-FED) specific resource below.
1751    pub async fn list_csm_threats_agent_rules(
1752        &self,
1753        params: ListCSMThreatsAgentRulesOptionalParams,
1754    ) -> Result<
1755        crate::datadogV2::model::CloudWorkloadSecurityAgentRulesListResponse,
1756        datadog::Error<ListCSMThreatsAgentRulesError>,
1757    > {
1758        match self
1759            .list_csm_threats_agent_rules_with_http_info(params)
1760            .await
1761        {
1762            Ok(response_content) => {
1763                if let Some(e) = response_content.entity {
1764                    Ok(e)
1765                } else {
1766                    Err(datadog::Error::Serde(serde::de::Error::custom(
1767                        "response content was None",
1768                    )))
1769                }
1770            }
1771            Err(err) => Err(err),
1772        }
1773    }
1774
1775    /// Get the list of Workload Protection agent rules.
1776    ///
1777    /// **Note**: This endpoint is not available for the Government (US1-FED) site. Please reference the (US1-FED) specific resource below.
1778    pub async fn list_csm_threats_agent_rules_with_http_info(
1779        &self,
1780        params: ListCSMThreatsAgentRulesOptionalParams,
1781    ) -> Result<
1782        datadog::ResponseContent<
1783            crate::datadogV2::model::CloudWorkloadSecurityAgentRulesListResponse,
1784        >,
1785        datadog::Error<ListCSMThreatsAgentRulesError>,
1786    > {
1787        let local_configuration = &self.config;
1788        let operation_id = "v2.list_csm_threats_agent_rules";
1789
1790        // unbox and build optional parameters
1791        let policy_id = params.policy_id;
1792
1793        let local_client = &self.client;
1794
1795        let local_uri_str = format!(
1796            "{}/api/v2/remote_config/products/cws/agent_rules",
1797            local_configuration.get_operation_host(operation_id)
1798        );
1799        let mut local_req_builder =
1800            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1801
1802        if let Some(ref local_query_param) = policy_id {
1803            local_req_builder =
1804                local_req_builder.query(&[("policy_id", &local_query_param.to_string())]);
1805        };
1806
1807        // build headers
1808        let mut headers = HeaderMap::new();
1809        headers.insert("Accept", HeaderValue::from_static("application/json"));
1810
1811        // build user agent
1812        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1813            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1814            Err(e) => {
1815                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1816                headers.insert(
1817                    reqwest::header::USER_AGENT,
1818                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1819                )
1820            }
1821        };
1822
1823        // build auth
1824        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1825            headers.insert(
1826                "DD-API-KEY",
1827                HeaderValue::from_str(local_key.key.as_str())
1828                    .expect("failed to parse DD-API-KEY header"),
1829            );
1830        };
1831        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1832            headers.insert(
1833                "DD-APPLICATION-KEY",
1834                HeaderValue::from_str(local_key.key.as_str())
1835                    .expect("failed to parse DD-APPLICATION-KEY header"),
1836            );
1837        };
1838
1839        local_req_builder = local_req_builder.headers(headers);
1840        let local_req = local_req_builder.build()?;
1841        log::debug!("request content: {:?}", local_req.body());
1842        let local_resp = local_client.execute(local_req).await?;
1843
1844        let local_status = local_resp.status();
1845        let local_content = local_resp.text().await?;
1846        log::debug!("response content: {}", local_content);
1847
1848        if !local_status.is_client_error() && !local_status.is_server_error() {
1849            match serde_json::from_str::<
1850                crate::datadogV2::model::CloudWorkloadSecurityAgentRulesListResponse,
1851            >(&local_content)
1852            {
1853                Ok(e) => {
1854                    return Ok(datadog::ResponseContent {
1855                        status: local_status,
1856                        content: local_content,
1857                        entity: Some(e),
1858                    })
1859                }
1860                Err(e) => return Err(datadog::Error::Serde(e)),
1861            };
1862        } else {
1863            let local_entity: Option<ListCSMThreatsAgentRulesError> =
1864                serde_json::from_str(&local_content).ok();
1865            let local_error = datadog::ResponseContent {
1866                status: local_status,
1867                content: local_content,
1868                entity: local_entity,
1869            };
1870            Err(datadog::Error::ResponseError(local_error))
1871        }
1872    }
1873
1874    /// Get the list of agent rules.
1875    ///
1876    /// **Note**: This endpoint should only be used for the Government (US1-FED) site.
1877    pub async fn list_cloud_workload_security_agent_rules(
1878        &self,
1879    ) -> Result<
1880        crate::datadogV2::model::CloudWorkloadSecurityAgentRulesListResponse,
1881        datadog::Error<ListCloudWorkloadSecurityAgentRulesError>,
1882    > {
1883        match self
1884            .list_cloud_workload_security_agent_rules_with_http_info()
1885            .await
1886        {
1887            Ok(response_content) => {
1888                if let Some(e) = response_content.entity {
1889                    Ok(e)
1890                } else {
1891                    Err(datadog::Error::Serde(serde::de::Error::custom(
1892                        "response content was None",
1893                    )))
1894                }
1895            }
1896            Err(err) => Err(err),
1897        }
1898    }
1899
1900    /// Get the list of agent rules.
1901    ///
1902    /// **Note**: This endpoint should only be used for the Government (US1-FED) site.
1903    pub async fn list_cloud_workload_security_agent_rules_with_http_info(
1904        &self,
1905    ) -> Result<
1906        datadog::ResponseContent<
1907            crate::datadogV2::model::CloudWorkloadSecurityAgentRulesListResponse,
1908        >,
1909        datadog::Error<ListCloudWorkloadSecurityAgentRulesError>,
1910    > {
1911        let local_configuration = &self.config;
1912        let operation_id = "v2.list_cloud_workload_security_agent_rules";
1913
1914        let local_client = &self.client;
1915
1916        let local_uri_str = format!(
1917            "{}/api/v2/security_monitoring/cloud_workload_security/agent_rules",
1918            local_configuration.get_operation_host(operation_id)
1919        );
1920        let mut local_req_builder =
1921            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1922
1923        // build headers
1924        let mut headers = HeaderMap::new();
1925        headers.insert("Accept", HeaderValue::from_static("application/json"));
1926
1927        // build user agent
1928        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1929            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1930            Err(e) => {
1931                log::warn!("Failed to parse user agent header: {e}, falling back to default");
1932                headers.insert(
1933                    reqwest::header::USER_AGENT,
1934                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1935                )
1936            }
1937        };
1938
1939        // build auth
1940        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1941            headers.insert(
1942                "DD-API-KEY",
1943                HeaderValue::from_str(local_key.key.as_str())
1944                    .expect("failed to parse DD-API-KEY header"),
1945            );
1946        };
1947        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1948            headers.insert(
1949                "DD-APPLICATION-KEY",
1950                HeaderValue::from_str(local_key.key.as_str())
1951                    .expect("failed to parse DD-APPLICATION-KEY header"),
1952            );
1953        };
1954
1955        local_req_builder = local_req_builder.headers(headers);
1956        let local_req = local_req_builder.build()?;
1957        log::debug!("request content: {:?}", local_req.body());
1958        let local_resp = local_client.execute(local_req).await?;
1959
1960        let local_status = local_resp.status();
1961        let local_content = local_resp.text().await?;
1962        log::debug!("response content: {}", local_content);
1963
1964        if !local_status.is_client_error() && !local_status.is_server_error() {
1965            match serde_json::from_str::<
1966                crate::datadogV2::model::CloudWorkloadSecurityAgentRulesListResponse,
1967            >(&local_content)
1968            {
1969                Ok(e) => {
1970                    return Ok(datadog::ResponseContent {
1971                        status: local_status,
1972                        content: local_content,
1973                        entity: Some(e),
1974                    })
1975                }
1976                Err(e) => return Err(datadog::Error::Serde(e)),
1977            };
1978        } else {
1979            let local_entity: Option<ListCloudWorkloadSecurityAgentRulesError> =
1980                serde_json::from_str(&local_content).ok();
1981            let local_error = datadog::ResponseContent {
1982                status: local_status,
1983                content: local_content,
1984                entity: local_entity,
1985            };
1986            Err(datadog::Error::ResponseError(local_error))
1987        }
1988    }
1989
1990    /// Update a specific Workload Protection policy.
1991    /// Returns the policy object when the request is successful.
1992    ///
1993    /// **Note**: This endpoint is not available for the Government (US1-FED) site. Please reference the (US1-FED) specific resource below.
1994    pub async fn update_csm_threats_agent_policy(
1995        &self,
1996        policy_id: String,
1997        body: crate::datadogV2::model::CloudWorkloadSecurityAgentPolicyUpdateRequest,
1998    ) -> Result<
1999        crate::datadogV2::model::CloudWorkloadSecurityAgentPolicyResponse,
2000        datadog::Error<UpdateCSMThreatsAgentPolicyError>,
2001    > {
2002        match self
2003            .update_csm_threats_agent_policy_with_http_info(policy_id, body)
2004            .await
2005        {
2006            Ok(response_content) => {
2007                if let Some(e) = response_content.entity {
2008                    Ok(e)
2009                } else {
2010                    Err(datadog::Error::Serde(serde::de::Error::custom(
2011                        "response content was None",
2012                    )))
2013                }
2014            }
2015            Err(err) => Err(err),
2016        }
2017    }
2018
2019    /// Update a specific Workload Protection policy.
2020    /// Returns the policy object when the request is successful.
2021    ///
2022    /// **Note**: This endpoint is not available for the Government (US1-FED) site. Please reference the (US1-FED) specific resource below.
2023    pub async fn update_csm_threats_agent_policy_with_http_info(
2024        &self,
2025        policy_id: String,
2026        body: crate::datadogV2::model::CloudWorkloadSecurityAgentPolicyUpdateRequest,
2027    ) -> Result<
2028        datadog::ResponseContent<crate::datadogV2::model::CloudWorkloadSecurityAgentPolicyResponse>,
2029        datadog::Error<UpdateCSMThreatsAgentPolicyError>,
2030    > {
2031        let local_configuration = &self.config;
2032        let operation_id = "v2.update_csm_threats_agent_policy";
2033
2034        let local_client = &self.client;
2035
2036        let local_uri_str = format!(
2037            "{}/api/v2/remote_config/products/cws/policy/{policy_id}",
2038            local_configuration.get_operation_host(operation_id),
2039            policy_id = datadog::urlencode(policy_id)
2040        );
2041        let mut local_req_builder =
2042            local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
2043
2044        // build headers
2045        let mut headers = HeaderMap::new();
2046        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
2047        headers.insert("Accept", HeaderValue::from_static("application/json"));
2048
2049        // build user agent
2050        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2051            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2052            Err(e) => {
2053                log::warn!("Failed to parse user agent header: {e}, falling back to default");
2054                headers.insert(
2055                    reqwest::header::USER_AGENT,
2056                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2057                )
2058            }
2059        };
2060
2061        // build auth
2062        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2063            headers.insert(
2064                "DD-API-KEY",
2065                HeaderValue::from_str(local_key.key.as_str())
2066                    .expect("failed to parse DD-API-KEY header"),
2067            );
2068        };
2069        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2070            headers.insert(
2071                "DD-APPLICATION-KEY",
2072                HeaderValue::from_str(local_key.key.as_str())
2073                    .expect("failed to parse DD-APPLICATION-KEY header"),
2074            );
2075        };
2076
2077        // build body parameters
2078        let output = Vec::new();
2079        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2080        if body.serialize(&mut ser).is_ok() {
2081            if let Some(content_encoding) = headers.get("Content-Encoding") {
2082                match content_encoding.to_str().unwrap_or_default() {
2083                    "gzip" => {
2084                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2085                        let _ = enc.write_all(ser.into_inner().as_slice());
2086                        match enc.finish() {
2087                            Ok(buf) => {
2088                                local_req_builder = local_req_builder.body(buf);
2089                            }
2090                            Err(e) => return Err(datadog::Error::Io(e)),
2091                        }
2092                    }
2093                    "deflate" => {
2094                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2095                        let _ = enc.write_all(ser.into_inner().as_slice());
2096                        match enc.finish() {
2097                            Ok(buf) => {
2098                                local_req_builder = local_req_builder.body(buf);
2099                            }
2100                            Err(e) => return Err(datadog::Error::Io(e)),
2101                        }
2102                    }
2103                    "zstd1" => {
2104                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2105                        let _ = enc.write_all(ser.into_inner().as_slice());
2106                        match enc.finish() {
2107                            Ok(buf) => {
2108                                local_req_builder = local_req_builder.body(buf);
2109                            }
2110                            Err(e) => return Err(datadog::Error::Io(e)),
2111                        }
2112                    }
2113                    _ => {
2114                        local_req_builder = local_req_builder.body(ser.into_inner());
2115                    }
2116                }
2117            } else {
2118                local_req_builder = local_req_builder.body(ser.into_inner());
2119            }
2120        }
2121
2122        local_req_builder = local_req_builder.headers(headers);
2123        let local_req = local_req_builder.build()?;
2124        log::debug!("request content: {:?}", local_req.body());
2125        let local_resp = local_client.execute(local_req).await?;
2126
2127        let local_status = local_resp.status();
2128        let local_content = local_resp.text().await?;
2129        log::debug!("response content: {}", local_content);
2130
2131        if !local_status.is_client_error() && !local_status.is_server_error() {
2132            match serde_json::from_str::<
2133                crate::datadogV2::model::CloudWorkloadSecurityAgentPolicyResponse,
2134            >(&local_content)
2135            {
2136                Ok(e) => {
2137                    return Ok(datadog::ResponseContent {
2138                        status: local_status,
2139                        content: local_content,
2140                        entity: Some(e),
2141                    })
2142                }
2143                Err(e) => return Err(datadog::Error::Serde(e)),
2144            };
2145        } else {
2146            let local_entity: Option<UpdateCSMThreatsAgentPolicyError> =
2147                serde_json::from_str(&local_content).ok();
2148            let local_error = datadog::ResponseContent {
2149                status: local_status,
2150                content: local_content,
2151                entity: local_entity,
2152            };
2153            Err(datadog::Error::ResponseError(local_error))
2154        }
2155    }
2156
2157    /// Update a specific Workload Protection Agent rule.
2158    /// Returns the agent rule object when the request is successful.
2159    ///
2160    /// **Note**: This endpoint is not available for the Government (US1-FED) site. Please reference the (US1-FED) specific resource below.
2161    pub async fn update_csm_threats_agent_rule(
2162        &self,
2163        agent_rule_id: String,
2164        body: crate::datadogV2::model::CloudWorkloadSecurityAgentRuleUpdateRequest,
2165        params: UpdateCSMThreatsAgentRuleOptionalParams,
2166    ) -> Result<
2167        crate::datadogV2::model::CloudWorkloadSecurityAgentRuleResponse,
2168        datadog::Error<UpdateCSMThreatsAgentRuleError>,
2169    > {
2170        match self
2171            .update_csm_threats_agent_rule_with_http_info(agent_rule_id, body, params)
2172            .await
2173        {
2174            Ok(response_content) => {
2175                if let Some(e) = response_content.entity {
2176                    Ok(e)
2177                } else {
2178                    Err(datadog::Error::Serde(serde::de::Error::custom(
2179                        "response content was None",
2180                    )))
2181                }
2182            }
2183            Err(err) => Err(err),
2184        }
2185    }
2186
2187    /// Update a specific Workload Protection Agent rule.
2188    /// Returns the agent rule object when the request is successful.
2189    ///
2190    /// **Note**: This endpoint is not available for the Government (US1-FED) site. Please reference the (US1-FED) specific resource below.
2191    pub async fn update_csm_threats_agent_rule_with_http_info(
2192        &self,
2193        agent_rule_id: String,
2194        body: crate::datadogV2::model::CloudWorkloadSecurityAgentRuleUpdateRequest,
2195        params: UpdateCSMThreatsAgentRuleOptionalParams,
2196    ) -> Result<
2197        datadog::ResponseContent<crate::datadogV2::model::CloudWorkloadSecurityAgentRuleResponse>,
2198        datadog::Error<UpdateCSMThreatsAgentRuleError>,
2199    > {
2200        let local_configuration = &self.config;
2201        let operation_id = "v2.update_csm_threats_agent_rule";
2202
2203        // unbox and build optional parameters
2204        let policy_id = params.policy_id;
2205
2206        let local_client = &self.client;
2207
2208        let local_uri_str = format!(
2209            "{}/api/v2/remote_config/products/cws/agent_rules/{agent_rule_id}",
2210            local_configuration.get_operation_host(operation_id),
2211            agent_rule_id = datadog::urlencode(agent_rule_id)
2212        );
2213        let mut local_req_builder =
2214            local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
2215
2216        if let Some(ref local_query_param) = policy_id {
2217            local_req_builder =
2218                local_req_builder.query(&[("policy_id", &local_query_param.to_string())]);
2219        };
2220
2221        // build headers
2222        let mut headers = HeaderMap::new();
2223        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
2224        headers.insert("Accept", HeaderValue::from_static("application/json"));
2225
2226        // build user agent
2227        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2228            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2229            Err(e) => {
2230                log::warn!("Failed to parse user agent header: {e}, falling back to default");
2231                headers.insert(
2232                    reqwest::header::USER_AGENT,
2233                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2234                )
2235            }
2236        };
2237
2238        // build auth
2239        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2240            headers.insert(
2241                "DD-API-KEY",
2242                HeaderValue::from_str(local_key.key.as_str())
2243                    .expect("failed to parse DD-API-KEY header"),
2244            );
2245        };
2246        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2247            headers.insert(
2248                "DD-APPLICATION-KEY",
2249                HeaderValue::from_str(local_key.key.as_str())
2250                    .expect("failed to parse DD-APPLICATION-KEY header"),
2251            );
2252        };
2253
2254        // build body parameters
2255        let output = Vec::new();
2256        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2257        if body.serialize(&mut ser).is_ok() {
2258            if let Some(content_encoding) = headers.get("Content-Encoding") {
2259                match content_encoding.to_str().unwrap_or_default() {
2260                    "gzip" => {
2261                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2262                        let _ = enc.write_all(ser.into_inner().as_slice());
2263                        match enc.finish() {
2264                            Ok(buf) => {
2265                                local_req_builder = local_req_builder.body(buf);
2266                            }
2267                            Err(e) => return Err(datadog::Error::Io(e)),
2268                        }
2269                    }
2270                    "deflate" => {
2271                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2272                        let _ = enc.write_all(ser.into_inner().as_slice());
2273                        match enc.finish() {
2274                            Ok(buf) => {
2275                                local_req_builder = local_req_builder.body(buf);
2276                            }
2277                            Err(e) => return Err(datadog::Error::Io(e)),
2278                        }
2279                    }
2280                    "zstd1" => {
2281                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2282                        let _ = enc.write_all(ser.into_inner().as_slice());
2283                        match enc.finish() {
2284                            Ok(buf) => {
2285                                local_req_builder = local_req_builder.body(buf);
2286                            }
2287                            Err(e) => return Err(datadog::Error::Io(e)),
2288                        }
2289                    }
2290                    _ => {
2291                        local_req_builder = local_req_builder.body(ser.into_inner());
2292                    }
2293                }
2294            } else {
2295                local_req_builder = local_req_builder.body(ser.into_inner());
2296            }
2297        }
2298
2299        local_req_builder = local_req_builder.headers(headers);
2300        let local_req = local_req_builder.build()?;
2301        log::debug!("request content: {:?}", local_req.body());
2302        let local_resp = local_client.execute(local_req).await?;
2303
2304        let local_status = local_resp.status();
2305        let local_content = local_resp.text().await?;
2306        log::debug!("response content: {}", local_content);
2307
2308        if !local_status.is_client_error() && !local_status.is_server_error() {
2309            match serde_json::from_str::<
2310                crate::datadogV2::model::CloudWorkloadSecurityAgentRuleResponse,
2311            >(&local_content)
2312            {
2313                Ok(e) => {
2314                    return Ok(datadog::ResponseContent {
2315                        status: local_status,
2316                        content: local_content,
2317                        entity: Some(e),
2318                    })
2319                }
2320                Err(e) => return Err(datadog::Error::Serde(e)),
2321            };
2322        } else {
2323            let local_entity: Option<UpdateCSMThreatsAgentRuleError> =
2324                serde_json::from_str(&local_content).ok();
2325            let local_error = datadog::ResponseContent {
2326                status: local_status,
2327                content: local_content,
2328                entity: local_entity,
2329            };
2330            Err(datadog::Error::ResponseError(local_error))
2331        }
2332    }
2333
2334    /// Update a specific agent rule.
2335    /// Returns the agent rule object when the request is successful.
2336    ///
2337    /// **Note**: This endpoint should only be used for the Government (US1-FED) site.
2338    pub async fn update_cloud_workload_security_agent_rule(
2339        &self,
2340        agent_rule_id: String,
2341        body: crate::datadogV2::model::CloudWorkloadSecurityAgentRuleUpdateRequest,
2342    ) -> Result<
2343        crate::datadogV2::model::CloudWorkloadSecurityAgentRuleResponse,
2344        datadog::Error<UpdateCloudWorkloadSecurityAgentRuleError>,
2345    > {
2346        match self
2347            .update_cloud_workload_security_agent_rule_with_http_info(agent_rule_id, body)
2348            .await
2349        {
2350            Ok(response_content) => {
2351                if let Some(e) = response_content.entity {
2352                    Ok(e)
2353                } else {
2354                    Err(datadog::Error::Serde(serde::de::Error::custom(
2355                        "response content was None",
2356                    )))
2357                }
2358            }
2359            Err(err) => Err(err),
2360        }
2361    }
2362
2363    /// Update a specific agent rule.
2364    /// Returns the agent rule object when the request is successful.
2365    ///
2366    /// **Note**: This endpoint should only be used for the Government (US1-FED) site.
2367    pub async fn update_cloud_workload_security_agent_rule_with_http_info(
2368        &self,
2369        agent_rule_id: String,
2370        body: crate::datadogV2::model::CloudWorkloadSecurityAgentRuleUpdateRequest,
2371    ) -> Result<
2372        datadog::ResponseContent<crate::datadogV2::model::CloudWorkloadSecurityAgentRuleResponse>,
2373        datadog::Error<UpdateCloudWorkloadSecurityAgentRuleError>,
2374    > {
2375        let local_configuration = &self.config;
2376        let operation_id = "v2.update_cloud_workload_security_agent_rule";
2377
2378        let local_client = &self.client;
2379
2380        let local_uri_str = format!(
2381            "{}/api/v2/security_monitoring/cloud_workload_security/agent_rules/{agent_rule_id}",
2382            local_configuration.get_operation_host(operation_id),
2383            agent_rule_id = datadog::urlencode(agent_rule_id)
2384        );
2385        let mut local_req_builder =
2386            local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
2387
2388        // build headers
2389        let mut headers = HeaderMap::new();
2390        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
2391        headers.insert("Accept", HeaderValue::from_static("application/json"));
2392
2393        // build user agent
2394        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2395            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2396            Err(e) => {
2397                log::warn!("Failed to parse user agent header: {e}, falling back to default");
2398                headers.insert(
2399                    reqwest::header::USER_AGENT,
2400                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2401                )
2402            }
2403        };
2404
2405        // build auth
2406        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2407            headers.insert(
2408                "DD-API-KEY",
2409                HeaderValue::from_str(local_key.key.as_str())
2410                    .expect("failed to parse DD-API-KEY header"),
2411            );
2412        };
2413        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2414            headers.insert(
2415                "DD-APPLICATION-KEY",
2416                HeaderValue::from_str(local_key.key.as_str())
2417                    .expect("failed to parse DD-APPLICATION-KEY header"),
2418            );
2419        };
2420
2421        // build body parameters
2422        let output = Vec::new();
2423        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2424        if body.serialize(&mut ser).is_ok() {
2425            if let Some(content_encoding) = headers.get("Content-Encoding") {
2426                match content_encoding.to_str().unwrap_or_default() {
2427                    "gzip" => {
2428                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2429                        let _ = enc.write_all(ser.into_inner().as_slice());
2430                        match enc.finish() {
2431                            Ok(buf) => {
2432                                local_req_builder = local_req_builder.body(buf);
2433                            }
2434                            Err(e) => return Err(datadog::Error::Io(e)),
2435                        }
2436                    }
2437                    "deflate" => {
2438                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2439                        let _ = enc.write_all(ser.into_inner().as_slice());
2440                        match enc.finish() {
2441                            Ok(buf) => {
2442                                local_req_builder = local_req_builder.body(buf);
2443                            }
2444                            Err(e) => return Err(datadog::Error::Io(e)),
2445                        }
2446                    }
2447                    "zstd1" => {
2448                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2449                        let _ = enc.write_all(ser.into_inner().as_slice());
2450                        match enc.finish() {
2451                            Ok(buf) => {
2452                                local_req_builder = local_req_builder.body(buf);
2453                            }
2454                            Err(e) => return Err(datadog::Error::Io(e)),
2455                        }
2456                    }
2457                    _ => {
2458                        local_req_builder = local_req_builder.body(ser.into_inner());
2459                    }
2460                }
2461            } else {
2462                local_req_builder = local_req_builder.body(ser.into_inner());
2463            }
2464        }
2465
2466        local_req_builder = local_req_builder.headers(headers);
2467        let local_req = local_req_builder.build()?;
2468        log::debug!("request content: {:?}", local_req.body());
2469        let local_resp = local_client.execute(local_req).await?;
2470
2471        let local_status = local_resp.status();
2472        let local_content = local_resp.text().await?;
2473        log::debug!("response content: {}", local_content);
2474
2475        if !local_status.is_client_error() && !local_status.is_server_error() {
2476            match serde_json::from_str::<
2477                crate::datadogV2::model::CloudWorkloadSecurityAgentRuleResponse,
2478            >(&local_content)
2479            {
2480                Ok(e) => {
2481                    return Ok(datadog::ResponseContent {
2482                        status: local_status,
2483                        content: local_content,
2484                        entity: Some(e),
2485                    })
2486                }
2487                Err(e) => return Err(datadog::Error::Serde(e)),
2488            };
2489        } else {
2490            let local_entity: Option<UpdateCloudWorkloadSecurityAgentRuleError> =
2491                serde_json::from_str(&local_content).ok();
2492            let local_error = datadog::ResponseContent {
2493                status: local_status,
2494                content: local_content,
2495                entity: local_entity,
2496            };
2497            Err(datadog::Error::ResponseError(local_error))
2498        }
2499    }
2500}