datadog_api_client/datadogV2/model/
model_finding_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/// The JSON:API attributes of the finding.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct FindingAttributes {
14    /// The Datadog relative link for this finding.
15    #[serde(rename = "datadog_link")]
16    pub datadog_link: Option<String>,
17    /// The description and remediation steps for this finding.
18    #[serde(rename = "description")]
19    pub description: Option<String>,
20    /// The evaluation of the finding.
21    #[serde(rename = "evaluation")]
22    pub evaluation: Option<crate::datadogV2::model::FindingEvaluation>,
23    /// The date on which the evaluation for this finding changed (Unix ms).
24    #[serde(rename = "evaluation_changed_at")]
25    pub evaluation_changed_at: Option<i64>,
26    /// The cloud-based ID for the resource related to the finding.
27    #[serde(rename = "external_id")]
28    pub external_id: Option<String>,
29    /// Information about the mute status of this finding.
30    #[serde(rename = "mute")]
31    pub mute: Option<crate::datadogV2::model::FindingMute>,
32    /// The resource name of this finding.
33    #[serde(rename = "resource")]
34    pub resource: Option<String>,
35    /// The date on which the resource was discovered (Unix ms).
36    #[serde(rename = "resource_discovery_date")]
37    pub resource_discovery_date: Option<i64>,
38    /// The resource type of this finding.
39    #[serde(rename = "resource_type")]
40    pub resource_type: Option<String>,
41    /// The rule that triggered this finding.
42    #[serde(rename = "rule")]
43    pub rule: Option<crate::datadogV2::model::FindingRule>,
44    /// The status of the finding.
45    #[serde(rename = "status")]
46    pub status: Option<crate::datadogV2::model::FindingStatus>,
47    /// The tags associated with this finding.
48    #[serde(rename = "tags")]
49    pub tags: Option<Vec<String>>,
50    /// The vulnerability type of the finding.
51    #[serde(rename = "vulnerability_type")]
52    pub vulnerability_type: Option<crate::datadogV2::model::FindingVulnerabilityType>,
53    #[serde(flatten)]
54    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
55    #[serde(skip)]
56    #[serde(default)]
57    pub(crate) _unparsed: bool,
58}
59
60impl FindingAttributes {
61    pub fn new() -> FindingAttributes {
62        FindingAttributes {
63            datadog_link: None,
64            description: None,
65            evaluation: None,
66            evaluation_changed_at: None,
67            external_id: None,
68            mute: None,
69            resource: None,
70            resource_discovery_date: None,
71            resource_type: None,
72            rule: None,
73            status: None,
74            tags: None,
75            vulnerability_type: None,
76            additional_properties: std::collections::BTreeMap::new(),
77            _unparsed: false,
78        }
79    }
80
81    pub fn datadog_link(mut self, value: String) -> Self {
82        self.datadog_link = Some(value);
83        self
84    }
85
86    pub fn description(mut self, value: String) -> Self {
87        self.description = Some(value);
88        self
89    }
90
91    pub fn evaluation(mut self, value: crate::datadogV2::model::FindingEvaluation) -> Self {
92        self.evaluation = Some(value);
93        self
94    }
95
96    pub fn evaluation_changed_at(mut self, value: i64) -> Self {
97        self.evaluation_changed_at = Some(value);
98        self
99    }
100
101    pub fn external_id(mut self, value: String) -> Self {
102        self.external_id = Some(value);
103        self
104    }
105
106    pub fn mute(mut self, value: crate::datadogV2::model::FindingMute) -> Self {
107        self.mute = Some(value);
108        self
109    }
110
111    pub fn resource(mut self, value: String) -> Self {
112        self.resource = Some(value);
113        self
114    }
115
116    pub fn resource_discovery_date(mut self, value: i64) -> Self {
117        self.resource_discovery_date = Some(value);
118        self
119    }
120
121    pub fn resource_type(mut self, value: String) -> Self {
122        self.resource_type = Some(value);
123        self
124    }
125
126    pub fn rule(mut self, value: crate::datadogV2::model::FindingRule) -> Self {
127        self.rule = Some(value);
128        self
129    }
130
131    pub fn status(mut self, value: crate::datadogV2::model::FindingStatus) -> Self {
132        self.status = Some(value);
133        self
134    }
135
136    pub fn tags(mut self, value: Vec<String>) -> Self {
137        self.tags = Some(value);
138        self
139    }
140
141    pub fn vulnerability_type(
142        mut self,
143        value: crate::datadogV2::model::FindingVulnerabilityType,
144    ) -> Self {
145        self.vulnerability_type = Some(value);
146        self
147    }
148
149    pub fn additional_properties(
150        mut self,
151        value: std::collections::BTreeMap<String, serde_json::Value>,
152    ) -> Self {
153        self.additional_properties = value;
154        self
155    }
156}
157
158impl Default for FindingAttributes {
159    fn default() -> Self {
160        Self::new()
161    }
162}
163
164impl<'de> Deserialize<'de> for FindingAttributes {
165    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
166    where
167        D: Deserializer<'de>,
168    {
169        struct FindingAttributesVisitor;
170        impl<'a> Visitor<'a> for FindingAttributesVisitor {
171            type Value = FindingAttributes;
172
173            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
174                f.write_str("a mapping")
175            }
176
177            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
178            where
179                M: MapAccess<'a>,
180            {
181                let mut datadog_link: Option<String> = None;
182                let mut description: Option<String> = None;
183                let mut evaluation: Option<crate::datadogV2::model::FindingEvaluation> = None;
184                let mut evaluation_changed_at: Option<i64> = None;
185                let mut external_id: Option<String> = None;
186                let mut mute: Option<crate::datadogV2::model::FindingMute> = None;
187                let mut resource: Option<String> = None;
188                let mut resource_discovery_date: Option<i64> = None;
189                let mut resource_type: Option<String> = None;
190                let mut rule: Option<crate::datadogV2::model::FindingRule> = None;
191                let mut status: Option<crate::datadogV2::model::FindingStatus> = None;
192                let mut tags: Option<Vec<String>> = None;
193                let mut vulnerability_type: Option<
194                    crate::datadogV2::model::FindingVulnerabilityType,
195                > = None;
196                let mut additional_properties: std::collections::BTreeMap<
197                    String,
198                    serde_json::Value,
199                > = std::collections::BTreeMap::new();
200                let mut _unparsed = false;
201
202                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
203                    match k.as_str() {
204                        "datadog_link" => {
205                            if v.is_null() {
206                                continue;
207                            }
208                            datadog_link =
209                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
210                        }
211                        "description" => {
212                            if v.is_null() {
213                                continue;
214                            }
215                            description =
216                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
217                        }
218                        "evaluation" => {
219                            if v.is_null() {
220                                continue;
221                            }
222                            evaluation = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
223                            if let Some(ref _evaluation) = evaluation {
224                                match _evaluation {
225                                    crate::datadogV2::model::FindingEvaluation::UnparsedObject(
226                                        _evaluation,
227                                    ) => {
228                                        _unparsed = true;
229                                    }
230                                    _ => {}
231                                }
232                            }
233                        }
234                        "evaluation_changed_at" => {
235                            if v.is_null() {
236                                continue;
237                            }
238                            evaluation_changed_at =
239                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
240                        }
241                        "external_id" => {
242                            if v.is_null() {
243                                continue;
244                            }
245                            external_id =
246                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
247                        }
248                        "mute" => {
249                            if v.is_null() {
250                                continue;
251                            }
252                            mute = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
253                        }
254                        "resource" => {
255                            if v.is_null() {
256                                continue;
257                            }
258                            resource = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
259                        }
260                        "resource_discovery_date" => {
261                            if v.is_null() {
262                                continue;
263                            }
264                            resource_discovery_date =
265                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
266                        }
267                        "resource_type" => {
268                            if v.is_null() {
269                                continue;
270                            }
271                            resource_type =
272                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
273                        }
274                        "rule" => {
275                            if v.is_null() {
276                                continue;
277                            }
278                            rule = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
279                        }
280                        "status" => {
281                            if v.is_null() {
282                                continue;
283                            }
284                            status = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
285                            if let Some(ref _status) = status {
286                                match _status {
287                                    crate::datadogV2::model::FindingStatus::UnparsedObject(
288                                        _status,
289                                    ) => {
290                                        _unparsed = true;
291                                    }
292                                    _ => {}
293                                }
294                            }
295                        }
296                        "tags" => {
297                            if v.is_null() {
298                                continue;
299                            }
300                            tags = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
301                        }
302                        "vulnerability_type" => {
303                            if v.is_null() {
304                                continue;
305                            }
306                            vulnerability_type =
307                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
308                            if let Some(ref _vulnerability_type) = vulnerability_type {
309                                match _vulnerability_type {
310                                    crate::datadogV2::model::FindingVulnerabilityType::UnparsedObject(_vulnerability_type) => {
311                                        _unparsed = true;
312                                    },
313                                    _ => {}
314                                }
315                            }
316                        }
317                        &_ => {
318                            if let Ok(value) = serde_json::from_value(v.clone()) {
319                                additional_properties.insert(k, value);
320                            }
321                        }
322                    }
323                }
324
325                let content = FindingAttributes {
326                    datadog_link,
327                    description,
328                    evaluation,
329                    evaluation_changed_at,
330                    external_id,
331                    mute,
332                    resource,
333                    resource_discovery_date,
334                    resource_type,
335                    rule,
336                    status,
337                    tags,
338                    vulnerability_type,
339                    additional_properties,
340                    _unparsed,
341                };
342
343                Ok(content)
344            }
345        }
346
347        deserializer.deserialize_any(FindingAttributesVisitor)
348    }
349}