datadog_api_client/datadogV2/model/
model_authn_mapping_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 AuthN Mapping.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct AuthNMappingAttributes {
14    /// Key portion of a key/value pair of the attribute sent from the Identity Provider.
15    #[serde(rename = "attribute_key")]
16    pub attribute_key: Option<String>,
17    /// Value portion of a key/value pair of the attribute sent from the Identity Provider.
18    #[serde(rename = "attribute_value")]
19    pub attribute_value: Option<String>,
20    /// Creation time of the AuthN Mapping.
21    #[serde(rename = "created_at")]
22    pub created_at: Option<chrono::DateTime<chrono::Utc>>,
23    /// Time of last AuthN Mapping modification.
24    #[serde(rename = "modified_at")]
25    pub modified_at: Option<chrono::DateTime<chrono::Utc>>,
26    /// The ID of the SAML assertion attribute.
27    #[serde(rename = "saml_assertion_attribute_id")]
28    pub saml_assertion_attribute_id: Option<String>,
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 AuthNMappingAttributes {
37    pub fn new() -> AuthNMappingAttributes {
38        AuthNMappingAttributes {
39            attribute_key: None,
40            attribute_value: None,
41            created_at: None,
42            modified_at: None,
43            saml_assertion_attribute_id: None,
44            additional_properties: std::collections::BTreeMap::new(),
45            _unparsed: false,
46        }
47    }
48
49    pub fn attribute_key(mut self, value: String) -> Self {
50        self.attribute_key = Some(value);
51        self
52    }
53
54    pub fn attribute_value(mut self, value: String) -> Self {
55        self.attribute_value = Some(value);
56        self
57    }
58
59    pub fn created_at(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
60        self.created_at = Some(value);
61        self
62    }
63
64    pub fn modified_at(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
65        self.modified_at = Some(value);
66        self
67    }
68
69    pub fn saml_assertion_attribute_id(mut self, value: String) -> Self {
70        self.saml_assertion_attribute_id = Some(value);
71        self
72    }
73
74    pub fn additional_properties(
75        mut self,
76        value: std::collections::BTreeMap<String, serde_json::Value>,
77    ) -> Self {
78        self.additional_properties = value;
79        self
80    }
81}
82
83impl Default for AuthNMappingAttributes {
84    fn default() -> Self {
85        Self::new()
86    }
87}
88
89impl<'de> Deserialize<'de> for AuthNMappingAttributes {
90    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
91    where
92        D: Deserializer<'de>,
93    {
94        struct AuthNMappingAttributesVisitor;
95        impl<'a> Visitor<'a> for AuthNMappingAttributesVisitor {
96            type Value = AuthNMappingAttributes;
97
98            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
99                f.write_str("a mapping")
100            }
101
102            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
103            where
104                M: MapAccess<'a>,
105            {
106                let mut attribute_key: Option<String> = None;
107                let mut attribute_value: Option<String> = None;
108                let mut created_at: Option<chrono::DateTime<chrono::Utc>> = None;
109                let mut modified_at: Option<chrono::DateTime<chrono::Utc>> = None;
110                let mut saml_assertion_attribute_id: Option<String> = None;
111                let mut additional_properties: std::collections::BTreeMap<
112                    String,
113                    serde_json::Value,
114                > = std::collections::BTreeMap::new();
115                let mut _unparsed = false;
116
117                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
118                    match k.as_str() {
119                        "attribute_key" => {
120                            if v.is_null() {
121                                continue;
122                            }
123                            attribute_key =
124                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
125                        }
126                        "attribute_value" => {
127                            if v.is_null() {
128                                continue;
129                            }
130                            attribute_value =
131                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
132                        }
133                        "created_at" => {
134                            if v.is_null() {
135                                continue;
136                            }
137                            created_at = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
138                        }
139                        "modified_at" => {
140                            if v.is_null() {
141                                continue;
142                            }
143                            modified_at =
144                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
145                        }
146                        "saml_assertion_attribute_id" => {
147                            if v.is_null() {
148                                continue;
149                            }
150                            saml_assertion_attribute_id =
151                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
152                        }
153                        &_ => {
154                            if let Ok(value) = serde_json::from_value(v.clone()) {
155                                additional_properties.insert(k, value);
156                            }
157                        }
158                    }
159                }
160
161                let content = AuthNMappingAttributes {
162                    attribute_key,
163                    attribute_value,
164                    created_at,
165                    modified_at,
166                    saml_assertion_attribute_id,
167                    additional_properties,
168                    _unparsed,
169                };
170
171                Ok(content)
172            }
173        }
174
175        deserializer.deserialize_any(AuthNMappingAttributesVisitor)
176    }
177}