|
| 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. |
| 4 | +use serde::de::{Error, MapAccess, Visitor}; |
| 5 | +use serde::{Deserialize, Deserializer, Serialize}; |
| 6 | +use serde_with::skip_serializing_none; |
| 7 | +use std::fmt::{self, Formatter}; |
| 8 | + |
| 9 | +/// Log source configuration. |
| 10 | +#[non_exhaustive] |
| 11 | +#[skip_serializing_none] |
| 12 | +#[derive(Clone, Debug, PartialEq, Serialize)] |
| 13 | +pub struct AWSLambdaForwarderConfigLogSourceConfig { |
| 14 | + /// List of AWS log source tag filters. Defaults to `[]`. |
| 15 | + #[serde(rename = "tag_filters")] |
| 16 | + pub tag_filters: Option<Vec<crate::datadogV2::model::AWSLogSourceTagFilter>>, |
| 17 | + #[serde(flatten)] |
| 18 | + pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>, |
| 19 | + #[serde(skip)] |
| 20 | + #[serde(default)] |
| 21 | + pub(crate) _unparsed: bool, |
| 22 | +} |
| 23 | + |
| 24 | +impl AWSLambdaForwarderConfigLogSourceConfig { |
| 25 | + pub fn new() -> AWSLambdaForwarderConfigLogSourceConfig { |
| 26 | + AWSLambdaForwarderConfigLogSourceConfig { |
| 27 | + tag_filters: None, |
| 28 | + additional_properties: std::collections::BTreeMap::new(), |
| 29 | + _unparsed: false, |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + pub fn tag_filters( |
| 34 | + mut self, |
| 35 | + value: Vec<crate::datadogV2::model::AWSLogSourceTagFilter>, |
| 36 | + ) -> Self { |
| 37 | + self.tag_filters = Some(value); |
| 38 | + self |
| 39 | + } |
| 40 | + |
| 41 | + pub fn additional_properties( |
| 42 | + mut self, |
| 43 | + value: std::collections::BTreeMap<String, serde_json::Value>, |
| 44 | + ) -> Self { |
| 45 | + self.additional_properties = value; |
| 46 | + self |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +impl Default for AWSLambdaForwarderConfigLogSourceConfig { |
| 51 | + fn default() -> Self { |
| 52 | + Self::new() |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +impl<'de> Deserialize<'de> for AWSLambdaForwarderConfigLogSourceConfig { |
| 57 | + fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> |
| 58 | + where |
| 59 | + D: Deserializer<'de>, |
| 60 | + { |
| 61 | + struct AWSLambdaForwarderConfigLogSourceConfigVisitor; |
| 62 | + impl<'a> Visitor<'a> for AWSLambdaForwarderConfigLogSourceConfigVisitor { |
| 63 | + type Value = AWSLambdaForwarderConfigLogSourceConfig; |
| 64 | + |
| 65 | + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { |
| 66 | + f.write_str("a mapping") |
| 67 | + } |
| 68 | + |
| 69 | + fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error> |
| 70 | + where |
| 71 | + M: MapAccess<'a>, |
| 72 | + { |
| 73 | + let mut tag_filters: Option<Vec<crate::datadogV2::model::AWSLogSourceTagFilter>> = |
| 74 | + None; |
| 75 | + let mut additional_properties: std::collections::BTreeMap< |
| 76 | + String, |
| 77 | + serde_json::Value, |
| 78 | + > = std::collections::BTreeMap::new(); |
| 79 | + let mut _unparsed = false; |
| 80 | + |
| 81 | + while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? { |
| 82 | + match k.as_str() { |
| 83 | + "tag_filters" => { |
| 84 | + if v.is_null() { |
| 85 | + continue; |
| 86 | + } |
| 87 | + tag_filters = |
| 88 | + Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 89 | + } |
| 90 | + &_ => { |
| 91 | + if let Ok(value) = serde_json::from_value(v.clone()) { |
| 92 | + additional_properties.insert(k, value); |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + let content = AWSLambdaForwarderConfigLogSourceConfig { |
| 99 | + tag_filters, |
| 100 | + additional_properties, |
| 101 | + _unparsed, |
| 102 | + }; |
| 103 | + |
| 104 | + Ok(content) |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + deserializer.deserialize_any(AWSLambdaForwarderConfigLogSourceConfigVisitor) |
| 109 | + } |
| 110 | +} |
0 commit comments