datadog_api_client/datadogV2/model/
model_user_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/// Attributes of user object returned by the API.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct UserAttributes {
14    /// Creation time of the user.
15    #[serde(rename = "created_at")]
16    pub created_at: Option<chrono::DateTime<chrono::Utc>>,
17    /// Whether the user is disabled.
18    #[serde(rename = "disabled")]
19    pub disabled: Option<bool>,
20    /// Email of the user.
21    #[serde(rename = "email")]
22    pub email: Option<String>,
23    /// Handle of the user.
24    #[serde(rename = "handle")]
25    pub handle: Option<String>,
26    /// URL of the user's icon.
27    #[serde(rename = "icon")]
28    pub icon: Option<String>,
29    /// If user has MFA enabled.
30    #[serde(rename = "mfa_enabled")]
31    pub mfa_enabled: Option<bool>,
32    /// Time that the user was last modified.
33    #[serde(rename = "modified_at")]
34    pub modified_at: Option<chrono::DateTime<chrono::Utc>>,
35    /// Name of the user.
36    #[serde(rename = "name", default, with = "::serde_with::rust::double_option")]
37    pub name: Option<Option<String>>,
38    /// Whether the user is a service account.
39    #[serde(rename = "service_account")]
40    pub service_account: Option<bool>,
41    /// Status of the user.
42    #[serde(rename = "status")]
43    pub status: Option<String>,
44    /// Title of the user.
45    #[serde(rename = "title", default, with = "::serde_with::rust::double_option")]
46    pub title: Option<Option<String>>,
47    /// Whether the user is verified.
48    #[serde(rename = "verified")]
49    pub verified: Option<bool>,
50    #[serde(flatten)]
51    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
52    #[serde(skip)]
53    #[serde(default)]
54    pub(crate) _unparsed: bool,
55}
56
57impl UserAttributes {
58    pub fn new() -> UserAttributes {
59        UserAttributes {
60            created_at: None,
61            disabled: None,
62            email: None,
63            handle: None,
64            icon: None,
65            mfa_enabled: None,
66            modified_at: None,
67            name: None,
68            service_account: None,
69            status: None,
70            title: None,
71            verified: None,
72            additional_properties: std::collections::BTreeMap::new(),
73            _unparsed: false,
74        }
75    }
76
77    pub fn created_at(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
78        self.created_at = Some(value);
79        self
80    }
81
82    pub fn disabled(mut self, value: bool) -> Self {
83        self.disabled = Some(value);
84        self
85    }
86
87    pub fn email(mut self, value: String) -> Self {
88        self.email = Some(value);
89        self
90    }
91
92    pub fn handle(mut self, value: String) -> Self {
93        self.handle = Some(value);
94        self
95    }
96
97    pub fn icon(mut self, value: String) -> Self {
98        self.icon = Some(value);
99        self
100    }
101
102    pub fn mfa_enabled(mut self, value: bool) -> Self {
103        self.mfa_enabled = Some(value);
104        self
105    }
106
107    pub fn modified_at(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
108        self.modified_at = Some(value);
109        self
110    }
111
112    pub fn name(mut self, value: Option<String>) -> Self {
113        self.name = Some(value);
114        self
115    }
116
117    pub fn service_account(mut self, value: bool) -> Self {
118        self.service_account = Some(value);
119        self
120    }
121
122    pub fn status(mut self, value: String) -> Self {
123        self.status = Some(value);
124        self
125    }
126
127    pub fn title(mut self, value: Option<String>) -> Self {
128        self.title = Some(value);
129        self
130    }
131
132    pub fn verified(mut self, value: bool) -> Self {
133        self.verified = Some(value);
134        self
135    }
136
137    pub fn additional_properties(
138        mut self,
139        value: std::collections::BTreeMap<String, serde_json::Value>,
140    ) -> Self {
141        self.additional_properties = value;
142        self
143    }
144}
145
146impl Default for UserAttributes {
147    fn default() -> Self {
148        Self::new()
149    }
150}
151
152impl<'de> Deserialize<'de> for UserAttributes {
153    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
154    where
155        D: Deserializer<'de>,
156    {
157        struct UserAttributesVisitor;
158        impl<'a> Visitor<'a> for UserAttributesVisitor {
159            type Value = UserAttributes;
160
161            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
162                f.write_str("a mapping")
163            }
164
165            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
166            where
167                M: MapAccess<'a>,
168            {
169                let mut created_at: Option<chrono::DateTime<chrono::Utc>> = None;
170                let mut disabled: Option<bool> = None;
171                let mut email: Option<String> = None;
172                let mut handle: Option<String> = None;
173                let mut icon: Option<String> = None;
174                let mut mfa_enabled: Option<bool> = None;
175                let mut modified_at: Option<chrono::DateTime<chrono::Utc>> = None;
176                let mut name: Option<Option<String>> = None;
177                let mut service_account: Option<bool> = None;
178                let mut status: Option<String> = None;
179                let mut title: Option<Option<String>> = None;
180                let mut verified: Option<bool> = None;
181                let mut additional_properties: std::collections::BTreeMap<
182                    String,
183                    serde_json::Value,
184                > = std::collections::BTreeMap::new();
185                let mut _unparsed = false;
186
187                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
188                    match k.as_str() {
189                        "created_at" => {
190                            if v.is_null() {
191                                continue;
192                            }
193                            created_at = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
194                        }
195                        "disabled" => {
196                            if v.is_null() {
197                                continue;
198                            }
199                            disabled = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
200                        }
201                        "email" => {
202                            if v.is_null() {
203                                continue;
204                            }
205                            email = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
206                        }
207                        "handle" => {
208                            if v.is_null() {
209                                continue;
210                            }
211                            handle = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
212                        }
213                        "icon" => {
214                            if v.is_null() {
215                                continue;
216                            }
217                            icon = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
218                        }
219                        "mfa_enabled" => {
220                            if v.is_null() {
221                                continue;
222                            }
223                            mfa_enabled =
224                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
225                        }
226                        "modified_at" => {
227                            if v.is_null() {
228                                continue;
229                            }
230                            modified_at =
231                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
232                        }
233                        "name" => {
234                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
235                        }
236                        "service_account" => {
237                            if v.is_null() {
238                                continue;
239                            }
240                            service_account =
241                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
242                        }
243                        "status" => {
244                            if v.is_null() {
245                                continue;
246                            }
247                            status = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
248                        }
249                        "title" => {
250                            title = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
251                        }
252                        "verified" => {
253                            if v.is_null() {
254                                continue;
255                            }
256                            verified = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
257                        }
258                        &_ => {
259                            if let Ok(value) = serde_json::from_value(v.clone()) {
260                                additional_properties.insert(k, value);
261                            }
262                        }
263                    }
264                }
265
266                let content = UserAttributes {
267                    created_at,
268                    disabled,
269                    email,
270                    handle,
271                    icon,
272                    mfa_enabled,
273                    modified_at,
274                    name,
275                    service_account,
276                    status,
277                    title,
278                    verified,
279                    additional_properties,
280                    _unparsed,
281                };
282
283                Ok(content)
284            }
285        }
286
287        deserializer.deserialize_any(UserAttributesVisitor)
288    }
289}