datadog_api_client/datadogV1/model/
model_webhooks_integration_custom_variable_response.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/// Custom variable for Webhook integration.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct WebhooksIntegrationCustomVariableResponse {
14    /// Make custom variable is secret or not.
15    /// If the custom variable is secret, the value is not returned in the response payload.
16    #[serde(rename = "is_secret")]
17    pub is_secret: bool,
18    /// The name of the variable. It corresponds with `<CUSTOM_VARIABLE_NAME>`. It must only contains upper-case characters, integers or underscores.
19    #[serde(rename = "name")]
20    pub name: String,
21    /// Value of the custom variable. It won't be returned if the variable is secret.
22    #[serde(rename = "value")]
23    pub value: Option<String>,
24    #[serde(flatten)]
25    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
26    #[serde(skip)]
27    #[serde(default)]
28    pub(crate) _unparsed: bool,
29}
30
31impl WebhooksIntegrationCustomVariableResponse {
32    pub fn new(is_secret: bool, name: String) -> WebhooksIntegrationCustomVariableResponse {
33        WebhooksIntegrationCustomVariableResponse {
34            is_secret,
35            name,
36            value: None,
37            additional_properties: std::collections::BTreeMap::new(),
38            _unparsed: false,
39        }
40    }
41
42    pub fn value(mut self, value: String) -> Self {
43        self.value = Some(value);
44        self
45    }
46
47    pub fn additional_properties(
48        mut self,
49        value: std::collections::BTreeMap<String, serde_json::Value>,
50    ) -> Self {
51        self.additional_properties = value;
52        self
53    }
54}
55
56impl<'de> Deserialize<'de> for WebhooksIntegrationCustomVariableResponse {
57    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
58    where
59        D: Deserializer<'de>,
60    {
61        struct WebhooksIntegrationCustomVariableResponseVisitor;
62        impl<'a> Visitor<'a> for WebhooksIntegrationCustomVariableResponseVisitor {
63            type Value = WebhooksIntegrationCustomVariableResponse;
64
65            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
66                f.write_str("a mapping")
67            }
68
69            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
70            where
71                M: MapAccess<'a>,
72            {
73                let mut is_secret: Option<bool> = None;
74                let mut name: Option<String> = None;
75                let mut value: Option<String> = None;
76                let mut additional_properties: std::collections::BTreeMap<
77                    String,
78                    serde_json::Value,
79                > = std::collections::BTreeMap::new();
80                let mut _unparsed = false;
81
82                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
83                    match k.as_str() {
84                        "is_secret" => {
85                            is_secret = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
86                        }
87                        "name" => {
88                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
89                        }
90                        "value" => {
91                            if v.is_null() {
92                                continue;
93                            }
94                            value = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
95                        }
96                        &_ => {
97                            if let Ok(value) = serde_json::from_value(v.clone()) {
98                                additional_properties.insert(k, value);
99                            }
100                        }
101                    }
102                }
103                let is_secret = is_secret.ok_or_else(|| M::Error::missing_field("is_secret"))?;
104                let name = name.ok_or_else(|| M::Error::missing_field("name"))?;
105
106                let content = WebhooksIntegrationCustomVariableResponse {
107                    is_secret,
108                    name,
109                    value,
110                    additional_properties,
111                    _unparsed,
112                };
113
114                Ok(content)
115            }
116        }
117
118        deserializer.deserialize_any(WebhooksIntegrationCustomVariableResponseVisitor)
119    }
120}