|
| 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 | +/// Dictionary containing the key `excluded_resource_providers` which has to be a list of Microsoft Azure Resource Provider names. |
| 10 | +/// This feature is currently being beta tested. |
| 11 | +/// In order to enable all resource providers for metric collection, pass: |
| 12 | +/// `metrics_config: {"excluded_resource_providers": []}` (i.e., an empty list for `excluded_resource_providers`). |
| 13 | +#[non_exhaustive] |
| 14 | +#[skip_serializing_none] |
| 15 | +#[derive(Clone, Debug, PartialEq, Serialize)] |
| 16 | +pub struct AzureAccountMetricsConfig { |
| 17 | + /// List of Microsoft Azure Resource Providers to exclude from metric collection. |
| 18 | + #[serde(rename = "excluded_resource_providers")] |
| 19 | + pub excluded_resource_providers: Option<Vec<String>>, |
| 20 | + #[serde(skip)] |
| 21 | + #[serde(default)] |
| 22 | + pub(crate) _unparsed: bool, |
| 23 | +} |
| 24 | + |
| 25 | +impl AzureAccountMetricsConfig { |
| 26 | + pub fn new() -> AzureAccountMetricsConfig { |
| 27 | + AzureAccountMetricsConfig { |
| 28 | + excluded_resource_providers: None, |
| 29 | + _unparsed: false, |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + pub fn excluded_resource_providers(mut self, value: Vec<String>) -> Self { |
| 34 | + self.excluded_resource_providers = Some(value); |
| 35 | + self |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +impl Default for AzureAccountMetricsConfig { |
| 40 | + fn default() -> Self { |
| 41 | + Self::new() |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +impl<'de> Deserialize<'de> for AzureAccountMetricsConfig { |
| 46 | + fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> |
| 47 | + where |
| 48 | + D: Deserializer<'de>, |
| 49 | + { |
| 50 | + struct AzureAccountMetricsConfigVisitor; |
| 51 | + impl<'a> Visitor<'a> for AzureAccountMetricsConfigVisitor { |
| 52 | + type Value = AzureAccountMetricsConfig; |
| 53 | + |
| 54 | + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { |
| 55 | + f.write_str("a mapping") |
| 56 | + } |
| 57 | + |
| 58 | + fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error> |
| 59 | + where |
| 60 | + M: MapAccess<'a>, |
| 61 | + { |
| 62 | + let mut excluded_resource_providers: Option<Vec<String>> = None; |
| 63 | + let mut _unparsed = false; |
| 64 | + |
| 65 | + while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? { |
| 66 | + match k.as_str() { |
| 67 | + "excluded_resource_providers" => { |
| 68 | + if v.is_null() { |
| 69 | + continue; |
| 70 | + } |
| 71 | + excluded_resource_providers = |
| 72 | + Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 73 | + } |
| 74 | + &_ => {} |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + let content = AzureAccountMetricsConfig { |
| 79 | + excluded_resource_providers, |
| 80 | + _unparsed, |
| 81 | + }; |
| 82 | + |
| 83 | + Ok(content) |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + deserializer.deserialize_any(AzureAccountMetricsConfigVisitor) |
| 88 | + } |
| 89 | +} |
0 commit comments