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