datadog_api_client/datadogV2/model/
model_observability_pipeline_elasticsearch_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 `elasticsearch` destination writes logs to an Elasticsearch cluster.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct ObservabilityPipelineElasticsearchDestination {
14    /// The Elasticsearch API version to use. Set to `auto` to auto-detect.
15    #[serde(rename = "api_version")]
16    pub api_version:
17        Option<crate::datadogV2::model::ObservabilityPipelineElasticsearchDestinationApiVersion>,
18    /// The index to write logs to in Elasticsearch.
19    #[serde(rename = "bulk_index")]
20    pub bulk_index: Option<String>,
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    /// The destination type. The value should always be `elasticsearch`.
28    #[serde(rename = "type")]
29    pub type_: crate::datadogV2::model::ObservabilityPipelineElasticsearchDestinationType,
30    #[serde(flatten)]
31    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
32    #[serde(skip)]
33    #[serde(default)]
34    pub(crate) _unparsed: bool,
35}
36
37impl ObservabilityPipelineElasticsearchDestination {
38    pub fn new(
39        id: String,
40        inputs: Vec<String>,
41        type_: crate::datadogV2::model::ObservabilityPipelineElasticsearchDestinationType,
42    ) -> ObservabilityPipelineElasticsearchDestination {
43        ObservabilityPipelineElasticsearchDestination {
44            api_version: None,
45            bulk_index: None,
46            id,
47            inputs,
48            type_,
49            additional_properties: std::collections::BTreeMap::new(),
50            _unparsed: false,
51        }
52    }
53
54    pub fn api_version(
55        mut self,
56        value: crate::datadogV2::model::ObservabilityPipelineElasticsearchDestinationApiVersion,
57    ) -> Self {
58        self.api_version = Some(value);
59        self
60    }
61
62    pub fn bulk_index(mut self, value: String) -> Self {
63        self.bulk_index = Some(value);
64        self
65    }
66
67    pub fn additional_properties(
68        mut self,
69        value: std::collections::BTreeMap<String, serde_json::Value>,
70    ) -> Self {
71        self.additional_properties = value;
72        self
73    }
74}
75
76impl<'de> Deserialize<'de> for ObservabilityPipelineElasticsearchDestination {
77    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
78    where
79        D: Deserializer<'de>,
80    {
81        struct ObservabilityPipelineElasticsearchDestinationVisitor;
82        impl<'a> Visitor<'a> for ObservabilityPipelineElasticsearchDestinationVisitor {
83            type Value = ObservabilityPipelineElasticsearchDestination;
84
85            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
86                f.write_str("a mapping")
87            }
88
89            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
90            where
91                M: MapAccess<'a>,
92            {
93                let mut api_version: Option<crate::datadogV2::model::ObservabilityPipelineElasticsearchDestinationApiVersion> = None;
94                let mut bulk_index: Option<String> = None;
95                let mut id: Option<String> = None;
96                let mut inputs: Option<Vec<String>> = None;
97                let mut type_: Option<
98                    crate::datadogV2::model::ObservabilityPipelineElasticsearchDestinationType,
99                > = None;
100                let mut additional_properties: std::collections::BTreeMap<
101                    String,
102                    serde_json::Value,
103                > = std::collections::BTreeMap::new();
104                let mut _unparsed = false;
105
106                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
107                    match k.as_str() {
108                        "api_version" => {
109                            if v.is_null() {
110                                continue;
111                            }
112                            api_version =
113                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
114                            if let Some(ref _api_version) = api_version {
115                                match _api_version {
116                                    crate::datadogV2::model::ObservabilityPipelineElasticsearchDestinationApiVersion::UnparsedObject(_api_version) => {
117                                        _unparsed = true;
118                                    },
119                                    _ => {}
120                                }
121                            }
122                        }
123                        "bulk_index" => {
124                            if v.is_null() {
125                                continue;
126                            }
127                            bulk_index = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
128                        }
129                        "id" => {
130                            id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
131                        }
132                        "inputs" => {
133                            inputs = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
134                        }
135                        "type" => {
136                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
137                            if let Some(ref _type_) = type_ {
138                                match _type_ {
139                                    crate::datadogV2::model::ObservabilityPipelineElasticsearchDestinationType::UnparsedObject(_type_) => {
140                                        _unparsed = true;
141                                    },
142                                    _ => {}
143                                }
144                            }
145                        }
146                        &_ => {
147                            if let Ok(value) = serde_json::from_value(v.clone()) {
148                                additional_properties.insert(k, value);
149                            }
150                        }
151                    }
152                }
153                let id = id.ok_or_else(|| M::Error::missing_field("id"))?;
154                let inputs = inputs.ok_or_else(|| M::Error::missing_field("inputs"))?;
155                let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
156
157                let content = ObservabilityPipelineElasticsearchDestination {
158                    api_version,
159                    bulk_index,
160                    id,
161                    inputs,
162                    type_,
163                    additional_properties,
164                    _unparsed,
165                };
166
167                Ok(content)
168            }
169        }
170
171        deserializer.deserialize_any(ObservabilityPipelineElasticsearchDestinationVisitor)
172    }
173}