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