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,76 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Common flag setup and parsing for Cloud API Gateway surface."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.command_lib.iam import completers as iam_completers
from googlecloudsdk.command_lib.util.args import labels_util
def AddDisplayNameArg(parser):
"""Adds the display name arg to the parser."""
parser.add_argument(
'--display-name',
help="""\
Human readable name which can optionally be supplied.
""")
def AddManagedServiceFlag(parser):
"""Adds the managed service flag."""
parser.add_argument(
'--managed-service',
help="""\
The name of a pre-existing Google Managed Service.
""")
def AddBackendAuthServiceAccountFlag(parser):
"""Adds the backend auth service account flag."""
parser.add_argument(
'--backend-auth-service-account',
help="""\
Service account which will be used to sign tokens for backends with \
authentication configured.
""")
def ProcessLabelsFlag(labels, message):
"""Parses labels into a specific message format."""
class Object(object):
pass
if labels:
labels_obj = Object()
labels_obj.labels = labels
labels = labels_util.ParseCreateArgs(
labels_obj,
message)
return labels
class GatewayIamRolesCompleter(iam_completers.IamRolesCompleter):
def __init__(self, **kwargs):
super(GatewayIamRolesCompleter, self).__init__(
resource_collection='apigateway.projects.locations.gateways',
resource_dest='gateway',
**kwargs)

View File

@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Exceptions for Cloud API Gateway surface."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.core import exceptions
class Error(exceptions.Error):
"""Exceptions for API Gateway errors."""
class OperationErrorException(Error):
pass
class TimeoutError(Error):
pass

View File

@@ -0,0 +1,68 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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.
"""Utilities for interacting with Cloud API Gateway operations."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.core import log
from googlecloudsdk.core import resources
def PrintOperationResultWithWaitEpilogue(operation_ref, result):
"""Prints the operation result with wait epilogue.
Args:
operation_ref: Resource reference for the operation
result: Epiloque string to be printed
"""
log.status.Print("""\
{}. Use the following command to wait for its completion:
gcloud api-gateway operations wait {}
""".format(result, operation_ref.RelativeName()))
def PrintOperationResult(op_name, op_client, service=None,
wait_string='Waiting for long running operation',
async_string='Asynchronous operation is in progress',
is_async=False):
"""Prints results for an operation.
Args:
op_name: name of the operation.
op_client: client for accessing operation data.
service: the service which operation result can be grabbed.
wait_string: string to use while waiting for polling operation
async_string: string to print out for operation waiting
is_async: whether to wait for aync operations or not.
Returns:
The object which is returned by the service if async is false,
otherwise null
"""
operation_ref = resources.REGISTRY.Parse(
op_name,
collection='apigateway.projects.locations.operations')
if is_async:
PrintOperationResultWithWaitEpilogue(operation_ref, async_string)
else:
return op_client.WaitForOperation(operation_ref, wait_string, service)

View File

@@ -0,0 +1,263 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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 resource args for Cloud API Gateway surface."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope.concepts import concepts
from googlecloudsdk.calliope.concepts import deps
from googlecloudsdk.command_lib.util.concepts import concept_parsers
from googlecloudsdk.command_lib.util.concepts import presentation_specs
def LocationAttributeConfig(default=None):
"""Creates location attribute config."""
default_keyword = default
if default == '-':
default_keyword = 'a wildcard'
fallthroughs = []
if default:
fallthroughs.append(
deps.Fallthrough(
lambda: default,
'Location for API and API Configs. Defaults to {}'.format(
default_keyword)))
return concepts.ResourceParameterAttributeConfig(
name='location',
fallthroughs=fallthroughs,
help_text='Cloud location for {resource}.')
def GatewayAttributeConfig(name='gateway'):
return concepts.ResourceParameterAttributeConfig(
name=name,
help_text='Name for API Gateway')
def ApiAttributeConfig(name='api', wildcard=False):
fallthroughs = []
if wildcard:
fallthroughs.append(
deps.Fallthrough(
lambda: '-',
'Defaults to wildcard for all APIs'))
return concepts.ResourceParameterAttributeConfig(
name=name,
fallthroughs=fallthroughs,
help_text='API ID.')
def ApiConfigAttributeConfig(name='api-config'):
return concepts.ResourceParameterAttributeConfig(
name=name,
help_text='API Config ID.')
def OperationAttributeConfig(name='operation'):
return concepts.ResourceParameterAttributeConfig(
name=name,
help_text='The name for the API Gateway operation')
def GetLocationResourceSpec(resource_name='location', default=None):
return concepts.ResourceSpec(
'apigateway.projects.locations',
resource_name=resource_name,
locationsId=LocationAttributeConfig(default=default),
projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG)
def GetGatewayResourceSpec(resource_name='gateway'):
return concepts.ResourceSpec(
'apigateway.projects.locations.gateways',
resource_name=resource_name,
gatewaysId=GatewayAttributeConfig(),
locationsId=LocationAttributeConfig(),
projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG)
def GetApiResourceSpec(resource_name='api', wildcard=False):
return concepts.ResourceSpec(
'apigateway.projects.locations.apis',
resource_name=resource_name,
apisId=ApiAttributeConfig(wildcard=wildcard),
locationsId=LocationAttributeConfig(default='global'),
projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG)
def GetApiConfigResourceSpec(resource_name='api-config'):
return concepts.ResourceSpec(
'apigateway.projects.locations.apis.configs',
resource_name=resource_name,
configsId=ApiConfigAttributeConfig(),
apisId=ApiAttributeConfig(),
locationsId=LocationAttributeConfig(default='global'),
projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG)
def GetOperationResourceSpec(resource_name='operation'):
return concepts.ResourceSpec(
'apigateway.projects.locations.operations',
resource_name=resource_name,
operationsId=OperationAttributeConfig(),
locationsId=LocationAttributeConfig(),
projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG)
def AddGatewayResourceArg(parser, verb, positional=False, required=True):
"""Adds Gateway resource argument to parser.
Args:
parser: parser to add arg to
verb: action being taken with the Gateway
positional: Boolean indicating if argument is positional, default False
required: Boolean for if this is required, default is True
Returns: None
"""
if positional:
name = 'gateway'
else:
name = '--gateway'
concept_parsers.ConceptParser.ForResource(
name,
GetGatewayResourceSpec(),
'Name for gateway which will be {}.'.format(verb),
required=required).AddToParser(parser)
def AddGatewayApiConfigResourceArgs(parser, verb, gateway_required=True,
api_config_required=True):
"""Adds Gateway and API Config resource arguments to parser.
Args:
parser: parser to add arg to
verb: action being taken with the Gateway
gateway_required: Boolean for if Gateway is required, default is True
api_config_required: Boolean for if API Config is required, default is True
Returns: None
"""
concept_parsers.ConceptParser(
[
presentation_specs.ResourcePresentationSpec(
'gateway',
GetGatewayResourceSpec(),
'Name for gateway which will be {}.'.format(verb),
required=gateway_required),
presentation_specs.ResourcePresentationSpec(
'--api-config',
GetApiConfigResourceSpec(),
'Resource name for API config the gateway will use.',
flag_name_overrides={'location': ''},
required=api_config_required)
]).AddToParser(parser)
def AddLocationResourceArg(parser, verb, positional=False, default=None,
required=True):
"""Adds location resource argument to parser.
Args:
parser: parser to add arg to
verb: action being taken with the location
positional: Optional boolean indiicating if argument is positional
default: Optional default value for the arg
required: Boolean for if this is required, default is True
Returns: None
"""
if positional:
name = 'location'
else:
name = '--location'
override = None
if default == 'global':
override = {'location': ''}
concept_parsers.ConceptParser.ForResource(
name,
GetLocationResourceSpec(default=default),
'Parent location which {}.'.format(verb),
flag_name_overrides=override,
required=required).AddToParser(parser)
def AddApiResourceArg(parser, verb, positional=False, required=True,
wildcard=False):
"""Adds API resource argument to parser.
Args:
parser: parser to add arg to
verb: action being taken with the API
positional: Optional boolean indiicating if argument is positional
required: Boolean for if this is required, default is True
wildcard: Boolean. Does arg have a default wildcard? default: False
Returns: None
"""
if positional:
name = 'api'
else:
name = '--api'
concept_parsers.ConceptParser.ForResource(
name,
GetApiResourceSpec(wildcard=wildcard),
'Name for API which {}.'.format(verb),
flag_name_overrides={'location': ''},
required=required).AddToParser(parser)
def AddApiConfigResourceArg(parser, verb, positional=False, required=True):
"""Adds API Config resource argument to parser.
Args:
parser: parser to add arg to
verb: action being taken with the API Config
positional: Boolean indicating if argument is positional, default False
required: Boolean for if this is required, default is True
Returns: None
"""
if positional:
name = 'api_config'
else:
name = '--api-config'
concept_parsers.ConceptParser.ForResource(
name,
GetApiConfigResourceSpec(),
'Name for API Config which will be {}.'.format(verb),
flag_name_overrides={'location': ''},
required=required).AddToParser(parser)
def AddOperationResourceArgs(parser, verb):
concept_parsers.ConceptParser.ForResource(
'operation',
GetOperationResourceSpec(),
'The name of the operation to {}.'.format(verb),
required=True).AddToParser(parser)