datadog_api_client/datadogV2/model/
model_dataset_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/// Dataset metadata and configuration(s).
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct DatasetAttributes {
14    /// Timestamp when the dataset was created.
15    #[serde(
16        rename = "created_at",
17        default,
18        with = "::serde_with::rust::double_option"
19    )]
20    pub created_at: Option<Option<chrono::DateTime<chrono::Utc>>>,
21    /// Unique ID of the user who created the dataset.
22    #[serde(rename = "created_by")]
23    pub created_by: Option<uuid::Uuid>,
24    /// Name of the dataset.
25    #[serde(rename = "name")]
26    pub name: String,
27    /// List of access principals, formatted as `principal_type:id`. Principal can be 'team' or 'role'.
28    #[serde(rename = "principals")]
29    pub principals: Vec<String>,
30    /// List of product-specific filters.
31    #[serde(rename = "product_filters")]
32    pub product_filters: Vec<crate::datadogV2::model::FiltersPerProduct>,
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 DatasetAttributes {
41    pub fn new(
42        name: String,
43        principals: Vec<String>,
44        product_filters: Vec<crate::datadogV2::model::FiltersPerProduct>,
45    ) -> DatasetAttributes {
46        DatasetAttributes {
47            created_at: None,
48            created_by: None,
49            name,
50            principals,
51            product_filters,
52            additional_properties: std::collections::BTreeMap::new(),
53            _unparsed: false,
54        }
55    }
56
57    pub fn created_at(mut self, value: Option<chrono::DateTime<chrono::Utc>>) -> Self {
58        self.created_at = Some(value);
59        self
60    }
61
62    pub fn created_by(mut self, value: uuid::Uuid) -> Self {
63        self.created_by = 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 DatasetAttributes {
77    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
78    where
79        D: Deserializer<'de>,
80    {
81        struct DatasetAttributesVisitor;
82        impl<'a> Visitor<'a> for DatasetAttributesVisitor {
83            type Value = DatasetAttributes;
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 created_at: Option<Option<chrono::DateTime<chrono::Utc>>> = None;
94                let mut created_by: Option<uuid::Uuid> = None;
95                let mut name: Option<String> = None;
96                let mut principals: Option<Vec<String>> = None;
97                let mut product_filters: Option<Vec<crate::datadogV2::model::FiltersPerProduct>> =
98                    None;
99                let mut additional_properties: std::collections::BTreeMap<
100                    String,
101                    serde_json::Value,
102                > = std::collections::BTreeMap::new();
103                let mut _unparsed = false;
104
105                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
106                    match k.as_str() {
107                        "created_at" => {
108                            created_at = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
109                        }
110                        "created_by" => {
111                            if v.is_null() {
112                                continue;
113                            }
114                            created_by = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
115                        }
116                        "name" => {
117                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
118                        }
119                        "principals" => {
120                            principals = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
121                        }
122                        "product_filters" => {
123                            product_filters =
124                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
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 name = name.ok_or_else(|| M::Error::missing_field("name"))?;
134                let principals = principals.ok_or_else(|| M::Error::missing_field("principals"))?;
135                let product_filters =
136                    product_filters.ok_or_else(|| M::Error::missing_field("product_filters"))?;
137
138                let content = DatasetAttributes {
139                    created_at,
140                    created_by,
141                    name,
142                    principals,
143                    product_filters,
144                    additional_properties,
145                    _unparsed,
146                };
147
148                Ok(content)
149            }
150        }
151
152        deserializer.deserialize_any(DatasetAttributesVisitor)
153    }
154}