datadog_api_client/datadogV2/model/
model_cloudflare_integration_update.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 `CloudflareIntegrationUpdate` object.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct CloudflareIntegrationUpdate {
14    /// The definition of the `CloudflareCredentialsUpdate` object.
15    #[serde(rename = "credentials")]
16    pub credentials: Option<crate::datadogV2::model::CloudflareCredentialsUpdate>,
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 CloudflareIntegrationUpdate {
28    pub fn new(
29        type_: crate::datadogV2::model::CloudflareIntegrationType,
30    ) -> CloudflareIntegrationUpdate {
31        CloudflareIntegrationUpdate {
32            credentials: None,
33            type_,
34            additional_properties: std::collections::BTreeMap::new(),
35            _unparsed: false,
36        }
37    }
38
39    pub fn credentials(
40        mut self,
41        value: crate::datadogV2::model::CloudflareCredentialsUpdate,
42    ) -> Self {
43        self.credentials = 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 CloudflareIntegrationUpdate {
57    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
58    where
59        D: Deserializer<'de>,
60    {
61        struct CloudflareIntegrationUpdateVisitor;
62        impl<'a> Visitor<'a> for CloudflareIntegrationUpdateVisitor {
63            type Value = CloudflareIntegrationUpdate;
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 credentials: Option<crate::datadogV2::model::CloudflareCredentialsUpdate> =
74                    None;
75                let mut type_: Option<crate::datadogV2::model::CloudflareIntegrationType> = 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                        "credentials" => {
85                            if v.is_null() {
86                                continue;
87                            }
88                            credentials =
89                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
90                            if let Some(ref _credentials) = credentials {
91                                match _credentials {
92                                    crate::datadogV2::model::CloudflareCredentialsUpdate::UnparsedObject(_credentials) => {
93                                        _unparsed = true;
94                                    },
95                                    _ => {}
96                                }
97                            }
98                        }
99                        "type" => {
100                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
101                            if let Some(ref _type_) = type_ {
102                                match _type_ {
103                                    crate::datadogV2::model::CloudflareIntegrationType::UnparsedObject(_type_) => {
104                                        _unparsed = true;
105                                    },
106                                    _ => {}
107                                }
108                            }
109                        }
110                        &_ => {
111                            if let Ok(value) = serde_json::from_value(v.clone()) {
112                                additional_properties.insert(k, value);
113                            }
114                        }
115                    }
116                }
117                let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
118
119                let content = CloudflareIntegrationUpdate {
120                    credentials,
121                    type_,
122                    additional_properties,
123                    _unparsed,
124                };
125
126                Ok(content)
127            }
128        }
129
130        deserializer.deserialize_any(CloudflareIntegrationUpdateVisitor)
131    }
132}