datadog_api_client/datadogV2/model/
model_observability_pipeline_gcp_auth.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/// GCP credentials used to authenticate with Google Cloud Storage.
10///
11#[non_exhaustive]
12#[skip_serializing_none]
13#[derive(Clone, Debug, PartialEq, Serialize)]
14pub struct ObservabilityPipelineGcpAuth {
15    /// Path to the GCP service account key file.
16    #[serde(rename = "credentials_file")]
17    pub credentials_file: String,
18    #[serde(flatten)]
19    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
20    #[serde(skip)]
21    #[serde(default)]
22    pub(crate) _unparsed: bool,
23}
24
25impl ObservabilityPipelineGcpAuth {
26    pub fn new(credentials_file: String) -> ObservabilityPipelineGcpAuth {
27        ObservabilityPipelineGcpAuth {
28            credentials_file,
29            additional_properties: std::collections::BTreeMap::new(),
30            _unparsed: false,
31        }
32    }
33
34    pub fn additional_properties(
35        mut self,
36        value: std::collections::BTreeMap<String, serde_json::Value>,
37    ) -> Self {
38        self.additional_properties = value;
39        self
40    }
41}
42
43impl<'de> Deserialize<'de> for ObservabilityPipelineGcpAuth {
44    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
45    where
46        D: Deserializer<'de>,
47    {
48        struct ObservabilityPipelineGcpAuthVisitor;
49        impl<'a> Visitor<'a> for ObservabilityPipelineGcpAuthVisitor {
50            type Value = ObservabilityPipelineGcpAuth;
51
52            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
53                f.write_str("a mapping")
54            }
55
56            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
57            where
58                M: MapAccess<'a>,
59            {
60                let mut credentials_file: Option<String> = None;
61                let mut additional_properties: std::collections::BTreeMap<
62                    String,
63                    serde_json::Value,
64                > = std::collections::BTreeMap::new();
65                let mut _unparsed = false;
66
67                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
68                    match k.as_str() {
69                        "credentials_file" => {
70                            credentials_file =
71                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
72                        }
73                        &_ => {
74                            if let Ok(value) = serde_json::from_value(v.clone()) {
75                                additional_properties.insert(k, value);
76                            }
77                        }
78                    }
79                }
80                let credentials_file =
81                    credentials_file.ok_or_else(|| M::Error::missing_field("credentials_file"))?;
82
83                let content = ObservabilityPipelineGcpAuth {
84                    credentials_file,
85                    additional_properties,
86                    _unparsed,
87                };
88
89                Ok(content)
90            }
91        }
92
93        deserializer.deserialize_any(ObservabilityPipelineGcpAuthVisitor)
94    }
95}