datadog_api_client/datadogV2/model/
model_sensitive_data_scanner_configuration.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/// A Sensitive Data Scanner configuration.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct SensitiveDataScannerConfiguration {
14    /// ID of the configuration.
15    #[serde(rename = "id")]
16    pub id: Option<String>,
17    /// Sensitive Data Scanner configuration type.
18    #[serde(rename = "type")]
19    pub type_: Option<crate::datadogV2::model::SensitiveDataScannerConfigurationType>,
20    #[serde(flatten)]
21    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
22    #[serde(skip)]
23    #[serde(default)]
24    pub(crate) _unparsed: bool,
25}
26
27impl SensitiveDataScannerConfiguration {
28    pub fn new() -> SensitiveDataScannerConfiguration {
29        SensitiveDataScannerConfiguration {
30            id: None,
31            type_: None,
32            additional_properties: std::collections::BTreeMap::new(),
33            _unparsed: false,
34        }
35    }
36
37    pub fn id(mut self, value: String) -> Self {
38        self.id = Some(value);
39        self
40    }
41
42    pub fn type_(
43        mut self,
44        value: crate::datadogV2::model::SensitiveDataScannerConfigurationType,
45    ) -> Self {
46        self.type_ = Some(value);
47        self
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 Default for SensitiveDataScannerConfiguration {
60    fn default() -> Self {
61        Self::new()
62    }
63}
64
65impl<'de> Deserialize<'de> for SensitiveDataScannerConfiguration {
66    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
67    where
68        D: Deserializer<'de>,
69    {
70        struct SensitiveDataScannerConfigurationVisitor;
71        impl<'a> Visitor<'a> for SensitiveDataScannerConfigurationVisitor {
72            type Value = SensitiveDataScannerConfiguration;
73
74            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
75                f.write_str("a mapping")
76            }
77
78            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
79            where
80                M: MapAccess<'a>,
81            {
82                let mut id: Option<String> = None;
83                let mut type_: Option<
84                    crate::datadogV2::model::SensitiveDataScannerConfigurationType,
85                > = None;
86                let mut additional_properties: std::collections::BTreeMap<
87                    String,
88                    serde_json::Value,
89                > = std::collections::BTreeMap::new();
90                let mut _unparsed = false;
91
92                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
93                    match k.as_str() {
94                        "id" => {
95                            if v.is_null() {
96                                continue;
97                            }
98                            id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
99                        }
100                        "type" => {
101                            if v.is_null() {
102                                continue;
103                            }
104                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
105                            if let Some(ref _type_) = type_ {
106                                match _type_ {
107                                    crate::datadogV2::model::SensitiveDataScannerConfigurationType::UnparsedObject(_type_) => {
108                                        _unparsed = true;
109                                    },
110                                    _ => {}
111                                }
112                            }
113                        }
114                        &_ => {
115                            if let Ok(value) = serde_json::from_value(v.clone()) {
116                                additional_properties.insert(k, value);
117                            }
118                        }
119                    }
120                }
121
122                let content = SensitiveDataScannerConfiguration {
123                    id,
124                    type_,
125                    additional_properties,
126                    _unparsed,
127                };
128
129                Ok(content)
130            }
131        }
132
133        deserializer.deserialize_any(SensitiveDataScannerConfigurationVisitor)
134    }
135}