datadog_api_client/datadogV1/model/
model_logs_pipeline_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/// Nested Pipelines are pipelines within a pipeline. Use Nested Pipelines to split the processing into two steps.
10/// For example, first use a high-level filtering such as team and then a second level of filtering based on the
11/// integration, service, or any other tag or attribute.
12///
13/// A pipeline can contain Nested Pipelines and Processors whereas a Nested Pipeline can only contain Processors.
14#[non_exhaustive]
15#[skip_serializing_none]
16#[derive(Clone, Debug, PartialEq, Serialize)]
17pub struct LogsPipelineProcessor {
18    /// Filter for logs.
19    #[serde(rename = "filter")]
20    pub filter: Option<crate::datadogV1::model::LogsFilter>,
21    /// Whether or not the processor is enabled.
22    #[serde(rename = "is_enabled")]
23    pub is_enabled: Option<bool>,
24    /// Name of the processor.
25    #[serde(rename = "name")]
26    pub name: Option<String>,
27    /// Ordered list of processors in this pipeline.
28    #[serde(rename = "processors")]
29    pub processors: Option<Vec<crate::datadogV1::model::LogsProcessor>>,
30    /// Type of logs pipeline processor.
31    #[serde(rename = "type")]
32    pub type_: crate::datadogV1::model::LogsPipelineProcessorType,
33    #[serde(flatten)]
34    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
35    #[serde(skip)]
36    #[serde(default)]
37    pub(crate) _unparsed: bool,
38}
39
40impl LogsPipelineProcessor {
41    pub fn new(type_: crate::datadogV1::model::LogsPipelineProcessorType) -> LogsPipelineProcessor {
42        LogsPipelineProcessor {
43            filter: None,
44            is_enabled: None,
45            name: None,
46            processors: None,
47            type_,
48            additional_properties: std::collections::BTreeMap::new(),
49            _unparsed: false,
50        }
51    }
52
53    pub fn filter(mut self, value: crate::datadogV1::model::LogsFilter) -> Self {
54        self.filter = Some(value);
55        self
56    }
57
58    pub fn is_enabled(mut self, value: bool) -> Self {
59        self.is_enabled = Some(value);
60        self
61    }
62
63    pub fn name(mut self, value: String) -> Self {
64        self.name = Some(value);
65        self
66    }
67
68    pub fn processors(mut self, value: Vec<crate::datadogV1::model::LogsProcessor>) -> Self {
69        self.processors = Some(value);
70        self
71    }
72
73    pub fn additional_properties(
74        mut self,
75        value: std::collections::BTreeMap<String, serde_json::Value>,
76    ) -> Self {
77        self.additional_properties = value;
78        self
79    }
80}
81
82impl<'de> Deserialize<'de> for LogsPipelineProcessor {
83    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
84    where
85        D: Deserializer<'de>,
86    {
87        struct LogsPipelineProcessorVisitor;
88        impl<'a> Visitor<'a> for LogsPipelineProcessorVisitor {
89            type Value = LogsPipelineProcessor;
90
91            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
92                f.write_str("a mapping")
93            }
94
95            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
96            where
97                M: MapAccess<'a>,
98            {
99                let mut filter: Option<crate::datadogV1::model::LogsFilter> = None;
100                let mut is_enabled: Option<bool> = None;
101                let mut name: Option<String> = None;
102                let mut processors: Option<Vec<crate::datadogV1::model::LogsProcessor>> = None;
103                let mut type_: Option<crate::datadogV1::model::LogsPipelineProcessorType> = None;
104                let mut additional_properties: std::collections::BTreeMap<
105                    String,
106                    serde_json::Value,
107                > = std::collections::BTreeMap::new();
108                let mut _unparsed = false;
109
110                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
111                    match k.as_str() {
112                        "filter" => {
113                            if v.is_null() {
114                                continue;
115                            }
116                            filter = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
117                        }
118                        "is_enabled" => {
119                            if v.is_null() {
120                                continue;
121                            }
122                            is_enabled = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
123                        }
124                        "name" => {
125                            if v.is_null() {
126                                continue;
127                            }
128                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
129                        }
130                        "processors" => {
131                            if v.is_null() {
132                                continue;
133                            }
134                            processors = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
135                        }
136                        "type" => {
137                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
138                            if let Some(ref _type_) = type_ {
139                                match _type_ {
140                                    crate::datadogV1::model::LogsPipelineProcessorType::UnparsedObject(_type_) => {
141                                        _unparsed = true;
142                                    },
143                                    _ => {}
144                                }
145                            }
146                        }
147                        &_ => {
148                            if let Ok(value) = serde_json::from_value(v.clone()) {
149                                additional_properties.insert(k, value);
150                            }
151                        }
152                    }
153                }
154                let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
155
156                let content = LogsPipelineProcessor {
157                    filter,
158                    is_enabled,
159                    name,
160                    processors,
161                    type_,
162                    additional_properties,
163                    _unparsed,
164                };
165
166                Ok(content)
167            }
168        }
169
170        deserializer.deserialize_any(LogsPipelineProcessorVisitor)
171    }
172}