Skip to content

Add metric_namespace_configs to GCP v2 API #365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.6",
"regenerated": "2024-11-05 21:07:09.415913",
"spec_repo_commit": "6c0fa1b6"
"regenerated": "2024-11-05 22:28:16.921323",
"spec_repo_commit": "2db17c21"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2024-11-05 21:07:09.434355",
"spec_repo_commit": "6c0fa1b6"
"regenerated": "2024-11-05 22:28:16.941353",
"spec_repo_commit": "2db17c21"
}
}
}
22 changes: 22 additions & 0 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9623,6 +9623,20 @@ components:
nullable: true
type: array
type: object
GCPMetricNamespaceConfig:
description: Configuration for a GCP metric namespace.
properties:
disabled:
default: false
description: When disabled, Datadog does not collect metrics that are related
to this GCP metric namespace.
example: true
type: boolean
id:
description: The id of the GCP metric namespace.
example: aiplatform
type: string
type: object
GCPSTSDelegateAccount:
description: Datadog principal service account info.
properties:
Expand Down Expand Up @@ -9725,6 +9739,14 @@ components:
account.'
example: true
type: boolean
metric_namespace_configs:
description: Configurations for GCP metric namespaces.
example:
- disabled: true
id: aiplatform
items:
$ref: '#/components/schemas/GCPMetricNamespaceConfig'
type: array
resource_collection_enabled:
description: When enabled, Datadog scans for all resources in your GCP environment.
type: boolean
Expand Down
2 changes: 2 additions & 0 deletions src/datadogV2/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,8 @@ pub mod model_gcpsts_service_account;
pub use self::model_gcpsts_service_account::GCPSTSServiceAccount;
pub mod model_gcpsts_service_account_attributes;
pub use self::model_gcpsts_service_account_attributes::GCPSTSServiceAccountAttributes;
pub mod model_gcp_metric_namespace_config;
pub use self::model_gcp_metric_namespace_config::GCPMetricNamespaceConfig;
pub mod model_gcp_service_account_meta;
pub use self::model_gcp_service_account_meta::GCPServiceAccountMeta;
pub mod model_gcp_service_account_type;
Expand Down
122 changes: 122 additions & 0 deletions src/datadogV2/model/model_gcp_metric_namespace_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.
use serde::de::{Error, MapAccess, Visitor};
use serde::{Deserialize, Deserializer, Serialize};
use serde_with::skip_serializing_none;
use std::fmt::{self, Formatter};

/// Configuration for a GCP metric namespace.
#[non_exhaustive]
#[skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct GCPMetricNamespaceConfig {
/// When disabled, Datadog does not collect metrics that are related to this GCP metric namespace.
#[serde(rename = "disabled")]
pub disabled: Option<bool>,
/// The id of the GCP metric namespace.
#[serde(rename = "id")]
pub id: Option<String>,
#[serde(flatten)]
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
#[serde(skip)]
#[serde(default)]
pub(crate) _unparsed: bool,
}

impl GCPMetricNamespaceConfig {
pub fn new() -> GCPMetricNamespaceConfig {
GCPMetricNamespaceConfig {
disabled: None,
id: None,
additional_properties: std::collections::BTreeMap::new(),
_unparsed: false,
}
}

pub fn disabled(mut self, value: bool) -> Self {
self.disabled = Some(value);
self
}

pub fn id(mut self, value: String) -> Self {
self.id = Some(value);
self
}

pub fn additional_properties(
mut self,
value: std::collections::BTreeMap<String, serde_json::Value>,
) -> Self {
self.additional_properties = value;
self
}
}

impl Default for GCPMetricNamespaceConfig {
fn default() -> Self {
Self::new()
}
}

impl<'de> Deserialize<'de> for GCPMetricNamespaceConfig {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct GCPMetricNamespaceConfigVisitor;
impl<'a> Visitor<'a> for GCPMetricNamespaceConfigVisitor {
type Value = GCPMetricNamespaceConfig;

fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str("a mapping")
}

fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
where
M: MapAccess<'a>,
{
let mut disabled: Option<bool> = None;
let mut id: Option<String> = None;
let mut additional_properties: std::collections::BTreeMap<
String,
serde_json::Value,
> = std::collections::BTreeMap::new();
let mut _unparsed = false;

while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
match k.as_str() {
"disabled" => {
if v.is_null() {
continue;
}
disabled = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"id" => {
if v.is_null() {
continue;
}
id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
&_ => {
if let Ok(value) = serde_json::from_value(v.clone()) {
additional_properties.insert(k, value);
}
}
}
}

let content = GCPMetricNamespaceConfig {
disabled,
id,
additional_properties,
_unparsed,
};

Ok(content)
}
}

deserializer.deserialize_any(GCPMetricNamespaceConfigVisitor)
}
}
23 changes: 23 additions & 0 deletions src/datadogV2/model/model_gcpsts_service_account_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ pub struct GCPSTSServiceAccountAttributes {
/// When enabled, Datadog will attempt to collect Security Command Center Findings. Note: This requires additional permissions on the service account.
#[serde(rename = "is_security_command_center_enabled")]
pub is_security_command_center_enabled: Option<bool>,
/// Configurations for GCP metric namespaces.
#[serde(rename = "metric_namespace_configs")]
pub metric_namespace_configs: Option<Vec<crate::datadogV2::model::GCPMetricNamespaceConfig>>,
/// When enabled, Datadog scans for all resources in your GCP environment.
#[serde(rename = "resource_collection_enabled")]
pub resource_collection_enabled: Option<bool>,
Expand All @@ -57,6 +60,7 @@ impl GCPSTSServiceAccountAttributes {
is_cspm_enabled: None,
is_resource_change_collection_enabled: None,
is_security_command_center_enabled: None,
metric_namespace_configs: None,
resource_collection_enabled: None,
additional_properties: std::collections::BTreeMap::new(),
_unparsed: false,
Expand Down Expand Up @@ -103,6 +107,14 @@ impl GCPSTSServiceAccountAttributes {
self
}

pub fn metric_namespace_configs(
mut self,
value: Vec<crate::datadogV2::model::GCPMetricNamespaceConfig>,
) -> Self {
self.metric_namespace_configs = Some(value);
self
}

pub fn resource_collection_enabled(mut self, value: bool) -> Self {
self.resource_collection_enabled = Some(value);
self
Expand Down Expand Up @@ -148,6 +160,9 @@ impl<'de> Deserialize<'de> for GCPSTSServiceAccountAttributes {
let mut is_cspm_enabled: Option<bool> = None;
let mut is_resource_change_collection_enabled: Option<bool> = None;
let mut is_security_command_center_enabled: Option<bool> = None;
let mut metric_namespace_configs: Option<
Vec<crate::datadogV2::model::GCPMetricNamespaceConfig>,
> = None;
let mut resource_collection_enabled: Option<bool> = None;
let mut additional_properties: std::collections::BTreeMap<
String,
Expand Down Expand Up @@ -212,6 +227,13 @@ impl<'de> Deserialize<'de> for GCPSTSServiceAccountAttributes {
is_security_command_center_enabled =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"metric_namespace_configs" => {
if v.is_null() {
continue;
}
metric_namespace_configs =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"resource_collection_enabled" => {
if v.is_null() {
continue;
Expand All @@ -236,6 +258,7 @@ impl<'de> Deserialize<'de> for GCPSTSServiceAccountAttributes {
is_cspm_enabled,
is_resource_change_collection_enabled,
is_security_command_center_enabled,
metric_namespace_configs,
resource_collection_enabled,
additional_properties,
_unparsed,
Expand Down
8 changes: 4 additions & 4 deletions tests/scenarios/features/v2/gcp_integration.feature
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ Feature: GCP Integration
@generated @skip @team:DataDog/gcp-integrations
Scenario: Create a new entry for your service account returns "Bad Request" response
Given new "CreateGCPSTSAccount" request
And body with value {"data": {"attributes": {"account_tags": [], "client_email": "[email protected]", "cloud_run_revision_filters": ["$KEY:$VALUE"], "host_filters": [], "is_resource_change_collection_enabled": true, "is_security_command_center_enabled": true}, "type": "gcp_service_account"}}
And body with value {"data": {"attributes": {"account_tags": [], "client_email": "[email protected]", "cloud_run_revision_filters": ["$KEY:$VALUE"], "host_filters": [], "is_resource_change_collection_enabled": true, "is_security_command_center_enabled": true, "metric_namespace_configs": [{"disabled": true, "id": "aiplatform"}]}, "type": "gcp_service_account"}}
When the request is sent
Then the response status is 400 Bad Request

@generated @skip @team:DataDog/gcp-integrations
Scenario: Create a new entry for your service account returns "Conflict" response
Given new "CreateGCPSTSAccount" request
And body with value {"data": {"attributes": {"account_tags": [], "client_email": "[email protected]", "cloud_run_revision_filters": ["$KEY:$VALUE"], "host_filters": [], "is_resource_change_collection_enabled": true, "is_security_command_center_enabled": true}, "type": "gcp_service_account"}}
And body with value {"data": {"attributes": {"account_tags": [], "client_email": "[email protected]", "cloud_run_revision_filters": ["$KEY:$VALUE"], "host_filters": [], "is_resource_change_collection_enabled": true, "is_security_command_center_enabled": true, "metric_namespace_configs": [{"disabled": true, "id": "aiplatform"}]}, "type": "gcp_service_account"}}
When the request is sent
Then the response status is 409 Conflict

Expand Down Expand Up @@ -151,15 +151,15 @@ Feature: GCP Integration
Scenario: Update STS Service Account returns "Bad Request" response
Given new "UpdateGCPSTSAccount" request
And request contains "account_id" parameter from "REPLACE.ME"
And body with value {"data": {"attributes": {"account_tags": [], "client_email": "[email protected]", "cloud_run_revision_filters": ["$KEY:$VALUE"], "host_filters": [], "is_resource_change_collection_enabled": true, "is_security_command_center_enabled": true}, "id": "d291291f-12c2-22g4-j290-123456678897", "type": "gcp_service_account"}}
And body with value {"data": {"attributes": {"account_tags": [], "client_email": "[email protected]", "cloud_run_revision_filters": ["$KEY:$VALUE"], "host_filters": [], "is_resource_change_collection_enabled": true, "is_security_command_center_enabled": true, "metric_namespace_configs": [{"disabled": true, "id": "aiplatform"}]}, "id": "d291291f-12c2-22g4-j290-123456678897", "type": "gcp_service_account"}}
When the request is sent
Then the response status is 400 Bad Request

@generated @skip @team:DataDog/gcp-integrations
Scenario: Update STS Service Account returns "Not Found" response
Given new "UpdateGCPSTSAccount" request
And request contains "account_id" parameter from "REPLACE.ME"
And body with value {"data": {"attributes": {"account_tags": [], "client_email": "[email protected]", "cloud_run_revision_filters": ["$KEY:$VALUE"], "host_filters": [], "is_resource_change_collection_enabled": true, "is_security_command_center_enabled": true}, "id": "d291291f-12c2-22g4-j290-123456678897", "type": "gcp_service_account"}}
And body with value {"data": {"attributes": {"account_tags": [], "client_email": "[email protected]", "cloud_run_revision_filters": ["$KEY:$VALUE"], "host_filters": [], "is_resource_change_collection_enabled": true, "is_security_command_center_enabled": true, "metric_namespace_configs": [{"disabled": true, "id": "aiplatform"}]}, "id": "d291291f-12c2-22g4-j290-123456678897", "type": "gcp_service_account"}}
When the request is sent
Then the response status is 404 Not Found

Expand Down
Loading