datadog_api_client/datadogV1/model/
model_logs_decoder_processor.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 decoder processor decodes any source attribute containing a
10/// base64/base16-encoded UTF-8/ASCII string back to its original value, storing the
11/// result in a target attribute.
12#[non_exhaustive]
13#[skip_serializing_none]
14#[derive(Clone, Debug, PartialEq, Serialize)]
15pub struct LogsDecoderProcessor {
16    /// The encoding used to represent the binary data.
17    #[serde(rename = "binary_to_text_encoding")]
18    pub binary_to_text_encoding: crate::datadogV1::model::LogsDecoderProcessorBinaryToTextEncoding,
19    /// The original representation of input string.
20    #[serde(rename = "input_representation")]
21    pub input_representation: crate::datadogV1::model::LogsDecoderProcessorInputRepresentation,
22    /// Whether the processor is enabled.
23    #[serde(rename = "is_enabled")]
24    pub is_enabled: Option<bool>,
25    /// Name of the processor.
26    #[serde(rename = "name")]
27    pub name: Option<String>,
28    /// Name of the log attribute with the encoded data.
29    #[serde(rename = "source")]
30    pub source: String,
31    /// Name of the log attribute that contains the decoded data.
32    #[serde(rename = "target")]
33    pub target: String,
34    /// Type of logs decoder processor.
35    #[serde(rename = "type")]
36    pub type_: crate::datadogV1::model::LogsDecoderProcessorType,
37    #[serde(flatten)]
38    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
39    #[serde(skip)]
40    #[serde(default)]
41    pub(crate) _unparsed: bool,
42}
43
44impl LogsDecoderProcessor {
45    pub fn new(
46        binary_to_text_encoding: crate::datadogV1::model::LogsDecoderProcessorBinaryToTextEncoding,
47        input_representation: crate::datadogV1::model::LogsDecoderProcessorInputRepresentation,
48        source: String,
49        target: String,
50        type_: crate::datadogV1::model::LogsDecoderProcessorType,
51    ) -> LogsDecoderProcessor {
52        LogsDecoderProcessor {
53            binary_to_text_encoding,
54            input_representation,
55            is_enabled: None,
56            name: None,
57            source,
58            target,
59            type_,
60            additional_properties: std::collections::BTreeMap::new(),
61            _unparsed: false,
62        }
63    }
64
65    pub fn is_enabled(mut self, value: bool) -> Self {
66        self.is_enabled = Some(value);
67        self
68    }
69
70    pub fn name(mut self, value: String) -> Self {
71        self.name = Some(value);
72        self
73    }
74
75    pub fn additional_properties(
76        mut self,
77        value: std::collections::BTreeMap<String, serde_json::Value>,
78    ) -> Self {
79        self.additional_properties = value;
80        self
81    }
82}
83
84impl<'de> Deserialize<'de> for LogsDecoderProcessor {
85    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
86    where
87        D: Deserializer<'de>,
88    {
89        struct LogsDecoderProcessorVisitor;
90        impl<'a> Visitor<'a> for LogsDecoderProcessorVisitor {
91            type Value = LogsDecoderProcessor;
92
93            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
94                f.write_str("a mapping")
95            }
96
97            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
98            where
99                M: MapAccess<'a>,
100            {
101                let mut binary_to_text_encoding: Option<
102                    crate::datadogV1::model::LogsDecoderProcessorBinaryToTextEncoding,
103                > = None;
104                let mut input_representation: Option<
105                    crate::datadogV1::model::LogsDecoderProcessorInputRepresentation,
106                > = None;
107                let mut is_enabled: Option<bool> = None;
108                let mut name: Option<String> = None;
109                let mut source: Option<String> = None;
110                let mut target: Option<String> = None;
111                let mut type_: Option<crate::datadogV1::model::LogsDecoderProcessorType> = None;
112                let mut additional_properties: std::collections::BTreeMap<
113                    String,
114                    serde_json::Value,
115                > = std::collections::BTreeMap::new();
116                let mut _unparsed = false;
117
118                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
119                    match k.as_str() {
120                        "binary_to_text_encoding" => {
121                            binary_to_text_encoding =
122                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
123                            if let Some(ref _binary_to_text_encoding) = binary_to_text_encoding {
124                                match _binary_to_text_encoding {
125                                    crate::datadogV1::model::LogsDecoderProcessorBinaryToTextEncoding::UnparsedObject(_binary_to_text_encoding) => {
126                                        _unparsed = true;
127                                    },
128                                    _ => {}
129                                }
130                            }
131                        }
132                        "input_representation" => {
133                            input_representation =
134                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
135                            if let Some(ref _input_representation) = input_representation {
136                                match _input_representation {
137                                    crate::datadogV1::model::LogsDecoderProcessorInputRepresentation::UnparsedObject(_input_representation) => {
138                                        _unparsed = true;
139                                    },
140                                    _ => {}
141                                }
142                            }
143                        }
144                        "is_enabled" => {
145                            if v.is_null() {
146                                continue;
147                            }
148                            is_enabled = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
149                        }
150                        "name" => {
151                            if v.is_null() {
152                                continue;
153                            }
154                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
155                        }
156                        "source" => {
157                            source = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
158                        }
159                        "target" => {
160                            target = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
161                        }
162                        "type" => {
163                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
164                            if let Some(ref _type_) = type_ {
165                                match _type_ {
166                                    crate::datadogV1::model::LogsDecoderProcessorType::UnparsedObject(_type_) => {
167                                        _unparsed = true;
168                                    },
169                                    _ => {}
170                                }
171                            }
172                        }
173                        &_ => {
174                            if let Ok(value) = serde_json::from_value(v.clone()) {
175                                additional_properties.insert(k, value);
176                            }
177                        }
178                    }
179                }
180                let binary_to_text_encoding = binary_to_text_encoding
181                    .ok_or_else(|| M::Error::missing_field("binary_to_text_encoding"))?;
182                let input_representation = input_representation
183                    .ok_or_else(|| M::Error::missing_field("input_representation"))?;
184                let source = source.ok_or_else(|| M::Error::missing_field("source"))?;
185                let target = target.ok_or_else(|| M::Error::missing_field("target"))?;
186                let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
187
188                let content = LogsDecoderProcessor {
189                    binary_to_text_encoding,
190                    input_representation,
191                    is_enabled,
192                    name,
193                    source,
194                    target,
195                    type_,
196                    additional_properties,
197                    _unparsed,
198                };
199
200                Ok(content)
201            }
202        }
203
204        deserializer.deserialize_any(LogsDecoderProcessorVisitor)
205    }
206}