datadog_api_client/datadogV2/model/
model_aws_lambda_forwarder_config.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/// Log Autosubscription configuration for Datadog Forwarder Lambda functions. Automatically set up triggers for existing
10/// and new logs for some services, ensuring no logs from new resources are missed and saving time spent on manual configuration.
11#[non_exhaustive]
12#[skip_serializing_none]
13#[derive(Clone, Debug, PartialEq, Serialize)]
14pub struct AWSLambdaForwarderConfig {
15    /// List of Datadog Lambda Log Forwarder ARNs in your AWS account. Defaults to `[]`.
16    #[serde(rename = "lambdas")]
17    pub lambdas: Option<Vec<String>>,
18    /// Log source configuration.
19    #[serde(rename = "log_source_config")]
20    pub log_source_config: Option<crate::datadogV2::model::AWSLambdaForwarderConfigLogSourceConfig>,
21    /// List of service IDs set to enable automatic log collection. Discover the list of available services with the
22    /// [Get list of AWS log ready services](<https://docs.datadoghq.com/api/latest/aws-logs-integration/#get-list-of-aws-log-ready-services>) endpoint.
23    #[serde(rename = "sources")]
24    pub sources: Option<Vec<String>>,
25    #[serde(flatten)]
26    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
27    #[serde(skip)]
28    #[serde(default)]
29    pub(crate) _unparsed: bool,
30}
31
32impl AWSLambdaForwarderConfig {
33    pub fn new() -> AWSLambdaForwarderConfig {
34        AWSLambdaForwarderConfig {
35            lambdas: None,
36            log_source_config: None,
37            sources: None,
38            additional_properties: std::collections::BTreeMap::new(),
39            _unparsed: false,
40        }
41    }
42
43    pub fn lambdas(mut self, value: Vec<String>) -> Self {
44        self.lambdas = Some(value);
45        self
46    }
47
48    pub fn log_source_config(
49        mut self,
50        value: crate::datadogV2::model::AWSLambdaForwarderConfigLogSourceConfig,
51    ) -> Self {
52        self.log_source_config = Some(value);
53        self
54    }
55
56    pub fn sources(mut self, value: Vec<String>) -> Self {
57        self.sources = Some(value);
58        self
59    }
60
61    pub fn additional_properties(
62        mut self,
63        value: std::collections::BTreeMap<String, serde_json::Value>,
64    ) -> Self {
65        self.additional_properties = value;
66        self
67    }
68}
69
70impl Default for AWSLambdaForwarderConfig {
71    fn default() -> Self {
72        Self::new()
73    }
74}
75
76impl<'de> Deserialize<'de> for AWSLambdaForwarderConfig {
77    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
78    where
79        D: Deserializer<'de>,
80    {
81        struct AWSLambdaForwarderConfigVisitor;
82        impl<'a> Visitor<'a> for AWSLambdaForwarderConfigVisitor {
83            type Value = AWSLambdaForwarderConfig;
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 lambdas: Option<Vec<String>> = None;
94                let mut log_source_config: Option<
95                    crate::datadogV2::model::AWSLambdaForwarderConfigLogSourceConfig,
96                > = None;
97                let mut sources: Option<Vec<String>> = None;
98                let mut additional_properties: std::collections::BTreeMap<
99                    String,
100                    serde_json::Value,
101                > = std::collections::BTreeMap::new();
102                let mut _unparsed = false;
103
104                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
105                    match k.as_str() {
106                        "lambdas" => {
107                            if v.is_null() {
108                                continue;
109                            }
110                            lambdas = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
111                        }
112                        "log_source_config" => {
113                            if v.is_null() {
114                                continue;
115                            }
116                            log_source_config =
117                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
118                        }
119                        "sources" => {
120                            if v.is_null() {
121                                continue;
122                            }
123                            sources = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
124                        }
125                        &_ => {
126                            if let Ok(value) = serde_json::from_value(v.clone()) {
127                                additional_properties.insert(k, value);
128                            }
129                        }
130                    }
131                }
132
133                let content = AWSLambdaForwarderConfig {
134                    lambdas,
135                    log_source_config,
136                    sources,
137                    additional_properties,
138                    _unparsed,
139                };
140
141                Ok(content)
142            }
143        }
144
145        deserializer.deserialize_any(AWSLambdaForwarderConfigVisitor)
146    }
147}