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,29 @@
# -*- 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.
"""Package for the apigateway/gateways CLI subcommands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
class Gateways(base.Group):
"""Manage Cloud API Gateway Gateways.
Commands for managing Cloud API Gateway Gateways.
"""

View File

@@ -0,0 +1,57 @@
# -*- 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.
"""Command to add IAM policy binding for a model."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.api_gateway import gateways
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.api_gateway import common_flags
from googlecloudsdk.command_lib.api_gateway import resource_args
from googlecloudsdk.command_lib.iam import iam_util
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
@base.DefaultUniverseOnly
class AddIamPolicyBinding(base.Command):
"""Add IAM policy binding to a gateway."""
detailed_help = {
'EXAMPLES':
"""\
To add an IAM policy binding for the role of 'roles/editor' for the
user 'test-user@gmail.com' on the gateway 'my-gateway', run:
$ {command} my-gateway --member='user:test-user@gmail.com' --role='roles/editor
"""
}
@staticmethod
def Args(parser):
resource_args.AddGatewayResourceArg(parser,
'IAM policy binding will be added to',
positional=True)
iam_util.AddArgsForAddIamPolicyBinding(
parser,
common_flags.GatewayIamRolesCompleter)
def Run(self, args):
gateway_ref = args.CONCEPTS.gateway.Parse()
return gateways.GatewayClient().AddIamPolicyBinding(
gateway_ref, args.member, args.role)

View File

@@ -0,0 +1,73 @@
# -*- 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.
"""`gcloud api-gateway gateways create` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.api_gateway import gateways
from googlecloudsdk.api_lib.api_gateway import operations
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.api_gateway import common_flags
from googlecloudsdk.command_lib.api_gateway import operations_util
from googlecloudsdk.command_lib.api_gateway import resource_args
from googlecloudsdk.command_lib.util.args import labels_util
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
@base.DefaultUniverseOnly
class Create(base.CreateCommand):
"""Create a new gateway."""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To create a gateway in 'us-central1' run:
$ {command} my-gateway --api=my-api --api-config=my-config --location=us-central1
""",
}
@staticmethod
def Args(parser):
base.ASYNC_FLAG.AddToParser(parser)
common_flags.AddDisplayNameArg(parser)
labels_util.AddCreateLabelsFlags(parser)
resource_args.AddGatewayApiConfigResourceArgs(parser, 'created')
def Run(self, args):
gateway_ref = args.CONCEPTS.gateway.Parse()
api_config_ref = args.CONCEPTS.api_config.Parse()
gateways_client = gateways.GatewayClient()
resp = gateways_client.Create(gateway_ref,
api_config_ref,
display_name=args.display_name,
labels=args.labels)
wait = 'Waiting for API Gateway [{}] to be created with [{}] config'.format(
gateway_ref.Name(), api_config_ref.RelativeName())
return operations_util.PrintOperationResult(
resp.name,
operations.OperationsClient(),
service=gateways_client.service,
wait_string=wait,
is_async=args.async_)

View File

@@ -0,0 +1,91 @@
# -*- 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.
"""`gcloud api-gateway gateways delete` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.api_gateway import gateways
from googlecloudsdk.api_lib.api_gateway import operations
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.api_gateway import operations_util
from googlecloudsdk.command_lib.api_gateway import resource_args
from googlecloudsdk.core.console import console_io
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
@base.DefaultUniverseOnly
class Delete(base.DeleteCommand):
"""Delete an API Gateway."""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To delete a gateway 'my-gateway' in 'us-central1', run:
$ {command} my-gateway --location=us-central1
""",
}
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
Args:
parser: An argparse parser that you can use to add arguments that go
on the command line after this command. Positional arguments are
allowed.
"""
base.ASYNC_FLAG.AddToParser(parser)
resource_args.AddGatewayResourceArg(parser, 'deleted', positional=True)
def Run(self, args):
"""Run 'api-gateway gateways delete'.
Args:
args: argparse.Namespace, The arguments that this command was invoked
with.
Raises:
OperationCancelledError
Returns:
The response from the Delete API call.
"""
gateway_ref = args.CONCEPTS.gateway.Parse()
# Prompt with a warning before continuing.
console_io.PromptContinue(
message='Are you sure? This will delete the gateway \'{}\', '
'along with all of the associated consumer '
'information.'.format(gateway_ref.RelativeName()),
prompt_string='Continue anyway',
default=True,
throw_if_unattended=True,
cancel_on_no=True)
resp = gateways.GatewayClient().Delete(gateway_ref)
wait = 'Waiting for API Gateway [{}] to be deleted'.format(
gateway_ref.Name())
return operations_util.PrintOperationResult(
resp.name, operations.OperationsClient(), wait_string=wait,
is_async=args.async_)

View File

@@ -0,0 +1,51 @@
# -*- 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.
"""`gcloud api-gateway gateways describe` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.api_gateway import gateways
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.api_gateway import resource_args
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
@base.DefaultUniverseOnly
class Describe(base.DescribeCommand):
"""Show details about a specific gateway."""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To show details about a Gateway in us-central1, run:
$ {command} my-gateway --location=us-central1
""",
}
@staticmethod
def Args(parser):
resource_args.AddGatewayResourceArg(parser, 'created', positional=True)
def Run(self, args):
gateway_ref = args.CONCEPTS.gateway.Parse()
return gateways.GatewayClient().Get(gateway_ref)

View File

@@ -0,0 +1,53 @@
# -*- 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.
"""Command for getting IAM policies for gateways."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.api_gateway import gateways
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.api_gateway import resource_args
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
@base.DefaultUniverseOnly
class GetIamPolicy(base.ListCommand):
"""Get the IAM policy for a gateway."""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To print the IAM policy for a given gateway, run:
$ {command} my-gateway --location=us-central1
""",
}
@staticmethod
def Args(parser):
resource_args.AddGatewayResourceArg(parser, 'for which to get IAM policy',
positional=True)
base.URI_FLAG.RemoveFromParser(parser)
def Run(self, args):
gateway_ref = args.CONCEPTS.gateway.Parse()
return gateways.GatewayClient().GetIamPolicy(gateway_ref)

View File

@@ -0,0 +1,77 @@
# -*- 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.
"""api-gateway gateways list command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.api_gateway import gateways
from googlecloudsdk.api_lib.util import common_args
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.api_gateway import resource_args
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
@base.DefaultUniverseOnly
class List(base.ListCommand):
"""List API Gateways."""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To list all gateways, run:
$ {command}
To list all gateways within the 'us-central1' location:
$ {command} --location=us-central1
""",
}
LIST_FORMAT = """
table(
name.segment(5):label=GATEWAY_ID,
name.segment(3):label=LOCATION,
displayName,
state,
createTime.date(),
updateTime.date()
)"""
@staticmethod
def Args(parser):
resource_args.AddLocationResourceArg(parser,
'gateways will be listed from',
default='-',
required=False)
# Remove unneeded list-related flags from parser
base.URI_FLAG.RemoveFromParser(parser)
parser.display_info.AddFormat(List.LIST_FORMAT)
def Run(self, args):
parent_ref = args.CONCEPTS.location.Parse()
sort_by = common_args.ParseSortByArg(args.sort_by)
return gateways.GatewayClient().List(parent_ref.RelativeName(),
filters=args.filter,
limit=args.limit,
page_size=args.page_size,
sort_by=sort_by)

View File

@@ -0,0 +1,59 @@
# -*- 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.
"""Command to add IAM policy binding for a model."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.api_gateway import gateways
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.api_gateway import common_flags
from googlecloudsdk.command_lib.api_gateway import resource_args
from googlecloudsdk.command_lib.iam import iam_util
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
@base.DefaultUniverseOnly
class RemoveIamPolicyBinding(base.Command):
"""Remove IAM policy binding from a gateway."""
detailed_help = {
'EXAMPLES':
"""\
To remove an IAM policy binding for the role of 'roles/editor' for the
user 'test-user@gmail.com' on Gateway 'my-gateway' in us-central1, run:
$ {command} my-gateway --location='us-central1'
--member='user:test-user@gmail.com'
--role='roles/editor'
""",
}
@staticmethod
def Args(parser):
resource_args.AddGatewayResourceArg(parser,
'IAM policy binding will be added to',
positional=True)
iam_util.AddArgsForRemoveIamPolicyBinding(
parser,
common_flags.GatewayIamRolesCompleter)
def Run(self, args):
gateway_ref = args.CONCEPTS.gateway.Parse()
return gateways.GatewayClient().RemoveIamPolicyBinding(
gateway_ref, args.member, args.role)

View File

@@ -0,0 +1,92 @@
# -*- 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.
"""`gcloud api-gateway gateways update` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.api_gateway import gateways
from googlecloudsdk.api_lib.api_gateway import operations
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.api_gateway import common_flags
from googlecloudsdk.command_lib.api_gateway import operations_util
from googlecloudsdk.command_lib.api_gateway import resource_args
from googlecloudsdk.command_lib.util.args import labels_util
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
@base.DefaultUniverseOnly
class Update(base.UpdateCommand):
"""Update an API Gateway."""
detailed_help = {
'EXAMPLES':
"""\
To update the display name of a gateway, run:
$ {command} my-gateway --location=us-central1 --display-name="New Display Name"
""",
}
@staticmethod
def Args(parser):
base.ASYNC_FLAG.AddToParser(parser)
common_flags.AddDisplayNameArg(parser)
labels_util.AddUpdateLabelsFlags(parser)
resource_args.AddGatewayApiConfigResourceArgs(parser, 'updated',
api_config_required=False)
def Run(self, args):
gateway_ref = args.CONCEPTS.gateway.Parse()
gateways_client = gateways.GatewayClient()
gateway, mask = self.ProcessUpdates(gateways_client.Get(gateway_ref), args)
resp = gateways_client.Update(gateway, update_mask=mask)
wait = 'Waiting for API Gateway [{}] to be updated'.format(
gateway_ref.Name())
return operations_util.PrintOperationResult(
resp.name,
operations.OperationsClient(),
service=gateways_client.service,
wait_string=wait,
is_async=args.async_)
def ProcessUpdates(self, gateway, args):
api_config_ref = args.CONCEPTS.api_config.Parse()
update_mask = []
labels_update = labels_util.ProcessUpdateArgsLazy(
args,
gateway.LabelsValue,
lambda: gateway.labels)
if labels_update.needs_update:
gateway.labels = labels_update.labels
update_mask.append('labels')
if api_config_ref:
gateway.apiConfig = api_config_ref.RelativeName()
update_mask.append('apiConfig')
if args.display_name:
gateway.displayName = args.display_name
update_mask.append('displayName')
return gateway, ','.join(update_mask)