datadog_api_client/datadogV2/model/
model_observability_pipeline_amazon_s3_source.rs1use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9#[non_exhaustive]
13#[skip_serializing_none]
14#[derive(Clone, Debug, PartialEq, Serialize)]
15pub struct ObservabilityPipelineAmazonS3Source {
16 #[serde(rename = "auth")]
20 pub auth: Option<crate::datadogV2::model::ObservabilityPipelineAwsAuth>,
21 #[serde(rename = "id")]
23 pub id: String,
24 #[serde(rename = "region")]
26 pub region: String,
27 #[serde(rename = "tls")]
29 pub tls: Option<crate::datadogV2::model::ObservabilityPipelineTls>,
30 #[serde(rename = "type")]
32 pub type_: crate::datadogV2::model::ObservabilityPipelineAmazonS3SourceType,
33 #[serde(flatten)]
34 pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
35 #[serde(skip)]
36 #[serde(default)]
37 pub(crate) _unparsed: bool,
38}
39
40impl ObservabilityPipelineAmazonS3Source {
41 pub fn new(
42 id: String,
43 region: String,
44 type_: crate::datadogV2::model::ObservabilityPipelineAmazonS3SourceType,
45 ) -> ObservabilityPipelineAmazonS3Source {
46 ObservabilityPipelineAmazonS3Source {
47 auth: None,
48 id,
49 region,
50 tls: None,
51 type_,
52 additional_properties: std::collections::BTreeMap::new(),
53 _unparsed: false,
54 }
55 }
56
57 pub fn auth(mut self, value: crate::datadogV2::model::ObservabilityPipelineAwsAuth) -> Self {
58 self.auth = Some(value);
59 self
60 }
61
62 pub fn tls(mut self, value: crate::datadogV2::model::ObservabilityPipelineTls) -> Self {
63 self.tls = 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 ObservabilityPipelineAmazonS3Source {
77 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
78 where
79 D: Deserializer<'de>,
80 {
81 struct ObservabilityPipelineAmazonS3SourceVisitor;
82 impl<'a> Visitor<'a> for ObservabilityPipelineAmazonS3SourceVisitor {
83 type Value = ObservabilityPipelineAmazonS3Source;
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 auth: Option<crate::datadogV2::model::ObservabilityPipelineAwsAuth> = None;
94 let mut id: Option<String> = None;
95 let mut region: Option<String> = None;
96 let mut tls: Option<crate::datadogV2::model::ObservabilityPipelineTls> = None;
97 let mut type_: Option<
98 crate::datadogV2::model::ObservabilityPipelineAmazonS3SourceType,
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 "auth" => {
109 if v.is_null() {
110 continue;
111 }
112 auth = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
113 }
114 "id" => {
115 id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
116 }
117 "region" => {
118 region = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
119 }
120 "tls" => {
121 if v.is_null() {
122 continue;
123 }
124 tls = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
125 }
126 "type" => {
127 type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
128 if let Some(ref _type_) = type_ {
129 match _type_ {
130 crate::datadogV2::model::ObservabilityPipelineAmazonS3SourceType::UnparsedObject(_type_) => {
131 _unparsed = true;
132 },
133 _ => {}
134 }
135 }
136 }
137 &_ => {
138 if let Ok(value) = serde_json::from_value(v.clone()) {
139 additional_properties.insert(k, value);
140 }
141 }
142 }
143 }
144 let id = id.ok_or_else(|| M::Error::missing_field("id"))?;
145 let region = region.ok_or_else(|| M::Error::missing_field("region"))?;
146 let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
147
148 let content = ObservabilityPipelineAmazonS3Source {
149 auth,
150 id,
151 region,
152 tls,
153 type_,
154 additional_properties,
155 _unparsed,
156 };
157
158 Ok(content)
159 }
160 }
161
162 deserializer.deserialize_any(ObservabilityPipelineAmazonS3SourceVisitor)
163 }
164}