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    /// The API key.
21    #[serde(rename = "key")]
22    pub key: Option<String>,
23    /// The last four characters of the API key.
24    #[serde(rename = "last4")]
25    pub last4: Option<String>,
26    /// Date the API key was last modified.
27    #[serde(rename = "modified_at")]
28    pub modified_at: Option<chrono::DateTime<chrono::Utc>>,
29    /// Name of the API key.
30    #[serde(rename = "name")]
31    pub name: Option<String>,
32    /// The remote config read enabled status.
33    #[serde(rename = "remote_config_read_enabled")]
34    pub remote_config_read_enabled: 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 FullAPIKeyAttributes {
43    pub fn new() -> FullAPIKeyAttributes {
44        FullAPIKeyAttributes {
45            category: None,
46            created_at: None,
47            key: None,
48            last4: None,
49            modified_at: None,
50            name: None,
51            remote_config_read_enabled: None,
52            additional_properties: std::collections::BTreeMap::new(),
53            _unparsed: false,
54        }
55    }
56
57    pub fn category(mut self, value: String) -> Self {
58        self.category = Some(value);
59        self
60    }
61
62    pub fn created_at(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
63        self.created_at = Some(value);
64        self
65    }
66
67    pub fn key(mut self, value: String) -> Self {
68        self.key = Some(value);
69        self
70    }
71
72    pub fn last4(mut self, value: String) -> Self {
73        self.last4 = Some(value);
74        self
75    }
76
77    pub fn modified_at(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
78        self.modified_at = 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 remote_config_read_enabled(mut self, value: bool) -> Self {
88        self.remote_config_read_enabled = 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 FullAPIKeyAttributes {
102    fn default() -> Self {
103        Self::new()
104    }
105}
106
107impl<'de> Deserialize<'de> for FullAPIKeyAttributes {
108    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
109    where
110        D: Deserializer<'de>,
111    {
112        struct FullAPIKeyAttributesVisitor;
113        impl<'a> Visitor<'a> for FullAPIKeyAttributesVisitor {
114            type Value = FullAPIKeyAttributes;
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 category: Option<String> = None;
125                let mut created_at: Option<chrono::DateTime<chrono::Utc>> = None;
126                let mut key: Option<String> = None;
127                let mut last4: Option<String> = None;
128                let mut modified_at: Option<chrono::DateTime<chrono::Utc>> = None;
129                let mut name: Option<String> = None;
130                let mut remote_config_read_enabled: 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                        "category" => {
140                            if v.is_null() {
141                                continue;
142                            }
143                            category = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
144                        }
145                        "created_at" => {
146                            if v.is_null() {
147                                continue;
148                            }
149                            created_at = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
150                        }
151                        "key" => {
152                            if v.is_null() {
153                                continue;
154                            }
155                            key = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
156                        }
157                        "last4" => {
158                            if v.is_null() {
159                                continue;
160                            }
161                            last4 = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
162                        }
163                        "modified_at" => {
164                            if v.is_null() {
165                                continue;
166                            }
167                            modified_at =
168                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
169                        }
170                        "name" => {
171                            if v.is_null() {
172                                continue;
173                            }
174                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
175                        }
176                        "remote_config_read_enabled" => {
177                            if v.is_null() {
178                                continue;
179                            }
180                            remote_config_read_enabled =
181                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
182                        }
183                        &_ => {
184                            if let Ok(value) = serde_json::from_value(v.clone()) {
185                                additional_properties.insert(k, value);
186                            }
187                        }
188                    }
189                }
190
191                let content = FullAPIKeyAttributes {
192                    category,
193                    created_at,
194                    key,
195                    last4,
196                    modified_at,
197                    name,
198                    remote_config_read_enabled,
199                    additional_properties,
200                    _unparsed,
201                };
202
203                Ok(content)
204            }
205        }
206
207        deserializer.deserialize_any(FullAPIKeyAttributesVisitor)
208    }
209}