datadog_api_client/datadogV2/model/
model_dataset_attributes_request.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 configurations.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct DatasetAttributesRequest {
14    /// Name of the dataset.
15    #[serde(rename = "name")]
16    pub name: String,
17    /// List of access principals, formatted as `principal_type:id`. Principal can be 'team' or 'role'.
18    #[serde(rename = "principals")]
19    pub principals: Vec<String>,
20    /// List of product-specific filters.
21    #[serde(rename = "product_filters")]
22    pub product_filters: Vec<crate::datadogV2::model::FiltersPerProduct>,
23    #[serde(flatten)]
24    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
25    #[serde(skip)]
26    #[serde(default)]
27    pub(crate) _unparsed: bool,
28}
29
30impl DatasetAttributesRequest {
31    pub fn new(
32        name: String,
33        principals: Vec<String>,
34        product_filters: Vec<crate::datadogV2::model::FiltersPerProduct>,
35    ) -> DatasetAttributesRequest {
36        DatasetAttributesRequest {
37            name,
38            principals,
39            product_filters,
40            additional_properties: std::collections::BTreeMap::new(),
41            _unparsed: false,
42        }
43    }
44
45    pub fn additional_properties(
46        mut self,
47        value: std::collections::BTreeMap<String, serde_json::Value>,
48    ) -> Self {
49        self.additional_properties = value;
50        self
51    }
52}
53
54impl<'de> Deserialize<'de> for DatasetAttributesRequest {
55    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
56    where
57        D: Deserializer<'de>,
58    {
59        struct DatasetAttributesRequestVisitor;
60        impl<'a> Visitor<'a> for DatasetAttributesRequestVisitor {
61            type Value = DatasetAttributesRequest;
62
63            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
64                f.write_str("a mapping")
65            }
66
67            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
68            where
69                M: MapAccess<'a>,
70            {
71                let mut name: Option<String> = None;
72                let mut principals: Option<Vec<String>> = None;
73                let mut product_filters: Option<Vec<crate::datadogV2::model::FiltersPerProduct>> =
74                    None;
75                let mut additional_properties: std::collections::BTreeMap<
76                    String,
77                    serde_json::Value,
78                > = std::collections::BTreeMap::new();
79                let mut _unparsed = false;
80
81                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
82                    match k.as_str() {
83                        "name" => {
84                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
85                        }
86                        "principals" => {
87                            principals = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
88                        }
89                        "product_filters" => {
90                            product_filters =
91                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
92                        }
93                        &_ => {
94                            if let Ok(value) = serde_json::from_value(v.clone()) {
95                                additional_properties.insert(k, value);
96                            }
97                        }
98                    }
99                }
100                let name = name.ok_or_else(|| M::Error::missing_field("name"))?;
101                let principals = principals.ok_or_else(|| M::Error::missing_field("principals"))?;
102                let product_filters =
103                    product_filters.ok_or_else(|| M::Error::missing_field("product_filters"))?;
104
105                let content = DatasetAttributesRequest {
106                    name,
107                    principals,
108                    product_filters,
109                    additional_properties,
110                    _unparsed,
111                };
112
113                Ok(content)
114            }
115        }
116
117        deserializer.deserialize_any(DatasetAttributesRequestVisitor)
118    }
119}