datadog_api_client/datadogV2/model/
model_permission_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 a permission.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct PermissionAttributes {
14    /// Creation time of the permission.
15    #[serde(rename = "created")]
16    pub created: Option<chrono::DateTime<chrono::Utc>>,
17    /// Description of the permission.
18    #[serde(rename = "description")]
19    pub description: Option<String>,
20    /// Displayed name for the permission.
21    #[serde(rename = "display_name")]
22    pub display_name: Option<String>,
23    /// Display type.
24    #[serde(rename = "display_type")]
25    pub display_type: Option<String>,
26    /// Name of the permission group.
27    #[serde(rename = "group_name")]
28    pub group_name: Option<String>,
29    /// Name of the permission.
30    #[serde(rename = "name")]
31    pub name: Option<String>,
32    /// Whether or not the permission is restricted.
33    #[serde(rename = "restricted")]
34    pub restricted: Option<bool>,
35    #[serde(flatten)]
36    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
37    #[serde(skip)]
38    #[serde(default)]
39    pub(crate) _unparsed: bool,
40}
41
42impl PermissionAttributes {
43    pub fn new() -> PermissionAttributes {
44        PermissionAttributes {
45            created: None,
46            description: None,
47            display_name: None,
48            display_type: None,
49            group_name: None,
50            name: None,
51            restricted: None,
52            additional_properties: std::collections::BTreeMap::new(),
53            _unparsed: false,
54        }
55    }
56
57    pub fn created(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
58        self.created = Some(value);
59        self
60    }
61
62    pub fn description(mut self, value: String) -> Self {
63        self.description = Some(value);
64        self
65    }
66
67    pub fn display_name(mut self, value: String) -> Self {
68        self.display_name = Some(value);
69        self
70    }
71
72    pub fn display_type(mut self, value: String) -> Self {
73        self.display_type = Some(value);
74        self
75    }
76
77    pub fn group_name(mut self, value: String) -> Self {
78        self.group_name = Some(value);
79        self
80    }
81
82    pub fn name(mut self, value: String) -> Self {
83        self.name = Some(value);
84        self
85    }
86
87    pub fn restricted(mut self, value: bool) -> Self {
88        self.restricted = Some(value);
89        self
90    }
91
92    pub fn additional_properties(
93        mut self,
94        value: std::collections::BTreeMap<String, serde_json::Value>,
95    ) -> Self {
96        self.additional_properties = value;
97        self
98    }
99}
100
101impl Default for PermissionAttributes {
102    fn default() -> Self {
103        Self::new()
104    }
105}
106
107impl<'de> Deserialize<'de> for PermissionAttributes {
108    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
109    where
110        D: Deserializer<'de>,
111    {
112        struct PermissionAttributesVisitor;
113        impl<'a> Visitor<'a> for PermissionAttributesVisitor {
114            type Value = PermissionAttributes;
115
116            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
117                f.write_str("a mapping")
118            }
119
120            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
121            where
122                M: MapAccess<'a>,
123            {
124                let mut created: Option<chrono::DateTime<chrono::Utc>> = None;
125                let mut description: Option<String> = None;
126                let mut display_name: Option<String> = None;
127                let mut display_type: Option<String> = None;
128                let mut group_name: Option<String> = None;
129                let mut name: Option<String> = None;
130                let mut restricted: Option<bool> = None;
131                let mut additional_properties: std::collections::BTreeMap<
132                    String,
133                    serde_json::Value,
134                > = std::collections::BTreeMap::new();
135                let mut _unparsed = false;
136
137                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
138                    match k.as_str() {
139                        "created" => {
140                            if v.is_null() {
141                                continue;
142                            }
143                            created = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
144                        }
145                        "description" => {
146                            if v.is_null() {
147                                continue;
148                            }
149                            description =
150                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
151                        }
152                        "display_name" => {
153                            if v.is_null() {
154                                continue;
155                            }
156                            display_name =
157                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
158                        }
159                        "display_type" => {
160                            if v.is_null() {
161                                continue;
162                            }
163                            display_type =
164                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
165                        }
166                        "group_name" => {
167                            if v.is_null() {
168                                continue;
169                            }
170                            group_name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
171                        }
172                        "name" => {
173                            if v.is_null() {
174                                continue;
175                            }
176                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
177                        }
178                        "restricted" => {
179                            if v.is_null() {
180                                continue;
181                            }
182                            restricted = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
183                        }
184                        &_ => {
185                            if let Ok(value) = serde_json::from_value(v.clone()) {
186                                additional_properties.insert(k, value);
187                            }
188                        }
189                    }
190                }
191
192                let content = PermissionAttributes {
193                    created,
194                    description,
195                    display_name,
196                    display_type,
197                    group_name,
198                    name,
199                    restricted,
200                    additional_properties,
201                    _unparsed,
202                };
203
204                Ok(content)
205            }
206        }
207
208        deserializer.deserialize_any(PermissionAttributesVisitor)
209    }
210}