datadog_api_client/datadogV2/api/
api_agentless_scanning.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/// CreateAwsOnDemandTaskError is a struct for typed errors of method [`AgentlessScanningAPI::create_aws_on_demand_task`]
14#[derive(Debug, Clone, Serialize, Deserialize)]
15#[serde(untagged)]
16pub enum CreateAwsOnDemandTaskError {
17    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
18    UnknownValue(serde_json::Value),
19}
20
21/// CreateAwsScanOptionsError is a struct for typed errors of method [`AgentlessScanningAPI::create_aws_scan_options`]
22#[derive(Debug, Clone, Serialize, Deserialize)]
23#[serde(untagged)]
24pub enum CreateAwsScanOptionsError {
25    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
26    UnknownValue(serde_json::Value),
27}
28
29/// DeleteAwsScanOptionsError is a struct for typed errors of method [`AgentlessScanningAPI::delete_aws_scan_options`]
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum DeleteAwsScanOptionsError {
33    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
34    UnknownValue(serde_json::Value),
35}
36
37/// GetAwsOnDemandTaskError is a struct for typed errors of method [`AgentlessScanningAPI::get_aws_on_demand_task`]
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum GetAwsOnDemandTaskError {
41    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
42    UnknownValue(serde_json::Value),
43}
44
45/// ListAwsOnDemandTasksError is a struct for typed errors of method [`AgentlessScanningAPI::list_aws_on_demand_tasks`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum ListAwsOnDemandTasksError {
49    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
50    UnknownValue(serde_json::Value),
51}
52
53/// ListAwsScanOptionsError is a struct for typed errors of method [`AgentlessScanningAPI::list_aws_scan_options`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum ListAwsScanOptionsError {
57    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
58    UnknownValue(serde_json::Value),
59}
60
61/// UpdateAwsScanOptionsError is a struct for typed errors of method [`AgentlessScanningAPI::update_aws_scan_options`]
62#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum UpdateAwsScanOptionsError {
65    APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
66    UnknownValue(serde_json::Value),
67}
68
69/// Datadog Agentless Scanning provides visibility into risks and vulnerabilities
70/// within your hosts, running containers, and serverless functions—all without
71/// requiring teams to install Agents on every host or where Agents cannot be installed.
72/// Agentless offers also Sensitive Data Scanning capabilities on your storage.
73/// Go to <https://www.datadoghq.com/blog/agentless-scanning/> to learn more.
74#[derive(Debug, Clone)]
75pub struct AgentlessScanningAPI {
76    config: datadog::Configuration,
77    client: reqwest_middleware::ClientWithMiddleware,
78}
79
80impl Default for AgentlessScanningAPI {
81    fn default() -> Self {
82        Self::with_config(datadog::Configuration::default())
83    }
84}
85
86impl AgentlessScanningAPI {
87    pub fn new() -> Self {
88        Self::default()
89    }
90    pub fn with_config(config: datadog::Configuration) -> Self {
91        let mut reqwest_client_builder = reqwest::Client::builder();
92
93        if let Some(proxy_url) = &config.proxy_url {
94            let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
95            reqwest_client_builder = reqwest_client_builder.proxy(proxy);
96        }
97
98        let mut middleware_client_builder =
99            reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
100
101        if config.enable_retry {
102            struct RetryableStatus;
103            impl reqwest_retry::RetryableStrategy for RetryableStatus {
104                fn handle(
105                    &self,
106                    res: &Result<reqwest::Response, reqwest_middleware::Error>,
107                ) -> Option<reqwest_retry::Retryable> {
108                    match res {
109                        Ok(success) => reqwest_retry::default_on_request_success(success),
110                        Err(_) => None,
111                    }
112                }
113            }
114            let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
115                .build_with_max_retries(config.max_retries);
116
117            let retry_middleware =
118                reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
119                    backoff_policy,
120                    RetryableStatus,
121                );
122
123            middleware_client_builder = middleware_client_builder.with(retry_middleware);
124        }
125
126        let client = middleware_client_builder.build();
127
128        Self { config, client }
129    }
130
131    pub fn with_client_and_config(
132        config: datadog::Configuration,
133        client: reqwest_middleware::ClientWithMiddleware,
134    ) -> Self {
135        Self { config, client }
136    }
137
138    /// Trigger the scan of an AWS resource with a high priority. Agentless scanning must be activated for the AWS account containing the resource to scan.
139    pub async fn create_aws_on_demand_task(
140        &self,
141        body: crate::datadogV2::model::AwsOnDemandCreateRequest,
142    ) -> Result<
143        crate::datadogV2::model::AwsOnDemandResponse,
144        datadog::Error<CreateAwsOnDemandTaskError>,
145    > {
146        match self.create_aws_on_demand_task_with_http_info(body).await {
147            Ok(response_content) => {
148                if let Some(e) = response_content.entity {
149                    Ok(e)
150                } else {
151                    Err(datadog::Error::Serde(serde::de::Error::custom(
152                        "response content was None",
153                    )))
154                }
155            }
156            Err(err) => Err(err),
157        }
158    }
159
160    /// Trigger the scan of an AWS resource with a high priority. Agentless scanning must be activated for the AWS account containing the resource to scan.
161    pub async fn create_aws_on_demand_task_with_http_info(
162        &self,
163        body: crate::datadogV2::model::AwsOnDemandCreateRequest,
164    ) -> Result<
165        datadog::ResponseContent<crate::datadogV2::model::AwsOnDemandResponse>,
166        datadog::Error<CreateAwsOnDemandTaskError>,
167    > {
168        let local_configuration = &self.config;
169        let operation_id = "v2.create_aws_on_demand_task";
170
171        let local_client = &self.client;
172
173        let local_uri_str = format!(
174            "{}/api/v2/agentless_scanning/ondemand/aws",
175            local_configuration.get_operation_host(operation_id)
176        );
177        let mut local_req_builder =
178            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
179
180        // build headers
181        let mut headers = HeaderMap::new();
182        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
183        headers.insert("Accept", HeaderValue::from_static("application/json"));
184
185        // build user agent
186        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
187            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
188            Err(e) => {
189                log::warn!("Failed to parse user agent header: {e}, falling back to default");
190                headers.insert(
191                    reqwest::header::USER_AGENT,
192                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
193                )
194            }
195        };
196
197        // build auth
198        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
199            headers.insert(
200                "DD-API-KEY",
201                HeaderValue::from_str(local_key.key.as_str())
202                    .expect("failed to parse DD-API-KEY header"),
203            );
204        };
205        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
206            headers.insert(
207                "DD-APPLICATION-KEY",
208                HeaderValue::from_str(local_key.key.as_str())
209                    .expect("failed to parse DD-APPLICATION-KEY header"),
210            );
211        };
212
213        // build body parameters
214        let output = Vec::new();
215        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
216        if body.serialize(&mut ser).is_ok() {
217            if let Some(content_encoding) = headers.get("Content-Encoding") {
218                match content_encoding.to_str().unwrap_or_default() {
219                    "gzip" => {
220                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
221                        let _ = enc.write_all(ser.into_inner().as_slice());
222                        match enc.finish() {
223                            Ok(buf) => {
224                                local_req_builder = local_req_builder.body(buf);
225                            }
226                            Err(e) => return Err(datadog::Error::Io(e)),
227                        }
228                    }
229                    "deflate" => {
230                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
231                        let _ = enc.write_all(ser.into_inner().as_slice());
232                        match enc.finish() {
233                            Ok(buf) => {
234                                local_req_builder = local_req_builder.body(buf);
235                            }
236                            Err(e) => return Err(datadog::Error::Io(e)),
237                        }
238                    }
239                    "zstd1" => {
240                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
241                        let _ = enc.write_all(ser.into_inner().as_slice());
242                        match enc.finish() {
243                            Ok(buf) => {
244                                local_req_builder = local_req_builder.body(buf);
245                            }
246                            Err(e) => return Err(datadog::Error::Io(e)),
247                        }
248                    }
249                    _ => {
250                        local_req_builder = local_req_builder.body(ser.into_inner());
251                    }
252                }
253            } else {
254                local_req_builder = local_req_builder.body(ser.into_inner());
255            }
256        }
257
258        local_req_builder = local_req_builder.headers(headers);
259        let local_req = local_req_builder.build()?;
260        log::debug!("request content: {:?}", local_req.body());
261        let local_resp = local_client.execute(local_req).await?;
262
263        let local_status = local_resp.status();
264        let local_content = local_resp.text().await?;
265        log::debug!("response content: {}", local_content);
266
267        if !local_status.is_client_error() && !local_status.is_server_error() {
268            match serde_json::from_str::<crate::datadogV2::model::AwsOnDemandResponse>(
269                &local_content,
270            ) {
271                Ok(e) => {
272                    return Ok(datadog::ResponseContent {
273                        status: local_status,
274                        content: local_content,
275                        entity: Some(e),
276                    })
277                }
278                Err(e) => return Err(datadog::Error::Serde(e)),
279            };
280        } else {
281            let local_entity: Option<CreateAwsOnDemandTaskError> =
282                serde_json::from_str(&local_content).ok();
283            let local_error = datadog::ResponseContent {
284                status: local_status,
285                content: local_content,
286                entity: local_entity,
287            };
288            Err(datadog::Error::ResponseError(local_error))
289        }
290    }
291
292    /// Activate Agentless scan options for an AWS account.
293    pub async fn create_aws_scan_options(
294        &self,
295        body: crate::datadogV2::model::AwsScanOptionsCreateRequest,
296    ) -> Result<
297        crate::datadogV2::model::AwsScanOptionsResponse,
298        datadog::Error<CreateAwsScanOptionsError>,
299    > {
300        match self.create_aws_scan_options_with_http_info(body).await {
301            Ok(response_content) => {
302                if let Some(e) = response_content.entity {
303                    Ok(e)
304                } else {
305                    Err(datadog::Error::Serde(serde::de::Error::custom(
306                        "response content was None",
307                    )))
308                }
309            }
310            Err(err) => Err(err),
311        }
312    }
313
314    /// Activate Agentless scan options for an AWS account.
315    pub async fn create_aws_scan_options_with_http_info(
316        &self,
317        body: crate::datadogV2::model::AwsScanOptionsCreateRequest,
318    ) -> Result<
319        datadog::ResponseContent<crate::datadogV2::model::AwsScanOptionsResponse>,
320        datadog::Error<CreateAwsScanOptionsError>,
321    > {
322        let local_configuration = &self.config;
323        let operation_id = "v2.create_aws_scan_options";
324
325        let local_client = &self.client;
326
327        let local_uri_str = format!(
328            "{}/api/v2/agentless_scanning/accounts/aws",
329            local_configuration.get_operation_host(operation_id)
330        );
331        let mut local_req_builder =
332            local_client.request(reqwest::Method::POST, local_uri_str.as_str());
333
334        // build headers
335        let mut headers = HeaderMap::new();
336        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
337        headers.insert("Accept", HeaderValue::from_static("application/json"));
338
339        // build user agent
340        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
341            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
342            Err(e) => {
343                log::warn!("Failed to parse user agent header: {e}, falling back to default");
344                headers.insert(
345                    reqwest::header::USER_AGENT,
346                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
347                )
348            }
349        };
350
351        // build auth
352        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
353            headers.insert(
354                "DD-API-KEY",
355                HeaderValue::from_str(local_key.key.as_str())
356                    .expect("failed to parse DD-API-KEY header"),
357            );
358        };
359        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
360            headers.insert(
361                "DD-APPLICATION-KEY",
362                HeaderValue::from_str(local_key.key.as_str())
363                    .expect("failed to parse DD-APPLICATION-KEY header"),
364            );
365        };
366
367        // build body parameters
368        let output = Vec::new();
369        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
370        if body.serialize(&mut ser).is_ok() {
371            if let Some(content_encoding) = headers.get("Content-Encoding") {
372                match content_encoding.to_str().unwrap_or_default() {
373                    "gzip" => {
374                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
375                        let _ = enc.write_all(ser.into_inner().as_slice());
376                        match enc.finish() {
377                            Ok(buf) => {
378                                local_req_builder = local_req_builder.body(buf);
379                            }
380                            Err(e) => return Err(datadog::Error::Io(e)),
381                        }
382                    }
383                    "deflate" => {
384                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
385                        let _ = enc.write_all(ser.into_inner().as_slice());
386                        match enc.finish() {
387                            Ok(buf) => {
388                                local_req_builder = local_req_builder.body(buf);
389                            }
390                            Err(e) => return Err(datadog::Error::Io(e)),
391                        }
392                    }
393                    "zstd1" => {
394                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
395                        let _ = enc.write_all(ser.into_inner().as_slice());
396                        match enc.finish() {
397                            Ok(buf) => {
398                                local_req_builder = local_req_builder.body(buf);
399                            }
400                            Err(e) => return Err(datadog::Error::Io(e)),
401                        }
402                    }
403                    _ => {
404                        local_req_builder = local_req_builder.body(ser.into_inner());
405                    }
406                }
407            } else {
408                local_req_builder = local_req_builder.body(ser.into_inner());
409            }
410        }
411
412        local_req_builder = local_req_builder.headers(headers);
413        let local_req = local_req_builder.build()?;
414        log::debug!("request content: {:?}", local_req.body());
415        let local_resp = local_client.execute(local_req).await?;
416
417        let local_status = local_resp.status();
418        let local_content = local_resp.text().await?;
419        log::debug!("response content: {}", local_content);
420
421        if !local_status.is_client_error() && !local_status.is_server_error() {
422            match serde_json::from_str::<crate::datadogV2::model::AwsScanOptionsResponse>(
423                &local_content,
424            ) {
425                Ok(e) => {
426                    return Ok(datadog::ResponseContent {
427                        status: local_status,
428                        content: local_content,
429                        entity: Some(e),
430                    })
431                }
432                Err(e) => return Err(datadog::Error::Serde(e)),
433            };
434        } else {
435            let local_entity: Option<CreateAwsScanOptionsError> =
436                serde_json::from_str(&local_content).ok();
437            let local_error = datadog::ResponseContent {
438                status: local_status,
439                content: local_content,
440                entity: local_entity,
441            };
442            Err(datadog::Error::ResponseError(local_error))
443        }
444    }
445
446    /// Delete Agentless scan options for an AWS account.
447    pub async fn delete_aws_scan_options(
448        &self,
449        account_id: String,
450    ) -> Result<(), datadog::Error<DeleteAwsScanOptionsError>> {
451        match self
452            .delete_aws_scan_options_with_http_info(account_id)
453            .await
454        {
455            Ok(_) => Ok(()),
456            Err(err) => Err(err),
457        }
458    }
459
460    /// Delete Agentless scan options for an AWS account.
461    pub async fn delete_aws_scan_options_with_http_info(
462        &self,
463        account_id: String,
464    ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteAwsScanOptionsError>> {
465        let local_configuration = &self.config;
466        let operation_id = "v2.delete_aws_scan_options";
467
468        let local_client = &self.client;
469
470        let local_uri_str = format!(
471            "{}/api/v2/agentless_scanning/accounts/aws/{account_id}",
472            local_configuration.get_operation_host(operation_id),
473            account_id = datadog::urlencode(account_id)
474        );
475        let mut local_req_builder =
476            local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
477
478        // build headers
479        let mut headers = HeaderMap::new();
480        headers.insert("Accept", HeaderValue::from_static("*/*"));
481
482        // build user agent
483        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
484            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
485            Err(e) => {
486                log::warn!("Failed to parse user agent header: {e}, falling back to default");
487                headers.insert(
488                    reqwest::header::USER_AGENT,
489                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
490                )
491            }
492        };
493
494        // build auth
495        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
496            headers.insert(
497                "DD-API-KEY",
498                HeaderValue::from_str(local_key.key.as_str())
499                    .expect("failed to parse DD-API-KEY header"),
500            );
501        };
502        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
503            headers.insert(
504                "DD-APPLICATION-KEY",
505                HeaderValue::from_str(local_key.key.as_str())
506                    .expect("failed to parse DD-APPLICATION-KEY header"),
507            );
508        };
509
510        local_req_builder = local_req_builder.headers(headers);
511        let local_req = local_req_builder.build()?;
512        log::debug!("request content: {:?}", local_req.body());
513        let local_resp = local_client.execute(local_req).await?;
514
515        let local_status = local_resp.status();
516        let local_content = local_resp.text().await?;
517        log::debug!("response content: {}", local_content);
518
519        if !local_status.is_client_error() && !local_status.is_server_error() {
520            Ok(datadog::ResponseContent {
521                status: local_status,
522                content: local_content,
523                entity: None,
524            })
525        } else {
526            let local_entity: Option<DeleteAwsScanOptionsError> =
527                serde_json::from_str(&local_content).ok();
528            let local_error = datadog::ResponseContent {
529                status: local_status,
530                content: local_content,
531                entity: local_entity,
532            };
533            Err(datadog::Error::ResponseError(local_error))
534        }
535    }
536
537    /// Fetch the data of a specific on demand task.
538    pub async fn get_aws_on_demand_task(
539        &self,
540        task_id: String,
541    ) -> Result<crate::datadogV2::model::AwsOnDemandResponse, datadog::Error<GetAwsOnDemandTaskError>>
542    {
543        match self.get_aws_on_demand_task_with_http_info(task_id).await {
544            Ok(response_content) => {
545                if let Some(e) = response_content.entity {
546                    Ok(e)
547                } else {
548                    Err(datadog::Error::Serde(serde::de::Error::custom(
549                        "response content was None",
550                    )))
551                }
552            }
553            Err(err) => Err(err),
554        }
555    }
556
557    /// Fetch the data of a specific on demand task.
558    pub async fn get_aws_on_demand_task_with_http_info(
559        &self,
560        task_id: String,
561    ) -> Result<
562        datadog::ResponseContent<crate::datadogV2::model::AwsOnDemandResponse>,
563        datadog::Error<GetAwsOnDemandTaskError>,
564    > {
565        let local_configuration = &self.config;
566        let operation_id = "v2.get_aws_on_demand_task";
567
568        let local_client = &self.client;
569
570        let local_uri_str = format!(
571            "{}/api/v2/agentless_scanning/ondemand/aws/{task_id}",
572            local_configuration.get_operation_host(operation_id),
573            task_id = datadog::urlencode(task_id)
574        );
575        let mut local_req_builder =
576            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
577
578        // build headers
579        let mut headers = HeaderMap::new();
580        headers.insert("Accept", HeaderValue::from_static("application/json"));
581
582        // build user agent
583        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
584            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
585            Err(e) => {
586                log::warn!("Failed to parse user agent header: {e}, falling back to default");
587                headers.insert(
588                    reqwest::header::USER_AGENT,
589                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
590                )
591            }
592        };
593
594        // build auth
595        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
596            headers.insert(
597                "DD-API-KEY",
598                HeaderValue::from_str(local_key.key.as_str())
599                    .expect("failed to parse DD-API-KEY header"),
600            );
601        };
602        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
603            headers.insert(
604                "DD-APPLICATION-KEY",
605                HeaderValue::from_str(local_key.key.as_str())
606                    .expect("failed to parse DD-APPLICATION-KEY header"),
607            );
608        };
609
610        local_req_builder = local_req_builder.headers(headers);
611        let local_req = local_req_builder.build()?;
612        log::debug!("request content: {:?}", local_req.body());
613        let local_resp = local_client.execute(local_req).await?;
614
615        let local_status = local_resp.status();
616        let local_content = local_resp.text().await?;
617        log::debug!("response content: {}", local_content);
618
619        if !local_status.is_client_error() && !local_status.is_server_error() {
620            match serde_json::from_str::<crate::datadogV2::model::AwsOnDemandResponse>(
621                &local_content,
622            ) {
623                Ok(e) => {
624                    return Ok(datadog::ResponseContent {
625                        status: local_status,
626                        content: local_content,
627                        entity: Some(e),
628                    })
629                }
630                Err(e) => return Err(datadog::Error::Serde(e)),
631            };
632        } else {
633            let local_entity: Option<GetAwsOnDemandTaskError> =
634                serde_json::from_str(&local_content).ok();
635            let local_error = datadog::ResponseContent {
636                status: local_status,
637                content: local_content,
638                entity: local_entity,
639            };
640            Err(datadog::Error::ResponseError(local_error))
641        }
642    }
643
644    /// Fetches the most recent 1000 AWS on demand tasks.
645    pub async fn list_aws_on_demand_tasks(
646        &self,
647    ) -> Result<
648        crate::datadogV2::model::AwsOnDemandListResponse,
649        datadog::Error<ListAwsOnDemandTasksError>,
650    > {
651        match self.list_aws_on_demand_tasks_with_http_info().await {
652            Ok(response_content) => {
653                if let Some(e) = response_content.entity {
654                    Ok(e)
655                } else {
656                    Err(datadog::Error::Serde(serde::de::Error::custom(
657                        "response content was None",
658                    )))
659                }
660            }
661            Err(err) => Err(err),
662        }
663    }
664
665    /// Fetches the most recent 1000 AWS on demand tasks.
666    pub async fn list_aws_on_demand_tasks_with_http_info(
667        &self,
668    ) -> Result<
669        datadog::ResponseContent<crate::datadogV2::model::AwsOnDemandListResponse>,
670        datadog::Error<ListAwsOnDemandTasksError>,
671    > {
672        let local_configuration = &self.config;
673        let operation_id = "v2.list_aws_on_demand_tasks";
674
675        let local_client = &self.client;
676
677        let local_uri_str = format!(
678            "{}/api/v2/agentless_scanning/ondemand/aws",
679            local_configuration.get_operation_host(operation_id)
680        );
681        let mut local_req_builder =
682            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
683
684        // build headers
685        let mut headers = HeaderMap::new();
686        headers.insert("Accept", HeaderValue::from_static("application/json"));
687
688        // build user agent
689        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
690            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
691            Err(e) => {
692                log::warn!("Failed to parse user agent header: {e}, falling back to default");
693                headers.insert(
694                    reqwest::header::USER_AGENT,
695                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
696                )
697            }
698        };
699
700        // build auth
701        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
702            headers.insert(
703                "DD-API-KEY",
704                HeaderValue::from_str(local_key.key.as_str())
705                    .expect("failed to parse DD-API-KEY header"),
706            );
707        };
708        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
709            headers.insert(
710                "DD-APPLICATION-KEY",
711                HeaderValue::from_str(local_key.key.as_str())
712                    .expect("failed to parse DD-APPLICATION-KEY header"),
713            );
714        };
715
716        local_req_builder = local_req_builder.headers(headers);
717        let local_req = local_req_builder.build()?;
718        log::debug!("request content: {:?}", local_req.body());
719        let local_resp = local_client.execute(local_req).await?;
720
721        let local_status = local_resp.status();
722        let local_content = local_resp.text().await?;
723        log::debug!("response content: {}", local_content);
724
725        if !local_status.is_client_error() && !local_status.is_server_error() {
726            match serde_json::from_str::<crate::datadogV2::model::AwsOnDemandListResponse>(
727                &local_content,
728            ) {
729                Ok(e) => {
730                    return Ok(datadog::ResponseContent {
731                        status: local_status,
732                        content: local_content,
733                        entity: Some(e),
734                    })
735                }
736                Err(e) => return Err(datadog::Error::Serde(e)),
737            };
738        } else {
739            let local_entity: Option<ListAwsOnDemandTasksError> =
740                serde_json::from_str(&local_content).ok();
741            let local_error = datadog::ResponseContent {
742                status: local_status,
743                content: local_content,
744                entity: local_entity,
745            };
746            Err(datadog::Error::ResponseError(local_error))
747        }
748    }
749
750    /// Fetches the scan options configured for AWS accounts.
751    pub async fn list_aws_scan_options(
752        &self,
753    ) -> Result<
754        crate::datadogV2::model::AwsScanOptionsListResponse,
755        datadog::Error<ListAwsScanOptionsError>,
756    > {
757        match self.list_aws_scan_options_with_http_info().await {
758            Ok(response_content) => {
759                if let Some(e) = response_content.entity {
760                    Ok(e)
761                } else {
762                    Err(datadog::Error::Serde(serde::de::Error::custom(
763                        "response content was None",
764                    )))
765                }
766            }
767            Err(err) => Err(err),
768        }
769    }
770
771    /// Fetches the scan options configured for AWS accounts.
772    pub async fn list_aws_scan_options_with_http_info(
773        &self,
774    ) -> Result<
775        datadog::ResponseContent<crate::datadogV2::model::AwsScanOptionsListResponse>,
776        datadog::Error<ListAwsScanOptionsError>,
777    > {
778        let local_configuration = &self.config;
779        let operation_id = "v2.list_aws_scan_options";
780
781        let local_client = &self.client;
782
783        let local_uri_str = format!(
784            "{}/api/v2/agentless_scanning/accounts/aws",
785            local_configuration.get_operation_host(operation_id)
786        );
787        let mut local_req_builder =
788            local_client.request(reqwest::Method::GET, local_uri_str.as_str());
789
790        // build headers
791        let mut headers = HeaderMap::new();
792        headers.insert("Accept", HeaderValue::from_static("application/json"));
793
794        // build user agent
795        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
796            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
797            Err(e) => {
798                log::warn!("Failed to parse user agent header: {e}, falling back to default");
799                headers.insert(
800                    reqwest::header::USER_AGENT,
801                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
802                )
803            }
804        };
805
806        // build auth
807        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
808            headers.insert(
809                "DD-API-KEY",
810                HeaderValue::from_str(local_key.key.as_str())
811                    .expect("failed to parse DD-API-KEY header"),
812            );
813        };
814        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
815            headers.insert(
816                "DD-APPLICATION-KEY",
817                HeaderValue::from_str(local_key.key.as_str())
818                    .expect("failed to parse DD-APPLICATION-KEY header"),
819            );
820        };
821
822        local_req_builder = local_req_builder.headers(headers);
823        let local_req = local_req_builder.build()?;
824        log::debug!("request content: {:?}", local_req.body());
825        let local_resp = local_client.execute(local_req).await?;
826
827        let local_status = local_resp.status();
828        let local_content = local_resp.text().await?;
829        log::debug!("response content: {}", local_content);
830
831        if !local_status.is_client_error() && !local_status.is_server_error() {
832            match serde_json::from_str::<crate::datadogV2::model::AwsScanOptionsListResponse>(
833                &local_content,
834            ) {
835                Ok(e) => {
836                    return Ok(datadog::ResponseContent {
837                        status: local_status,
838                        content: local_content,
839                        entity: Some(e),
840                    })
841                }
842                Err(e) => return Err(datadog::Error::Serde(e)),
843            };
844        } else {
845            let local_entity: Option<ListAwsScanOptionsError> =
846                serde_json::from_str(&local_content).ok();
847            let local_error = datadog::ResponseContent {
848                status: local_status,
849                content: local_content,
850                entity: local_entity,
851            };
852            Err(datadog::Error::ResponseError(local_error))
853        }
854    }
855
856    /// Update the Agentless scan options for an activated account.
857    pub async fn update_aws_scan_options(
858        &self,
859        account_id: String,
860        body: crate::datadogV2::model::AwsScanOptionsUpdateRequest,
861    ) -> Result<(), datadog::Error<UpdateAwsScanOptionsError>> {
862        match self
863            .update_aws_scan_options_with_http_info(account_id, body)
864            .await
865        {
866            Ok(_) => Ok(()),
867            Err(err) => Err(err),
868        }
869    }
870
871    /// Update the Agentless scan options for an activated account.
872    pub async fn update_aws_scan_options_with_http_info(
873        &self,
874        account_id: String,
875        body: crate::datadogV2::model::AwsScanOptionsUpdateRequest,
876    ) -> Result<datadog::ResponseContent<()>, datadog::Error<UpdateAwsScanOptionsError>> {
877        let local_configuration = &self.config;
878        let operation_id = "v2.update_aws_scan_options";
879
880        let local_client = &self.client;
881
882        let local_uri_str = format!(
883            "{}/api/v2/agentless_scanning/accounts/aws/{account_id}",
884            local_configuration.get_operation_host(operation_id),
885            account_id = datadog::urlencode(account_id)
886        );
887        let mut local_req_builder =
888            local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
889
890        // build headers
891        let mut headers = HeaderMap::new();
892        headers.insert("Content-Type", HeaderValue::from_static("application/json"));
893        headers.insert("Accept", HeaderValue::from_static("*/*"));
894
895        // build user agent
896        match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
897            Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
898            Err(e) => {
899                log::warn!("Failed to parse user agent header: {e}, falling back to default");
900                headers.insert(
901                    reqwest::header::USER_AGENT,
902                    HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
903                )
904            }
905        };
906
907        // build auth
908        if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
909            headers.insert(
910                "DD-API-KEY",
911                HeaderValue::from_str(local_key.key.as_str())
912                    .expect("failed to parse DD-API-KEY header"),
913            );
914        };
915        if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
916            headers.insert(
917                "DD-APPLICATION-KEY",
918                HeaderValue::from_str(local_key.key.as_str())
919                    .expect("failed to parse DD-APPLICATION-KEY header"),
920            );
921        };
922
923        // build body parameters
924        let output = Vec::new();
925        let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
926        if body.serialize(&mut ser).is_ok() {
927            if let Some(content_encoding) = headers.get("Content-Encoding") {
928                match content_encoding.to_str().unwrap_or_default() {
929                    "gzip" => {
930                        let mut enc = GzEncoder::new(Vec::new(), Compression::default());
931                        let _ = enc.write_all(ser.into_inner().as_slice());
932                        match enc.finish() {
933                            Ok(buf) => {
934                                local_req_builder = local_req_builder.body(buf);
935                            }
936                            Err(e) => return Err(datadog::Error::Io(e)),
937                        }
938                    }
939                    "deflate" => {
940                        let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
941                        let _ = enc.write_all(ser.into_inner().as_slice());
942                        match enc.finish() {
943                            Ok(buf) => {
944                                local_req_builder = local_req_builder.body(buf);
945                            }
946                            Err(e) => return Err(datadog::Error::Io(e)),
947                        }
948                    }
949                    "zstd1" => {
950                        let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
951                        let _ = enc.write_all(ser.into_inner().as_slice());
952                        match enc.finish() {
953                            Ok(buf) => {
954                                local_req_builder = local_req_builder.body(buf);
955                            }
956                            Err(e) => return Err(datadog::Error::Io(e)),
957                        }
958                    }
959                    _ => {
960                        local_req_builder = local_req_builder.body(ser.into_inner());
961                    }
962                }
963            } else {
964                local_req_builder = local_req_builder.body(ser.into_inner());
965            }
966        }
967
968        local_req_builder = local_req_builder.headers(headers);
969        let local_req = local_req_builder.build()?;
970        log::debug!("request content: {:?}", local_req.body());
971        let local_resp = local_client.execute(local_req).await?;
972
973        let local_status = local_resp.status();
974        let local_content = local_resp.text().await?;
975        log::debug!("response content: {}", local_content);
976
977        if !local_status.is_client_error() && !local_status.is_server_error() {
978            Ok(datadog::ResponseContent {
979                status: local_status,
980                content: local_content,
981                entity: None,
982            })
983        } else {
984            let local_entity: Option<UpdateAwsScanOptionsError> =
985                serde_json::from_str(&local_content).ok();
986            let local_error = datadog::ResponseContent {
987                status: local_status,
988                content: local_content,
989                entity: local_entity,
990            };
991            Err(datadog::Error::ResponseError(local_error))
992        }
993    }
994}