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,147 @@
# -*- 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.
"""Shared util methods common to BQExports commands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import re
from googlecloudsdk.command_lib.scc import errors
from googlecloudsdk.command_lib.scc import util
def ValidateAndGetBigQueryExportV1Name(args):
"""Returns relative resource name for a v1 B2igQuery export.
Validates on regexes for args containing full names or short names with
resources. Localization is supported by the
ValidateAndGetBigQueryExportV2Name method.
Args:
args: an argparse object that should contain .BIG_QUERY_EXPORT, optionally 1
of .organization, .folder, .project
Examples:
args with BIG_QUERY_EXPORT="organizations/123/bigQueryExports/config1"
returns the BIG_QUERY_EXPORT
args with BIG_QUERY_EXPORT="config1" and projects="projects/123" returns
projects/123/bigQueryExports/config1
"""
bq_export_name = args.BIG_QUERY_EXPORT
long_name_format = re.compile(
"(organizations|projects|folders)/.*/bigQueryExports/[a-z]([a-z0-9-]{0,61}[a-z0-9])?$"
).match(bq_export_name)
short_name_format = re.compile("^[a-z]([a-z0-9-]{0,61}[a-z0-9])?$").match(
bq_export_name
)
if not long_name_format and not short_name_format:
if "/" in bq_export_name:
raise errors.InvalidSCCInputError(
"BigQuery export must match the full resource name, or "
"`--organization=`, `--folder=` or `--project=` must be provided."
)
else:
raise errors.InvalidSCCInputError(
"BigQuery export id does not match the pattern "
"'^[a-z]([a-z0-9-]{0,61}[a-z0-9])?$'."
)
if long_name_format:
return bq_export_name
if short_name_format:
parent = util.GetParentFromNamedArguments(args)
if parent is None:
raise errors.InvalidSCCInputError(
"BigQuery export must match the full resource name, or "
"`--organization=`, `--folder=` or `--project=` must be provided."
)
else:
return (
util.GetParentFromNamedArguments(args)
+ "/bigQueryExports/"
+ bq_export_name
)
def ValidateAndGetBigQueryExportV2Name(args):
"""Returns relative resource name for a v2 Big Query export.
Validates on regexes for args containing full names with locations or short
names with resources.
Args:
args: an argparse object that should contain .BIG_QUERY_EXPORT, optionally 1
of .organization, .folder, .project; and optionally .location
Examples:
args with BIG_QUERY_EXPORT="organizations/123/bigQueryExports/config1"
and location="locations/us" returns
organizations/123/locations/us/bigQueryExports/config1
args with
BIG_QUERY_EXPORT="folders/123/locations/us/bigQueryExports/config1"
and returns folders/123/locations/us/bigQueryExports/config1
args with BIG_QUERY_EXPORT="config1", projects="projects/123", and
locations="us" returns projects/123/bigQueryExports/config1
"""
id_pattern = re.compile("^[a-z]([a-z0-9-]{0,61}[a-z0-9])?$")
nonregionalized_resource_pattern = re.compile(
"(organizations|projects|folders)/.+/bigQueryExports/[a-z]([a-z0-9-]{0,61}[a-z0-9])?$"
)
regionalized_resource_pattern = re.compile(
"(organizations|projects|folders)/.+/locations/.+/bigQueryExports/[a-z]([a-z0-9-]{0,61}[a-z0-9])?$"
)
bq_export_id = args.BIG_QUERY_EXPORT
location = util.ValidateAndGetLocation(args, "v2")
# id-only pattern (short name): compose the full name
if id_pattern.match(bq_export_id):
parent = util.GetParentFromNamedArguments(args)
if parent is None:
raise errors.InvalidSCCInputError(
"BigQuery export must match the full resource name, or "
"`--organization=`, `--folder=` or `--project=` must be provided."
)
return f"{parent}/locations/{location}/bigQueryExports/{bq_export_id}"
# v2=style regionalized patterns
if regionalized_resource_pattern.match(bq_export_id):
return bq_export_id
# v1-style nonregionalized patterns are acceptable
if nonregionalized_resource_pattern.match(bq_export_id):
# Handle config id as full resource name
[parent_segment, id_segment] = bq_export_id.split("/bigQueryExports/")
return f"{parent_segment}/locations/{location}/bigQueryExports/{id_segment}"
raise errors.InvalidSCCInputError(
"BigQuery export must match"
" (organizations|projects|folders)/.+/bigQueryExports/[a-z]([a-z0-9-]{0,61}[a-z0-9])?$"
" (organizations|projects|folders)/.+/locations/.+/bigQueryExports/[a-z]([a-z0-9-]{0,61}[a-z0-9])?$"
" or [a-zA-Z0-9-_]{1,128}$."
)

View File

@@ -0,0 +1,117 @@
# -*- 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.
"""Shared flags definitions for flags and arguments for BigQuery Exports."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from googlecloudsdk.calliope import base
DATASET_FLAG_OPTIONAL = base.Argument(
'--dataset',
help="""
The dataset to write findings updates to.""",
)
DATASET_FLAG_REQUIRED = base.Argument(
'--dataset',
required=True,
help="""
The dataset to write findings updates to.""",
)
DESCRIPTION_FLAG = base.Argument(
'--description',
help="""
The text that will be used to describe a BigQuery export.""",
)
# Note:
# SCC's custom --filter is passing the streaming config filter as part of
# the request body. However --filter is a global filter flag in gcloud. The
# --filter flag in gcloud (outside of this command) is used for client side
# filtering. This has led to a collision in logic as gcloud believes the
# update is trying to perform client side filtering. In the context of
# notifications, it is instead updating the streaming config filter.
#
# Any future new commands should reconsider not using --filter for this logic
# and perhaps use a different name to avoid any collisions with gcloud logic.
FILTER_FLAG = base.Argument(
'--filter',
help="""
The filter string which will applied to findings muted by a BigQuery export.
""",
)
PAGE_TOKEN_FLAG = base.Argument(
'--page-token',
help="""
Response objects will return a non-null value for page-token to
indicate that there is at least one additional page of data. User can
either directly request that page by specifying the page-token
explicitly or let gcloud fetch one-page-at-a-time.""",
)
UPDATE_MASK_FLAG = base.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.
""",
)
def AddBigQueryPositionalArgument(parser):
"""Add BigQuery Export as a positional argument."""
parser.add_argument(
'BIG_QUERY_EXPORT',
metavar='BIG_QUERY_EXPORT',
help="""\
ID of the BigQuery export e.g. `my-bq-export` or the full
resource name of the BigQuery export e.g.
`organizations/123/bigQueryExports/my-bq-export`.
""",
)
return parser
def AddParentGroup(parser, required=False):
"""Set folder/org/project as mutually exclusive group."""
resource_group = parser.add_group(required=required, mutex=True)
resource_group.add_argument(
'--organization',
help="""\
Organization where the BigQuery export resides. Formatted as
organizations/123 or just 123.
""",
)
resource_group.add_argument(
'--folder',
help="""\
Folder where the BigQuery export resides. Formatted as folders/456 or
just 456.
""",
)
resource_group.add_argument(
'--project',
help="""\
Project (id or number) where the BigQuery export resides. Formatted
as projects/789 or just 789.
""",
)
return parser