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