datadog_api_client/datadogV1/model/
model_ip_prefixes_webhooks.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/// Available prefix information for the Webhook endpoints.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct IPPrefixesWebhooks {
14    /// List of IPv4 prefixes.
15    #[serde(rename = "prefixes_ipv4")]
16    pub prefixes_ipv4: Option<Vec<String>>,
17    /// List of IPv6 prefixes.
18    #[serde(rename = "prefixes_ipv6")]
19    pub prefixes_ipv6: Option<Vec<String>>,
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 IPPrefixesWebhooks {
28    pub fn new() -> IPPrefixesWebhooks {
29        IPPrefixesWebhooks {
30            prefixes_ipv4: None,
31            prefixes_ipv6: None,
32            additional_properties: std::collections::BTreeMap::new(),
33            _unparsed: false,
34        }
35    }
36
37    pub fn prefixes_ipv4(mut self, value: Vec<String>) -> Self {
38        self.prefixes_ipv4 = Some(value);
39        self
40    }
41
42    pub fn prefixes_ipv6(mut self, value: Vec<String>) -> Self {
43        self.prefixes_ipv6 = 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 Default for IPPrefixesWebhooks {
57    fn default() -> Self {
58        Self::new()
59    }
60}
61
62impl<'de> Deserialize<'de> for IPPrefixesWebhooks {
63    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
64    where
65        D: Deserializer<'de>,
66    {
67        struct IPPrefixesWebhooksVisitor;
68        impl<'a> Visitor<'a> for IPPrefixesWebhooksVisitor {
69            type Value = IPPrefixesWebhooks;
70
71            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
72                f.write_str("a mapping")
73            }
74
75            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
76            where
77                M: MapAccess<'a>,
78            {
79                let mut prefixes_ipv4: Option<Vec<String>> = None;
80                let mut prefixes_ipv6: Option<Vec<String>> = None;
81                let mut additional_properties: std::collections::BTreeMap<
82                    String,
83                    serde_json::Value,
84                > = std::collections::BTreeMap::new();
85                let mut _unparsed = false;
86
87                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
88                    match k.as_str() {
89                        "prefixes_ipv4" => {
90                            if v.is_null() {
91                                continue;
92                            }
93                            prefixes_ipv4 =
94                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
95                        }
96                        "prefixes_ipv6" => {
97                            if v.is_null() {
98                                continue;
99                            }
100                            prefixes_ipv6 =
101                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
102                        }
103                        &_ => {
104                            if let Ok(value) = serde_json::from_value(v.clone()) {
105                                additional_properties.insert(k, value);
106                            }
107                        }
108                    }
109                }
110
111                let content = IPPrefixesWebhooks {
112                    prefixes_ipv4,
113                    prefixes_ipv6,
114                    additional_properties,
115                    _unparsed,
116                };
117
118                Ok(content)
119            }
120        }
121
122        deserializer.deserialize_any(IPPrefixesWebhooksVisitor)
123    }
124}