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