datadog_api_client/datadogV2/model/
model_workflow_data_update_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 definition of `WorkflowDataUpdateAttributes` object.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct WorkflowDataUpdateAttributes {
14    /// When the workflow was created.
15    #[serde(rename = "createdAt")]
16    pub created_at: Option<chrono::DateTime<chrono::Utc>>,
17    /// Description of the workflow.
18    #[serde(rename = "description")]
19    pub description: Option<String>,
20    /// Name of the workflow.
21    #[serde(rename = "name")]
22    pub name: Option<String>,
23    /// Set the workflow to published or unpublished. Workflows in an unpublished state will only be executable via manual runs. Automatic triggers such as Schedule will not execute the workflow until it is published.
24    #[serde(rename = "published")]
25    pub published: Option<bool>,
26    /// The spec defines what the workflow does.
27    #[serde(rename = "spec")]
28    pub spec: Option<crate::datadogV2::model::Spec>,
29    /// Tags of the workflow.
30    #[serde(rename = "tags")]
31    pub tags: Option<Vec<String>>,
32    /// When the workflow was last updated.
33    #[serde(rename = "updatedAt")]
34    pub updated_at: Option<chrono::DateTime<chrono::Utc>>,
35    /// If a Webhook trigger is defined on this workflow, a webhookSecret is required and should be provided here.
36    #[serde(rename = "webhookSecret")]
37    pub webhook_secret: Option<String>,
38    #[serde(flatten)]
39    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
40    #[serde(skip)]
41    #[serde(default)]
42    pub(crate) _unparsed: bool,
43}
44
45impl WorkflowDataUpdateAttributes {
46    pub fn new() -> WorkflowDataUpdateAttributes {
47        WorkflowDataUpdateAttributes {
48            created_at: None,
49            description: None,
50            name: None,
51            published: None,
52            spec: None,
53            tags: None,
54            updated_at: None,
55            webhook_secret: None,
56            additional_properties: std::collections::BTreeMap::new(),
57            _unparsed: false,
58        }
59    }
60
61    pub fn created_at(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
62        self.created_at = Some(value);
63        self
64    }
65
66    pub fn description(mut self, value: String) -> Self {
67        self.description = Some(value);
68        self
69    }
70
71    pub fn name(mut self, value: String) -> Self {
72        self.name = Some(value);
73        self
74    }
75
76    pub fn published(mut self, value: bool) -> Self {
77        self.published = Some(value);
78        self
79    }
80
81    pub fn spec(mut self, value: crate::datadogV2::model::Spec) -> Self {
82        self.spec = Some(value);
83        self
84    }
85
86    pub fn tags(mut self, value: Vec<String>) -> Self {
87        self.tags = Some(value);
88        self
89    }
90
91    pub fn updated_at(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
92        self.updated_at = Some(value);
93        self
94    }
95
96    pub fn webhook_secret(mut self, value: String) -> Self {
97        self.webhook_secret = Some(value);
98        self
99    }
100
101    pub fn additional_properties(
102        mut self,
103        value: std::collections::BTreeMap<String, serde_json::Value>,
104    ) -> Self {
105        self.additional_properties = value;
106        self
107    }
108}
109
110impl Default for WorkflowDataUpdateAttributes {
111    fn default() -> Self {
112        Self::new()
113    }
114}
115
116impl<'de> Deserialize<'de> for WorkflowDataUpdateAttributes {
117    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
118    where
119        D: Deserializer<'de>,
120    {
121        struct WorkflowDataUpdateAttributesVisitor;
122        impl<'a> Visitor<'a> for WorkflowDataUpdateAttributesVisitor {
123            type Value = WorkflowDataUpdateAttributes;
124
125            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
126                f.write_str("a mapping")
127            }
128
129            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
130            where
131                M: MapAccess<'a>,
132            {
133                let mut created_at: Option<chrono::DateTime<chrono::Utc>> = None;
134                let mut description: Option<String> = None;
135                let mut name: Option<String> = None;
136                let mut published: Option<bool> = None;
137                let mut spec: Option<crate::datadogV2::model::Spec> = None;
138                let mut tags: Option<Vec<String>> = None;
139                let mut updated_at: Option<chrono::DateTime<chrono::Utc>> = None;
140                let mut webhook_secret: Option<String> = None;
141                let mut additional_properties: std::collections::BTreeMap<
142                    String,
143                    serde_json::Value,
144                > = std::collections::BTreeMap::new();
145                let mut _unparsed = false;
146
147                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
148                    match k.as_str() {
149                        "createdAt" => {
150                            if v.is_null() {
151                                continue;
152                            }
153                            created_at = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
154                        }
155                        "description" => {
156                            if v.is_null() {
157                                continue;
158                            }
159                            description =
160                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
161                        }
162                        "name" => {
163                            if v.is_null() {
164                                continue;
165                            }
166                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
167                        }
168                        "published" => {
169                            if v.is_null() {
170                                continue;
171                            }
172                            published = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
173                        }
174                        "spec" => {
175                            if v.is_null() {
176                                continue;
177                            }
178                            spec = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
179                        }
180                        "tags" => {
181                            if v.is_null() {
182                                continue;
183                            }
184                            tags = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
185                        }
186                        "updatedAt" => {
187                            if v.is_null() {
188                                continue;
189                            }
190                            updated_at = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
191                        }
192                        "webhookSecret" => {
193                            if v.is_null() {
194                                continue;
195                            }
196                            webhook_secret =
197                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
198                        }
199                        &_ => {
200                            if let Ok(value) = serde_json::from_value(v.clone()) {
201                                additional_properties.insert(k, value);
202                            }
203                        }
204                    }
205                }
206
207                let content = WorkflowDataUpdateAttributes {
208                    created_at,
209                    description,
210                    name,
211                    published,
212                    spec,
213                    tags,
214                    updated_at,
215                    webhook_secret,
216                    additional_properties,
217                    _unparsed,
218                };
219
220                Ok(content)
221            }
222        }
223
224        deserializer.deserialize_any(WorkflowDataUpdateAttributesVisitor)
225    }
226}