datadog_api_client/datadogV2/model/
model_action_query_spec_object.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 action query spec object.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct ActionQuerySpecObject {
14    /// The connection group to use for an action query.
15    #[serde(rename = "connectionGroup")]
16    pub connection_group: Option<crate::datadogV2::model::ActionQuerySpecConnectionGroup>,
17    /// The ID of the custom connection to use for this action query.
18    #[serde(rename = "connectionId")]
19    pub connection_id: Option<String>,
20    /// The fully qualified name of the action type.
21    #[serde(rename = "fqn")]
22    pub fqn: String,
23    /// The inputs to the action query. These are the values that are passed to the action when it is triggered.
24    #[serde(rename = "inputs")]
25    pub inputs: Option<crate::datadogV2::model::ActionQuerySpecInputs>,
26    #[serde(flatten)]
27    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
28    #[serde(skip)]
29    #[serde(default)]
30    pub(crate) _unparsed: bool,
31}
32
33impl ActionQuerySpecObject {
34    pub fn new(fqn: String) -> ActionQuerySpecObject {
35        ActionQuerySpecObject {
36            connection_group: None,
37            connection_id: None,
38            fqn,
39            inputs: None,
40            additional_properties: std::collections::BTreeMap::new(),
41            _unparsed: false,
42        }
43    }
44
45    pub fn connection_group(
46        mut self,
47        value: crate::datadogV2::model::ActionQuerySpecConnectionGroup,
48    ) -> Self {
49        self.connection_group = Some(value);
50        self
51    }
52
53    pub fn connection_id(mut self, value: String) -> Self {
54        self.connection_id = Some(value);
55        self
56    }
57
58    pub fn inputs(mut self, value: crate::datadogV2::model::ActionQuerySpecInputs) -> Self {
59        self.inputs = Some(value);
60        self
61    }
62
63    pub fn additional_properties(
64        mut self,
65        value: std::collections::BTreeMap<String, serde_json::Value>,
66    ) -> Self {
67        self.additional_properties = value;
68        self
69    }
70}
71
72impl<'de> Deserialize<'de> for ActionQuerySpecObject {
73    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
74    where
75        D: Deserializer<'de>,
76    {
77        struct ActionQuerySpecObjectVisitor;
78        impl<'a> Visitor<'a> for ActionQuerySpecObjectVisitor {
79            type Value = ActionQuerySpecObject;
80
81            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
82                f.write_str("a mapping")
83            }
84
85            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
86            where
87                M: MapAccess<'a>,
88            {
89                let mut connection_group: Option<
90                    crate::datadogV2::model::ActionQuerySpecConnectionGroup,
91                > = None;
92                let mut connection_id: Option<String> = None;
93                let mut fqn: Option<String> = None;
94                let mut inputs: Option<crate::datadogV2::model::ActionQuerySpecInputs> = None;
95                let mut additional_properties: std::collections::BTreeMap<
96                    String,
97                    serde_json::Value,
98                > = std::collections::BTreeMap::new();
99                let mut _unparsed = false;
100
101                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
102                    match k.as_str() {
103                        "connectionGroup" => {
104                            if v.is_null() {
105                                continue;
106                            }
107                            connection_group =
108                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
109                        }
110                        "connectionId" => {
111                            if v.is_null() {
112                                continue;
113                            }
114                            connection_id =
115                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
116                        }
117                        "fqn" => {
118                            fqn = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
119                        }
120                        "inputs" => {
121                            if v.is_null() {
122                                continue;
123                            }
124                            inputs = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
125                            if let Some(ref _inputs) = inputs {
126                                match _inputs {
127                                    crate::datadogV2::model::ActionQuerySpecInputs::UnparsedObject(_inputs) => {
128                                        _unparsed = true;
129                                    },
130                                    _ => {}
131                                }
132                            }
133                        }
134                        &_ => {
135                            if let Ok(value) = serde_json::from_value(v.clone()) {
136                                additional_properties.insert(k, value);
137                            }
138                        }
139                    }
140                }
141                let fqn = fqn.ok_or_else(|| M::Error::missing_field("fqn"))?;
142
143                let content = ActionQuerySpecObject {
144                    connection_group,
145                    connection_id,
146                    fqn,
147                    inputs,
148                    additional_properties,
149                    _unparsed,
150                };
151
152                Ok(content)
153            }
154        }
155
156        deserializer.deserialize_any(ActionQuerySpecObjectVisitor)
157    }
158}