datadog_api_client/datadogV2/model/
model_cloudflare_integration.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 definition of the `CloudflareIntegration` object.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct CloudflareIntegration {
14    /// The definition of the `CloudflareCredentials` object.
15    #[serde(rename = "credentials")]
16    pub credentials: crate::datadogV2::model::CloudflareCredentials,
17    /// The definition of the `CloudflareIntegrationType` object.
18    #[serde(rename = "type")]
19    pub type_: crate::datadogV2::model::CloudflareIntegrationType,
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 CloudflareIntegration {
28    pub fn new(
29        credentials: crate::datadogV2::model::CloudflareCredentials,
30        type_: crate::datadogV2::model::CloudflareIntegrationType,
31    ) -> CloudflareIntegration {
32        CloudflareIntegration {
33            credentials,
34            type_,
35            additional_properties: std::collections::BTreeMap::new(),
36            _unparsed: false,
37        }
38    }
39
40    pub fn additional_properties(
41        mut self,
42        value: std::collections::BTreeMap<String, serde_json::Value>,
43    ) -> Self {
44        self.additional_properties = value;
45        self
46    }
47}
48
49impl<'de> Deserialize<'de> for CloudflareIntegration {
50    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
51    where
52        D: Deserializer<'de>,
53    {
54        struct CloudflareIntegrationVisitor;
55        impl<'a> Visitor<'a> for CloudflareIntegrationVisitor {
56            type Value = CloudflareIntegration;
57
58            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
59                f.write_str("a mapping")
60            }
61
62            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
63            where
64                M: MapAccess<'a>,
65            {
66                let mut credentials: Option<crate::datadogV2::model::CloudflareCredentials> = None;
67                let mut type_: Option<crate::datadogV2::model::CloudflareIntegrationType> = None;
68                let mut additional_properties: std::collections::BTreeMap<
69                    String,
70                    serde_json::Value,
71                > = std::collections::BTreeMap::new();
72                let mut _unparsed = false;
73
74                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
75                    match k.as_str() {
76                        "credentials" => {
77                            credentials =
78                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
79                            if let Some(ref _credentials) = credentials {
80                                match _credentials {
81                                    crate::datadogV2::model::CloudflareCredentials::UnparsedObject(_credentials) => {
82                                        _unparsed = true;
83                                    },
84                                    _ => {}
85                                }
86                            }
87                        }
88                        "type" => {
89                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
90                            if let Some(ref _type_) = type_ {
91                                match _type_ {
92                                    crate::datadogV2::model::CloudflareIntegrationType::UnparsedObject(_type_) => {
93                                        _unparsed = true;
94                                    },
95                                    _ => {}
96                                }
97                            }
98                        }
99                        &_ => {
100                            if let Ok(value) = serde_json::from_value(v.clone()) {
101                                additional_properties.insert(k, value);
102                            }
103                        }
104                    }
105                }
106                let credentials =
107                    credentials.ok_or_else(|| M::Error::missing_field("credentials"))?;
108                let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
109
110                let content = CloudflareIntegration {
111                    credentials,
112                    type_,
113                    additional_properties,
114                    _unparsed,
115                };
116
117                Ok(content)
118            }
119        }
120
121        deserializer.deserialize_any(CloudflareIntegrationVisitor)
122    }
123}