Skip to content

Add metric_namespace_configs to GCP v2 API #2087

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:13.880957",
"spec_repo_commit": "6c0fa1b6"
"regenerated": "2024-11-05 22:28:17.976412",
"spec_repo_commit": "2db17c21"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2024-11-05 21:07:13.899409",
"spec_repo_commit": "6c0fa1b6"
"regenerated": "2024-11-05 22:28:17.995053",
"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
8 changes: 4 additions & 4 deletions 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": "datadog-service-account@test-project.iam.gserviceaccount.com", "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": "datadog-service-account@test-project.iam.gserviceaccount.com", "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": "datadog-service-account@test-project.iam.gserviceaccount.com", "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": "datadog-service-account@test-project.iam.gserviceaccount.com", "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": "datadog-service-account@test-project.iam.gserviceaccount.com", "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": "datadog-service-account@test-project.iam.gserviceaccount.com", "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": "datadog-service-account@test-project.iam.gserviceaccount.com", "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": "datadog-service-account@test-project.iam.gserviceaccount.com", "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
1 change: 1 addition & 0 deletions lib/datadog_api_client/inflector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1454,6 +1454,7 @@ def overrides
"v2.full_api_key_attributes" => "FullAPIKeyAttributes",
"v2.full_application_key" => "FullApplicationKey",
"v2.full_application_key_attributes" => "FullApplicationKeyAttributes",
"v2.gcp_metric_namespace_config" => "GCPMetricNamespaceConfig",
"v2.gcp_service_account_meta" => "GCPServiceAccountMeta",
"v2.gcp_service_account_type" => "GCPServiceAccountType",
"v2.gcpsts_delegate_account" => "GCPSTSDelegateAccount",
Expand Down
115 changes: 115 additions & 0 deletions lib/datadog_api_client/v2/models/gcp_metric_namespace_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
=begin
#Datadog API V2 Collection

#Collection of all Datadog Public endpoints.

The version of the OpenAPI document: 1.0
Contact: support@datadoghq.com
Generated by: https://github.com/DataDog/datadog-api-client-ruby/tree/master/.generator

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 2020-Present Datadog, Inc.

=end

require 'date'
require 'time'

module DatadogAPIClient::V2
# Configuration for a GCP metric namespace.
class GCPMetricNamespaceConfig
include BaseGenericModel

# When disabled, Datadog does not collect metrics that are related to this GCP metric namespace.
attr_accessor :disabled

# The id of the GCP metric namespace.
attr_accessor :id

attr_accessor :additional_properties

# Attribute mapping from ruby-style variable name to JSON key.
# @!visibility private
def self.attribute_map
{
:'disabled' => :'disabled',
:'id' => :'id'
}
end

# Attribute type mapping.
# @!visibility private
def self.openapi_types
{
:'disabled' => :'Boolean',
:'id' => :'String'
}
end

# Initializes the object
# @param attributes [Hash] Model attributes in the form of hash
# @!visibility private
def initialize(attributes = {})
if (!attributes.is_a?(Hash))
fail ArgumentError, "The input argument (attributes) must be a hash in `DatadogAPIClient::V2::GCPMetricNamespaceConfig` initialize method"
end

self.additional_properties = {}
# check to see if the attribute exists and convert string to symbol for hash key
attributes = attributes.each_with_object({}) { |(k, v), h|
if (!self.class.attribute_map.key?(k.to_sym))
self.additional_properties[k.to_sym] = v
else
h[k.to_sym] = v
end
}

if attributes.key?(:'disabled')
self.disabled = attributes[:'disabled']
end

if attributes.key?(:'id')
self.id = attributes[:'id']
end
end

# Returns the object in the form of hash, with additionalProperties support.
# @return [Hash] Returns the object in the form of hash
# @!visibility private
def to_hash
hash = {}
self.class.attribute_map.each_pair do |attr, param|
value = self.send(attr)
if value.nil?
is_nullable = self.class.openapi_nullable.include?(attr)
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
end

hash[param] = _to_hash(value)
end
self.additional_properties.each_pair do |attr, value|
hash[attr] = value
end
hash
end

# Checks equality by comparing each attribute.
# @param o [Object] Object to be compared
# @!visibility private
def ==(o)
return true if self.equal?(o)
self.class == o.class &&
disabled == o.disabled &&
id == o.id
additional_properties == o.additional_properties
end

# Calculates hash code according to all attributes.
# @return [Integer] Hash code
# @!visibility private
def hash
[disabled, id].hash
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class GCPSTSServiceAccountAttributes
# When enabled, Datadog will attempt to collect Security Command Center Findings. Note: This requires additional permissions on the service account.
attr_accessor :is_security_command_center_enabled

# Configurations for GCP metric namespaces.
attr_accessor :metric_namespace_configs

# When enabled, Datadog scans for all resources in your GCP environment.
attr_accessor :resource_collection_enabled

Expand All @@ -63,6 +66,7 @@ def self.attribute_map
:'is_cspm_enabled' => :'is_cspm_enabled',
:'is_resource_change_collection_enabled' => :'is_resource_change_collection_enabled',
:'is_security_command_center_enabled' => :'is_security_command_center_enabled',
:'metric_namespace_configs' => :'metric_namespace_configs',
:'resource_collection_enabled' => :'resource_collection_enabled'
}
end
Expand All @@ -79,6 +83,7 @@ def self.openapi_types
:'is_cspm_enabled' => :'Boolean',
:'is_resource_change_collection_enabled' => :'Boolean',
:'is_security_command_center_enabled' => :'Boolean',
:'metric_namespace_configs' => :'Array<GCPMetricNamespaceConfig>',
:'resource_collection_enabled' => :'Boolean'
}
end
Expand Down Expand Up @@ -139,6 +144,12 @@ def initialize(attributes = {})
self.is_security_command_center_enabled = attributes[:'is_security_command_center_enabled']
end

if attributes.key?(:'metric_namespace_configs')
if (value = attributes[:'metric_namespace_configs']).is_a?(Array)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Violation

Consider using Array() to ensure the type is that of an array (...read more)

The rule "Use Array() to ensure your variable is an array" is important for ensuring your code behaves as expected, regardless of the type of data it receives. It is common in Ruby to need to iterate through an array of items. However, if the variable is not an array, this can lead to unexpected behavior or errors.

The Array() method in Ruby is a Kernel method that converts its argument to an Array. If the argument is already an Array, it returns the argument. If the argument is nil, it returns an empty Array. This can be used to ensure that a variable is an array before trying to iterate over it, preventing potential errors or unexpected behavior.

By using Array(foos), you can ensure that foos is an array before you try to iterate over it with each. This prevents the need to check if foos is an array with foos.is_a?(Array) and makes your code cleaner and easier to understand.

View in Datadog  Leave us feedback  Documentation

self.metric_namespace_configs = value
end
end

if attributes.key?(:'resource_collection_enabled')
self.resource_collection_enabled = attributes[:'resource_collection_enabled']
end
Expand Down Expand Up @@ -178,6 +189,7 @@ def ==(o)
is_cspm_enabled == o.is_cspm_enabled &&
is_resource_change_collection_enabled == o.is_resource_change_collection_enabled &&
is_security_command_center_enabled == o.is_security_command_center_enabled &&
metric_namespace_configs == o.metric_namespace_configs &&
resource_collection_enabled == o.resource_collection_enabled
additional_properties == o.additional_properties
end
Expand All @@ -186,7 +198,7 @@ def ==(o)
# @return [Integer] Hash code
# @!visibility private
def hash
[account_tags, automute, client_email, cloud_run_revision_filters, host_filters, is_cspm_enabled, is_resource_change_collection_enabled, is_security_command_center_enabled, resource_collection_enabled].hash
[account_tags, automute, client_email, cloud_run_revision_filters, host_filters, is_cspm_enabled, is_resource_change_collection_enabled, is_security_command_center_enabled, metric_namespace_configs, resource_collection_enabled].hash
end
end
end
Loading