datadog_api_client/datadogV2/model/
model_custom_connection_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 custom connection attributes.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct CustomConnectionAttributes {
14    /// The name of the custom connection.
15    #[serde(rename = "name")]
16    pub name: Option<String>,
17    /// Information about the Private Action Runner used by the custom connection, if the custom connection is associated with a Private Action Runner.
18    #[serde(rename = "onPremRunner")]
19    pub on_prem_runner: Option<crate::datadogV2::model::CustomConnectionAttributesOnPremRunner>,
20    #[serde(flatten)]
21    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
22    #[serde(skip)]
23    #[serde(default)]
24    pub(crate) _unparsed: bool,
25}
26
27impl CustomConnectionAttributes {
28    pub fn new() -> CustomConnectionAttributes {
29        CustomConnectionAttributes {
30            name: None,
31            on_prem_runner: None,
32            additional_properties: std::collections::BTreeMap::new(),
33            _unparsed: false,
34        }
35    }
36
37    pub fn name(mut self, value: String) -> Self {
38        self.name = Some(value);
39        self
40    }
41
42    pub fn on_prem_runner(
43        mut self,
44        value: crate::datadogV2::model::CustomConnectionAttributesOnPremRunner,
45    ) -> Self {
46        self.on_prem_runner = Some(value);
47        self
48    }
49
50    pub fn additional_properties(
51        mut self,
52        value: std::collections::BTreeMap<String, serde_json::Value>,
53    ) -> Self {
54        self.additional_properties = value;
55        self
56    }
57}
58
59impl Default for CustomConnectionAttributes {
60    fn default() -> Self {
61        Self::new()
62    }
63}
64
65impl<'de> Deserialize<'de> for CustomConnectionAttributes {
66    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
67    where
68        D: Deserializer<'de>,
69    {
70        struct CustomConnectionAttributesVisitor;
71        impl<'a> Visitor<'a> for CustomConnectionAttributesVisitor {
72            type Value = CustomConnectionAttributes;
73
74            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
75                f.write_str("a mapping")
76            }
77
78            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
79            where
80                M: MapAccess<'a>,
81            {
82                let mut name: Option<String> = None;
83                let mut on_prem_runner: Option<
84                    crate::datadogV2::model::CustomConnectionAttributesOnPremRunner,
85                > = None;
86                let mut additional_properties: std::collections::BTreeMap<
87                    String,
88                    serde_json::Value,
89                > = std::collections::BTreeMap::new();
90                let mut _unparsed = false;
91
92                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
93                    match k.as_str() {
94                        "name" => {
95                            if v.is_null() {
96                                continue;
97                            }
98                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
99                        }
100                        "onPremRunner" => {
101                            if v.is_null() {
102                                continue;
103                            }
104                            on_prem_runner =
105                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
106                        }
107                        &_ => {
108                            if let Ok(value) = serde_json::from_value(v.clone()) {
109                                additional_properties.insert(k, value);
110                            }
111                        }
112                    }
113                }
114
115                let content = CustomConnectionAttributes {
116                    name,
117                    on_prem_runner,
118                    additional_properties,
119                    _unparsed,
120                };
121
122                Ok(content)
123            }
124        }
125
126        deserializer.deserialize_any(CustomConnectionAttributesVisitor)
127    }
128}