datadog_api_client/datadogV2/model/
model_api_key_update_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 used to update an API Key.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct APIKeyUpdateAttributes {
14    /// The APIKeyUpdateAttributes category.
15    #[serde(rename = "category")]
16    pub category: Option<String>,
17    /// Name of the API key.
18    #[serde(rename = "name")]
19    pub name: String,
20    /// The APIKeyUpdateAttributes remote_config_read_enabled.
21    #[serde(rename = "remote_config_read_enabled")]
22    pub remote_config_read_enabled: Option<bool>,
23    #[serde(flatten)]
24    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
25    #[serde(skip)]
26    #[serde(default)]
27    pub(crate) _unparsed: bool,
28}
29
30impl APIKeyUpdateAttributes {
31    pub fn new(name: String) -> APIKeyUpdateAttributes {
32        APIKeyUpdateAttributes {
33            category: None,
34            name,
35            remote_config_read_enabled: None,
36            additional_properties: std::collections::BTreeMap::new(),
37            _unparsed: false,
38        }
39    }
40
41    pub fn category(mut self, value: String) -> Self {
42        self.category = Some(value);
43        self
44    }
45
46    pub fn remote_config_read_enabled(mut self, value: bool) -> Self {
47        self.remote_config_read_enabled = Some(value);
48        self
49    }
50
51    pub fn additional_properties(
52        mut self,
53        value: std::collections::BTreeMap<String, serde_json::Value>,
54    ) -> Self {
55        self.additional_properties = value;
56        self
57    }
58}
59
60impl<'de> Deserialize<'de> for APIKeyUpdateAttributes {
61    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
62    where
63        D: Deserializer<'de>,
64    {
65        struct APIKeyUpdateAttributesVisitor;
66        impl<'a> Visitor<'a> for APIKeyUpdateAttributesVisitor {
67            type Value = APIKeyUpdateAttributes;
68
69            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
70                f.write_str("a mapping")
71            }
72
73            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
74            where
75                M: MapAccess<'a>,
76            {
77                let mut category: Option<String> = None;
78                let mut name: Option<String> = None;
79                let mut remote_config_read_enabled: Option<bool> = None;
80                let mut additional_properties: std::collections::BTreeMap<
81                    String,
82                    serde_json::Value,
83                > = std::collections::BTreeMap::new();
84                let mut _unparsed = false;
85
86                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
87                    match k.as_str() {
88                        "category" => {
89                            if v.is_null() {
90                                continue;
91                            }
92                            category = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
93                        }
94                        "name" => {
95                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
96                        }
97                        "remote_config_read_enabled" => {
98                            if v.is_null() {
99                                continue;
100                            }
101                            remote_config_read_enabled =
102                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
103                        }
104                        &_ => {
105                            if let Ok(value) = serde_json::from_value(v.clone()) {
106                                additional_properties.insert(k, value);
107                            }
108                        }
109                    }
110                }
111                let name = name.ok_or_else(|| M::Error::missing_field("name"))?;
112
113                let content = APIKeyUpdateAttributes {
114                    category,
115                    name,
116                    remote_config_read_enabled,
117                    additional_properties,
118                    _unparsed,
119                };
120
121                Ok(content)
122            }
123        }
124
125        deserializer.deserialize_any(APIKeyUpdateAttributesVisitor)
126    }
127}