datadog_api_client/datadogV2/model/
model_observability_pipeline_socket_destination.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 `socket` destination sends logs over TCP or UDP to a remote server.
10///
11#[non_exhaustive]
12#[skip_serializing_none]
13#[derive(Clone, Debug, PartialEq, Serialize)]
14pub struct ObservabilityPipelineSocketDestination {
15    /// Encoding format for log events.
16    #[serde(rename = "encoding")]
17    pub encoding: crate::datadogV2::model::ObservabilityPipelineSocketDestinationEncoding,
18    /// Framing method configuration.
19    #[serde(rename = "framing")]
20    pub framing: crate::datadogV2::model::ObservabilityPipelineSocketDestinationFraming,
21    /// The unique identifier for this component.
22    #[serde(rename = "id")]
23    pub id: String,
24    /// A list of component IDs whose output is used as the `input` for this component.
25    #[serde(rename = "inputs")]
26    pub inputs: Vec<String>,
27    /// Protocol used to send logs.
28    #[serde(rename = "mode")]
29    pub mode: crate::datadogV2::model::ObservabilityPipelineSocketDestinationMode,
30    /// Configuration for enabling TLS encryption between the pipeline component and external services.
31    #[serde(rename = "tls")]
32    pub tls: Option<crate::datadogV2::model::ObservabilityPipelineTls>,
33    /// The destination type. The value should always be `socket`.
34    #[serde(rename = "type")]
35    pub type_: crate::datadogV2::model::ObservabilityPipelineSocketDestinationType,
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 ObservabilityPipelineSocketDestination {
44    pub fn new(
45        encoding: crate::datadogV2::model::ObservabilityPipelineSocketDestinationEncoding,
46        framing: crate::datadogV2::model::ObservabilityPipelineSocketDestinationFraming,
47        id: String,
48        inputs: Vec<String>,
49        mode: crate::datadogV2::model::ObservabilityPipelineSocketDestinationMode,
50        type_: crate::datadogV2::model::ObservabilityPipelineSocketDestinationType,
51    ) -> ObservabilityPipelineSocketDestination {
52        ObservabilityPipelineSocketDestination {
53            encoding,
54            framing,
55            id,
56            inputs,
57            mode,
58            tls: None,
59            type_,
60            additional_properties: std::collections::BTreeMap::new(),
61            _unparsed: false,
62        }
63    }
64
65    pub fn tls(mut self, value: crate::datadogV2::model::ObservabilityPipelineTls) -> Self {
66        self.tls = Some(value);
67        self
68    }
69
70    pub fn additional_properties(
71        mut self,
72        value: std::collections::BTreeMap<String, serde_json::Value>,
73    ) -> Self {
74        self.additional_properties = value;
75        self
76    }
77}
78
79impl<'de> Deserialize<'de> for ObservabilityPipelineSocketDestination {
80    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
81    where
82        D: Deserializer<'de>,
83    {
84        struct ObservabilityPipelineSocketDestinationVisitor;
85        impl<'a> Visitor<'a> for ObservabilityPipelineSocketDestinationVisitor {
86            type Value = ObservabilityPipelineSocketDestination;
87
88            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
89                f.write_str("a mapping")
90            }
91
92            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
93            where
94                M: MapAccess<'a>,
95            {
96                let mut encoding: Option<
97                    crate::datadogV2::model::ObservabilityPipelineSocketDestinationEncoding,
98                > = None;
99                let mut framing: Option<
100                    crate::datadogV2::model::ObservabilityPipelineSocketDestinationFraming,
101                > = None;
102                let mut id: Option<String> = None;
103                let mut inputs: Option<Vec<String>> = None;
104                let mut mode: Option<
105                    crate::datadogV2::model::ObservabilityPipelineSocketDestinationMode,
106                > = None;
107                let mut tls: Option<crate::datadogV2::model::ObservabilityPipelineTls> = None;
108                let mut type_: Option<
109                    crate::datadogV2::model::ObservabilityPipelineSocketDestinationType,
110                > = None;
111                let mut additional_properties: std::collections::BTreeMap<
112                    String,
113                    serde_json::Value,
114                > = std::collections::BTreeMap::new();
115                let mut _unparsed = false;
116
117                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
118                    match k.as_str() {
119                        "encoding" => {
120                            encoding = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
121                            if let Some(ref _encoding) = encoding {
122                                match _encoding {
123                                    crate::datadogV2::model::ObservabilityPipelineSocketDestinationEncoding::UnparsedObject(_encoding) => {
124                                        _unparsed = true;
125                                    },
126                                    _ => {}
127                                }
128                            }
129                        }
130                        "framing" => {
131                            framing = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
132                            if let Some(ref _framing) = framing {
133                                match _framing {
134                                    crate::datadogV2::model::ObservabilityPipelineSocketDestinationFraming::UnparsedObject(_framing) => {
135                                        _unparsed = true;
136                                    },
137                                    _ => {}
138                                }
139                            }
140                        }
141                        "id" => {
142                            id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
143                        }
144                        "inputs" => {
145                            inputs = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
146                        }
147                        "mode" => {
148                            mode = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
149                            if let Some(ref _mode) = mode {
150                                match _mode {
151                                    crate::datadogV2::model::ObservabilityPipelineSocketDestinationMode::UnparsedObject(_mode) => {
152                                        _unparsed = true;
153                                    },
154                                    _ => {}
155                                }
156                            }
157                        }
158                        "tls" => {
159                            if v.is_null() {
160                                continue;
161                            }
162                            tls = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
163                        }
164                        "type" => {
165                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
166                            if let Some(ref _type_) = type_ {
167                                match _type_ {
168                                    crate::datadogV2::model::ObservabilityPipelineSocketDestinationType::UnparsedObject(_type_) => {
169                                        _unparsed = true;
170                                    },
171                                    _ => {}
172                                }
173                            }
174                        }
175                        &_ => {
176                            if let Ok(value) = serde_json::from_value(v.clone()) {
177                                additional_properties.insert(k, value);
178                            }
179                        }
180                    }
181                }
182                let encoding = encoding.ok_or_else(|| M::Error::missing_field("encoding"))?;
183                let framing = framing.ok_or_else(|| M::Error::missing_field("framing"))?;
184                let id = id.ok_or_else(|| M::Error::missing_field("id"))?;
185                let inputs = inputs.ok_or_else(|| M::Error::missing_field("inputs"))?;
186                let mode = mode.ok_or_else(|| M::Error::missing_field("mode"))?;
187                let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
188
189                let content = ObservabilityPipelineSocketDestination {
190                    encoding,
191                    framing,
192                    id,
193                    inputs,
194                    mode,
195                    tls,
196                    type_,
197                    additional_properties,
198                    _unparsed,
199                };
200
201                Ok(content)
202            }
203        }
204
205        deserializer.deserialize_any(ObservabilityPipelineSocketDestinationVisitor)
206    }
207}