datadog_api_client/datadogV2/model/
model_custom_destination_create_request_attributes.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 attributes associated with the custom destination.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct CustomDestinationCreateRequestAttributes {
14    /// Whether logs matching this custom destination should be forwarded or not.
15    #[serde(rename = "enabled")]
16    pub enabled: Option<bool>,
17    /// Whether tags from the forwarded logs should be forwarded or not.
18    #[serde(rename = "forward_tags")]
19    pub forward_tags: Option<bool>,
20    /// List of [keys of tags](<https://docs.datadoghq.com/getting_started/tagging/#define-tags>) to be filtered.
21    ///
22    /// An empty list represents no restriction is in place and either all or no tags will be
23    /// forwarded depending on `forward_tags_restriction_list_type` parameter.
24    #[serde(rename = "forward_tags_restriction_list")]
25    pub forward_tags_restriction_list: Option<Vec<String>>,
26    /// How `forward_tags_restriction_list` parameter should be interpreted.
27    /// If `ALLOW_LIST`, then only tags whose keys on the forwarded logs match the ones on the restriction list
28    /// are forwarded.
29    ///
30    /// `BLOCK_LIST` works the opposite way. It does not forward the tags matching the ones on the list.
31    #[serde(rename = "forward_tags_restriction_list_type")]
32    pub forward_tags_restriction_list_type:
33        Option<crate::datadogV2::model::CustomDestinationAttributeTagsRestrictionListType>,
34    /// A custom destination's location to forward logs.
35    #[serde(rename = "forwarder_destination")]
36    pub forwarder_destination: crate::datadogV2::model::CustomDestinationForwardDestination,
37    /// The custom destination name.
38    #[serde(rename = "name")]
39    pub name: String,
40    /// The custom destination query and filter. Logs matching this query are forwarded to the destination.
41    #[serde(rename = "query")]
42    pub query: Option<String>,
43    #[serde(flatten)]
44    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
45    #[serde(skip)]
46    #[serde(default)]
47    pub(crate) _unparsed: bool,
48}
49
50impl CustomDestinationCreateRequestAttributes {
51    pub fn new(
52        forwarder_destination: crate::datadogV2::model::CustomDestinationForwardDestination,
53        name: String,
54    ) -> CustomDestinationCreateRequestAttributes {
55        CustomDestinationCreateRequestAttributes {
56            enabled: None,
57            forward_tags: None,
58            forward_tags_restriction_list: None,
59            forward_tags_restriction_list_type: None,
60            forwarder_destination,
61            name,
62            query: None,
63            additional_properties: std::collections::BTreeMap::new(),
64            _unparsed: false,
65        }
66    }
67
68    pub fn enabled(mut self, value: bool) -> Self {
69        self.enabled = Some(value);
70        self
71    }
72
73    pub fn forward_tags(mut self, value: bool) -> Self {
74        self.forward_tags = Some(value);
75        self
76    }
77
78    pub fn forward_tags_restriction_list(mut self, value: Vec<String>) -> Self {
79        self.forward_tags_restriction_list = Some(value);
80        self
81    }
82
83    pub fn forward_tags_restriction_list_type(
84        mut self,
85        value: crate::datadogV2::model::CustomDestinationAttributeTagsRestrictionListType,
86    ) -> Self {
87        self.forward_tags_restriction_list_type = Some(value);
88        self
89    }
90
91    pub fn query(mut self, value: String) -> Self {
92        self.query = Some(value);
93        self
94    }
95
96    pub fn additional_properties(
97        mut self,
98        value: std::collections::BTreeMap<String, serde_json::Value>,
99    ) -> Self {
100        self.additional_properties = value;
101        self
102    }
103}
104
105impl<'de> Deserialize<'de> for CustomDestinationCreateRequestAttributes {
106    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
107    where
108        D: Deserializer<'de>,
109    {
110        struct CustomDestinationCreateRequestAttributesVisitor;
111        impl<'a> Visitor<'a> for CustomDestinationCreateRequestAttributesVisitor {
112            type Value = CustomDestinationCreateRequestAttributes;
113
114            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
115                f.write_str("a mapping")
116            }
117
118            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
119            where
120                M: MapAccess<'a>,
121            {
122                let mut enabled: Option<bool> = None;
123                let mut forward_tags: Option<bool> = None;
124                let mut forward_tags_restriction_list: Option<Vec<String>> = None;
125                let mut forward_tags_restriction_list_type: Option<
126                    crate::datadogV2::model::CustomDestinationAttributeTagsRestrictionListType,
127                > = None;
128                let mut forwarder_destination: Option<
129                    crate::datadogV2::model::CustomDestinationForwardDestination,
130                > = None;
131                let mut name: Option<String> = None;
132                let mut query: Option<String> = None;
133                let mut additional_properties: std::collections::BTreeMap<
134                    String,
135                    serde_json::Value,
136                > = std::collections::BTreeMap::new();
137                let mut _unparsed = false;
138
139                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
140                    match k.as_str() {
141                        "enabled" => {
142                            if v.is_null() {
143                                continue;
144                            }
145                            enabled = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
146                        }
147                        "forward_tags" => {
148                            if v.is_null() {
149                                continue;
150                            }
151                            forward_tags =
152                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
153                        }
154                        "forward_tags_restriction_list" => {
155                            if v.is_null() {
156                                continue;
157                            }
158                            forward_tags_restriction_list =
159                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
160                        }
161                        "forward_tags_restriction_list_type" => {
162                            if v.is_null() {
163                                continue;
164                            }
165                            forward_tags_restriction_list_type =
166                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
167                            if let Some(ref _forward_tags_restriction_list_type) =
168                                forward_tags_restriction_list_type
169                            {
170                                match _forward_tags_restriction_list_type {
171                                    crate::datadogV2::model::CustomDestinationAttributeTagsRestrictionListType::UnparsedObject(_forward_tags_restriction_list_type) => {
172                                        _unparsed = true;
173                                    },
174                                    _ => {}
175                                }
176                            }
177                        }
178                        "forwarder_destination" => {
179                            forwarder_destination =
180                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
181                            if let Some(ref _forwarder_destination) = forwarder_destination {
182                                match _forwarder_destination {
183                                    crate::datadogV2::model::CustomDestinationForwardDestination::UnparsedObject(_forwarder_destination) => {
184                                        _unparsed = true;
185                                    },
186                                    _ => {}
187                                }
188                            }
189                        }
190                        "name" => {
191                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
192                        }
193                        "query" => {
194                            if v.is_null() {
195                                continue;
196                            }
197                            query = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
198                        }
199                        &_ => {
200                            if let Ok(value) = serde_json::from_value(v.clone()) {
201                                additional_properties.insert(k, value);
202                            }
203                        }
204                    }
205                }
206                let forwarder_destination = forwarder_destination
207                    .ok_or_else(|| M::Error::missing_field("forwarder_destination"))?;
208                let name = name.ok_or_else(|| M::Error::missing_field("name"))?;
209
210                let content = CustomDestinationCreateRequestAttributes {
211                    enabled,
212                    forward_tags,
213                    forward_tags_restriction_list,
214                    forward_tags_restriction_list_type,
215                    forwarder_destination,
216                    name,
217                    query,
218                    additional_properties,
219                    _unparsed,
220                };
221
222                Ok(content)
223            }
224        }
225
226        deserializer.deserialize_any(CustomDestinationCreateRequestAttributesVisitor)
227    }
228}