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,30 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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.
"""The queues command group for the Cloud Tasks CLI."""
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.BETA,
base.ReleaseTrack.GA)
class Queues(base.Group):
"""Manage Cloud Tasks queues.
Commands for managing Google Cloud Tasks queues.
"""

View File

@@ -0,0 +1,46 @@
release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Add IAM policy binding for a tasks queue.
description: |
Add an IAM policy binding to a tasks queue's access policy.
examples: |
To add an IAM policy binding for the role of 'roles/editor' for the user 'test-user@gmail.com'
with queue 'my-queue' and location='my-location', run:
$ {command} my-queue --location='my-location' --member='user:test-user@gmail.com' --role='roles/editor'
See https://cloud.google.com/iam/docs/managing-policies for details of
policy role and member types.
request:
collection: cloudtasks.projects.locations.queues
arguments:
resource:
help_text: The task queue for which to add IAM policy binding to.
spec: !REF googlecloudsdk.command_lib.tasks.resources:queue
ALPHA:
help_text:
brief: Add IAM policy binding for a tasks queue.
description: |
Add an IAM policy binding to a tasks queue's access policy. One binding consists of a member,
a role, and an optional condition.
examples: |
To add an IAM policy binding for the role of 'roles/editor' for the user 'test-user@gmail.com'
with queue 'my-queue' and location='my-location', run:
$ {command} my-queue --location='my-location' --member='user:test-user@gmail.com' --role='roles/editor'
To add an IAM policy binding which expires at the end of the year 2018 for the role of
'roles/cloudtasks.queueAdmin' and the user 'test-user@gmail.com' with queue 'my-queue' and location='my-location', run:
$ {command} my-queue --location='my-location' --member='user:test-user@gmail.com' --role='roles/cloudtasks.queueAdmin' --condition='expression=request.time < timestamp("2019-01-01T00:00:00Z"),title=expires_end_of_2018,description=Expires at midnight on 2018-12-31'
See https://cloud.google.com/iam/docs/managing-policies for details of
policy role and member types.
iam:
enable_condition: true

View File

@@ -0,0 +1,164 @@
# -*- 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 tasks queues create command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.tasks import GetApiAdapter
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.tasks import constants
from googlecloudsdk.command_lib.tasks import flags
from googlecloudsdk.command_lib.tasks import parsers
from googlecloudsdk.core import log
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Create(base.CreateCommand):
"""Create a Cloud Tasks queue.
The flags available to this command represent the fields of a queue that are
mutable.
"""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To create a Cloud Tasks queue:
$ {command} my-queue
--max-attempts=10 --max-retry-duration=5s
--max-doublings=4 --min-backoff=1s
--max-backoff=10s
--max-dispatches-per-second=100
--max-concurrent-dispatches=10
--routing-override=service:abc
""",
}
@staticmethod
def Args(parser):
flags.AddQueueResourceArg(parser, 'to create')
flags.AddLocationFlag(parser)
flags.AddCreatePushQueueFlags(parser)
def Run(self, args):
if self.ReleaseTrack() == base.ReleaseTrack.BETA:
queue_type = args.type
else:
queue_type = constants.PUSH_QUEUE
api = GetApiAdapter(self.ReleaseTrack())
queues_client = api.queues
queue_ref = parsers.ParseQueue(args.queue, args.location)
location_ref = parsers.ExtractLocationRefFromQueueRef(queue_ref)
queue_config = parsers.ParseCreateOrUpdateQueueArgs(
args, queue_type, api.messages,
release_track=self.ReleaseTrack())
if self.ReleaseTrack() == base.ReleaseTrack.ALPHA:
create_response = queues_client.Create(
location_ref,
queue_ref,
retry_config=queue_config.retryConfig,
rate_limits=queue_config.rateLimits,
app_engine_http_target=queue_config.appEngineHttpTarget,
http_target=queue_config.httpTarget)
elif self.ReleaseTrack() == base.ReleaseTrack.BETA:
create_response = queues_client.Create(
location_ref,
queue_ref,
retry_config=queue_config.retryConfig,
rate_limits=queue_config.rateLimits,
app_engine_http_queue=queue_config.appEngineHttpQueue,
stackdriver_logging_config=queue_config.stackdriverLoggingConfig,
http_target=queue_config.httpTarget,
queue_type=queue_config.type,
)
else:
create_response = queues_client.Create(
location_ref,
queue_ref,
retry_config=queue_config.retryConfig,
rate_limits=queue_config.rateLimits,
app_engine_routing_override=queue_config.appEngineRoutingOverride,
http_target=queue_config.httpTarget,
stackdriver_logging_config=queue_config.stackdriverLoggingConfig)
log.CreatedResource(
parsers.GetConsolePromptString(queue_ref.RelativeName()), 'queue')
return create_response
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class BetaCreate(Create):
"""Create a Cloud Tasks queue.
The flags available to this command represent the fields of a queue that are
mutable.
"""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To create a Cloud Tasks queue:
$ {command} my-queue
--max-attempts=10 --max-retry-duration=5s
--max-doublings=4 --min-backoff=1s
--max-backoff=10s
--max-dispatches-per-second=100
--max-concurrent-dispatches=10
--routing-override=service:abc
""",
}
@staticmethod
def Args(parser):
flags.AddQueueResourceArg(parser, 'to create')
flags.AddLocationFlag(parser)
flags.AddCreatePushQueueFlags(parser, release_track=base.ReleaseTrack.BETA)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class AlphaCreate(Create):
"""Create a Cloud Tasks queue.
The flags available to this command represent the fields of a queue that are
mutable.
"""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To create a Cloud Tasks queue:
$ {command} my-queue
--max-attempts=10 --max-retry-duration=5s
--max-doublings=4 --min-backoff=1s
--max-backoff=10s
--max-tasks-dispatched-per-second=100
--max-concurrent-tasks=10
--routing-override=service:abc
""",
}
@staticmethod
def Args(parser):
flags.AddQueueResourceArg(parser, 'to create')
flags.AddLocationFlag(parser)
flags.AddCreatePushQueueFlags(parser, release_track=base.ReleaseTrack.ALPHA)

View File

@@ -0,0 +1,145 @@
# -*- 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 tasks queues create command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.tasks import GetApiAdapter
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.tasks import constants
from googlecloudsdk.command_lib.tasks import flags
from googlecloudsdk.command_lib.tasks import parsers
from googlecloudsdk.core import log
@base.Deprecate(is_removed=False,
warning='This command is deprecated. '
'Use `gcloud beta tasks queues create` instead')
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class CreateAppEngine(base.CreateCommand):
"""Create a Cloud Tasks queue.
The flags available to this command represent the fields of a queue that are
mutable.
"""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To create a Cloud Tasks queue:
$ {command} my-queue
--max-attempts=10 --max-retry-duration=5s
--max-doublings=4 --min-backoff=1s
--max-backoff=10s
--max-dispatches-per-second=100
--max-concurrent-dispatches=10
--routing-override=service:abc
""",
}
def __init__(self, *args, **kwargs):
super(CreateAppEngine, self).__init__(*args, **kwargs)
self.is_alpha = False
@staticmethod
def Args(parser):
flags.AddQueueResourceArg(parser, 'to create')
flags.AddLocationFlag(parser)
flags.AddCreatePushQueueFlags(
parser,
release_track=base.ReleaseTrack.BETA,
app_engine_queue=True,
http_queue=False,
)
def Run(self, args):
api = GetApiAdapter(self.ReleaseTrack())
queues_client = api.queues
queue_ref = parsers.ParseQueue(args.queue, args.location)
location_ref = parsers.ExtractLocationRefFromQueueRef(queue_ref)
queue_config = parsers.ParseCreateOrUpdateQueueArgs(
args,
constants.PUSH_QUEUE,
api.messages,
release_track=self.ReleaseTrack(),
http_queue=False,
)
if not self.is_alpha:
create_response = queues_client.Create(
location_ref,
queue_ref,
retry_config=queue_config.retryConfig,
rate_limits=queue_config.rateLimits,
app_engine_http_queue=queue_config.appEngineHttpQueue,
stackdriver_logging_config=queue_config.stackdriverLoggingConfig)
else:
create_response = queues_client.Create(
location_ref,
queue_ref,
retry_config=queue_config.retryConfig,
rate_limits=queue_config.rateLimits,
app_engine_http_target=queue_config.appEngineHttpTarget)
log.CreatedResource(
parsers.GetConsolePromptString(queue_ref.RelativeName()), 'queue')
return create_response
@base.Deprecate(is_removed=False,
warning='This command group is deprecated. '
'Use `gcloud alpha tasks queues create` instead')
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class AlphaCreateAppEngine(CreateAppEngine):
"""Create a Cloud Tasks queue.
The flags available to this command represent the fields of a queue that are
mutable.
"""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To create a Cloud Tasks queue:
$ {command} my-queue
--max-attempts=10 --max-retry-duration=5s
--max-doublings=4 --min-backoff=1s
--max-backoff=10s
--max-tasks-dispatched-per-second=100
--max-concurrent-tasks=10
--routing-override=service:abc
""",
}
def __init__(self, *args, **kwargs):
super(AlphaCreateAppEngine, self).__init__(*args, **kwargs)
self.is_alpha = True
@staticmethod
def Args(parser):
flags.AddQueueResourceArg(parser, 'to create')
flags.AddLocationFlag(parser)
flags.AddCreatePushQueueFlags(
parser,
release_track=base.ReleaseTrack.ALPHA,
app_engine_queue=True,
http_queue=False,
)

View File

@@ -0,0 +1,88 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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 tasks queues create-pull-queue` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.tasks import GetApiAdapter
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.tasks import constants
from googlecloudsdk.command_lib.tasks import flags
from googlecloudsdk.command_lib.tasks import parsers
from googlecloudsdk.core import log
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class CreatePull(base.CreateCommand):
"""Create a pull queue.
The flags available to this command represent the fields of a pull queue
that are mutable.
If you have early access to Cloud Tasks, refer to the following guide for
more information about the different queue target types:
https://cloud.google.com/cloud-tasks/docs/queue-types.
For access, sign up here: https://goo.gl/Ya0AZd
"""
detailed_help = {
'DESCRIPTION':
"""
{description}
""",
'EXAMPLES':
"""
To create a Cloud Tasks pull queue:
$ {command} my-queue
--max-attempts=10 --max-retry-duration=10s
""",
}
@staticmethod
def Args(parser):
flags.AddQueueResourceArg(parser, 'to create')
flags.AddLocationFlag(parser)
flags.AddCreatePullQueueFlags(parser)
def Run(self, args):
api = GetApiAdapter(self.ReleaseTrack())
queues_client = api.queues
queue_ref = parsers.ParseQueue(args.queue, args.location)
location_ref = parsers.ExtractLocationRefFromQueueRef(queue_ref)
queue_config = parsers.ParseCreateOrUpdateQueueArgs(
args,
constants.PULL_QUEUE,
api.messages,
release_track=self.ReleaseTrack())
if self.ReleaseTrack() == base.ReleaseTrack.ALPHA:
create_response = queues_client.Create(
location_ref,
queue_ref,
retry_config=queue_config.retryConfig,
rate_limits=queue_config.rateLimits,
pull_target=queue_config.pullTarget)
else:
create_response = queues_client.Create(
location_ref,
queue_ref,
retry_config=queue_config.retryConfig,
rate_limits=queue_config.rateLimits,
queue_type=queue_config.type)
log.CreatedResource(
parsers.GetConsolePromptString(queue_ref.RelativeName()), 'queue')
return create_response

View File

@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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 tasks queues delete` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.tasks import GetApiAdapter
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.tasks import flags
from googlecloudsdk.command_lib.tasks import parsers
from googlecloudsdk.core import log
from googlecloudsdk.core.console import console_io
class Delete(base.DeleteCommand):
"""Delete a queue."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To delete a queue:
$ {command} my-queue
""",
}
@staticmethod
def Args(parser):
flags.AddQueueResourceArg(parser, 'to delete')
flags.AddLocationFlag(parser)
def Run(self, args):
queues_client = GetApiAdapter(self.ReleaseTrack()).queues
queue_ref = parsers.ParseQueue(args.queue, args.location)
queue_short = parsers.GetConsolePromptString(queue_ref.RelativeName())
console_io.PromptContinue(
cancel_on_no=True,
prompt_string=(
'Deleted queues can not be re-created for a duration of up to 7 '
'days. Are you sure you want to delete: [{}]'.format(queue_short)))
queues_client.Delete(queue_ref)
log.DeletedResource(queue_short, 'queue')

View File

@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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 tasks queues describe` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.tasks import GetApiAdapter
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.tasks import flags
from googlecloudsdk.command_lib.tasks import parsers
class Describe(base.DescribeCommand):
"""Show details about a queue."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To describe queue:
$ {command} my-queue
""",
}
@staticmethod
def Args(parser):
flags.AddQueueResourceArg(parser, 'to describe')
flags.AddLocationFlag(parser)
def Run(self, args):
queues_client = GetApiAdapter(self.ReleaseTrack()).queues
queue_ref = parsers.ParseQueue(args.queue, args.location)
return queues_client.Get(queue_ref)

View File

@@ -0,0 +1,28 @@
release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Get the IAM policy for a queue.
description: |
*{command}* displays the IAM policy associated with a queue.
If formatted as JSON, the output can be edited and used as
a policy file for *set-iam-policy*. The output includes an "etag"
field identifying the version emitted and allowing detection of
concurrent policy updates; see
$ {parent_command} set-iam-policy for additional details.
examples: |
To print the IAM policy for a given queue, run:
$ {command} my-queue
request:
collection: cloudtasks.projects.locations.queues
api_version: v2
BETA:
api_version: v2beta3
ALPHA:
api_version: v2beta2
arguments:
resource:
help_text: The Cloud Tasks queue for which to display the IAM policy.
spec: !REF googlecloudsdk.command_lib.tasks.resources:queue

View File

@@ -0,0 +1,73 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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 tasks queues list` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.tasks import GetApiAdapter
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.tasks import app
from googlecloudsdk.command_lib.tasks import flags
from googlecloudsdk.command_lib.tasks import list_formats
from googlecloudsdk.command_lib.tasks import parsers
@base.ReleaseTracks(base.ReleaseTrack.GA)
class List(base.ListCommand):
"""List all queues."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To list all queues:
$ {command}
""",
}
@staticmethod
def Args(parser):
flags.AddLocationFlag(parser)
list_formats.AddListQueuesFormats(parser)
def Run(self, args):
queues_client = GetApiAdapter(self.ReleaseTrack()).queues
app_location = args.location or app.ResolveAppLocation(
parsers.ParseProject())
region_ref = parsers.ParseLocation(app_location)
return queues_client.List(region_ref, args.limit, args.page_size)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class AlphaList(List):
"""List all queues."""
@staticmethod
def Args(parser):
flags.AddLocationFlag(parser)
list_formats.AddListQueuesFormats(parser, version=base.ReleaseTrack.ALPHA)
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class BetaList(List):
"""List all queues including their type."""
@staticmethod
def Args(parser):
flags.AddLocationFlag(parser)
list_formats.AddListQueuesFormats(parser, version=base.ReleaseTrack.BETA)

View File

@@ -0,0 +1,55 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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 tasks queues pause` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.tasks import GetApiAdapter
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.tasks import flags
from googlecloudsdk.command_lib.tasks import parsers
from googlecloudsdk.core import log
class Pause(base.Command):
"""Pause a queue.
If a queue is paused then the system will stop executing the tasks in the
queue until it is resumed. Tasks can still be added when the queue is paused.
"""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To pause a queue:
$ {command} my-queue
""",
}
@staticmethod
def Args(parser):
flags.AddQueueResourceArg(parser, 'to pause')
flags.AddLocationFlag(parser)
def Run(self, args):
queues_client = GetApiAdapter(self.ReleaseTrack()).queues
queue_ref = parsers.ParseQueue(args.queue, args.location)
queues_client.Pause(queue_ref)
log.status.Print('Paused queue [{}].'.format(
parsers.GetConsolePromptString(queue_ref.RelativeName())))

View File

@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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 tasks queues purge` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.tasks import GetApiAdapter
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.tasks import flags
from googlecloudsdk.command_lib.tasks import parsers
from googlecloudsdk.core import log
from googlecloudsdk.core.console import console_io
class Purge(base.Command):
"""Purge a queue by deleting all of its tasks.
This command purges a queue by deleting all of its tasks. Purge operations can
take up to one minute to take effect. Tasks might be dispatched before the
purge takes effect. A purge is irreversible. All tasks created before this
command is run are permanently deleted.
"""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To purge a queue:
$ {command} my-queue
""",
}
@staticmethod
def Args(parser):
flags.AddQueueResourceArg(parser, 'to purge')
flags.AddLocationFlag(parser)
def Run(self, args):
queues_client = GetApiAdapter(self.ReleaseTrack()).queues
queue_ref = parsers.ParseQueue(args.queue, args.location)
queue_short = parsers.GetConsolePromptString(queue_ref.RelativeName())
console_io.PromptContinue(
cancel_on_no=True,
prompt_string='Are you sure you want to purge: [{}]'.format(
queue_short))
queues_client.Purge(queue_ref)
log.status.Print('Purged queue [{}].'.format(queue_short))

View File

@@ -0,0 +1,46 @@
release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Remove IAM policy binding of tasks queue.
description: |
Remove an IAM policy binding of a tasks queue's access policy.
examples: |
To remove an IAM policy binding for the role of 'roles/editor' for the user 'test-user@gmail.com'
with queue 'my-queue' and location='my-location', run:
$ {command} my-queue --location='my-location' --member='user:test-user@gmail.com' --role='roles/editor'
See https://cloud.google.com/iam/docs/managing-policies for details of
policy role and member types.
request:
collection: cloudtasks.projects.locations.queues
arguments:
resource:
help_text: The task queue for which to remove IAM policy binding from.
spec: !REF googlecloudsdk.command_lib.tasks.resources:queue
ALPHA:
help_text:
brief: Remove IAM policy binding of a tasks queue.
description: |
Remove an IAM policy binding from the IAM policy binding of a tasks queue's access policy. One binding consists of a member,
a role, and an optional condition.
examples: |
To remove an IAM policy binding for the role of 'roles/editor' for the user 'test-user@gmail.com'
with queue 'my-queue' and location='my-location', run:
$ {command} my-queue --location='my-location' --member='user:test-user@gmail.com' --role='roles/editor'
To remove an IAM policy binding which expires at the end of the year 2018 for the role of
'roles/cloudtasks.queueAdmin' and the user 'test-user@gmail.com' with queue 'my-queue' and location='my-location', run:
$ {command} my-queue --location='my-location' --member='user:test-user@gmail.com' --role='roles/cloudtasks.queueAdmin' --condition='expression=request.time < timestamp("2019-01-01T00:00:00Z"),title=expires_end_of_2018,description=Expires at midnight on 2018-12-31'
See https://cloud.google.com/iam/docs/managing-policies for details of
policy role and member types.
iam:
enable_condition: true

View File

@@ -0,0 +1,51 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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 tasks queues resume` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.tasks import GetApiAdapter
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.tasks import flags
from googlecloudsdk.command_lib.tasks import parsers
from googlecloudsdk.core import log
class Resume(base.Command):
"""Request to resume a paused or disabled queue."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To resume a queue:
$ {command} my-queue
""",
}
@staticmethod
def Args(parser):
flags.AddQueueResourceArg(parser, 'to resume')
flags.AddLocationFlag(parser)
def Run(self, args):
queues_client = GetApiAdapter(self.ReleaseTrack()).queues
queue_ref = parsers.ParseQueue(args.queue, args.location)
queues_client.Resume(queue_ref)
log.status.Print('Resumed queue [{}].'.format(
parsers.GetConsolePromptString(queue_ref.RelativeName())))

View File

@@ -0,0 +1,30 @@
release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Set the IAM policy for a queue.
description: |
This command replaces the existing IAM policy for a queue, given a queue
and a file encoded in JSON or YAML that contains the IAM policy. If the
given policy file specifies an "etag" value, then the replacement will
succeed only if the policy already in place matches that etag. (An etag
obtained via `get-iam-policy` will prevent the replacement if the policy
for the queue has been subsequently updated.) A policy file that does not
contain an etag value will replace any existing policy for the queue.
examples: |
To set the IAM policy for a queue:
$ {command} my-queue policy-file.json
request:
collection: cloudtasks.projects.locations.queues
api_version: v2
BETA:
api_version: v2beta3
ALPHA:
api_version: v2beta2
arguments:
resource:
help_text: The queue for which to set the IAM policy.
spec: !REF googlecloudsdk.command_lib.tasks.resources:queue

View File

@@ -0,0 +1,237 @@
# -*- 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 tasks queues update` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.tasks import GetApiAdapter
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.tasks import constants
from googlecloudsdk.command_lib.tasks import flags
from googlecloudsdk.command_lib.tasks import parsers
from googlecloudsdk.core import log
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Update(base.UpdateCommand):
"""Update a Cloud Tasks queue.
The flags available to this command represent the fields of a queue that are
mutable.
"""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To update a Cloud Tasks queue:
$ {command} my-queue
--clear-max-attempts --clear-max-retry-duration
--clear-max-doublings --clear-min-backoff
--clear-max-backoff
--clear-max-dispatches-per-second
--clear-max-concurrent-dispatches
--clear-routing-override
""",
}
def __init__(self, *args, **kwargs):
super(Update, self).__init__(*args, **kwargs)
self.is_alpha = False
@staticmethod
def Args(parser):
flags.AddQueueResourceArg(parser, 'to update')
flags.AddLocationFlag(parser)
flags.AddUpdatePushQueueFlags(parser)
def Run(self, args):
if self.ReleaseTrack() == base.ReleaseTrack.BETA:
queue_type = args.type
else:
queue_type = constants.PUSH_QUEUE
parsers.CheckUpdateArgsSpecified(args,
queue_type,
release_track=self.ReleaseTrack())
api = GetApiAdapter(self.ReleaseTrack())
queues_client = api.queues
queue_ref = parsers.ParseQueue(args.queue, args.location)
queue_config = parsers.ParseCreateOrUpdateQueueArgs(
args,
queue_type,
api.messages,
is_update=True,
release_track=self.ReleaseTrack())
updated_fields = parsers.GetSpecifiedFieldsMask(
args, queue_type, release_track=self.ReleaseTrack())
if self.ReleaseTrack() == base.ReleaseTrack.ALPHA:
app_engine_routing_override = (
queue_config.appEngineHttpTarget.appEngineRoutingOverride
if queue_config.appEngineHttpTarget is not None else None)
http_target_args = parsers.GetHttpTargetArgs(queue_config)
update_response = queues_client.Patch(
queue_ref,
updated_fields,
retry_config=queue_config.retryConfig,
rate_limits=queue_config.rateLimits,
app_engine_routing_override=app_engine_routing_override,
http_uri_override=http_target_args['http_uri_override'],
http_method_override=http_target_args['http_method_override'],
http_header_override=http_target_args['http_header_override'],
http_oauth_email_override=http_target_args[
'http_oauth_email_override'
],
http_oauth_scope_override=http_target_args[
'http_oauth_scope_override'
],
http_oidc_email_override=http_target_args['http_oidc_email_override'],
http_oidc_audience_override=http_target_args[
'http_oidc_audience_override'
],
)
elif self.ReleaseTrack() == base.ReleaseTrack.BETA:
app_engine_routing_override = (
queue_config.appEngineHttpQueue.appEngineRoutingOverride
if queue_config.appEngineHttpQueue is not None else None)
http_target_args = parsers.GetHttpTargetArgs(queue_config)
update_response = queues_client.Patch(
queue_ref,
updated_fields,
retry_config=queue_config.retryConfig,
rate_limits=queue_config.rateLimits,
app_engine_routing_override=app_engine_routing_override,
stackdriver_logging_config=queue_config.stackdriverLoggingConfig,
queue_type=queue_config.type,
http_uri_override=http_target_args['http_uri_override'],
http_method_override=http_target_args['http_method_override'],
http_header_override=http_target_args['http_header_override'],
http_oauth_email_override=http_target_args[
'http_oauth_email_override'
],
http_oauth_scope_override=http_target_args[
'http_oauth_scope_override'
],
http_oidc_email_override=http_target_args['http_oidc_email_override'],
http_oidc_audience_override=http_target_args[
'http_oidc_audience_override'
],
)
else:
app_engine_routing_override = queue_config.appEngineRoutingOverride
http_target_args = parsers.GetHttpTargetArgs(queue_config)
update_response = queues_client.Patch(
queue_ref,
updated_fields,
retry_config=queue_config.retryConfig,
rate_limits=queue_config.rateLimits,
app_engine_routing_override=app_engine_routing_override,
stackdriver_logging_config=queue_config.stackdriverLoggingConfig,
http_uri_override=http_target_args['http_uri_override'],
http_method_override=http_target_args['http_method_override'],
http_header_override=http_target_args['http_header_override'],
http_oauth_email_override=http_target_args[
'http_oauth_email_override'
],
http_oauth_scope_override=http_target_args[
'http_oauth_scope_override'
],
http_oidc_email_override=http_target_args['http_oidc_email_override'],
http_oidc_audience_override=http_target_args[
'http_oidc_audience_override'
],
)
log.status.Print('Updated queue [{}].'.format(
parsers.GetConsolePromptString(queue_ref.RelativeName())))
return update_response
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class BetaUpdate(Update):
"""Update a Cloud Tasks queue.
The flags available to this command represent the fields of a queue that are
mutable.
"""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To update a Cloud Tasks queue:
$ {command} my-queue
--clear-max-attempts --clear-max-retry-duration
--clear-max-doublings --clear-min-backoff
--clear-max-backoff
--clear-max-dispatches-per-second
--clear-max-concurrent-dispatches
--clear-routing-override
""",
}
def __init__(self, *args, **kwargs):
super(BetaUpdate, self).__init__(*args, **kwargs)
self.is_alpha = False
@staticmethod
def Args(parser):
flags.AddQueueResourceArg(parser, 'to update')
flags.AddLocationFlag(parser)
flags.AddUpdatePushQueueFlags(
parser, release_track=base.ReleaseTrack.BETA)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class AlphaUpdate(Update):
"""Update a Cloud Tasks queue.
The flags available to this command represent the fields of a queue that are
mutable. Attempting to use this command on a different type of queue will
result in an error.
"""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To update a Cloud Tasks queue:
$ {command} my-queue
--clear-max-attempts --clear-max-retry-duration
--clear-max-doublings --clear-min-backoff
--clear-max-backoff
--clear-max-tasks-dispatched-per-second
--clear-max-concurrent-tasks
--clear-routing-override
""",
}
def __init__(self, *args, **kwargs):
super(AlphaUpdate, self).__init__(*args, **kwargs)
self.is_alpha = True
@staticmethod
def Args(parser):
flags.AddQueueResourceArg(parser, 'to update')
flags.AddLocationFlag(parser)
flags.AddUpdatePushQueueFlags(parser, release_track=base.ReleaseTrack.ALPHA)

View File

@@ -0,0 +1,156 @@
# -*- 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 tasks queues update` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.tasks import GetApiAdapter
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.tasks import constants
from googlecloudsdk.command_lib.tasks import flags
from googlecloudsdk.command_lib.tasks import parsers
from googlecloudsdk.core import log
@base.Deprecate(is_removed=False,
warning='This command is deprecated. '
'Use `gcloud beta tasks queues update` instead')
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class UpdateAppEngine(base.UpdateCommand):
"""Update a Cloud Tasks queue.
The flags available to this command represent the fields of a queue that are
mutable.
"""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To update a Cloud Tasks queue:
$ {command} my-queue
--clear-max-attempts --clear-max-retry-duration
--clear-max-doublings --clear-min-backoff
--clear-max-backoff
--clear-max-dispatches-per-second
--clear-max-concurrent-dispatches
--clear-routing-override
""",
}
def __init__(self, *args, **kwargs):
super(UpdateAppEngine, self).__init__(*args, **kwargs)
self.is_alpha = False
@staticmethod
def Args(parser):
flags.AddQueueResourceArg(parser, 'to update')
flags.AddLocationFlag(parser)
flags.AddUpdatePushQueueFlags(
parser,
release_track=base.ReleaseTrack.BETA,
app_engine_queue=True,
http_queue=False,
)
def Run(self, args):
parsers.CheckUpdateArgsSpecified(args,
constants.PUSH_QUEUE,
release_track=self.ReleaseTrack())
api = GetApiAdapter(self.ReleaseTrack())
queues_client = api.queues
queue_ref = parsers.ParseQueue(args.queue, args.location)
queue_config = parsers.ParseCreateOrUpdateQueueArgs(
args,
constants.PUSH_QUEUE,
api.messages,
is_update=True,
release_track=self.ReleaseTrack(),
http_queue=False,
)
updated_fields = parsers.GetSpecifiedFieldsMask(
args, constants.PUSH_QUEUE, release_track=self.ReleaseTrack())
if not self.is_alpha:
app_engine_routing_override = (
queue_config.appEngineHttpQueue.appEngineRoutingOverride
if queue_config.appEngineHttpQueue is not None else None)
update_response = queues_client.Patch(
queue_ref,
updated_fields,
retry_config=queue_config.retryConfig,
rate_limits=queue_config.rateLimits,
app_engine_routing_override=app_engine_routing_override,
stackdriver_logging_config=queue_config.stackdriverLoggingConfig)
else:
app_engine_routing_override = (
queue_config.appEngineHttpTarget.appEngineRoutingOverride
if queue_config.appEngineHttpTarget is not None else None)
update_response = queues_client.Patch(
queue_ref,
updated_fields,
retry_config=queue_config.retryConfig,
rate_limits=queue_config.rateLimits,
app_engine_routing_override=app_engine_routing_override)
log.status.Print('Updated queue [{}].'.format(
parsers.GetConsolePromptString(queue_ref.RelativeName())))
return update_response
@base.Deprecate(is_removed=False,
warning='This command is deprecated. '
'Use `gcloud alpha tasks queues update` instead')
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class AlphaUpdateAppEngine(UpdateAppEngine):
"""Update a Cloud Tasks queue.
The flags available to this command represent the fields of a queue that are
mutable. Attempting to use this command on a different type of queue will
result in an error.
"""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To update a Cloud Tasks queue:
$ {command} my-queue
--clear-max-attempts --clear-max-retry-duration
--clear-max-doublings --clear-min-backoff
--clear-max-backoff
--clear-max-tasks-dispatched-per-second
--clear-max-concurrent-tasks
--clear-routing-override
""",
}
def __init__(self, *args, **kwargs):
super(AlphaUpdateAppEngine, self).__init__(*args, **kwargs)
self.is_alpha = True
@staticmethod
def Args(parser):
flags.AddQueueResourceArg(parser, 'to update')
flags.AddLocationFlag(parser)
flags.AddUpdatePushQueueFlags(
parser,
release_track=base.ReleaseTrack.ALPHA,
app_engine_queue=True,
http_queue=False,
)

View File

@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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 tasks queues update-pull-queue` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.tasks import GetApiAdapter
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.tasks import constants
from googlecloudsdk.command_lib.tasks import flags
from googlecloudsdk.command_lib.tasks import parsers
from googlecloudsdk.core import log
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class UpdatePull(base.UpdateCommand):
"""Update a pull queue.
The flags available to this command represent the fields of a pull queue
that are mutable. Attempting to use this command on a different type of queue
will result in an error.
If you have early access to Cloud Tasks, refer to the following guide for
more information about the different queue target types:
https://cloud.google.com/cloud-tasks/docs/queue-types.
For access, sign up here: https://goo.gl/Ya0AZd
"""
@staticmethod
def Args(parser):
flags.AddQueueResourceArg(parser, 'to update')
flags.AddLocationFlag(parser)
flags.AddUpdatePullQueueFlags(parser)
def Run(self, args):
parsers.CheckUpdateArgsSpecified(args, constants.PULL_QUEUE,
release_track=self.ReleaseTrack())
api = GetApiAdapter(self.ReleaseTrack())
queues_client = api.queues
queue_ref = parsers.ParseQueue(args.queue, args.location)
queue_config = parsers.ParseCreateOrUpdateQueueArgs(
args,
constants.PULL_QUEUE,
api.messages,
is_update=True,
release_track=self.ReleaseTrack())
updated_fields = parsers.GetSpecifiedFieldsMask(
args, constants.PULL_QUEUE, release_track=self.ReleaseTrack())
update_response = queues_client.Patch(
queue_ref, updated_fields, retry_config=queue_config.retryConfig)
log.status.Print('Updated queue [{}].'.format(
parsers.GetConsolePromptString(queue_ref.RelativeName())))
return update_response