datadog_api_client/datadogV2/model/
model_confluent_account_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/// Attributes associated with the account creation request.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct ConfluentAccountCreateRequestAttributes {
14    /// The API key associated with your Confluent account.
15    #[serde(rename = "api_key")]
16    pub api_key: String,
17    /// The API secret associated with your Confluent account.
18    #[serde(rename = "api_secret")]
19    pub api_secret: String,
20    /// A list of Confluent resources associated with the Confluent account.
21    #[serde(rename = "resources")]
22    pub resources: Option<Vec<crate::datadogV2::model::ConfluentAccountResourceAttributes>>,
23    /// A list of strings representing tags. Can be a single key, or key-value pairs separated by a colon.
24    #[serde(rename = "tags")]
25    pub tags: Option<Vec<String>>,
26    #[serde(flatten)]
27    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
28    #[serde(skip)]
29    #[serde(default)]
30    pub(crate) _unparsed: bool,
31}
32
33impl ConfluentAccountCreateRequestAttributes {
34    pub fn new(api_key: String, api_secret: String) -> ConfluentAccountCreateRequestAttributes {
35        ConfluentAccountCreateRequestAttributes {
36            api_key,
37            api_secret,
38            resources: None,
39            tags: None,
40            additional_properties: std::collections::BTreeMap::new(),
41            _unparsed: false,
42        }
43    }
44
45    pub fn resources(
46        mut self,
47        value: Vec<crate::datadogV2::model::ConfluentAccountResourceAttributes>,
48    ) -> Self {
49        self.resources = Some(value);
50        self
51    }
52
53    pub fn tags(mut self, value: Vec<String>) -> Self {
54        self.tags = Some(value);
55        self
56    }
57
58    pub fn additional_properties(
59        mut self,
60        value: std::collections::BTreeMap<String, serde_json::Value>,
61    ) -> Self {
62        self.additional_properties = value;
63        self
64    }
65}
66
67impl<'de> Deserialize<'de> for ConfluentAccountCreateRequestAttributes {
68    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
69    where
70        D: Deserializer<'de>,
71    {
72        struct ConfluentAccountCreateRequestAttributesVisitor;
73        impl<'a> Visitor<'a> for ConfluentAccountCreateRequestAttributesVisitor {
74            type Value = ConfluentAccountCreateRequestAttributes;
75
76            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
77                f.write_str("a mapping")
78            }
79
80            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
81            where
82                M: MapAccess<'a>,
83            {
84                let mut api_key: Option<String> = None;
85                let mut api_secret: Option<String> = None;
86                let mut resources: Option<
87                    Vec<crate::datadogV2::model::ConfluentAccountResourceAttributes>,
88                > = None;
89                let mut tags: Option<Vec<String>> = None;
90                let mut additional_properties: std::collections::BTreeMap<
91                    String,
92                    serde_json::Value,
93                > = std::collections::BTreeMap::new();
94                let mut _unparsed = false;
95
96                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
97                    match k.as_str() {
98                        "api_key" => {
99                            api_key = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
100                        }
101                        "api_secret" => {
102                            api_secret = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
103                        }
104                        "resources" => {
105                            if v.is_null() {
106                                continue;
107                            }
108                            resources = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
109                        }
110                        "tags" => {
111                            if v.is_null() {
112                                continue;
113                            }
114                            tags = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
115                        }
116                        &_ => {
117                            if let Ok(value) = serde_json::from_value(v.clone()) {
118                                additional_properties.insert(k, value);
119                            }
120                        }
121                    }
122                }
123                let api_key = api_key.ok_or_else(|| M::Error::missing_field("api_key"))?;
124                let api_secret = api_secret.ok_or_else(|| M::Error::missing_field("api_secret"))?;
125
126                let content = ConfluentAccountCreateRequestAttributes {
127                    api_key,
128                    api_secret,
129                    resources,
130                    tags,
131                    additional_properties,
132                    _unparsed,
133                };
134
135                Ok(content)
136            }
137        }
138
139        deserializer.deserialize_any(ConfluentAccountCreateRequestAttributesVisitor)
140    }
141}