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