|
| 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 account filtering configuration. |
| 10 | +#[non_exhaustive] |
| 11 | +#[skip_serializing_none] |
| 12 | +#[derive(Clone, Debug, PartialEq, Serialize)] |
| 13 | +pub struct AccountFilteringConfig { |
| 14 | + /// The AWS account IDs to be excluded from your billing dataset. This field is used when `include_new_accounts` is `true`. |
| 15 | + #[serde(rename = "excluded_accounts")] |
| 16 | + pub excluded_accounts: Option<Vec<String>>, |
| 17 | + /// Whether or not to automatically include new member accounts by default in your billing dataset. |
| 18 | + #[serde(rename = "include_new_accounts")] |
| 19 | + pub include_new_accounts: Option<bool>, |
| 20 | + /// The AWS account IDs to be included in your billing dataset. This field is used when `include_new_accounts` is `false`. |
| 21 | + #[serde(rename = "included_accounts")] |
| 22 | + pub included_accounts: Option<Vec<String>>, |
| 23 | + #[serde(flatten)] |
| 24 | + pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>, |
| 25 | + #[serde(skip)] |
| 26 | + #[serde(default)] |
| 27 | + pub(crate) _unparsed: bool, |
| 28 | +} |
| 29 | + |
| 30 | +impl AccountFilteringConfig { |
| 31 | + pub fn new() -> AccountFilteringConfig { |
| 32 | + AccountFilteringConfig { |
| 33 | + excluded_accounts: None, |
| 34 | + include_new_accounts: None, |
| 35 | + included_accounts: None, |
| 36 | + additional_properties: std::collections::BTreeMap::new(), |
| 37 | + _unparsed: false, |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + pub fn excluded_accounts(mut self, value: Vec<String>) -> Self { |
| 42 | + self.excluded_accounts = Some(value); |
| 43 | + self |
| 44 | + } |
| 45 | + |
| 46 | + pub fn include_new_accounts(mut self, value: bool) -> Self { |
| 47 | + self.include_new_accounts = Some(value); |
| 48 | + self |
| 49 | + } |
| 50 | + |
| 51 | + pub fn included_accounts(mut self, value: Vec<String>) -> Self { |
| 52 | + self.included_accounts = Some(value); |
| 53 | + self |
| 54 | + } |
| 55 | + |
| 56 | + pub fn additional_properties( |
| 57 | + mut self, |
| 58 | + value: std::collections::BTreeMap<String, serde_json::Value>, |
| 59 | + ) -> Self { |
| 60 | + self.additional_properties = value; |
| 61 | + self |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +impl Default for AccountFilteringConfig { |
| 66 | + fn default() -> Self { |
| 67 | + Self::new() |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +impl<'de> Deserialize<'de> for AccountFilteringConfig { |
| 72 | + fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> |
| 73 | + where |
| 74 | + D: Deserializer<'de>, |
| 75 | + { |
| 76 | + struct AccountFilteringConfigVisitor; |
| 77 | + impl<'a> Visitor<'a> for AccountFilteringConfigVisitor { |
| 78 | + type Value = AccountFilteringConfig; |
| 79 | + |
| 80 | + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { |
| 81 | + f.write_str("a mapping") |
| 82 | + } |
| 83 | + |
| 84 | + fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error> |
| 85 | + where |
| 86 | + M: MapAccess<'a>, |
| 87 | + { |
| 88 | + let mut excluded_accounts: Option<Vec<String>> = None; |
| 89 | + let mut include_new_accounts: Option<bool> = None; |
| 90 | + let mut included_accounts: Option<Vec<String>> = None; |
| 91 | + let mut additional_properties: std::collections::BTreeMap< |
| 92 | + String, |
| 93 | + serde_json::Value, |
| 94 | + > = std::collections::BTreeMap::new(); |
| 95 | + let mut _unparsed = false; |
| 96 | + |
| 97 | + while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? { |
| 98 | + match k.as_str() { |
| 99 | + "excluded_accounts" => { |
| 100 | + if v.is_null() { |
| 101 | + continue; |
| 102 | + } |
| 103 | + excluded_accounts = |
| 104 | + Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 105 | + } |
| 106 | + "include_new_accounts" => { |
| 107 | + if v.is_null() { |
| 108 | + continue; |
| 109 | + } |
| 110 | + include_new_accounts = |
| 111 | + Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 112 | + } |
| 113 | + "included_accounts" => { |
| 114 | + if v.is_null() { |
| 115 | + continue; |
| 116 | + } |
| 117 | + included_accounts = |
| 118 | + Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 119 | + } |
| 120 | + &_ => { |
| 121 | + if let Ok(value) = serde_json::from_value(v.clone()) { |
| 122 | + additional_properties.insert(k, value); |
| 123 | + } |
| 124 | + } |
| 125 | + } |
| 126 | + } |
| 127 | + |
| 128 | + let content = AccountFilteringConfig { |
| 129 | + excluded_accounts, |
| 130 | + include_new_accounts, |
| 131 | + included_accounts, |
| 132 | + additional_properties, |
| 133 | + _unparsed, |
| 134 | + }; |
| 135 | + |
| 136 | + Ok(content) |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + deserializer.deserialize_any(AccountFilteringConfigVisitor) |
| 141 | + } |
| 142 | +} |
0 commit comments