|
| 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 | +/// Use this processor to remove an attribute from a log during processing. |
| 10 | +/// The processor strips the specified attribute from the log event, which is useful |
| 11 | +/// when the attribute contains sensitive data or is no longer needed downstream. |
| 12 | +#[non_exhaustive] |
| 13 | +#[skip_serializing_none] |
| 14 | +#[derive(Clone, Debug, PartialEq, Serialize)] |
| 15 | +pub struct LogsExcludeAttributeProcessor { |
| 16 | + /// Name of the log attribute to remove from the log event. |
| 17 | + #[serde(rename = "attribute_to_exclude")] |
| 18 | + pub attribute_to_exclude: String, |
| 19 | + /// Whether or not the processor is enabled. |
| 20 | + #[serde(rename = "is_enabled")] |
| 21 | + pub is_enabled: Option<bool>, |
| 22 | + /// Name of the processor. |
| 23 | + #[serde(rename = "name")] |
| 24 | + pub name: Option<String>, |
| 25 | + /// Type of logs exclude attribute processor. |
| 26 | + #[serde(rename = "type")] |
| 27 | + pub type_: crate::datadogV1::model::LogsExcludeAttributeProcessorType, |
| 28 | + #[serde(flatten)] |
| 29 | + pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>, |
| 30 | + #[serde(skip)] |
| 31 | + #[serde(default)] |
| 32 | + pub(crate) _unparsed: bool, |
| 33 | +} |
| 34 | + |
| 35 | +impl LogsExcludeAttributeProcessor { |
| 36 | + pub fn new( |
| 37 | + attribute_to_exclude: String, |
| 38 | + type_: crate::datadogV1::model::LogsExcludeAttributeProcessorType, |
| 39 | + ) -> LogsExcludeAttributeProcessor { |
| 40 | + LogsExcludeAttributeProcessor { |
| 41 | + attribute_to_exclude, |
| 42 | + is_enabled: None, |
| 43 | + name: None, |
| 44 | + type_, |
| 45 | + additional_properties: std::collections::BTreeMap::new(), |
| 46 | + _unparsed: false, |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + pub fn is_enabled(mut self, value: bool) -> Self { |
| 51 | + self.is_enabled = Some(value); |
| 52 | + self |
| 53 | + } |
| 54 | + |
| 55 | + pub fn name(mut self, value: String) -> Self { |
| 56 | + self.name = Some(value); |
| 57 | + self |
| 58 | + } |
| 59 | + |
| 60 | + pub fn additional_properties( |
| 61 | + mut self, |
| 62 | + value: std::collections::BTreeMap<String, serde_json::Value>, |
| 63 | + ) -> Self { |
| 64 | + self.additional_properties = value; |
| 65 | + self |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +impl<'de> Deserialize<'de> for LogsExcludeAttributeProcessor { |
| 70 | + fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> |
| 71 | + where |
| 72 | + D: Deserializer<'de>, |
| 73 | + { |
| 74 | + struct LogsExcludeAttributeProcessorVisitor; |
| 75 | + impl<'a> Visitor<'a> for LogsExcludeAttributeProcessorVisitor { |
| 76 | + type Value = LogsExcludeAttributeProcessor; |
| 77 | + |
| 78 | + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { |
| 79 | + f.write_str("a mapping") |
| 80 | + } |
| 81 | + |
| 82 | + fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error> |
| 83 | + where |
| 84 | + M: MapAccess<'a>, |
| 85 | + { |
| 86 | + let mut attribute_to_exclude: Option<String> = None; |
| 87 | + let mut is_enabled: Option<bool> = None; |
| 88 | + let mut name: Option<String> = None; |
| 89 | + let mut type_: Option<crate::datadogV1::model::LogsExcludeAttributeProcessorType> = |
| 90 | + None; |
| 91 | + let mut additional_properties: std::collections::BTreeMap< |
| 92 | + String, |
| 93 | + serde_json::Value, |
| 94 | + > = std::collections::BTreeMap::new(); |
| 95 | + let mut _unparsed = false; |
| 96 | + |
| 97 | + while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? { |
| 98 | + match k.as_str() { |
| 99 | + "attribute_to_exclude" => { |
| 100 | + attribute_to_exclude = |
| 101 | + Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 102 | + } |
| 103 | + "is_enabled" => { |
| 104 | + if v.is_null() { |
| 105 | + continue; |
| 106 | + } |
| 107 | + is_enabled = Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 108 | + } |
| 109 | + "name" => { |
| 110 | + if v.is_null() { |
| 111 | + continue; |
| 112 | + } |
| 113 | + name = Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 114 | + } |
| 115 | + "type" => { |
| 116 | + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 117 | + if let Some(ref _type_) = type_ { |
| 118 | + match _type_ { |
| 119 | + crate::datadogV1::model::LogsExcludeAttributeProcessorType::UnparsedObject(_type_) => { |
| 120 | + _unparsed = true; |
| 121 | + }, |
| 122 | + _ => {} |
| 123 | + } |
| 124 | + } |
| 125 | + } |
| 126 | + &_ => { |
| 127 | + if let Ok(value) = serde_json::from_value(v.clone()) { |
| 128 | + additional_properties.insert(k, value); |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | + } |
| 133 | + let attribute_to_exclude = attribute_to_exclude |
| 134 | + .ok_or_else(|| M::Error::missing_field("attribute_to_exclude"))?; |
| 135 | + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; |
| 136 | + |
| 137 | + let content = LogsExcludeAttributeProcessor { |
| 138 | + attribute_to_exclude, |
| 139 | + is_enabled, |
| 140 | + name, |
| 141 | + type_, |
| 142 | + additional_properties, |
| 143 | + _unparsed, |
| 144 | + }; |
| 145 | + |
| 146 | + Ok(content) |
| 147 | + } |
| 148 | + } |
| 149 | + |
| 150 | + deserializer.deserialize_any(LogsExcludeAttributeProcessorVisitor) |
| 151 | + } |
| 152 | +} |
0 commit comments