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,35 @@
# -*- 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.
"""Command group for Cloud Tasks."""
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 Tasks(base.Group):
"""Manage Cloud Tasks queues and tasks."""
category = base.CI_CD_CATEGORY
def Filter(self, context, args):
# TODO(b/190541099): Determine if command group works with project number
base.RequireProjectID(args)
del context, args
base.DisableUserProjectQuota()

View File

@@ -0,0 +1,41 @@
# -*- 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 acknowledge` 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
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Acknowledge(base.SilentCommand):
"""Acknowledge the lease on a task in a pull queue."""
@staticmethod
def Args(parser):
flags.AddTaskResourceArgs(parser, 'to acknowledge')
flags.AddLocationFlag(parser)
flags.AddTaskLeaseScheduleTimeFlag(parser, 'acknowledging')
def Run(self, args):
tasks_client = GetApiAdapter(self.ReleaseTrack()).tasks
queue_ref = parsers.ParseQueue(args.queue, args.location)
task_ref = parsers.ParseTask(args.task, queue_ref)
tasks_client.Acknowledge(task_ref, args.schedule_time)

View File

@@ -0,0 +1,65 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 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 buffer` 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
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class Buffer(base.Command):
"""Buffers a task into a queue."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To buffer into a queue:
$ {command} --queue=my-queue --location=us-central1
""",
}
@staticmethod
def Args(parser):
flags.AddQueueResourceFlag(parser, required=True)
flags.AddLocationFlag(
parser, required=True, helptext='The location where the queue exists.'
)
flags.AddTaskIdFlag(parser)
def Run(self, args):
api = GetApiAdapter(self.ReleaseTrack())
tasks_client = api.tasks
queue_ref = parsers.ParseQueue(args.queue, args.location)
task_id = parsers.ParseTaskId(args)
task_id = '' if task_id is None else task_id
tasks_client.Buffer(queue_ref, task_id)
log.status.Print(
'Buffered task in queue [{}].'.format(
parsers.GetConsolePromptString(queue_ref.RelativeName())
)
)

View File

@@ -0,0 +1,41 @@
# -*- 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 cancel-lease` 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
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class CancelLease(base.Command):
"""Cancel the lease on a task in a pull queue."""
@staticmethod
def Args(parser):
flags.AddTaskResourceArgs(parser, 'to cancel the lease of')
flags.AddLocationFlag(parser)
flags.AddTaskLeaseScheduleTimeFlag(parser, 'canceling')
def Run(self, args):
tasks_client = GetApiAdapter(self.ReleaseTrack()).tasks
queue_ref = parsers.ParseQueue(args.queue, args.location)
task_ref = parsers.ParseTask(args.task, queue_ref)
return tasks_client.CancelLease(task_ref, args.schedule_time)

View File

@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command group for Cloud Tasks."""
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 CmekConfig(base.Group):
"""Get or change CMEK configuration for Cloud Tasks."""

View File

@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""`gcloud tasks cmek-config 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
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class GetCmekConfig(base.Command):
"""Get CMEK configuration for Cloud Tasks in the specified location."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To get a CMEK config:
$ {command} --location=my-location
""",
}
@staticmethod
def Args(parser):
flags.DescribeCmekConfigResourceFlag(parser)
def Run(self, args):
api = GetApiAdapter(self.ReleaseTrack())
cmek_config_client = api.cmek_config
project_id, location_id = parsers.ParseKmsDescribeArgs(args)
cmek_config = cmek_config_client.GetCmekConfig(project_id, location_id)
return cmek_config

View File

@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""`gcloud tasks cmek-config 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 flags
from googlecloudsdk.command_lib.tasks import parsers
from googlecloudsdk.core import log
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class UpdateCmekConfig(base.Command):
"""Enable, disable, or edit CMEK configuration for Cloud Tasks in the specified location."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To update a CMEK config:
$ {command} --kms-key-name=projects/my-project/locations/my-location/keyRings/my-keyring/cryptoKeys/key
""",
}
@staticmethod
def Args(parser):
flags.AddCmekConfigResourceFlag(parser)
def Run(self, args):
api = GetApiAdapter(self.ReleaseTrack())
cmek_config_client = api.cmek_config
if args.clear_kms_key:
# When clearing, we only need to have location and _PROJECT()
project_id, location_id = parsers.ParseKmsClearArgs(args)
full_kms_key_name = ''
else:
project_id, full_kms_key_name, location_id = parsers.ParseKmsUpdateArgs(
args
)
cmek_config = cmek_config_client.UpdateCmekConfig(
project_id, location_id, full_kms_key_name, args.clear_kms_key
)
log.status.Print(
'Updated Cmek config for KMS key: [{}].'.format(
parsers.GetConsolePromptString(full_kms_key_name)
)
)
return cmek_config

View File

@@ -0,0 +1,98 @@
# -*- 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 create-app-engine-task` 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.BETA, base.ReleaseTrack.GA)
class CreateAppEngine(base.CreateCommand):
"""Create and add a task that targets App Engine."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To create a task:
$ {command} --queue=my-queue --relative-uri=/handler-path my-task
""",
}
@staticmethod
def Args(parser):
flags.AddCreateAppEngineTaskFlags(parser)
flags.AddLocationFlag(parser)
def Run(self, args):
api = GetApiAdapter(self.ReleaseTrack())
tasks_client = api.tasks
queue_ref = parsers.ParseQueue(args.queue, args.location)
task_ref = parsers.ParseTask(args.task,
queue_ref) if args.task else None
task_config = parsers.ParseCreateTaskArgs(
args, constants.APP_ENGINE_TASK, api.messages,
release_track=self.ReleaseTrack())
create_response = tasks_client.Create(
queue_ref, task_ref,
schedule_time=task_config.scheduleTime,
app_engine_http_request=task_config.appEngineHttpRequest)
log.CreatedResource(create_response.name, 'task')
return create_response
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class AlphaCreateAppEngine(base.CreateCommand):
"""Create and add a task that targets App Engine."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To create a task:
$ {command} --queue=my-queue --url=/handler-path my-task
""",
}
@staticmethod
def Args(parser):
flags.AddCreateAppEngineTaskFlags(parser, is_alpha=True)
flags.AddLocationFlag(parser)
def Run(self, args):
api = GetApiAdapter(self.ReleaseTrack())
tasks_client = api.tasks
queue_ref = parsers.ParseQueue(args.queue, args.location)
task_ref = parsers.ParseTask(args.task,
queue_ref) if args.task else None
task_config = parsers.ParseCreateTaskArgs(
args, constants.APP_ENGINE_TASK, api.messages,
release_track=self.ReleaseTrack())
create_response = tasks_client.Create(
queue_ref, task_ref,
schedule_time=task_config.scheduleTime,
app_engine_http_request=task_config.appEngineHttpRequest)
log.CreatedResource(create_response.name, 'task')
return create_response

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 tasks create-app-engine-task` 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,
base.ReleaseTrack.GA)
class CreateHttp(base.CreateCommand):
"""Create and add a task that targets a HTTP endpoint."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To create a task:
$ {command} --queue=my-queue
--url=http://example.com/handler-path my-task
""",
}
@staticmethod
def Args(parser):
flags.AddCreateHttpTaskFlags(parser)
flags.AddLocationFlag(parser)
def Run(self, args):
if self.ReleaseTrack() == base.ReleaseTrack.ALPHA:
# This functionality doesn't exist in the alpha API so use beta.
api_release_track = base.ReleaseTrack.BETA
else:
api_release_track = self.ReleaseTrack()
api = GetApiAdapter(api_release_track)
tasks_client = api.tasks
queue_ref = parsers.ParseQueue(args.queue, args.location)
task_ref = parsers.ParseTask(args.task,
queue_ref) if args.task else None
task_config = parsers.ParseCreateTaskArgs(
args, constants.HTTP_TASK, api.messages,
release_track=api_release_track)
create_response = tasks_client.Create(
queue_ref, task_ref,
schedule_time=task_config.scheduleTime,
http_request=task_config.httpRequest)
log.CreatedResource(create_response.name, 'task')
return create_response

View File

@@ -0,0 +1,52 @@
# -*- 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 create-pull-task` 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 CreatePull(base.CreateCommand):
"""Create and add a task to a pull queue."""
@staticmethod
def Args(parser):
flags.AddCreatePullTaskFlags(parser)
flags.AddLocationFlag(parser)
def Run(self, args):
api = GetApiAdapter(self.ReleaseTrack())
tasks_client = api.tasks
queue_ref = parsers.ParseQueue(args.queue, args.location)
task_ref = parsers.ParseTask(args.task,
queue_ref) if args.task else None
task_config = parsers.ParseCreateTaskArgs(
args, constants.PULL_TASK, api.messages,
release_track=self.ReleaseTrack())
create_response = tasks_client.Create(
queue_ref, task_ref,
schedule_time=task_config.scheduleTime,
pull_message=task_config.pullMessage)
log.CreatedResource(create_response.name, 'task')
return create_response

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 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
class Delete(base.DeleteCommand):
"""Delete a task from a queue."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To delete a task:
$ {command} --queue=my-queue my-task
""",
}
@staticmethod
def Args(parser):
flags.AddTaskResourceArgs(parser, 'to delete')
flags.AddLocationFlag(parser)
def Run(self, args):
tasks_client = GetApiAdapter(self.ReleaseTrack()).tasks
queue_ref = parsers.ParseQueue(args.queue, args.location)
task_ref = parsers.ParseTask(args.task, queue_ref)
tasks_client.Delete(task_ref)
log.DeletedResource(task_ref.Name(), kind='task')

View File

@@ -0,0 +1,85 @@
# -*- 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 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
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Describe(base.DescribeCommand):
"""Show details about a task."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To describe a task:
$ {command} --queue=my-queue my-task
""",
}
TASK_RESPONSE_VIEW_MAPPER = flags.GetTaskResponseViewMapper(
base.ReleaseTrack.GA)
@staticmethod
def Args(parser):
return Describe._Args(parser, Describe.TASK_RESPONSE_VIEW_MAPPER)
@staticmethod
def _Args(parser, task_response_view_mapper):
flags.AddTaskResourceArgs(parser, 'to describe')
flags.AddLocationFlag(parser)
task_response_view_mapper.choice_arg.AddToParser(parser)
def Run(self, args):
tasks_client = GetApiAdapter(self.ReleaseTrack()).tasks
queue_ref = parsers.ParseQueue(args.queue, args.location)
task_ref = parsers.ParseTask(args.task, queue_ref)
return tasks_client.Get(
task_ref,
response_view=self.TASK_RESPONSE_VIEW_MAPPER.GetEnumForChoice(
args.response_view))
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class BetaDescribe(Describe):
"""Show details about a task."""
TASK_RESPONSE_VIEW_MAPPER = flags.GetTaskResponseViewMapper(
base.ReleaseTrack.BETA)
@staticmethod
def Args(parser):
return Describe._Args(parser, BetaDescribe.TASK_RESPONSE_VIEW_MAPPER)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class AlphaDescribe(Describe):
"""Show details about a task."""
TASK_RESPONSE_VIEW_MAPPER = flags.GetTaskResponseViewMapper(
base.ReleaseTrack.ALPHA)
@staticmethod
def Args(parser):
return Describe._Args(parser, AlphaDescribe.TASK_RESPONSE_VIEW_MAPPER)

View File

@@ -0,0 +1,61 @@
# -*- 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 lease` 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 list_formats
from googlecloudsdk.command_lib.tasks import parsers
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Lease(base.ListCommand):
"""Leases a list of tasks and displays them.
Each task returned from this command will have its schedule time changed
based on the lease duration specified. A task that has been returned by
calling this command will not be returned in a different call before its
schedule time. After the work associated with a task is finished, the lease
holder should call `gcloud tasks acknowledge` on the task.
"""
@staticmethod
def Args(parser):
base.PAGE_SIZE_FLAG.RemoveFromParser(parser)
base.LIMIT_FLAG.RemoveFromParser(parser) # have our own --limit flag
flags.AddQueueResourceFlag(parser, required=True, plural_tasks=True)
flags.AddLocationFlag(parser)
flags.AddTaskLeaseDurationFlag(parser, helptext="""\
The number of seconds for the desired new lease duration for all tasks
leased, starting from now. The maximum lease duration is 1 week.
""")
flags.AddFilterLeasedTasksFlag(parser)
flags.AddMaxTasksToLeaseFlag(parser)
list_formats.AddListTasksFormats(parser, is_alpha=True)
def Run(self, args):
tasks_client = GetApiAdapter(self.ReleaseTrack()).tasks
queue_ref = parsers.ParseQueue(args.queue, args.location)
duration = parsers.FormatLeaseDuration(args.lease_duration)
filter_string = parsers.ParseTasksLeaseFilterFlags(args)
return tasks_client.Lease(queue_ref, duration, filter_string=filter_string,
max_tasks=args.limit).tasks

View File

@@ -0,0 +1,77 @@
# -*- 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 list_formats
from googlecloudsdk.command_lib.tasks import parsers
_DEFAULT_PAGE_SIZE = 25
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.GA)
class List(base.ListCommand):
"""List tasks."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To list tasks in a queue:
$ {command} --queue=my-queue
""",
}
@staticmethod
def Args(parser):
list_formats.AddListTasksFormats(parser)
flags.AddQueueResourceFlag(parser, plural_tasks=True)
flags.AddLocationFlag(parser)
base.PAGE_SIZE_FLAG.SetDefault(parser, _DEFAULT_PAGE_SIZE)
def Run(self, args):
tasks_client = GetApiAdapter(self.ReleaseTrack()).tasks
queue_ref = parsers.ParseQueue(args.queue, args.location)
return tasks_client.List(queue_ref, args.limit, args.page_size)
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class AlphaList(List):
"""List tasks."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To list tasks in a queue:
$ {command} --queue=my-queue
""",
}
@staticmethod
def Args(parser):
list_formats.AddListTasksFormats(parser, is_alpha=True)
flags.AddQueueResourceFlag(parser, plural_tasks=True)
flags.AddLocationFlag(parser)
base.PAGE_SIZE_FLAG.SetDefault(parser, _DEFAULT_PAGE_SIZE)

View File

@@ -0,0 +1,28 @@
# -*- 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.
"""Command group for Cloud Tasks."""
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 Locations(base.Group):
"""Get information about Cloud Tasks locations."""

View File

@@ -0,0 +1,47 @@
# -*- 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 locations 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 parsers
class Describe(base.DescribeCommand):
"""Show details about a location."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To describe a location:
$ {command} my-location
""",
}
@staticmethod
def Args(parser):
base.Argument(
'location', help='The Cloud location to describe.').AddToParser(parser)
def Run(self, args):
locations_client = GetApiAdapter(self.ReleaseTrack()).locations
location_ref = parsers.ParseLocation(args.location)
return locations_client.Get(location_ref)

View File

@@ -0,0 +1,47 @@
# -*- 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 locations 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 list_formats
from googlecloudsdk.command_lib.tasks import parsers
class List(base.ListCommand):
"""Lists the locations where Cloud Tasks is available."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To list the locations where Cloud Tasks is available:
$ {command}
""",
}
@staticmethod
def Args(parser):
list_formats.AddListLocationsFormats(parser)
def Run(self, args):
locations_client = GetApiAdapter(self.ReleaseTrack()).locations
project_ref = parsers.ParseProject()
return locations_client.List(project_ref, args.limit, args.page_size)

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

View File

@@ -0,0 +1,43 @@
# -*- 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 renew-lease` 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
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class RenewLease(base.Command):
"""Renew the lease on a task in a pull queue."""
@staticmethod
def Args(parser):
flags.AddTaskResourceArgs(parser, 'to renew the lease of')
flags.AddLocationFlag(parser)
flags.AddTaskLeaseScheduleTimeFlag(parser, 'renewing')
flags.AddTaskLeaseDurationFlag(parser)
def Run(self, args):
tasks_client = GetApiAdapter(self.ReleaseTrack()).tasks
queue_ref = parsers.ParseQueue(args.queue, args.location)
task_ref = parsers.ParseTask(args.task, queue_ref)
duration = parsers.FormatLeaseDuration(args.lease_duration)
return tasks_client.RenewLease(task_ref, args.schedule_time, duration)

View File

@@ -0,0 +1,49 @@
# -*- 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 run` 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 Run(base.Command):
"""Force a task to run now."""
detailed_help = {
'DESCRIPTION': """\
{description}
""",
'EXAMPLES': """\
To run a task:
$ {command} --queue=my-queue my-task
""",
}
@staticmethod
def Args(parser):
flags.AddTaskResourceArgs(parser, 'to run')
flags.AddLocationFlag(parser)
def Run(self, args):
tasks_client = GetApiAdapter(self.ReleaseTrack()).tasks
queue_ref = parsers.ParseQueue(args.queue, args.location)
task_ref = parsers.ParseTask(args.task, queue_ref)
return tasks_client.Run(task_ref)