|
| 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 | +/// Configuration for enabling TLS encryption between the pipeline component and external services. |
| 10 | +#[non_exhaustive] |
| 11 | +#[skip_serializing_none] |
| 12 | +#[derive(Clone, Debug, PartialEq, Serialize)] |
| 13 | +pub struct ObservabilityPipelineClientTls { |
| 14 | + /// Path to the Certificate Authority (CA) file used to validate the server’s TLS certificate. |
| 15 | + #[serde(rename = "ca_file")] |
| 16 | + pub ca_file: Option<String>, |
| 17 | + /// Path to the TLS client certificate file used to authenticate the pipeline component with upstream or downstream services. |
| 18 | + #[serde(rename = "crt_file")] |
| 19 | + pub crt_file: String, |
| 20 | + /// Path to the private key file associated with the TLS client certificate. Used for mutual TLS authentication. |
| 21 | + #[serde(rename = "key_file")] |
| 22 | + pub key_file: Option<String>, |
| 23 | + /// Name of the environment variable or secret that holds the passphrase for the private key file. |
| 24 | + #[serde(rename = "key_pass_key")] |
| 25 | + pub key_pass_key: Option<String>, |
| 26 | + /// Server name to use for Server Name Indication (SNI) and to verify against the certificate presented by the remote host. Use this when the address you connect to doesn't match the certificate's Common Name or Subject Alternative Name. |
| 27 | + #[serde(rename = "server_name")] |
| 28 | + pub server_name: Option<String>, |
| 29 | + #[serde(flatten)] |
| 30 | + pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>, |
| 31 | + #[serde(skip)] |
| 32 | + #[serde(default)] |
| 33 | + pub(crate) _unparsed: bool, |
| 34 | +} |
| 35 | + |
| 36 | +impl ObservabilityPipelineClientTls { |
| 37 | + pub fn new(crt_file: String) -> ObservabilityPipelineClientTls { |
| 38 | + ObservabilityPipelineClientTls { |
| 39 | + ca_file: None, |
| 40 | + crt_file, |
| 41 | + key_file: None, |
| 42 | + key_pass_key: None, |
| 43 | + server_name: None, |
| 44 | + additional_properties: std::collections::BTreeMap::new(), |
| 45 | + _unparsed: false, |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + pub fn ca_file(mut self, value: String) -> Self { |
| 50 | + self.ca_file = Some(value); |
| 51 | + self |
| 52 | + } |
| 53 | + |
| 54 | + pub fn key_file(mut self, value: String) -> Self { |
| 55 | + self.key_file = Some(value); |
| 56 | + self |
| 57 | + } |
| 58 | + |
| 59 | + pub fn key_pass_key(mut self, value: String) -> Self { |
| 60 | + self.key_pass_key = Some(value); |
| 61 | + self |
| 62 | + } |
| 63 | + |
| 64 | + pub fn server_name(mut self, value: String) -> Self { |
| 65 | + self.server_name = Some(value); |
| 66 | + self |
| 67 | + } |
| 68 | + |
| 69 | + pub fn additional_properties( |
| 70 | + mut self, |
| 71 | + value: std::collections::BTreeMap<String, serde_json::Value>, |
| 72 | + ) -> Self { |
| 73 | + self.additional_properties = value; |
| 74 | + self |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +impl<'de> Deserialize<'de> for ObservabilityPipelineClientTls { |
| 79 | + fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> |
| 80 | + where |
| 81 | + D: Deserializer<'de>, |
| 82 | + { |
| 83 | + struct ObservabilityPipelineClientTlsVisitor; |
| 84 | + impl<'a> Visitor<'a> for ObservabilityPipelineClientTlsVisitor { |
| 85 | + type Value = ObservabilityPipelineClientTls; |
| 86 | + |
| 87 | + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { |
| 88 | + f.write_str("a mapping") |
| 89 | + } |
| 90 | + |
| 91 | + fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error> |
| 92 | + where |
| 93 | + M: MapAccess<'a>, |
| 94 | + { |
| 95 | + let mut ca_file: Option<String> = None; |
| 96 | + let mut crt_file: Option<String> = None; |
| 97 | + let mut key_file: Option<String> = None; |
| 98 | + let mut key_pass_key: Option<String> = None; |
| 99 | + let mut server_name: Option<String> = None; |
| 100 | + let mut additional_properties: std::collections::BTreeMap< |
| 101 | + String, |
| 102 | + serde_json::Value, |
| 103 | + > = std::collections::BTreeMap::new(); |
| 104 | + let mut _unparsed = false; |
| 105 | + |
| 106 | + while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? { |
| 107 | + match k.as_str() { |
| 108 | + "ca_file" => { |
| 109 | + if v.is_null() { |
| 110 | + continue; |
| 111 | + } |
| 112 | + ca_file = Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 113 | + } |
| 114 | + "crt_file" => { |
| 115 | + crt_file = Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 116 | + } |
| 117 | + "key_file" => { |
| 118 | + if v.is_null() { |
| 119 | + continue; |
| 120 | + } |
| 121 | + key_file = Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 122 | + } |
| 123 | + "key_pass_key" => { |
| 124 | + if v.is_null() { |
| 125 | + continue; |
| 126 | + } |
| 127 | + key_pass_key = |
| 128 | + Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 129 | + } |
| 130 | + "server_name" => { |
| 131 | + if v.is_null() { |
| 132 | + continue; |
| 133 | + } |
| 134 | + server_name = |
| 135 | + Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 136 | + } |
| 137 | + &_ => { |
| 138 | + if let Ok(value) = serde_json::from_value(v.clone()) { |
| 139 | + additional_properties.insert(k, value); |
| 140 | + } |
| 141 | + } |
| 142 | + } |
| 143 | + } |
| 144 | + let crt_file = crt_file.ok_or_else(|| M::Error::missing_field("crt_file"))?; |
| 145 | + |
| 146 | + let content = ObservabilityPipelineClientTls { |
| 147 | + ca_file, |
| 148 | + crt_file, |
| 149 | + key_file, |
| 150 | + key_pass_key, |
| 151 | + server_name, |
| 152 | + additional_properties, |
| 153 | + _unparsed, |
| 154 | + }; |
| 155 | + |
| 156 | + Ok(content) |
| 157 | + } |
| 158 | + } |
| 159 | + |
| 160 | + deserializer.deserialize_any(ObservabilityPipelineClientTlsVisitor) |
| 161 | + } |
| 162 | +} |
0 commit comments