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