datadog_api_client/datadogV2/model/
model_change_event_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/// Change event attributes.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct ChangeEventAttributes {
14    /// Aggregation key of the event.
15    #[serde(rename = "aggregation_key")]
16    pub aggregation_key: Option<String>,
17    /// The entity that made the change.
18    #[serde(rename = "author")]
19    pub author: Option<crate::datadogV2::model::ChangeEventAttributesAuthor>,
20    /// JSON object of change metadata.
21    #[serde(rename = "change_metadata")]
22    pub change_metadata: Option<std::collections::BTreeMap<String, serde_json::Value>>,
23    /// A uniquely identified resource.
24    #[serde(rename = "changed_resource")]
25    pub changed_resource: Option<crate::datadogV2::model::ChangeEventAttributesChangedResource>,
26    /// JSON object of event system attributes.
27    #[serde(rename = "evt")]
28    pub evt: Option<crate::datadogV2::model::EventSystemAttributes>,
29    /// A list of resources impacted by this change.
30    #[serde(rename = "impacted_resources")]
31    pub impacted_resources:
32        Option<Vec<crate::datadogV2::model::ChangeEventAttributesImpactedResourcesItem>>,
33    /// The new state of the changed resource.
34    #[serde(rename = "new_value")]
35    pub new_value: Option<std::collections::BTreeMap<String, serde_json::Value>>,
36    /// The previous state of the changed resource.
37    #[serde(rename = "prev_value")]
38    pub prev_value: Option<std::collections::BTreeMap<String, serde_json::Value>>,
39    /// Service that triggered the event.
40    #[serde(rename = "service")]
41    pub service: Option<String>,
42    /// POSIX timestamp of the event.
43    #[serde(rename = "timestamp")]
44    pub timestamp: Option<i64>,
45    /// The title of the event.
46    #[serde(rename = "title")]
47    pub title: Option<String>,
48    #[serde(flatten)]
49    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
50    #[serde(skip)]
51    #[serde(default)]
52    pub(crate) _unparsed: bool,
53}
54
55impl ChangeEventAttributes {
56    pub fn new() -> ChangeEventAttributes {
57        ChangeEventAttributes {
58            aggregation_key: None,
59            author: None,
60            change_metadata: None,
61            changed_resource: None,
62            evt: None,
63            impacted_resources: None,
64            new_value: None,
65            prev_value: None,
66            service: None,
67            timestamp: None,
68            title: None,
69            additional_properties: std::collections::BTreeMap::new(),
70            _unparsed: false,
71        }
72    }
73
74    pub fn aggregation_key(mut self, value: String) -> Self {
75        self.aggregation_key = Some(value);
76        self
77    }
78
79    pub fn author(mut self, value: crate::datadogV2::model::ChangeEventAttributesAuthor) -> Self {
80        self.author = Some(value);
81        self
82    }
83
84    pub fn change_metadata(
85        mut self,
86        value: std::collections::BTreeMap<String, serde_json::Value>,
87    ) -> Self {
88        self.change_metadata = Some(value);
89        self
90    }
91
92    pub fn changed_resource(
93        mut self,
94        value: crate::datadogV2::model::ChangeEventAttributesChangedResource,
95    ) -> Self {
96        self.changed_resource = Some(value);
97        self
98    }
99
100    pub fn evt(mut self, value: crate::datadogV2::model::EventSystemAttributes) -> Self {
101        self.evt = Some(value);
102        self
103    }
104
105    pub fn impacted_resources(
106        mut self,
107        value: Vec<crate::datadogV2::model::ChangeEventAttributesImpactedResourcesItem>,
108    ) -> Self {
109        self.impacted_resources = Some(value);
110        self
111    }
112
113    pub fn new_value(
114        mut self,
115        value: std::collections::BTreeMap<String, serde_json::Value>,
116    ) -> Self {
117        self.new_value = Some(value);
118        self
119    }
120
121    pub fn prev_value(
122        mut self,
123        value: std::collections::BTreeMap<String, serde_json::Value>,
124    ) -> Self {
125        self.prev_value = Some(value);
126        self
127    }
128
129    pub fn service(mut self, value: String) -> Self {
130        self.service = Some(value);
131        self
132    }
133
134    pub fn timestamp(mut self, value: i64) -> Self {
135        self.timestamp = Some(value);
136        self
137    }
138
139    pub fn title(mut self, value: String) -> Self {
140        self.title = Some(value);
141        self
142    }
143
144    pub fn additional_properties(
145        mut self,
146        value: std::collections::BTreeMap<String, serde_json::Value>,
147    ) -> Self {
148        self.additional_properties = value;
149        self
150    }
151}
152
153impl Default for ChangeEventAttributes {
154    fn default() -> Self {
155        Self::new()
156    }
157}
158
159impl<'de> Deserialize<'de> for ChangeEventAttributes {
160    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
161    where
162        D: Deserializer<'de>,
163    {
164        struct ChangeEventAttributesVisitor;
165        impl<'a> Visitor<'a> for ChangeEventAttributesVisitor {
166            type Value = ChangeEventAttributes;
167
168            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
169                f.write_str("a mapping")
170            }
171
172            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
173            where
174                M: MapAccess<'a>,
175            {
176                let mut aggregation_key: Option<String> = None;
177                let mut author: Option<crate::datadogV2::model::ChangeEventAttributesAuthor> = None;
178                let mut change_metadata: Option<
179                    std::collections::BTreeMap<String, serde_json::Value>,
180                > = None;
181                let mut changed_resource: Option<
182                    crate::datadogV2::model::ChangeEventAttributesChangedResource,
183                > = None;
184                let mut evt: Option<crate::datadogV2::model::EventSystemAttributes> = None;
185                let mut impacted_resources: Option<
186                    Vec<crate::datadogV2::model::ChangeEventAttributesImpactedResourcesItem>,
187                > = None;
188                let mut new_value: Option<std::collections::BTreeMap<String, serde_json::Value>> =
189                    None;
190                let mut prev_value: Option<std::collections::BTreeMap<String, serde_json::Value>> =
191                    None;
192                let mut service: Option<String> = None;
193                let mut timestamp: Option<i64> = None;
194                let mut title: Option<String> = None;
195                let mut additional_properties: std::collections::BTreeMap<
196                    String,
197                    serde_json::Value,
198                > = std::collections::BTreeMap::new();
199                let mut _unparsed = false;
200
201                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
202                    match k.as_str() {
203                        "aggregation_key" => {
204                            if v.is_null() {
205                                continue;
206                            }
207                            aggregation_key =
208                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
209                        }
210                        "author" => {
211                            if v.is_null() {
212                                continue;
213                            }
214                            author = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
215                        }
216                        "change_metadata" => {
217                            if v.is_null() {
218                                continue;
219                            }
220                            change_metadata =
221                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
222                        }
223                        "changed_resource" => {
224                            if v.is_null() {
225                                continue;
226                            }
227                            changed_resource =
228                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
229                        }
230                        "evt" => {
231                            if v.is_null() {
232                                continue;
233                            }
234                            evt = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
235                        }
236                        "impacted_resources" => {
237                            if v.is_null() {
238                                continue;
239                            }
240                            impacted_resources =
241                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
242                        }
243                        "new_value" => {
244                            if v.is_null() {
245                                continue;
246                            }
247                            new_value = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
248                        }
249                        "prev_value" => {
250                            if v.is_null() {
251                                continue;
252                            }
253                            prev_value = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
254                        }
255                        "service" => {
256                            if v.is_null() {
257                                continue;
258                            }
259                            service = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
260                        }
261                        "timestamp" => {
262                            if v.is_null() {
263                                continue;
264                            }
265                            timestamp = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
266                        }
267                        "title" => {
268                            if v.is_null() {
269                                continue;
270                            }
271                            title = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
272                        }
273                        &_ => {
274                            if let Ok(value) = serde_json::from_value(v.clone()) {
275                                additional_properties.insert(k, value);
276                            }
277                        }
278                    }
279                }
280
281                let content = ChangeEventAttributes {
282                    aggregation_key,
283                    author,
284                    change_metadata,
285                    changed_resource,
286                    evt,
287                    impacted_resources,
288                    new_value,
289                    prev_value,
290                    service,
291                    timestamp,
292                    title,
293                    additional_properties,
294                    _unparsed,
295                };
296
297                Ok(content)
298            }
299        }
300
301        deserializer.deserialize_any(ChangeEventAttributesVisitor)
302    }
303}