datadog_api_client/datadogV2/model/
model_observability_pipeline_http_server_source.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 `http_server` source collects logs over HTTP POST from external services.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct ObservabilityPipelineHttpServerSource {
14    /// HTTP authentication method.
15    #[serde(rename = "auth_strategy")]
16    pub auth_strategy: crate::datadogV2::model::ObservabilityPipelineHttpServerSourceAuthStrategy,
17    /// The decoding format used to interpret incoming logs.
18    #[serde(rename = "decoding")]
19    pub decoding: crate::datadogV2::model::ObservabilityPipelineDecoding,
20    /// Unique ID for the HTTP server source.
21    #[serde(rename = "id")]
22    pub id: String,
23    /// Configuration for enabling TLS encryption between the pipeline component and external services.
24    #[serde(rename = "tls")]
25    pub tls: Option<crate::datadogV2::model::ObservabilityPipelineTls>,
26    /// The source type. The value should always be `http_server`.
27    #[serde(rename = "type")]
28    pub type_: crate::datadogV2::model::ObservabilityPipelineHttpServerSourceType,
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 ObservabilityPipelineHttpServerSource {
37    pub fn new(
38        auth_strategy: crate::datadogV2::model::ObservabilityPipelineHttpServerSourceAuthStrategy,
39        decoding: crate::datadogV2::model::ObservabilityPipelineDecoding,
40        id: String,
41        type_: crate::datadogV2::model::ObservabilityPipelineHttpServerSourceType,
42    ) -> ObservabilityPipelineHttpServerSource {
43        ObservabilityPipelineHttpServerSource {
44            auth_strategy,
45            decoding,
46            id,
47            tls: None,
48            type_,
49            additional_properties: std::collections::BTreeMap::new(),
50            _unparsed: false,
51        }
52    }
53
54    pub fn tls(mut self, value: crate::datadogV2::model::ObservabilityPipelineTls) -> Self {
55        self.tls = Some(value);
56        self
57    }
58
59    pub fn additional_properties(
60        mut self,
61        value: std::collections::BTreeMap<String, serde_json::Value>,
62    ) -> Self {
63        self.additional_properties = value;
64        self
65    }
66}
67
68impl<'de> Deserialize<'de> for ObservabilityPipelineHttpServerSource {
69    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
70    where
71        D: Deserializer<'de>,
72    {
73        struct ObservabilityPipelineHttpServerSourceVisitor;
74        impl<'a> Visitor<'a> for ObservabilityPipelineHttpServerSourceVisitor {
75            type Value = ObservabilityPipelineHttpServerSource;
76
77            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
78                f.write_str("a mapping")
79            }
80
81            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
82            where
83                M: MapAccess<'a>,
84            {
85                let mut auth_strategy: Option<
86                    crate::datadogV2::model::ObservabilityPipelineHttpServerSourceAuthStrategy,
87                > = None;
88                let mut decoding: Option<crate::datadogV2::model::ObservabilityPipelineDecoding> =
89                    None;
90                let mut id: Option<String> = None;
91                let mut tls: Option<crate::datadogV2::model::ObservabilityPipelineTls> = None;
92                let mut type_: Option<
93                    crate::datadogV2::model::ObservabilityPipelineHttpServerSourceType,
94                > = None;
95                let mut additional_properties: std::collections::BTreeMap<
96                    String,
97                    serde_json::Value,
98                > = std::collections::BTreeMap::new();
99                let mut _unparsed = false;
100
101                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
102                    match k.as_str() {
103                        "auth_strategy" => {
104                            auth_strategy =
105                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
106                            if let Some(ref _auth_strategy) = auth_strategy {
107                                match _auth_strategy {
108                                    crate::datadogV2::model::ObservabilityPipelineHttpServerSourceAuthStrategy::UnparsedObject(_auth_strategy) => {
109                                        _unparsed = true;
110                                    },
111                                    _ => {}
112                                }
113                            }
114                        }
115                        "decoding" => {
116                            decoding = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
117                            if let Some(ref _decoding) = decoding {
118                                match _decoding {
119                                    crate::datadogV2::model::ObservabilityPipelineDecoding::UnparsedObject(_decoding) => {
120                                        _unparsed = true;
121                                    },
122                                    _ => {}
123                                }
124                            }
125                        }
126                        "id" => {
127                            id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
128                        }
129                        "tls" => {
130                            if v.is_null() {
131                                continue;
132                            }
133                            tls = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
134                        }
135                        "type" => {
136                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
137                            if let Some(ref _type_) = type_ {
138                                match _type_ {
139                                    crate::datadogV2::model::ObservabilityPipelineHttpServerSourceType::UnparsedObject(_type_) => {
140                                        _unparsed = true;
141                                    },
142                                    _ => {}
143                                }
144                            }
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 auth_strategy =
154                    auth_strategy.ok_or_else(|| M::Error::missing_field("auth_strategy"))?;
155                let decoding = decoding.ok_or_else(|| M::Error::missing_field("decoding"))?;
156                let id = id.ok_or_else(|| M::Error::missing_field("id"))?;
157                let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
158
159                let content = ObservabilityPipelineHttpServerSource {
160                    auth_strategy,
161                    decoding,
162                    id,
163                    tls,
164                    type_,
165                    additional_properties,
166                    _unparsed,
167                };
168
169                Ok(content)
170            }
171        }
172
173        deserializer.deserialize_any(ObservabilityPipelineHttpServerSourceVisitor)
174    }
175}