datadog_api_client/datadogV2/model/
model_entity_v3_datastore.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/// Schema for datastore entities.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct EntityV3Datastore {
14    /// The version of the schema data that was used to populate this entity's data. This could be via the API, Terraform, or YAML file in a repository. The field is known as schema-version in the previous version.
15    #[serde(rename = "apiVersion")]
16    pub api_version: crate::datadogV2::model::EntityV3APIVersion,
17    /// Datadog product integrations for the datastore entity.
18    #[serde(rename = "datadog")]
19    pub datadog: Option<crate::datadogV2::model::EntityV3DatastoreDatadog>,
20    /// Custom extensions. This is the free-formed field to send client side metadata. No Datadog features are affected by this field.
21    #[serde(rename = "extensions")]
22    pub extensions: Option<std::collections::BTreeMap<String, serde_json::Value>>,
23    /// A base schema for defining third-party integrations.
24    #[serde(rename = "integrations")]
25    pub integrations: Option<crate::datadogV2::model::EntityV3Integrations>,
26    /// The definition of Entity V3 Datastore Kind object.
27    #[serde(rename = "kind")]
28    pub kind: crate::datadogV2::model::EntityV3DatastoreKind,
29    /// The definition of Entity V3 Metadata object.
30    #[serde(rename = "metadata")]
31    pub metadata: crate::datadogV2::model::EntityV3Metadata,
32    /// The definition of Entity V3 Datastore Spec object.
33    #[serde(rename = "spec")]
34    pub spec: Option<crate::datadogV2::model::EntityV3DatastoreSpec>,
35    #[serde(skip)]
36    #[serde(default)]
37    pub(crate) _unparsed: bool,
38}
39
40impl EntityV3Datastore {
41    pub fn new(
42        api_version: crate::datadogV2::model::EntityV3APIVersion,
43        kind: crate::datadogV2::model::EntityV3DatastoreKind,
44        metadata: crate::datadogV2::model::EntityV3Metadata,
45    ) -> EntityV3Datastore {
46        EntityV3Datastore {
47            api_version,
48            datadog: None,
49            extensions: None,
50            integrations: None,
51            kind,
52            metadata,
53            spec: None,
54            _unparsed: false,
55        }
56    }
57
58    pub fn datadog(mut self, value: crate::datadogV2::model::EntityV3DatastoreDatadog) -> Self {
59        self.datadog = Some(value);
60        self
61    }
62
63    pub fn extensions(
64        mut self,
65        value: std::collections::BTreeMap<String, serde_json::Value>,
66    ) -> Self {
67        self.extensions = Some(value);
68        self
69    }
70
71    pub fn integrations(mut self, value: crate::datadogV2::model::EntityV3Integrations) -> Self {
72        self.integrations = Some(value);
73        self
74    }
75
76    pub fn spec(mut self, value: crate::datadogV2::model::EntityV3DatastoreSpec) -> Self {
77        self.spec = Some(value);
78        self
79    }
80}
81
82impl<'de> Deserialize<'de> for EntityV3Datastore {
83    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
84    where
85        D: Deserializer<'de>,
86    {
87        struct EntityV3DatastoreVisitor;
88        impl<'a> Visitor<'a> for EntityV3DatastoreVisitor {
89            type Value = EntityV3Datastore;
90
91            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
92                f.write_str("a mapping")
93            }
94
95            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
96            where
97                M: MapAccess<'a>,
98            {
99                let mut api_version: Option<crate::datadogV2::model::EntityV3APIVersion> = None;
100                let mut datadog: Option<crate::datadogV2::model::EntityV3DatastoreDatadog> = None;
101                let mut extensions: Option<std::collections::BTreeMap<String, serde_json::Value>> =
102                    None;
103                let mut integrations: Option<crate::datadogV2::model::EntityV3Integrations> = None;
104                let mut kind: Option<crate::datadogV2::model::EntityV3DatastoreKind> = None;
105                let mut metadata: Option<crate::datadogV2::model::EntityV3Metadata> = None;
106                let mut spec: Option<crate::datadogV2::model::EntityV3DatastoreSpec> = None;
107                let mut _unparsed = false;
108
109                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
110                    match k.as_str() {
111                        "apiVersion" => {
112                            api_version =
113                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
114                            if let Some(ref _api_version) = api_version {
115                                match _api_version {
116                                    crate::datadogV2::model::EntityV3APIVersion::UnparsedObject(
117                                        _api_version,
118                                    ) => {
119                                        _unparsed = true;
120                                    }
121                                    _ => {}
122                                }
123                            }
124                        }
125                        "datadog" => {
126                            if v.is_null() {
127                                continue;
128                            }
129                            datadog = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
130                        }
131                        "extensions" => {
132                            if v.is_null() {
133                                continue;
134                            }
135                            extensions = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
136                        }
137                        "integrations" => {
138                            if v.is_null() {
139                                continue;
140                            }
141                            integrations =
142                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
143                        }
144                        "kind" => {
145                            kind = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
146                            if let Some(ref _kind) = kind {
147                                match _kind {
148                                    crate::datadogV2::model::EntityV3DatastoreKind::UnparsedObject(_kind) => {
149                                        _unparsed = true;
150                                    },
151                                    _ => {}
152                                }
153                            }
154                        }
155                        "metadata" => {
156                            metadata = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
157                        }
158                        "spec" => {
159                            if v.is_null() {
160                                continue;
161                            }
162                            spec = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
163                        }
164                        &_ => {
165                            return Err(serde::de::Error::custom(
166                                "Additional properties not allowed",
167                            ));
168                        }
169                    }
170                }
171                let api_version =
172                    api_version.ok_or_else(|| M::Error::missing_field("api_version"))?;
173                let kind = kind.ok_or_else(|| M::Error::missing_field("kind"))?;
174                let metadata = metadata.ok_or_else(|| M::Error::missing_field("metadata"))?;
175
176                let content = EntityV3Datastore {
177                    api_version,
178                    datadog,
179                    extensions,
180                    integrations,
181                    kind,
182                    metadata,
183                    spec,
184                    _unparsed,
185                };
186
187                Ok(content)
188            }
189        }
190
191        deserializer.deserialize_any(EntityV3DatastoreVisitor)
192    }
193}