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