datadog_api_client/datadogV2/model/
model_observability_pipeline_datadog_agent_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 `datadog_agent` source collects logs from the Datadog Agent.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct ObservabilityPipelineDatadogAgentSource {
14    /// The unique identifier for this component. Used to reference this component in other parts of the pipeline (e.g., as input to downstream components).
15    #[serde(rename = "id")]
16    pub id: String,
17    /// Configuration for enabling TLS encryption between the pipeline component and external services.
18    #[serde(rename = "tls")]
19    pub tls: Option<crate::datadogV2::model::ObservabilityPipelineTls>,
20    /// The source type. The value should always be `datadog_agent`.
21    #[serde(rename = "type")]
22    pub type_: crate::datadogV2::model::ObservabilityPipelineDatadogAgentSourceType,
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 ObservabilityPipelineDatadogAgentSource {
31    pub fn new(
32        id: String,
33        type_: crate::datadogV2::model::ObservabilityPipelineDatadogAgentSourceType,
34    ) -> ObservabilityPipelineDatadogAgentSource {
35        ObservabilityPipelineDatadogAgentSource {
36            id,
37            tls: None,
38            type_,
39            additional_properties: std::collections::BTreeMap::new(),
40            _unparsed: false,
41        }
42    }
43
44    pub fn tls(mut self, value: crate::datadogV2::model::ObservabilityPipelineTls) -> Self {
45        self.tls = Some(value);
46        self
47    }
48
49    pub fn additional_properties(
50        mut self,
51        value: std::collections::BTreeMap<String, serde_json::Value>,
52    ) -> Self {
53        self.additional_properties = value;
54        self
55    }
56}
57
58impl<'de> Deserialize<'de> for ObservabilityPipelineDatadogAgentSource {
59    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
60    where
61        D: Deserializer<'de>,
62    {
63        struct ObservabilityPipelineDatadogAgentSourceVisitor;
64        impl<'a> Visitor<'a> for ObservabilityPipelineDatadogAgentSourceVisitor {
65            type Value = ObservabilityPipelineDatadogAgentSource;
66
67            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
68                f.write_str("a mapping")
69            }
70
71            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
72            where
73                M: MapAccess<'a>,
74            {
75                let mut id: Option<String> = None;
76                let mut tls: Option<crate::datadogV2::model::ObservabilityPipelineTls> = None;
77                let mut type_: Option<
78                    crate::datadogV2::model::ObservabilityPipelineDatadogAgentSourceType,
79                > = None;
80                let mut additional_properties: std::collections::BTreeMap<
81                    String,
82                    serde_json::Value,
83                > = std::collections::BTreeMap::new();
84                let mut _unparsed = false;
85
86                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
87                    match k.as_str() {
88                        "id" => {
89                            id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
90                        }
91                        "tls" => {
92                            if v.is_null() {
93                                continue;
94                            }
95                            tls = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
96                        }
97                        "type" => {
98                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
99                            if let Some(ref _type_) = type_ {
100                                match _type_ {
101                                    crate::datadogV2::model::ObservabilityPipelineDatadogAgentSourceType::UnparsedObject(_type_) => {
102                                        _unparsed = true;
103                                    },
104                                    _ => {}
105                                }
106                            }
107                        }
108                        &_ => {
109                            if let Ok(value) = serde_json::from_value(v.clone()) {
110                                additional_properties.insert(k, value);
111                            }
112                        }
113                    }
114                }
115                let id = id.ok_or_else(|| M::Error::missing_field("id"))?;
116                let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
117
118                let content = ObservabilityPipelineDatadogAgentSource {
119                    id,
120                    tls,
121                    type_,
122                    additional_properties,
123                    _unparsed,
124                };
125
126                Ok(content)
127            }
128        }
129
130        deserializer.deserialize_any(ObservabilityPipelineDatadogAgentSourceVisitor)
131    }
132}