feat: Add new gcloud commands, API clients, and third-party libraries across various services.

This commit is contained in:
2026-01-01 20:26:35 +01:00
parent 5e23cbece0
commit a19e592eb7
25221 changed files with 8324611 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command group for Cloud SCC Mute Configs."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class MuteConfigs(base.Group):
"""Manage Cloud SCC (Security Command Center) mute configs."""
category = base.SECURITY_CATEGORY

View File

@@ -0,0 +1,134 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to Create a Cloud Security Command Center mute config."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from googlecloudsdk.api_lib.scc import securitycenter_client
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.scc import flags as scc_flags
from googlecloudsdk.command_lib.scc import util as scc_util
from googlecloudsdk.command_lib.scc.muteconfigs import flags
from googlecloudsdk.command_lib.scc.muteconfigs import util
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.GA, base.ReleaseTrack.ALPHA)
class Create(base.CreateCommand):
"""Create a Security Command Center mute config."""
detailed_help = {
"DESCRIPTION": "Create a Security Command Center mute config.",
"EXAMPLES": """
To create a mute config ``test-mute-config'' given organization ``123''
with a filter on category that equals to ``XSS_SCRIPTING'', run:
$ {command} test-mute-config --organization=123
--description="This is a test mute config"
--filter="category=\\"XSS_SCRIPTING\\""
To create a mute config ``test-mute-config'' given folder ``456'' with a
filter on category that equals to ``XSS_SCRIPTING'', run:
$ {command} test-mute-config --folder=456
--description="This is a test mute config"
--filter="category=\\"XSS_SCRIPTING\\""
To create a mute config ``test-mute-config'' given project ``789'' with a
filter on category that equals to ``XSS_SCRIPTING'', run:
$ {command} test-mute-config --project=789
--description="This is a test mute config"
--filter="category=\\"XSS_SCRIPTING\\""
To create a mute config ``test-mute-config'' given organization ``123'',
`location=eu` with a filter on category that equals to ``XSS_SCRIPTING'',
run:
$ {command} test-mute-config --organization=123
--description="This is a test mute config"
--filter="category=\\"XSS_SCRIPTING\\"" --location=eu""",
"API REFERENCE": """
This command uses the Security Command Center API. For more information,
see [Security Command Center API.](https://cloud.google.com/security-command-center/docs/reference/rest)""",
}
@staticmethod
def Args(parser):
# Add flags and positional arguments.
flags.MUTE_CONFIG_FLAG.AddToParser(parser)
flags.AddParentGroup(parser)
flags.DESCRIPTION_FLAG.AddToParser(parser)
flags.FILTER_FLAG.AddToParser(parser)
flags.TYPE_FLAG.AddToParser(parser)
flags.EXPIRY_TIME_FLAG.AddToParser(parser)
scc_flags.API_VERSION_FLAG.AddToParser(parser)
scc_flags.LOCATION_FLAG.AddToParser(parser)
parser.display_info.AddFormat(properties.VALUES.core.default_format.Get())
def Run(self, args):
# Determine what version to call from --location and --api-version.
version = scc_util.GetVersionFromArguments(args, args.mute_config)
# Build request from args.
messages = securitycenter_client.GetMessages(version)
request = messages.SecuritycenterOrganizationsMuteConfigsCreateRequest()
mute_config_type = util.ValidateAndGetType(args, version)
expiry_time = util.ValidateAndGetExpiryTime(args)
if version == "v2":
request.googleCloudSecuritycenterV2MuteConfig = (
messages.GoogleCloudSecuritycenterV2MuteConfig(
filter=args.filter,
description=args.description,
type=mute_config_type,
expiryTime=expiry_time,
)
)
else:
request.googleCloudSecuritycenterV1MuteConfig = (
messages.GoogleCloudSecuritycenterV1MuteConfig(
filter=args.filter,
description=args.description,
type=mute_config_type,
expiryTime=expiry_time,
)
)
request = _GenerateMuteConfig(args, request, version)
client = securitycenter_client.GetClient(version)
response = client.organizations_muteConfigs.Create(request)
log.status.Print("Created.")
return response
def _GenerateMuteConfig(args, req, version="v1"):
"""Updates parent and Generates a mute config."""
req.parent = util.ValidateAndGetParent(args)
if req.parent is not None:
if version == "v2":
req.parent = util.ValidateAndGetRegionalizedParent(args, req.parent)
req.muteConfigId = util.ValidateAndGetMuteConfigId(args)
else:
args.location = scc_util.ValidateAndGetLocation(args, version)
mute_config = util.ValidateAndGetMuteConfigFullResourceName(
args, version
)
req.muteConfigId = util.GetMuteConfigIdFromFullResourceName(mute_config)
req.parent = util.GetParentFromFullResourceName(mute_config, version)
args.filter = ""
return req

View File

@@ -0,0 +1,86 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to Delete a Cloud Security Command Center mute config."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from googlecloudsdk.api_lib.scc import securitycenter_client
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.scc import flags as scc_flags
from googlecloudsdk.command_lib.scc import util as scc_util
from googlecloudsdk.command_lib.scc.muteconfigs import flags
from googlecloudsdk.command_lib.scc.muteconfigs import util
from googlecloudsdk.core import log
from googlecloudsdk.core.console import console_io
@base.ReleaseTracks(base.ReleaseTrack.GA, base.ReleaseTrack.ALPHA)
class Delete(base.DeleteCommand):
"""Delete a Security Command Center mute config."""
detailed_help = {
"DESCRIPTION": "Delete a Security Command Center mute config.",
"EXAMPLES": """
To delete a mute config given organization ``123'' with id ``test-mute-config'', run:
$ {command} test-mute-config --organization=123
To delete a mute config given folder ``456'' with id
``test-mute-config'', run:
$ {command} test-mute-config --folder=456
To delete a mute config given project ``789'' with id
``test-mute-config'', run:
$ {command} test-mute-config --project=789
To delete a mute config given organization ``123'' with id
``test-mute-config'' and `location=eu`, run:
$ {command} test-mute-config --organization=123 --location=eu""",
"API REFERENCE": """
This command uses the Security Command Center API. For more information,
see [Security Command Center API.](https://cloud.google.com/security-command-center/docs/reference/rest)""",
}
@staticmethod
def Args(parser):
# Add flags and positional arguments.
flags.MUTE_CONFIG_FLAG.AddToParser(parser)
flags.AddParentGroup(parser)
scc_flags.API_VERSION_FLAG.AddToParser(parser)
scc_flags.LOCATION_FLAG.AddToParser(parser)
def Run(self, args):
# Issue prompt.
prompt = """Are you sure you want to delete a mute config?\n"""
console_io.PromptContinue(prompt, cancel_on_no=True)
# Determine what version to call from --location and --api-version.
version = scc_util.GetVersionFromArguments(args, args.mute_config)
messages = securitycenter_client.GetMessages(version)
request = messages.SecuritycenterOrganizationsMuteConfigsDeleteRequest()
# Generate name and send request if the user continues.
request = util.GenerateMuteConfigName(args, request, version)
client = securitycenter_client.GetClient(version)
response = client.organizations_muteConfigs.Delete(request)
log.status.Print("Deleted.")
return response

View File

@@ -0,0 +1,83 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to Get a Cloud Security Command Center mute config."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from googlecloudsdk.api_lib.scc import securitycenter_client
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.scc import flags as scc_flags
from googlecloudsdk.command_lib.scc import util as scc_util
from googlecloudsdk.command_lib.scc.muteconfigs import flags
from googlecloudsdk.command_lib.scc.muteconfigs import util
from googlecloudsdk.core import properties
# TODO: b/308476775 - Migrate Get command usage to Describe
@base.ReleaseTracks(base.ReleaseTrack.GA, base.ReleaseTrack.ALPHA)
class Get(base.Command):
"""Get a Security Command Center mute config."""
detailed_help = {
"DESCRIPTION": "Get a Security Command Center mute config.",
"EXAMPLES": """
To get a mute config given organization ``123'' with id ``test-mute-config'', run:
$ {command} test-mute-config --organization=123
To get a mute config given folder ``456'' with id
``test-mute-config'', run:
$ {command} test-mute-config --folder=456
To get a mute config given project ``789'' with id
``test-mute-config'', run:
$ {command} test-mute-config --project=789
To get a mute config given organization ``123'' with id
``test-mute-config'' and `location=eu`, run:
$ {command} test-mute-config --organization=123 --location=eu""",
"API REFERENCE": """
This command uses the Security Command Center API. For more information,
see [Security Command Center API.](https://cloud.google.com/security-command-center/docs/reference/rest)""",
}
@staticmethod
def Args(parser):
# Add flags and positional arguments.
flags.MUTE_CONFIG_FLAG.AddToParser(parser)
flags.AddParentGroup(parser)
scc_flags.API_VERSION_FLAG.AddToParser(parser)
scc_flags.LOCATION_FLAG.AddToParser(parser)
parser.display_info.AddFormat(properties.VALUES.core.default_format.Get())
def Run(self, args):
# Determine what version to call from --location and --api-version.
version = scc_util.GetVersionFromArguments(args, args.mute_config)
messages = securitycenter_client.GetMessages(version)
request = messages.SecuritycenterOrganizationsMuteConfigsGetRequest()
# Generate name and send request if the user continues.
request = util.GenerateMuteConfigName(args, request, version)
client = securitycenter_client.GetClient(version)
response = client.organizations_muteConfigs.Get(request)
return response

View File

@@ -0,0 +1,89 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to List a Cloud Security Command Center mute config."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from apitools.base.py import list_pager
from googlecloudsdk.api_lib.scc import securitycenter_client
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.scc import flags as scc_flags
from googlecloudsdk.command_lib.scc import util as scc_util
from googlecloudsdk.command_lib.scc.muteconfigs import flags
from googlecloudsdk.command_lib.scc.muteconfigs import util
@base.ReleaseTracks(base.ReleaseTrack.GA, base.ReleaseTrack.ALPHA)
class List(base.ListCommand):
"""ListSecurity Command Center mute configs."""
detailed_help = {
"DESCRIPTION": "List Security Command Center mute configs.",
"EXAMPLES": """
List mute configs under organization ``123'':
$ {command} --organization=123
List mute configs under folder ``456'':
$ {command} --folder=456
List mute configs under project ``789'':
$ {command} --project=789
List mute configs under organization ``123'' and `location=eu`:
$ {command} --organization=123 --location=eu""",
"API REFERENCE": """
This command uses the Security Command Center API. For more information,
see [Security Command Center API.](https://cloud.google.com/security-command-center/docs/reference/rest)""",
}
@staticmethod
def Args(parser):
# Remove URI flag. This flag is added from base.ListCommand and is not
# needed for this command.
base.URI_FLAG.RemoveFromParser(parser)
# Add flags and positional arguments
flags.AddParentGroup(parser, True)
scc_flags.API_VERSION_FLAG.AddToParser(parser)
scc_flags.LOCATION_FLAG.AddToParser(parser)
def Run(self, args):
# Determine what version to call from --location and --api-version.
version = scc_util.GetVersionFromArguments(args)
# Build request from args.
messages = securitycenter_client.GetMessages(version)
request = messages.SecuritycenterOrganizationsMuteConfigsListRequest()
request.parent = util.ValidateAndGetParent(args)
if version == "v2":
request.parent = util.ValidateAndGetRegionalizedParent(
args, request.parent
)
client = securitycenter_client.GetClient(version)
# Automatically handle pagination. All muteconfigs are returned regarldess
# of --page-size argument.
return list_pager.YieldFromList(
client.organizations_muteConfigs,
request,
batch_size_attribute="pageSize",
batch_size=args.page_size,
field="muteConfigs",
)

View File

@@ -0,0 +1,138 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to update a Cloud Security Command Center mute config."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from googlecloudsdk.api_lib.scc import securitycenter_client
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.scc import flags as scc_flags
from googlecloudsdk.command_lib.scc import util as scc_util
from googlecloudsdk.command_lib.scc.muteconfigs import flags
from googlecloudsdk.command_lib.scc.muteconfigs import util
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.GA, base.ReleaseTrack.ALPHA)
class Update(base.UpdateCommand):
"""Update a Security Command Center mute config."""
detailed_help = {
"DESCRIPTION": "Update a Security Command Center mute config.",
"EXAMPLES": """
Update a mute config with ``ID=test-mute-config'' under
``organization=123'' with a filter on category that equals to
XSS_SCRIPTING:
$ {command} test-mute-config --organization=123
--description="This is a test mute config"
--filter="category=\\"XSS_SCRIPTING\\""
Update a mute config with ``ID=test-mute-config'' under
``folder=456'' with a filter on category that equals to XSS_SCRIPTING:
$ {command} test-mute-config --folder=456
--description="This is a test mute config"
--filter="category=\\"XSS_SCRIPTING\\""
Update a mute config with ``ID=test-mute-config'' under
``project=789'' with a filter on category that equals to XSS_SCRIPTING:
$ {command} test-mute-config --project=789
--description="This is a test mute config"
--filter="category=\\"XSS_SCRIPTING\\""
Update a mute config with ``ID=test-mute-config'' under
``organization=123'' `location=eu` with a filter on category that
equals to XSS_SCRIPTING:
$ {command} test-mute-config --organization=123
--description="This is a test mute config"
--filter="category=\\"XSS_SCRIPTING\\"" --location=eu""",
"API REFERENCE": """
This command uses the Security Command Center API. For more information,
see [Security Command Center API.](https://cloud.google.com/security-command-center/docs/reference/rest)""",
}
@staticmethod
def Args(parser):
# Add flags and positional arguments
flags.AddParentGroup(parser)
flags.MUTE_CONFIG_FLAG.AddToParser(parser)
flags.DESCRIPTION_FLAG.AddToParser(parser)
flags.FILTER_FLAG.AddToParser(parser)
flags.EXPIRY_TIME_FLAG.AddToParser(parser)
scc_flags.API_VERSION_FLAG.AddToParser(parser)
scc_flags.LOCATION_FLAG.AddToParser(parser)
parser.add_argument(
"--update-mask",
help="""
Optional: If left unspecified (default), an update-mask is automatically
created using the flags specified in the command and only those values
are updated.""",
)
parser.display_info.AddFormat(properties.VALUES.core.default_format.Get())
def Run(self, args):
# Determine what version to call from --location and --api-version.
version = scc_util.GetVersionFromArguments(args, args.mute_config)
messages = securitycenter_client.GetMessages(version)
request = messages.SecuritycenterOrganizationsMuteConfigsPatchRequest()
# We don't have type information, so we defer validation to the API server.
expiry_time = util.ValidateAndGetExpiryTime(args)
if version == "v2":
request.googleCloudSecuritycenterV2MuteConfig = (
messages.GoogleCloudSecuritycenterV2MuteConfig(
description=args.description,
filter=args.filter,
expiryTime=expiry_time,
)
)
else:
request.googleCloudSecuritycenterV1MuteConfig = (
messages.GoogleCloudSecuritycenterV1MuteConfig(
description=args.description,
filter=args.filter,
expiryTime=expiry_time,
)
)
# Create update mask if none was specified
if not args.update_mask:
computed_update_mask = []
if args.IsKnownAndSpecified("description"):
computed_update_mask.append("description")
if args.IsKnownAndSpecified("filter"):
computed_update_mask.append("filter")
if args.IsKnownAndSpecified("expiry-time"):
computed_update_mask.append("expiry_time")
request.updateMask = ",".join(computed_update_mask)
else:
request.updateMask = args.update_mask
# Generate name and send request
request = util.GenerateMuteConfigName(args, request, version)
request.updateMask = scc_util.CleanUpUserMaskInput(request.updateMask)
args.filter = ""
client = securitycenter_client.GetClient(version)
response = client.organizations_muteConfigs.Patch(request)
log.status.Print("Updated.")
return response