datadog_api_client/datadogV2/model/
model_datadog_api_key_update.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/// The definition of the `DatadogAPIKey` object.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct DatadogAPIKeyUpdate {
14    /// The `DatadogAPIKeyUpdate` `api_key`.
15    #[serde(rename = "api_key")]
16    pub api_key: Option<String>,
17    /// The `DatadogAPIKeyUpdate` `app_key`.
18    #[serde(rename = "app_key")]
19    pub app_key: Option<String>,
20    /// The `DatadogAPIKeyUpdate` `datacenter`.
21    #[serde(rename = "datacenter")]
22    pub datacenter: Option<String>,
23    /// Custom subdomain used for Datadog URLs generated with this Connection. For example, if this org uses `<https://acme.datadoghq.com`> to access Datadog, set this field to `acme`. If this field is omitted, generated URLs will use the default site URL for its datacenter (see [<https://docs.datadoghq.com/getting_started/site]>(<https://docs.datadoghq.com/getting_started/site>)).
24    #[serde(rename = "subdomain")]
25    pub subdomain: Option<String>,
26    /// The definition of the `DatadogAPIKey` object.
27    #[serde(rename = "type")]
28    pub type_: crate::datadogV2::model::DatadogAPIKeyType,
29    #[serde(flatten)]
30    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
31    #[serde(skip)]
32    #[serde(default)]
33    pub(crate) _unparsed: bool,
34}
35
36impl DatadogAPIKeyUpdate {
37    pub fn new(type_: crate::datadogV2::model::DatadogAPIKeyType) -> DatadogAPIKeyUpdate {
38        DatadogAPIKeyUpdate {
39            api_key: None,
40            app_key: None,
41            datacenter: None,
42            subdomain: None,
43            type_,
44            additional_properties: std::collections::BTreeMap::new(),
45            _unparsed: false,
46        }
47    }
48
49    pub fn api_key(mut self, value: String) -> Self {
50        self.api_key = Some(value);
51        self
52    }
53
54    pub fn app_key(mut self, value: String) -> Self {
55        self.app_key = Some(value);
56        self
57    }
58
59    pub fn datacenter(mut self, value: String) -> Self {
60        self.datacenter = Some(value);
61        self
62    }
63
64    pub fn subdomain(mut self, value: String) -> Self {
65        self.subdomain = Some(value);
66        self
67    }
68
69    pub fn additional_properties(
70        mut self,
71        value: std::collections::BTreeMap<String, serde_json::Value>,
72    ) -> Self {
73        self.additional_properties = value;
74        self
75    }
76}
77
78impl<'de> Deserialize<'de> for DatadogAPIKeyUpdate {
79    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
80    where
81        D: Deserializer<'de>,
82    {
83        struct DatadogAPIKeyUpdateVisitor;
84        impl<'a> Visitor<'a> for DatadogAPIKeyUpdateVisitor {
85            type Value = DatadogAPIKeyUpdate;
86
87            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
88                f.write_str("a mapping")
89            }
90
91            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
92            where
93                M: MapAccess<'a>,
94            {
95                let mut api_key: Option<String> = None;
96                let mut app_key: Option<String> = None;
97                let mut datacenter: Option<String> = None;
98                let mut subdomain: Option<String> = None;
99                let mut type_: Option<crate::datadogV2::model::DatadogAPIKeyType> = None;
100                let mut additional_properties: std::collections::BTreeMap<
101                    String,
102                    serde_json::Value,
103                > = std::collections::BTreeMap::new();
104                let mut _unparsed = false;
105
106                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
107                    match k.as_str() {
108                        "api_key" => {
109                            if v.is_null() {
110                                continue;
111                            }
112                            api_key = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
113                        }
114                        "app_key" => {
115                            if v.is_null() {
116                                continue;
117                            }
118                            app_key = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
119                        }
120                        "datacenter" => {
121                            if v.is_null() {
122                                continue;
123                            }
124                            datacenter = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
125                        }
126                        "subdomain" => {
127                            if v.is_null() {
128                                continue;
129                            }
130                            subdomain = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
131                        }
132                        "type" => {
133                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
134                            if let Some(ref _type_) = type_ {
135                                match _type_ {
136                                    crate::datadogV2::model::DatadogAPIKeyType::UnparsedObject(
137                                        _type_,
138                                    ) => {
139                                        _unparsed = true;
140                                    }
141                                    _ => {}
142                                }
143                            }
144                        }
145                        &_ => {
146                            if let Ok(value) = serde_json::from_value(v.clone()) {
147                                additional_properties.insert(k, value);
148                            }
149                        }
150                    }
151                }
152                let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
153
154                let content = DatadogAPIKeyUpdate {
155                    api_key,
156                    app_key,
157                    datacenter,
158                    subdomain,
159                    type_,
160                    additional_properties,
161                    _unparsed,
162                };
163
164                Ok(content)
165            }
166        }
167
168        deserializer.deserialize_any(DatadogAPIKeyUpdateVisitor)
169    }
170}