datadog_api_client/datadogV2/model/
model_logs_archive_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 archive.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct LogsArchiveCreateRequestAttributes {
14    /// An archive's destination.
15    #[serde(rename = "destination")]
16    pub destination: crate::datadogV2::model::LogsArchiveCreateRequestDestination,
17    /// To store the tags in the archive, set the value "true".
18    /// If it is set to "false", the tags will be deleted when the logs are sent to the archive.
19    #[serde(rename = "include_tags")]
20    pub include_tags: Option<bool>,
21    /// The archive name.
22    #[serde(rename = "name")]
23    pub name: String,
24    /// The archive query/filter. Logs matching this query are included in the archive.
25    #[serde(rename = "query")]
26    pub query: String,
27    /// Maximum scan size for rehydration from this archive.
28    #[serde(
29        rename = "rehydration_max_scan_size_in_gb",
30        default,
31        with = "::serde_with::rust::double_option"
32    )]
33    pub rehydration_max_scan_size_in_gb: Option<Option<i64>>,
34    /// An array of tags to add to rehydrated logs from an archive.
35    #[serde(rename = "rehydration_tags")]
36    pub rehydration_tags: Option<Vec<String>>,
37    #[serde(flatten)]
38    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
39    #[serde(skip)]
40    #[serde(default)]
41    pub(crate) _unparsed: bool,
42}
43
44impl LogsArchiveCreateRequestAttributes {
45    pub fn new(
46        destination: crate::datadogV2::model::LogsArchiveCreateRequestDestination,
47        name: String,
48        query: String,
49    ) -> LogsArchiveCreateRequestAttributes {
50        LogsArchiveCreateRequestAttributes {
51            destination,
52            include_tags: None,
53            name,
54            query,
55            rehydration_max_scan_size_in_gb: None,
56            rehydration_tags: None,
57            additional_properties: std::collections::BTreeMap::new(),
58            _unparsed: false,
59        }
60    }
61
62    pub fn include_tags(mut self, value: bool) -> Self {
63        self.include_tags = Some(value);
64        self
65    }
66
67    pub fn rehydration_max_scan_size_in_gb(mut self, value: Option<i64>) -> Self {
68        self.rehydration_max_scan_size_in_gb = Some(value);
69        self
70    }
71
72    pub fn rehydration_tags(mut self, value: Vec<String>) -> Self {
73        self.rehydration_tags = Some(value);
74        self
75    }
76
77    pub fn additional_properties(
78        mut self,
79        value: std::collections::BTreeMap<String, serde_json::Value>,
80    ) -> Self {
81        self.additional_properties = value;
82        self
83    }
84}
85
86impl<'de> Deserialize<'de> for LogsArchiveCreateRequestAttributes {
87    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
88    where
89        D: Deserializer<'de>,
90    {
91        struct LogsArchiveCreateRequestAttributesVisitor;
92        impl<'a> Visitor<'a> for LogsArchiveCreateRequestAttributesVisitor {
93            type Value = LogsArchiveCreateRequestAttributes;
94
95            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
96                f.write_str("a mapping")
97            }
98
99            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
100            where
101                M: MapAccess<'a>,
102            {
103                let mut destination: Option<
104                    crate::datadogV2::model::LogsArchiveCreateRequestDestination,
105                > = None;
106                let mut include_tags: Option<bool> = None;
107                let mut name: Option<String> = None;
108                let mut query: Option<String> = None;
109                let mut rehydration_max_scan_size_in_gb: Option<Option<i64>> = None;
110                let mut rehydration_tags: Option<Vec<String>> = None;
111                let mut additional_properties: std::collections::BTreeMap<
112                    String,
113                    serde_json::Value,
114                > = std::collections::BTreeMap::new();
115                let mut _unparsed = false;
116
117                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
118                    match k.as_str() {
119                        "destination" => {
120                            destination =
121                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
122                            if let Some(ref _destination) = destination {
123                                match _destination {
124                                    crate::datadogV2::model::LogsArchiveCreateRequestDestination::UnparsedObject(_destination) => {
125                                        _unparsed = true;
126                                    },
127                                    _ => {}
128                                }
129                            }
130                        }
131                        "include_tags" => {
132                            if v.is_null() {
133                                continue;
134                            }
135                            include_tags =
136                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
137                        }
138                        "name" => {
139                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
140                        }
141                        "query" => {
142                            query = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
143                        }
144                        "rehydration_max_scan_size_in_gb" => {
145                            rehydration_max_scan_size_in_gb =
146                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
147                        }
148                        "rehydration_tags" => {
149                            if v.is_null() {
150                                continue;
151                            }
152                            rehydration_tags =
153                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
154                        }
155                        &_ => {
156                            if let Ok(value) = serde_json::from_value(v.clone()) {
157                                additional_properties.insert(k, value);
158                            }
159                        }
160                    }
161                }
162                let destination =
163                    destination.ok_or_else(|| M::Error::missing_field("destination"))?;
164                let name = name.ok_or_else(|| M::Error::missing_field("name"))?;
165                let query = query.ok_or_else(|| M::Error::missing_field("query"))?;
166
167                let content = LogsArchiveCreateRequestAttributes {
168                    destination,
169                    include_tags,
170                    name,
171                    query,
172                    rehydration_max_scan_size_in_gb,
173                    rehydration_tags,
174                    additional_properties,
175                    _unparsed,
176                };
177
178                Ok(content)
179            }
180        }
181
182        deserializer.deserialize_any(LogsArchiveCreateRequestAttributesVisitor)
183    }
184}