datadog_api_client/datadogV2/model/
model_observability_pipeline_http_client_source.rs1use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct ObservabilityPipelineHttpClientSource {
14 #[serde(rename = "auth_strategy")]
16 pub auth_strategy:
17 Option<crate::datadogV2::model::ObservabilityPipelineHttpClientSourceAuthStrategy>,
18 #[serde(rename = "decoding")]
20 pub decoding: crate::datadogV2::model::ObservabilityPipelineDecoding,
21 #[serde(rename = "id")]
23 pub id: String,
24 #[serde(rename = "scrape_interval_secs")]
26 pub scrape_interval_secs: Option<i64>,
27 #[serde(rename = "scrape_timeout_secs")]
29 pub scrape_timeout_secs: Option<i64>,
30 #[serde(rename = "tls")]
32 pub tls: Option<crate::datadogV2::model::ObservabilityPipelineTls>,
33 #[serde(rename = "type")]
35 pub type_: crate::datadogV2::model::ObservabilityPipelineHttpClientSourceType,
36 #[serde(flatten)]
37 pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
38 #[serde(skip)]
39 #[serde(default)]
40 pub(crate) _unparsed: bool,
41}
42
43impl ObservabilityPipelineHttpClientSource {
44 pub fn new(
45 decoding: crate::datadogV2::model::ObservabilityPipelineDecoding,
46 id: String,
47 type_: crate::datadogV2::model::ObservabilityPipelineHttpClientSourceType,
48 ) -> ObservabilityPipelineHttpClientSource {
49 ObservabilityPipelineHttpClientSource {
50 auth_strategy: None,
51 decoding,
52 id,
53 scrape_interval_secs: None,
54 scrape_timeout_secs: None,
55 tls: None,
56 type_,
57 additional_properties: std::collections::BTreeMap::new(),
58 _unparsed: false,
59 }
60 }
61
62 pub fn auth_strategy(
63 mut self,
64 value: crate::datadogV2::model::ObservabilityPipelineHttpClientSourceAuthStrategy,
65 ) -> Self {
66 self.auth_strategy = Some(value);
67 self
68 }
69
70 pub fn scrape_interval_secs(mut self, value: i64) -> Self {
71 self.scrape_interval_secs = Some(value);
72 self
73 }
74
75 pub fn scrape_timeout_secs(mut self, value: i64) -> Self {
76 self.scrape_timeout_secs = Some(value);
77 self
78 }
79
80 pub fn tls(mut self, value: crate::datadogV2::model::ObservabilityPipelineTls) -> Self {
81 self.tls = Some(value);
82 self
83 }
84
85 pub fn additional_properties(
86 mut self,
87 value: std::collections::BTreeMap<String, serde_json::Value>,
88 ) -> Self {
89 self.additional_properties = value;
90 self
91 }
92}
93
94impl<'de> Deserialize<'de> for ObservabilityPipelineHttpClientSource {
95 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
96 where
97 D: Deserializer<'de>,
98 {
99 struct ObservabilityPipelineHttpClientSourceVisitor;
100 impl<'a> Visitor<'a> for ObservabilityPipelineHttpClientSourceVisitor {
101 type Value = ObservabilityPipelineHttpClientSource;
102
103 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
104 f.write_str("a mapping")
105 }
106
107 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
108 where
109 M: MapAccess<'a>,
110 {
111 let mut auth_strategy: Option<
112 crate::datadogV2::model::ObservabilityPipelineHttpClientSourceAuthStrategy,
113 > = None;
114 let mut decoding: Option<crate::datadogV2::model::ObservabilityPipelineDecoding> =
115 None;
116 let mut id: Option<String> = None;
117 let mut scrape_interval_secs: Option<i64> = None;
118 let mut scrape_timeout_secs: Option<i64> = None;
119 let mut tls: Option<crate::datadogV2::model::ObservabilityPipelineTls> = None;
120 let mut type_: Option<
121 crate::datadogV2::model::ObservabilityPipelineHttpClientSourceType,
122 > = None;
123 let mut additional_properties: std::collections::BTreeMap<
124 String,
125 serde_json::Value,
126 > = std::collections::BTreeMap::new();
127 let mut _unparsed = false;
128
129 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
130 match k.as_str() {
131 "auth_strategy" => {
132 if v.is_null() {
133 continue;
134 }
135 auth_strategy =
136 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
137 if let Some(ref _auth_strategy) = auth_strategy {
138 match _auth_strategy {
139 crate::datadogV2::model::ObservabilityPipelineHttpClientSourceAuthStrategy::UnparsedObject(_auth_strategy) => {
140 _unparsed = true;
141 },
142 _ => {}
143 }
144 }
145 }
146 "decoding" => {
147 decoding = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
148 if let Some(ref _decoding) = decoding {
149 match _decoding {
150 crate::datadogV2::model::ObservabilityPipelineDecoding::UnparsedObject(_decoding) => {
151 _unparsed = true;
152 },
153 _ => {}
154 }
155 }
156 }
157 "id" => {
158 id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
159 }
160 "scrape_interval_secs" => {
161 if v.is_null() {
162 continue;
163 }
164 scrape_interval_secs =
165 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
166 }
167 "scrape_timeout_secs" => {
168 if v.is_null() {
169 continue;
170 }
171 scrape_timeout_secs =
172 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
173 }
174 "tls" => {
175 if v.is_null() {
176 continue;
177 }
178 tls = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
179 }
180 "type" => {
181 type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
182 if let Some(ref _type_) = type_ {
183 match _type_ {
184 crate::datadogV2::model::ObservabilityPipelineHttpClientSourceType::UnparsedObject(_type_) => {
185 _unparsed = true;
186 },
187 _ => {}
188 }
189 }
190 }
191 &_ => {
192 if let Ok(value) = serde_json::from_value(v.clone()) {
193 additional_properties.insert(k, value);
194 }
195 }
196 }
197 }
198 let decoding = decoding.ok_or_else(|| M::Error::missing_field("decoding"))?;
199 let id = id.ok_or_else(|| M::Error::missing_field("id"))?;
200 let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
201
202 let content = ObservabilityPipelineHttpClientSource {
203 auth_strategy,
204 decoding,
205 id,
206 scrape_interval_secs,
207 scrape_timeout_secs,
208 tls,
209 type_,
210 additional_properties,
211 _unparsed,
212 };
213
214 Ok(content)
215 }
216 }
217
218 deserializer.deserialize_any(ObservabilityPipelineHttpClientSourceVisitor)
219 }
220}