|
| 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. |
| 4 | +use serde::de::{Error, MapAccess, Visitor}; |
| 5 | +use serde::{Deserialize, Deserializer, Serialize}; |
| 6 | +use serde_with::skip_serializing_none; |
| 7 | +use std::fmt::{self, Formatter}; |
| 8 | + |
| 9 | +/// The `google_pubsub` destination publishes logs to a Google Cloud Pub/Sub topic. |
| 10 | +#[non_exhaustive] |
| 11 | +#[skip_serializing_none] |
| 12 | +#[derive(Clone, Debug, PartialEq, Serialize)] |
| 13 | +pub struct ObservabilityPipelineGooglePubSubDestination { |
| 14 | + /// GCP credentials used to authenticate with Google Cloud Storage. |
| 15 | + /// |
| 16 | + #[serde(rename = "auth")] |
| 17 | + pub auth: Option<crate::datadogV2::model::ObservabilityPipelineGcpAuth>, |
| 18 | + /// Encoding format for log events. |
| 19 | + #[serde(rename = "encoding")] |
| 20 | + pub encoding: crate::datadogV2::model::ObservabilityPipelineGooglePubSubDestinationEncoding, |
| 21 | + /// The unique identifier for this component. |
| 22 | + #[serde(rename = "id")] |
| 23 | + pub id: String, |
| 24 | + /// A list of component IDs whose output is used as the `input` for this component. |
| 25 | + #[serde(rename = "inputs")] |
| 26 | + pub inputs: Vec<String>, |
| 27 | + /// The GCP project ID that owns the Pub/Sub topic. |
| 28 | + #[serde(rename = "project")] |
| 29 | + pub project: String, |
| 30 | + /// Configuration for enabling TLS encryption between the pipeline component and external services. |
| 31 | + #[serde(rename = "tls")] |
| 32 | + pub tls: Option<crate::datadogV2::model::ObservabilityPipelineTls>, |
| 33 | + /// The Pub/Sub topic name to publish logs to. |
| 34 | + #[serde(rename = "topic")] |
| 35 | + pub topic: String, |
| 36 | + /// The destination type. The value should always be `google_pubsub`. |
| 37 | + #[serde(rename = "type")] |
| 38 | + pub type_: crate::datadogV2::model::ObservabilityPipelineGooglePubSubDestinationType, |
| 39 | + #[serde(flatten)] |
| 40 | + pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>, |
| 41 | + #[serde(skip)] |
| 42 | + #[serde(default)] |
| 43 | + pub(crate) _unparsed: bool, |
| 44 | +} |
| 45 | + |
| 46 | +impl ObservabilityPipelineGooglePubSubDestination { |
| 47 | + pub fn new( |
| 48 | + encoding: crate::datadogV2::model::ObservabilityPipelineGooglePubSubDestinationEncoding, |
| 49 | + id: String, |
| 50 | + inputs: Vec<String>, |
| 51 | + project: String, |
| 52 | + topic: String, |
| 53 | + type_: crate::datadogV2::model::ObservabilityPipelineGooglePubSubDestinationType, |
| 54 | + ) -> ObservabilityPipelineGooglePubSubDestination { |
| 55 | + ObservabilityPipelineGooglePubSubDestination { |
| 56 | + auth: None, |
| 57 | + encoding, |
| 58 | + id, |
| 59 | + inputs, |
| 60 | + project, |
| 61 | + tls: None, |
| 62 | + topic, |
| 63 | + type_, |
| 64 | + additional_properties: std::collections::BTreeMap::new(), |
| 65 | + _unparsed: false, |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + pub fn auth(mut self, value: crate::datadogV2::model::ObservabilityPipelineGcpAuth) -> Self { |
| 70 | + self.auth = Some(value); |
| 71 | + self |
| 72 | + } |
| 73 | + |
| 74 | + pub fn tls(mut self, value: crate::datadogV2::model::ObservabilityPipelineTls) -> Self { |
| 75 | + self.tls = Some(value); |
| 76 | + self |
| 77 | + } |
| 78 | + |
| 79 | + pub fn additional_properties( |
| 80 | + mut self, |
| 81 | + value: std::collections::BTreeMap<String, serde_json::Value>, |
| 82 | + ) -> Self { |
| 83 | + self.additional_properties = value; |
| 84 | + self |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +impl<'de> Deserialize<'de> for ObservabilityPipelineGooglePubSubDestination { |
| 89 | + fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> |
| 90 | + where |
| 91 | + D: Deserializer<'de>, |
| 92 | + { |
| 93 | + struct ObservabilityPipelineGooglePubSubDestinationVisitor; |
| 94 | + impl<'a> Visitor<'a> for ObservabilityPipelineGooglePubSubDestinationVisitor { |
| 95 | + type Value = ObservabilityPipelineGooglePubSubDestination; |
| 96 | + |
| 97 | + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { |
| 98 | + f.write_str("a mapping") |
| 99 | + } |
| 100 | + |
| 101 | + fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error> |
| 102 | + where |
| 103 | + M: MapAccess<'a>, |
| 104 | + { |
| 105 | + let mut auth: Option<crate::datadogV2::model::ObservabilityPipelineGcpAuth> = None; |
| 106 | + let mut encoding: Option< |
| 107 | + crate::datadogV2::model::ObservabilityPipelineGooglePubSubDestinationEncoding, |
| 108 | + > = None; |
| 109 | + let mut id: Option<String> = None; |
| 110 | + let mut inputs: Option<Vec<String>> = None; |
| 111 | + let mut project: Option<String> = None; |
| 112 | + let mut tls: Option<crate::datadogV2::model::ObservabilityPipelineTls> = None; |
| 113 | + let mut topic: Option<String> = None; |
| 114 | + let mut type_: Option< |
| 115 | + crate::datadogV2::model::ObservabilityPipelineGooglePubSubDestinationType, |
| 116 | + > = None; |
| 117 | + let mut additional_properties: std::collections::BTreeMap< |
| 118 | + String, |
| 119 | + serde_json::Value, |
| 120 | + > = std::collections::BTreeMap::new(); |
| 121 | + let mut _unparsed = false; |
| 122 | + |
| 123 | + while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? { |
| 124 | + match k.as_str() { |
| 125 | + "auth" => { |
| 126 | + if v.is_null() { |
| 127 | + continue; |
| 128 | + } |
| 129 | + auth = Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 130 | + } |
| 131 | + "encoding" => { |
| 132 | + encoding = Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 133 | + if let Some(ref _encoding) = encoding { |
| 134 | + match _encoding { |
| 135 | + crate::datadogV2::model::ObservabilityPipelineGooglePubSubDestinationEncoding::UnparsedObject(_encoding) => { |
| 136 | + _unparsed = true; |
| 137 | + }, |
| 138 | + _ => {} |
| 139 | + } |
| 140 | + } |
| 141 | + } |
| 142 | + "id" => { |
| 143 | + id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 144 | + } |
| 145 | + "inputs" => { |
| 146 | + inputs = Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 147 | + } |
| 148 | + "project" => { |
| 149 | + project = Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 150 | + } |
| 151 | + "tls" => { |
| 152 | + if v.is_null() { |
| 153 | + continue; |
| 154 | + } |
| 155 | + tls = Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 156 | + } |
| 157 | + "topic" => { |
| 158 | + topic = Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 159 | + } |
| 160 | + "type" => { |
| 161 | + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 162 | + if let Some(ref _type_) = type_ { |
| 163 | + match _type_ { |
| 164 | + crate::datadogV2::model::ObservabilityPipelineGooglePubSubDestinationType::UnparsedObject(_type_) => { |
| 165 | + _unparsed = true; |
| 166 | + }, |
| 167 | + _ => {} |
| 168 | + } |
| 169 | + } |
| 170 | + } |
| 171 | + &_ => { |
| 172 | + if let Ok(value) = serde_json::from_value(v.clone()) { |
| 173 | + additional_properties.insert(k, value); |
| 174 | + } |
| 175 | + } |
| 176 | + } |
| 177 | + } |
| 178 | + let encoding = encoding.ok_or_else(|| M::Error::missing_field("encoding"))?; |
| 179 | + let id = id.ok_or_else(|| M::Error::missing_field("id"))?; |
| 180 | + let inputs = inputs.ok_or_else(|| M::Error::missing_field("inputs"))?; |
| 181 | + let project = project.ok_or_else(|| M::Error::missing_field("project"))?; |
| 182 | + let topic = topic.ok_or_else(|| M::Error::missing_field("topic"))?; |
| 183 | + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; |
| 184 | + |
| 185 | + let content = ObservabilityPipelineGooglePubSubDestination { |
| 186 | + auth, |
| 187 | + encoding, |
| 188 | + id, |
| 189 | + inputs, |
| 190 | + project, |
| 191 | + tls, |
| 192 | + topic, |
| 193 | + type_, |
| 194 | + additional_properties, |
| 195 | + _unparsed, |
| 196 | + }; |
| 197 | + |
| 198 | + Ok(content) |
| 199 | + } |
| 200 | + } |
| 201 | + |
| 202 | + deserializer.deserialize_any(ObservabilityPipelineGooglePubSubDestinationVisitor) |
| 203 | + } |
| 204 | +} |
0 commit comments