datadog_api_client/datadogV2/model/
model_aws_scan_options_create_attributes.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 serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9/// Attributes for the AWS scan options to create.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct AwsScanOptionsCreateAttributes {
14    /// Indicates if scanning of Lambda functions is enabled.
15    #[serde(rename = "lambda")]
16    pub lambda: bool,
17    /// Indicates if scanning for sensitive data is enabled.
18    #[serde(rename = "sensitive_data")]
19    pub sensitive_data: bool,
20    /// Indicates if scanning for vulnerabilities in containers is enabled.
21    #[serde(rename = "vuln_containers_os")]
22    pub vuln_containers_os: bool,
23    /// Indicates if scanning for vulnerabilities in hosts is enabled.
24    #[serde(rename = "vuln_host_os")]
25    pub vuln_host_os: bool,
26    #[serde(flatten)]
27    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
28    #[serde(skip)]
29    #[serde(default)]
30    pub(crate) _unparsed: bool,
31}
32
33impl AwsScanOptionsCreateAttributes {
34    pub fn new(
35        lambda: bool,
36        sensitive_data: bool,
37        vuln_containers_os: bool,
38        vuln_host_os: bool,
39    ) -> AwsScanOptionsCreateAttributes {
40        AwsScanOptionsCreateAttributes {
41            lambda,
42            sensitive_data,
43            vuln_containers_os,
44            vuln_host_os,
45            additional_properties: std::collections::BTreeMap::new(),
46            _unparsed: false,
47        }
48    }
49
50    pub fn additional_properties(
51        mut self,
52        value: std::collections::BTreeMap<String, serde_json::Value>,
53    ) -> Self {
54        self.additional_properties = value;
55        self
56    }
57}
58
59impl<'de> Deserialize<'de> for AwsScanOptionsCreateAttributes {
60    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
61    where
62        D: Deserializer<'de>,
63    {
64        struct AwsScanOptionsCreateAttributesVisitor;
65        impl<'a> Visitor<'a> for AwsScanOptionsCreateAttributesVisitor {
66            type Value = AwsScanOptionsCreateAttributes;
67
68            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
69                f.write_str("a mapping")
70            }
71
72            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
73            where
74                M: MapAccess<'a>,
75            {
76                let mut lambda: Option<bool> = None;
77                let mut sensitive_data: Option<bool> = None;
78                let mut vuln_containers_os: Option<bool> = None;
79                let mut vuln_host_os: Option<bool> = None;
80                let mut additional_properties: std::collections::BTreeMap<
81                    String,
82                    serde_json::Value,
83                > = std::collections::BTreeMap::new();
84                let mut _unparsed = false;
85
86                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
87                    match k.as_str() {
88                        "lambda" => {
89                            lambda = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
90                        }
91                        "sensitive_data" => {
92                            sensitive_data =
93                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
94                        }
95                        "vuln_containers_os" => {
96                            vuln_containers_os =
97                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
98                        }
99                        "vuln_host_os" => {
100                            vuln_host_os =
101                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
102                        }
103                        &_ => {
104                            if let Ok(value) = serde_json::from_value(v.clone()) {
105                                additional_properties.insert(k, value);
106                            }
107                        }
108                    }
109                }
110                let lambda = lambda.ok_or_else(|| M::Error::missing_field("lambda"))?;
111                let sensitive_data =
112                    sensitive_data.ok_or_else(|| M::Error::missing_field("sensitive_data"))?;
113                let vuln_containers_os = vuln_containers_os
114                    .ok_or_else(|| M::Error::missing_field("vuln_containers_os"))?;
115                let vuln_host_os =
116                    vuln_host_os.ok_or_else(|| M::Error::missing_field("vuln_host_os"))?;
117
118                let content = AwsScanOptionsCreateAttributes {
119                    lambda,
120                    sensitive_data,
121                    vuln_containers_os,
122                    vuln_host_os,
123                    additional_properties,
124                    _unparsed,
125                };
126
127                Ok(content)
128            }
129        }
130
131        deserializer.deserialize_any(AwsScanOptionsCreateAttributesVisitor)
132    }
133}