Skip to content

Add account-tags to GCP Service Account Attributes #1678

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": "2023-09-29 18:12:31.811515",
"spec_repo_commit": "e476e87a"
"regenerated": "2023-10-02 15:35:47.592073",
"spec_repo_commit": "deb69b98"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2023-09-29 18:12:31.827382",
"spec_repo_commit": "e476e87a"
"regenerated": "2023-10-02 15:35:47.610380",
"spec_repo_commit": "deb69b98"
}
}
}
7 changes: 7 additions & 0 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5399,6 +5399,13 @@ components:
GCPSTSServiceAccountAttributes:
description: Attributes associated with your service account.
properties:
account_tags:
description: Tags to be associated with GCP metrics and service checks from
your account.
items:
description: Account Level Tag
type: string
type: array
automute:
description: Silence monitors for expected GCE instance shutdowns.
type: boolean
Expand Down
31 changes: 31 additions & 0 deletions examples/v2/gcp-integration/CreateGCPSTSAccount_109518525.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
Create a new entry for your service account with account_tags returns "OK" response
"""

from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.gcp_integration_api import GCPIntegrationApi
from datadog_api_client.v2.model.gcp_service_account_type import GCPServiceAccountType
from datadog_api_client.v2.model.gcpsts_service_account_attributes import GCPSTSServiceAccountAttributes
from datadog_api_client.v2.model.gcpsts_service_account_create_request import GCPSTSServiceAccountCreateRequest
from datadog_api_client.v2.model.gcpsts_service_account_data import GCPSTSServiceAccountData

body = GCPSTSServiceAccountCreateRequest(
data=GCPSTSServiceAccountData(
attributes=GCPSTSServiceAccountAttributes(
account_tags=[
"lorem",
"ipsum",
],
client_email="[email protected]",
host_filters=[],
),
type=GCPServiceAccountType.GCP_SERVICE_ACCOUNT,
),
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
api_instance = GCPIntegrationApi(api_client)
response = api_instance.create_gcpsts_account(body=body)

print(response)
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ class GCPSTSServiceAccountAttributes(ModelNormal):
@cached_property
def openapi_types(_):
return {
"account_tags": ([str],),
"automute": (bool,),
"client_email": (str,),
"host_filters": ([str],),
"is_cspm_enabled": (bool,),
}

attribute_map = {
"account_tags": "account_tags",
"automute": "automute",
"client_email": "client_email",
"host_filters": "host_filters",
Expand All @@ -32,6 +34,7 @@ def openapi_types(_):

def __init__(
self_,
account_tags: Union[List[str], UnsetType] = unset,
automute: Union[bool, UnsetType] = unset,
client_email: Union[str, UnsetType] = unset,
host_filters: Union[List[str], UnsetType] = unset,
Expand All @@ -41,6 +44,9 @@ def __init__(
"""
Attributes associated with your service account.

:param account_tags: Tags to be associated with GCP metrics and service checks from your account.
:type account_tags: [str], optional

:param automute: Silence monitors for expected GCE instance shutdowns.
:type automute: bool, optional

Expand All @@ -53,6 +59,8 @@ def __init__(
:param is_cspm_enabled: When enabled, Datadog performs configuration checks across your Google Cloud environment by continuously scanning every resource.
:type is_cspm_enabled: bool, optional
"""
if account_tags is not unset:
kwargs["account_tags"] = account_tags
if automute is not unset:
kwargs["automute"] = automute
if client_email is not unset:
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-06-16T14:05:25.134Z
2023-09-29T12:39:55.710Z
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
interactions:
- request:
body: '{"data":{"attributes":{"client_email":"47cdd79b4a719ac2@test-project.iam.gserviceaccount.com","host_filters":[]},"type":"gcp_service_account"}}'
body: '{"data":{"attributes":{"client_email":"80e3f00106389e6e@test-project.iam.gserviceaccount.com","host_filters":[]},"type":"gcp_service_account"}}'
headers:
accept:
- application/json
Expand All @@ -10,7 +10,7 @@ interactions:
uri: https://api.datadoghq.com/api/v2/integration/gcp/accounts
response:
body:
string: '{"data":{"type":"gcp_service_account","attributes":{"host_filters":[],"client_email":"47cdd79b4a719ac2@test-project.iam.gserviceaccount.com","is_cspm_enabled":false,"automute":false},"id":"3aa3ec77-9646-4f6a-bcd0-01e5124e2ad1"}}
string: '{"data":{"type":"gcp_service_account","id":"d6c68645-2b52-43e9-838c-9b7fdb809a8d","attributes":{"host_filters":[],"account_tags":[],"client_email":"80e3f00106389e6e@test-project.iam.gserviceaccount.com","is_cspm_enabled":false,"automute":false}}}

'
headers:
Expand All @@ -25,7 +25,7 @@ interactions:
accept:
- '*/*'
method: DELETE
uri: https://api.datadoghq.com/api/v2/integration/gcp/accounts/3aa3ec77-9646-4f6a-bcd0-01e5124e2ad1
uri: https://api.datadoghq.com/api/v2/integration/gcp/accounts/d6c68645-2b52-43e9-838c-9b7fdb809a8d
response:
body:
string: ''
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023-09-27T14:45:59.771Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
interactions:
- request:
body: '{"data":{"attributes":{"account_tags":["lorem","ipsum"],"client_email":"[email protected]","host_filters":[]},"type":"gcp_service_account"}}'
headers:
accept:
- application/json
content-type:
- application/json
method: POST
uri: https://api.datadoghq.com/api/v2/integration/gcp/accounts
response:
body:
string: '{"data":{"type":"gcp_service_account","attributes":{"host_filters":[],"client_email":"[email protected]","is_cspm_enabled":false,"automute":false,"account_tags":["lorem","ipsum"]},"id":"1cdedba8-a0a3-4036-82b0-ad8088dd0c02"}}

'
headers:
content-type:
- application/json
status:
code: 201
message: Created
- request:
body: null
headers:
accept:
- '*/*'
method: DELETE
uri: https://api.datadoghq.com/api/v2/integration/gcp/accounts/1cdedba8-a0a3-4036-82b0-ad8088dd0c02
response:
body:
string: ''
headers:
content-type:
- text/html; charset=utf-8
status:
code: 204
message: No Content
version: 1
18 changes: 14 additions & 4 deletions tests/v2/features/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": {"client_email": "[email protected]", "host_filters": []}, "type": "gcp_service_account"}}
And body with value {"data": {"attributes": {"account_tags": [], "client_email": "[email protected]", "host_filters": []}, "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": {"client_email": "[email protected]", "host_filters": []}, "type": "gcp_service_account"}}
And body with value {"data": {"attributes": {"account_tags": [], "client_email": "[email protected]", "host_filters": []}, "type": "gcp_service_account"}}
When the request is sent
Then the response status is 409 Conflict

Expand All @@ -54,6 +54,16 @@ Feature: GCP Integration
And the response "data.type" is equal to "gcp_service_account"
And the response "data.attributes.client_email" is equal to "{{ unique_hash }}@test-project.iam.gserviceaccount.com"

@team:DataDog/gcp-integrations
Scenario: Create a new entry for your service account with account_tags returns "OK" response
Given new "CreateGCPSTSAccount" request
And body with value {"data": {"attributes": {"account_tags": ["lorem", "ipsum"], "client_email": "{{ unique_hash }}@test-project.iam.gserviceaccount.com", "host_filters": []}, "type": "gcp_service_account"}}
When the request is sent
Then the response status is 201 OK
And the response "data.type" is equal to "gcp_service_account"
And the response "data.attributes.client_email" is equal to "{{ unique_hash }}@test-project.iam.gserviceaccount.com"
And the response "data.attributes.account_tags" is equal to ["lorem", "ipsum"]

@generated @skip @team:DataDog/gcp-integrations
Scenario: Delete an STS enabled GCP Account returns "Bad Request" response
Given new "DeleteGCPSTSAccount" request
Expand Down Expand Up @@ -93,15 +103,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": {"client_email": "[email protected]", "host_filters": []}, "id": "d291291f-12c2-22g4-j290-123456678897", "type": "gcp_service_account"}}
And body with value {"data": {"attributes": {"account_tags": [], "client_email": "[email protected]", "host_filters": []}, "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": {"client_email": "[email protected]", "host_filters": []}, "id": "d291291f-12c2-22g4-j290-123456678897", "type": "gcp_service_account"}}
And body with value {"data": {"attributes": {"account_tags": [], "client_email": "[email protected]", "host_filters": []}, "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