datadog_api_client/datadogV2/model/
model_aws_metrics_config.rs1use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct AWSMetricsConfig {
14 #[serde(rename = "automute_enabled")]
16 pub automute_enabled: Option<bool>,
17 #[serde(rename = "collect_cloudwatch_alarms")]
19 pub collect_cloudwatch_alarms: Option<bool>,
20 #[serde(rename = "collect_custom_metrics")]
22 pub collect_custom_metrics: Option<bool>,
23 #[serde(rename = "enabled")]
25 pub enabled: Option<bool>,
26 #[serde(rename = "namespace_filters")]
28 pub namespace_filters: Option<crate::datadogV2::model::AWSNamespaceFilters>,
29 #[serde(rename = "tag_filters")]
31 pub tag_filters: Option<Vec<crate::datadogV2::model::AWSNamespaceTagFilter>>,
32 #[serde(flatten)]
33 pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
34 #[serde(skip)]
35 #[serde(default)]
36 pub(crate) _unparsed: bool,
37}
38
39impl AWSMetricsConfig {
40 pub fn new() -> AWSMetricsConfig {
41 AWSMetricsConfig {
42 automute_enabled: None,
43 collect_cloudwatch_alarms: None,
44 collect_custom_metrics: None,
45 enabled: None,
46 namespace_filters: None,
47 tag_filters: None,
48 additional_properties: std::collections::BTreeMap::new(),
49 _unparsed: false,
50 }
51 }
52
53 pub fn automute_enabled(mut self, value: bool) -> Self {
54 self.automute_enabled = Some(value);
55 self
56 }
57
58 pub fn collect_cloudwatch_alarms(mut self, value: bool) -> Self {
59 self.collect_cloudwatch_alarms = Some(value);
60 self
61 }
62
63 pub fn collect_custom_metrics(mut self, value: bool) -> Self {
64 self.collect_custom_metrics = Some(value);
65 self
66 }
67
68 pub fn enabled(mut self, value: bool) -> Self {
69 self.enabled = Some(value);
70 self
71 }
72
73 pub fn namespace_filters(
74 mut self,
75 value: crate::datadogV2::model::AWSNamespaceFilters,
76 ) -> Self {
77 self.namespace_filters = Some(value);
78 self
79 }
80
81 pub fn tag_filters(
82 mut self,
83 value: Vec<crate::datadogV2::model::AWSNamespaceTagFilter>,
84 ) -> Self {
85 self.tag_filters = Some(value);
86 self
87 }
88
89 pub fn additional_properties(
90 mut self,
91 value: std::collections::BTreeMap<String, serde_json::Value>,
92 ) -> Self {
93 self.additional_properties = value;
94 self
95 }
96}
97
98impl Default for AWSMetricsConfig {
99 fn default() -> Self {
100 Self::new()
101 }
102}
103
104impl<'de> Deserialize<'de> for AWSMetricsConfig {
105 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
106 where
107 D: Deserializer<'de>,
108 {
109 struct AWSMetricsConfigVisitor;
110 impl<'a> Visitor<'a> for AWSMetricsConfigVisitor {
111 type Value = AWSMetricsConfig;
112
113 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
114 f.write_str("a mapping")
115 }
116
117 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
118 where
119 M: MapAccess<'a>,
120 {
121 let mut automute_enabled: Option<bool> = None;
122 let mut collect_cloudwatch_alarms: Option<bool> = None;
123 let mut collect_custom_metrics: Option<bool> = None;
124 let mut enabled: Option<bool> = None;
125 let mut namespace_filters: Option<crate::datadogV2::model::AWSNamespaceFilters> =
126 None;
127 let mut tag_filters: Option<Vec<crate::datadogV2::model::AWSNamespaceTagFilter>> =
128 None;
129 let mut additional_properties: std::collections::BTreeMap<
130 String,
131 serde_json::Value,
132 > = std::collections::BTreeMap::new();
133 let mut _unparsed = false;
134
135 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
136 match k.as_str() {
137 "automute_enabled" => {
138 if v.is_null() {
139 continue;
140 }
141 automute_enabled =
142 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
143 }
144 "collect_cloudwatch_alarms" => {
145 if v.is_null() {
146 continue;
147 }
148 collect_cloudwatch_alarms =
149 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
150 }
151 "collect_custom_metrics" => {
152 if v.is_null() {
153 continue;
154 }
155 collect_custom_metrics =
156 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
157 }
158 "enabled" => {
159 if v.is_null() {
160 continue;
161 }
162 enabled = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
163 }
164 "namespace_filters" => {
165 if v.is_null() {
166 continue;
167 }
168 namespace_filters =
169 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
170 if let Some(ref _namespace_filters) = namespace_filters {
171 match _namespace_filters {
172 crate::datadogV2::model::AWSNamespaceFilters::UnparsedObject(_namespace_filters) => {
173 _unparsed = true;
174 },
175 _ => {}
176 }
177 }
178 }
179 "tag_filters" => {
180 if v.is_null() {
181 continue;
182 }
183 tag_filters =
184 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
185 }
186 &_ => {
187 if let Ok(value) = serde_json::from_value(v.clone()) {
188 additional_properties.insert(k, value);
189 }
190 }
191 }
192 }
193
194 let content = AWSMetricsConfig {
195 automute_enabled,
196 collect_cloudwatch_alarms,
197 collect_custom_metrics,
198 enabled,
199 namespace_filters,
200 tag_filters,
201 additional_properties,
202 _unparsed,
203 };
204
205 Ok(content)
206 }
207 }
208
209 deserializer.deserialize_any(AWSMetricsConfigVisitor)
210 }
211}