datadog_api_client/datadogV2/model/
model_security_trigger.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/// Trigger a workflow from a Security Signal or Finding. For automatic triggering a handle must be configured and the workflow must be published.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct SecurityTrigger {
14    /// Defines a rate limit for a trigger.
15    #[serde(rename = "rateLimit")]
16    pub rate_limit: Option<crate::datadogV2::model::TriggerRateLimit>,
17    #[serde(flatten)]
18    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
19    #[serde(skip)]
20    #[serde(default)]
21    pub(crate) _unparsed: bool,
22}
23
24impl SecurityTrigger {
25    pub fn new() -> SecurityTrigger {
26        SecurityTrigger {
27            rate_limit: None,
28            additional_properties: std::collections::BTreeMap::new(),
29            _unparsed: false,
30        }
31    }
32
33    pub fn rate_limit(mut self, value: crate::datadogV2::model::TriggerRateLimit) -> Self {
34        self.rate_limit = Some(value);
35        self
36    }
37
38    pub fn additional_properties(
39        mut self,
40        value: std::collections::BTreeMap<String, serde_json::Value>,
41    ) -> Self {
42        self.additional_properties = value;
43        self
44    }
45}
46
47impl Default for SecurityTrigger {
48    fn default() -> Self {
49        Self::new()
50    }
51}
52
53impl<'de> Deserialize<'de> for SecurityTrigger {
54    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
55    where
56        D: Deserializer<'de>,
57    {
58        struct SecurityTriggerVisitor;
59        impl<'a> Visitor<'a> for SecurityTriggerVisitor {
60            type Value = SecurityTrigger;
61
62            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
63                f.write_str("a mapping")
64            }
65
66            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
67            where
68                M: MapAccess<'a>,
69            {
70                let mut rate_limit: Option<crate::datadogV2::model::TriggerRateLimit> = None;
71                let mut additional_properties: std::collections::BTreeMap<
72                    String,
73                    serde_json::Value,
74                > = std::collections::BTreeMap::new();
75                let mut _unparsed = false;
76
77                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
78                    match k.as_str() {
79                        "rateLimit" => {
80                            if v.is_null() {
81                                continue;
82                            }
83                            rate_limit = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
84                        }
85                        &_ => {
86                            if let Ok(value) = serde_json::from_value(v.clone()) {
87                                additional_properties.insert(k, value);
88                            }
89                        }
90                    }
91                }
92
93                let content = SecurityTrigger {
94                    rate_limit,
95                    additional_properties,
96                    _unparsed,
97                };
98
99                Ok(content)
100            }
101        }
102
103        deserializer.deserialize_any(SecurityTriggerVisitor)
104    }
105}