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

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 apis
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 API 'my-api', run:
$ {command} my-api --member='user:test-user@gmail.com' --role='roles/editor
""",
}
@staticmethod
def Args(parser):
resource_args.AddApiResourceArg(parser,
'IAM policy binding will be added to',
positional=True)
iam_util.AddArgsForAddIamPolicyBinding(
parser,
common_flags.GatewayIamRolesCompleter)
def Run(self, args):
api_ref = args.CONCEPTS.api.Parse()
return apis.ApiClient().AddIamPolicyBinding(
api_ref, args.member, args.role)

View File

@@ -0,0 +1,70 @@
# -*- 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 apis create` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.api_gateway import apis
from googlecloudsdk.api_lib.api_gateway import operations as ops
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 API."""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To create an API, run:
$ {command} my-api
""",
}
@staticmethod
def Args(parser):
base.ASYNC_FLAG.AddToParser(parser)
common_flags.AddDisplayNameArg(parser)
common_flags.AddManagedServiceFlag(parser)
labels_util.AddCreateLabelsFlags(parser)
resource_args.AddApiResourceArg(parser, 'created', positional=True)
def Run(self, args):
api_ref = args.CONCEPTS.api.Parse()
api_client = apis.ApiClient()
resp = api_client.Create(api_ref,
managed_service=args.managed_service,
labels=args.labels,
display_name=args.display_name)
return operations_util.PrintOperationResult(
resp.name,
ops.OperationsClient(),
service=api_client.service,
wait_string='Waiting for API [{}] to be created'.format(api_ref.Name()),
is_async=args.async_)

View File

@@ -0,0 +1,96 @@
# -*- 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.
"""`gcloud api-gateway apis delete` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.api_gateway import apis
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):
"""Deletes an API."""
detailed_help = {
'DESCRIPTION':
"""\
{description}
NOTE: All API configs belonging to the API will need to be deleted before
the API can be deleted.
""",
'EXAMPLES':
"""\
To delete an API 'my-api', run:
$ {command} my-api
NOTE: All API configs belonging to the API will need to be deleted before
the API can be deleted.
""",
}
@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.AddApiResourceArg(parser, 'will be deleted', positional=True)
def Run(self, args):
"""Run 'api-gateway apis delete'.
Args:
args: argparse.Namespace, The arguments that this command was invoked
with.
Returns:
The response from the Delete API call (or None if cancelled).
"""
api_ref = args.CONCEPTS.api.Parse()
# Prompt with a warning before continuing.
console_io.PromptContinue(
message='Are you sure? This will delete the API \'{}\', '
'along with all of the associated consumer '
'information.'.format(api_ref.RelativeName()),
prompt_string='Continue anyway',
default=True,
throw_if_unattended=True,
cancel_on_no=True)
resp = apis.ApiClient().Delete(api_ref)
wait = 'Waiting for API [{}] to be deleted'.format(
api_ref.Name())
return operations_util.PrintOperationResult(
resp.name, operations.OperationsClient(), wait_string=wait,
is_async=args.async_)

View File

@@ -0,0 +1,52 @@
# -*- 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.
"""`gcloud api-gateway apis describe` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.api_gateway import apis
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 API."""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To show details about an API, run:
$ {command} my-api
""",
}
@staticmethod
def Args(parser):
resource_args.AddApiResourceArg(parser, 'will be described',
positional=True)
def Run(self, args):
api_ref = args.CONCEPTS.api.Parse()
return apis.ApiClient().Get(api_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 apis."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.api_gateway import apis
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 an API."""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To print the IAM policy for a given API, run:
$ {command} my-api
""",
}
@staticmethod
def Args(parser):
resource_args.AddApiResourceArg(parser, 'for which to get IAM policy',
positional=True)
base.URI_FLAG.RemoveFromParser(parser)
def Run(self, args):
api_ref = args.CONCEPTS.api.Parse()
return apis.ApiClient().GetIamPolicy(api_ref)

View File

@@ -0,0 +1,73 @@
# -*- 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.
"""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 apis
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 APIs."""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To list all apis, run:
$ {command}
""",
}
LIST_FORMAT = """
table(
name.segment(5):label=API_ID,
displayName,
managedService,
state,
createTime.date()
)
"""
@staticmethod
def Args(parser):
resource_args.AddLocationResourceArg(parser,
'apis will be listed from',
default='global')
# 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 apis.ApiClient().List(parent_ref.RelativeName(),
filters=args.filter,
limit=args.limit,
page_size=args.page_size,
sort_by=sort_by)

View File

@@ -0,0 +1,58 @@
# -*- 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 apis
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 to 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 API 'my-api', run:
$ {command} my-api --member='user:test-user@gmail.com'
--role='roles/editor'
""",
}
@staticmethod
def Args(parser):
resource_args.AddApiResourceArg(parser,
'IAM policy binding will be added to',
positional=True)
iam_util.AddArgsForRemoveIamPolicyBinding(
parser,
common_flags.GatewayIamRolesCompleter)
def Run(self, args):
api_ref = args.CONCEPTS.api.Parse()
return apis.ApiClient().RemoveIamPolicyBinding(
api_ref, args.member, args.role)

View File

@@ -0,0 +1,92 @@
# -*- 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.
"""`gcloud api-gateway apis update` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from googlecloudsdk.api_lib.api_gateway import apis
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 API."""
detailed_help = {
'DESCRIPTION':
"""\
{description}
NOTE: Only the display name and labels attributes are mutable on an API.
""",
'EXAMPLES':
"""\
To update the display name of an API, run:
$ {command} my-api --display-name="New Display Name"
NOTE: Only the display name and labels attributes are mutable on an API.
""",
}
@staticmethod
def Args(parser):
base.ASYNC_FLAG.AddToParser(parser)
common_flags.AddDisplayNameArg(parser)
labels_util.AddUpdateLabelsFlags(parser)
resource_args.AddApiResourceArg(parser, 'updated', positional=True)
def Run(self, args):
api_ref = args.CONCEPTS.api.Parse()
api_client = apis.ApiClient()
api, mask = self.ProcessUpdates(api_client.Get(api_ref), args)
resp = api_client.Update(api, update_mask=mask)
return operations_util.PrintOperationResult(
resp.name,
operations.OperationsClient(),
service=api_client.service,
wait_string='Waiting for API [{}] to be updated'.format(api_ref.Name()),
is_async=args.async_)
def ProcessUpdates(self, api, args):
update_mask = []
labels_update = labels_util.ProcessUpdateArgsLazy(
args,
api.LabelsValue,
lambda: api.labels)
if labels_update.needs_update:
api.labels = labels_update.labels
update_mask.append('labels')
if args.display_name:
api.displayName = args.display_name
update_mask.append('displayName')
return api, ','.join(update_mask)