datadog_api_client/datadogV1/model/
model_synthetics_basic_auth_web.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/// Object to handle basic authentication when performing the test.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct SyntheticsBasicAuthWeb {
14    /// Password to use for the basic authentication.
15    #[serde(rename = "password")]
16    pub password: Option<String>,
17    /// The type of basic authentication to use when performing the test.
18    #[serde(rename = "type")]
19    pub type_: Option<crate::datadogV1::model::SyntheticsBasicAuthWebType>,
20    /// Username to use for the basic authentication.
21    #[serde(rename = "username")]
22    pub username: Option<String>,
23    #[serde(flatten)]
24    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
25    #[serde(skip)]
26    #[serde(default)]
27    pub(crate) _unparsed: bool,
28}
29
30impl SyntheticsBasicAuthWeb {
31    pub fn new() -> SyntheticsBasicAuthWeb {
32        SyntheticsBasicAuthWeb {
33            password: None,
34            type_: None,
35            username: None,
36            additional_properties: std::collections::BTreeMap::new(),
37            _unparsed: false,
38        }
39    }
40
41    pub fn password(mut self, value: String) -> Self {
42        self.password = Some(value);
43        self
44    }
45
46    pub fn type_(mut self, value: crate::datadogV1::model::SyntheticsBasicAuthWebType) -> Self {
47        self.type_ = Some(value);
48        self
49    }
50
51    pub fn username(mut self, value: String) -> Self {
52        self.username = Some(value);
53        self
54    }
55
56    pub fn additional_properties(
57        mut self,
58        value: std::collections::BTreeMap<String, serde_json::Value>,
59    ) -> Self {
60        self.additional_properties = value;
61        self
62    }
63}
64
65impl Default for SyntheticsBasicAuthWeb {
66    fn default() -> Self {
67        Self::new()
68    }
69}
70
71impl<'de> Deserialize<'de> for SyntheticsBasicAuthWeb {
72    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
73    where
74        D: Deserializer<'de>,
75    {
76        struct SyntheticsBasicAuthWebVisitor;
77        impl<'a> Visitor<'a> for SyntheticsBasicAuthWebVisitor {
78            type Value = SyntheticsBasicAuthWeb;
79
80            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
81                f.write_str("a mapping")
82            }
83
84            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
85            where
86                M: MapAccess<'a>,
87            {
88                let mut password: Option<String> = None;
89                let mut type_: Option<crate::datadogV1::model::SyntheticsBasicAuthWebType> = None;
90                let mut username: Option<String> = None;
91                let mut additional_properties: std::collections::BTreeMap<
92                    String,
93                    serde_json::Value,
94                > = std::collections::BTreeMap::new();
95                let mut _unparsed = false;
96
97                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
98                    match k.as_str() {
99                        "password" => {
100                            if v.is_null() {
101                                continue;
102                            }
103                            password = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
104                        }
105                        "type" => {
106                            if v.is_null() {
107                                continue;
108                            }
109                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
110                            if let Some(ref _type_) = type_ {
111                                match _type_ {
112                                    crate::datadogV1::model::SyntheticsBasicAuthWebType::UnparsedObject(_type_) => {
113                                        _unparsed = true;
114                                    },
115                                    _ => {}
116                                }
117                            }
118                        }
119                        "username" => {
120                            if v.is_null() {
121                                continue;
122                            }
123                            username = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
124                        }
125                        &_ => {
126                            if let Ok(value) = serde_json::from_value(v.clone()) {
127                                additional_properties.insert(k, value);
128                            }
129                        }
130                    }
131                }
132
133                let content = SyntheticsBasicAuthWeb {
134                    password,
135                    type_,
136                    username,
137                    additional_properties,
138                    _unparsed,
139                };
140
141                Ok(content)
142            }
143        }
144
145        deserializer.deserialize_any(SyntheticsBasicAuthWebVisitor)
146    }
147}