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