datadog_api_client/datadogV2/model/
model_http_token_auth.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 `HTTPTokenAuth` object.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct HTTPTokenAuth {
14    /// The definition of `HTTPBody` object.
15    #[serde(rename = "body")]
16    pub body: Option<crate::datadogV2::model::HTTPBody>,
17    /// The `HTTPTokenAuth` `headers`.
18    #[serde(rename = "headers")]
19    pub headers: Option<Vec<crate::datadogV2::model::HTTPHeader>>,
20    /// The `HTTPTokenAuth` `tokens`.
21    #[serde(rename = "tokens")]
22    pub tokens: Option<Vec<crate::datadogV2::model::HTTPToken>>,
23    /// The definition of `HTTPTokenAuthType` object.
24    #[serde(rename = "type")]
25    pub type_: crate::datadogV2::model::HTTPTokenAuthType,
26    /// The `HTTPTokenAuth` `url_parameters`.
27    #[serde(rename = "url_parameters")]
28    pub url_parameters: Option<Vec<crate::datadogV2::model::UrlParam>>,
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 HTTPTokenAuth {
37    pub fn new(type_: crate::datadogV2::model::HTTPTokenAuthType) -> HTTPTokenAuth {
38        HTTPTokenAuth {
39            body: None,
40            headers: None,
41            tokens: None,
42            type_,
43            url_parameters: None,
44            additional_properties: std::collections::BTreeMap::new(),
45            _unparsed: false,
46        }
47    }
48
49    pub fn body(mut self, value: crate::datadogV2::model::HTTPBody) -> Self {
50        self.body = Some(value);
51        self
52    }
53
54    pub fn headers(mut self, value: Vec<crate::datadogV2::model::HTTPHeader>) -> Self {
55        self.headers = Some(value);
56        self
57    }
58
59    pub fn tokens(mut self, value: Vec<crate::datadogV2::model::HTTPToken>) -> Self {
60        self.tokens = Some(value);
61        self
62    }
63
64    pub fn url_parameters(mut self, value: Vec<crate::datadogV2::model::UrlParam>) -> Self {
65        self.url_parameters = 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 HTTPTokenAuth {
79    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
80    where
81        D: Deserializer<'de>,
82    {
83        struct HTTPTokenAuthVisitor;
84        impl<'a> Visitor<'a> for HTTPTokenAuthVisitor {
85            type Value = HTTPTokenAuth;
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 body: Option<crate::datadogV2::model::HTTPBody> = None;
96                let mut headers: Option<Vec<crate::datadogV2::model::HTTPHeader>> = None;
97                let mut tokens: Option<Vec<crate::datadogV2::model::HTTPToken>> = None;
98                let mut type_: Option<crate::datadogV2::model::HTTPTokenAuthType> = None;
99                let mut url_parameters: Option<Vec<crate::datadogV2::model::UrlParam>> = 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                        "body" => {
109                            if v.is_null() {
110                                continue;
111                            }
112                            body = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
113                        }
114                        "headers" => {
115                            if v.is_null() {
116                                continue;
117                            }
118                            headers = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
119                        }
120                        "tokens" => {
121                            if v.is_null() {
122                                continue;
123                            }
124                            tokens = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
125                        }
126                        "type" => {
127                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
128                            if let Some(ref _type_) = type_ {
129                                match _type_ {
130                                    crate::datadogV2::model::HTTPTokenAuthType::UnparsedObject(
131                                        _type_,
132                                    ) => {
133                                        _unparsed = true;
134                                    }
135                                    _ => {}
136                                }
137                            }
138                        }
139                        "url_parameters" => {
140                            if v.is_null() {
141                                continue;
142                            }
143                            url_parameters =
144                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
145                        }
146                        &_ => {
147                            if let Ok(value) = serde_json::from_value(v.clone()) {
148                                additional_properties.insert(k, value);
149                            }
150                        }
151                    }
152                }
153                let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
154
155                let content = HTTPTokenAuth {
156                    body,
157                    headers,
158                    tokens,
159                    type_,
160                    url_parameters,
161                    additional_properties,
162                    _unparsed,
163                };
164
165                Ok(content)
166            }
167        }
168
169        deserializer.deserialize_any(HTTPTokenAuthVisitor)
170    }
171}