From e1fdc76f5369e53067a1748aecce9fa3940d9ee1 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Tue, 23 Feb 2021 18:33:41 -0800 Subject: [PATCH] chore: upgrade gapic-generator-python to 0.39.1 (#64) feat(v2beta3, v2beta2): introducing fields: ListQueuesRequest.read_mask, GetQueueRequest.read_mask, Queue.task_ttl, Queue.tombstone_ttl, Queue.stats and introducing messages: QueueStats feat: add from_service_account_info method to clients docs(v2beta3): updates to max burst size description docs(v2beta2): updates to AppEngineHttpRequest description test: add 3.9 unit tests docs: fix type references in docstrings --- .coveragerc | 22 +- .github/header-checker-lint.yml | 15 + .gitignore | 4 +- .kokoro/build.sh | 26 +- .kokoro/docs/docs-presubmit.cfg | 11 + .trampolinerc | 1 + CONTRIBUTING.rst | 22 +- LICENSE | 7 +- MANIFEST.in | 4 +- docs/_static/custom.css | 7 +- docs/tasks_v2/cloud_tasks.rst | 11 + docs/tasks_v2/services.rst | 6 +- docs/tasks_v2/types.rst | 1 + docs/tasks_v2beta2/cloud_tasks.rst | 11 + docs/tasks_v2beta2/services.rst | 6 +- docs/tasks_v2beta2/types.rst | 1 + docs/tasks_v2beta3/cloud_tasks.rst | 11 + docs/tasks_v2beta3/services.rst | 6 +- docs/tasks_v2beta3/types.rst | 1 + .../services/cloud_tasks/async_client.py | 331 ++++++------- .../tasks_v2/services/cloud_tasks/client.py | 411 ++++++++-------- .../tasks_v2/services/cloud_tasks/pagers.py | 43 +- .../services/cloud_tasks/transports/grpc.py | 23 +- .../cloud_tasks/transports/grpc_asyncio.py | 23 +- google/cloud/tasks_v2/types/cloudtasks.py | 20 +- google/cloud/tasks_v2/types/queue.py | 18 +- google/cloud/tasks_v2/types/target.py | 14 +- google/cloud/tasks_v2/types/task.py | 24 +- google/cloud/tasks_v2beta2/__init__.py | 2 + .../tasks_v2beta2/proto/cloudtasks.proto | 15 +- .../tasks_v2beta2/proto/old_target.proto | 25 + google/cloud/tasks_v2beta2/proto/queue.proto | 91 +++- google/cloud/tasks_v2beta2/proto/target.proto | 22 +- google/cloud/tasks_v2beta2/proto/task.proto | 3 +- .../services/cloud_tasks/async_client.py | 404 ++++++++-------- .../services/cloud_tasks/client.py | 452 ++++++++++-------- .../services/cloud_tasks/pagers.py | 43 +- .../services/cloud_tasks/transports/base.py | 40 +- .../services/cloud_tasks/transports/grpc.py | 23 +- .../cloud_tasks/transports/grpc_asyncio.py | 23 +- google/cloud/tasks_v2beta2/types/__init__.py | 2 + .../cloud/tasks_v2beta2/types/cloudtasks.py | 52 +- google/cloud/tasks_v2beta2/types/queue.py | 133 +++++- google/cloud/tasks_v2beta2/types/target.py | 18 +- google/cloud/tasks_v2beta2/types/task.py | 24 +- google/cloud/tasks_v2beta3/__init__.py | 4 + .../tasks_v2beta3/proto/cloudtasks.proto | 12 + google/cloud/tasks_v2beta3/proto/queue.proto | 81 +++- google/cloud/tasks_v2beta3/proto/target.proto | 24 + google/cloud/tasks_v2beta3/proto/task.proto | 9 + .../services/cloud_tasks/async_client.py | 363 +++++++------- .../services/cloud_tasks/client.py | 411 ++++++++-------- .../services/cloud_tasks/pagers.py | 43 +- .../services/cloud_tasks/transports/base.py | 32 +- .../services/cloud_tasks/transports/grpc.py | 23 +- .../cloud_tasks/transports/grpc_asyncio.py | 23 +- google/cloud/tasks_v2beta3/types/__init__.py | 4 + .../cloud/tasks_v2beta3/types/cloudtasks.py | 34 +- google/cloud/tasks_v2beta3/types/queue.py | 135 +++++- google/cloud/tasks_v2beta3/types/target.py | 50 +- google/cloud/tasks_v2beta3/types/task.py | 38 +- noxfile.py | 29 +- samples/snippets/noxfile.py | 2 +- scripts/fixup_tasks_v2beta2_keywords.py | 4 +- scripts/fixup_tasks_v2beta3_keywords.py | 4 +- synth.metadata | 159 +----- synth.py | 13 +- tasks-v2beta2-py.tar.gz | 0 tests/unit/gapic/tasks_v2/test_cloud_tasks.py | 209 ++++---- .../gapic/tasks_v2beta2/test_cloud_tasks.py | 209 ++++---- .../gapic/tasks_v2beta3/test_cloud_tasks.py | 209 ++++---- 71 files changed, 2661 insertions(+), 1915 deletions(-) create mode 100644 .github/header-checker-lint.yml create mode 100644 docs/tasks_v2/cloud_tasks.rst create mode 100644 docs/tasks_v2beta2/cloud_tasks.rst create mode 100644 docs/tasks_v2beta3/cloud_tasks.rst create mode 100644 google/cloud/tasks_v2beta2/proto/old_target.proto create mode 100644 tasks-v2beta2-py.tar.gz diff --git a/.coveragerc b/.coveragerc index 0284f6ba..eb43c0f5 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,27 +1,11 @@ -# -*- coding: utf-8 -*- -# -# Copyright 2020 Google LLC -# -# 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 -# -# https://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. - -# Generated by synthtool. DO NOT EDIT! [run] branch = True [report] fail_under = 100 show_missing = True -omit = google/cloud/tasks/__init__.py +omit = + google/cloud/tasks/__init__.py exclude_lines = # Re-enable the standard pragma pragma: NO COVER @@ -31,4 +15,4 @@ exclude_lines = # This is added at the module level as a safeguard for if someone # generates the code and tries to run it without pip installing. This # makes it virtually impossible to test properly. - except pkg_resources.DistributionNotFound \ No newline at end of file + except pkg_resources.DistributionNotFound diff --git a/.github/header-checker-lint.yml b/.github/header-checker-lint.yml new file mode 100644 index 00000000..fc281c05 --- /dev/null +++ b/.github/header-checker-lint.yml @@ -0,0 +1,15 @@ +{"allowedCopyrightHolders": ["Google LLC"], + "allowedLicenses": ["Apache-2.0", "MIT", "BSD-3"], + "ignoreFiles": ["**/requirements.txt", "**/requirements-test.txt"], + "sourceFileExtensions": [ + "ts", + "js", + "java", + "sh", + "Dockerfile", + "yaml", + "py", + "html", + "txt" + ] +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index b9daa52f..b4243ced 100644 --- a/.gitignore +++ b/.gitignore @@ -50,8 +50,10 @@ docs.metadata # Virtual environment env/ + +# Test logs coverage.xml -sponge_log.xml +*sponge_log.xml # System test environment variables. system_tests/local_test_setup diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 84a9a0ea..9183de36 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -15,7 +15,11 @@ set -eo pipefail -cd github/python-tasks +if [[ -z "${PROJECT_ROOT:-}" ]]; then + PROJECT_ROOT="github/python-tasks" +fi + +cd "${PROJECT_ROOT}" # Disable buffering, so that the logs stream through. export PYTHONUNBUFFERED=1 @@ -30,16 +34,26 @@ export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/service-account.json export PROJECT_ID=$(cat "${KOKORO_GFILE_DIR}/project-id.json") # Remove old nox -python3.6 -m pip uninstall --yes --quiet nox-automation +python3 -m pip uninstall --yes --quiet nox-automation # Install nox -python3.6 -m pip install --upgrade --quiet nox -python3.6 -m nox --version +python3 -m pip install --upgrade --quiet nox +python3 -m nox --version + +# If this is a continuous build, send the test log to the FlakyBot. +# See https://github.com/googleapis/repo-automation-bots/tree/master/packages/flakybot. +if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"continuous"* ]]; then + cleanup() { + chmod +x $KOKORO_GFILE_DIR/linux_amd64/flakybot + $KOKORO_GFILE_DIR/linux_amd64/flakybot + } + trap cleanup EXIT HUP +fi # If NOX_SESSION is set, it only runs the specified session, # otherwise run all the sessions. if [[ -n "${NOX_SESSION:-}" ]]; then - python3.6 -m nox -s "${NOX_SESSION:-}" + python3 -m nox -s ${NOX_SESSION:-} else - python3.6 -m nox + python3 -m nox fi diff --git a/.kokoro/docs/docs-presubmit.cfg b/.kokoro/docs/docs-presubmit.cfg index 11181078..84a8166b 100644 --- a/.kokoro/docs/docs-presubmit.cfg +++ b/.kokoro/docs/docs-presubmit.cfg @@ -15,3 +15,14 @@ env_vars: { key: "TRAMPOLINE_IMAGE_UPLOAD" value: "false" } + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/python-tasks/.kokoro/build.sh" +} + +# Only run this nox session. +env_vars: { + key: "NOX_SESSION" + value: "docs docfx" +} diff --git a/.trampolinerc b/.trampolinerc index 995ee291..383b6ec8 100644 --- a/.trampolinerc +++ b/.trampolinerc @@ -24,6 +24,7 @@ required_envvars+=( pass_down_envvars+=( "STAGING_BUCKET" "V2_STAGING_BUCKET" + "NOX_SESSION" ) # Prevent unintentional override on the default image. diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 8bbe3fb4..ad7cc2cb 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -70,9 +70,14 @@ We use `nox `__ to instrument our tests. - To test your changes, run unit tests with ``nox``:: $ nox -s unit-2.7 - $ nox -s unit-3.7 + $ nox -s unit-3.8 $ ... +- Args to pytest can be passed through the nox command separated by a `--`. For + example, to run a single test:: + + $ nox -s unit-3.8 -- -k + .. note:: The unit tests and system tests are described in the @@ -93,8 +98,12 @@ On Debian/Ubuntu:: ************ Coding Style ************ +- We use the automatic code formatter ``black``. You can run it using + the nox session ``blacken``. This will eliminate many lint errors. Run via:: + + $ nox -s blacken -- PEP8 compliance, with exceptions defined in the linter configuration. +- PEP8 compliance is required, with exceptions defined in the linter configuration. If you have ``nox`` installed, you can test that you have not introduced any non-compliant code via:: @@ -133,13 +142,18 @@ Running System Tests - To run system tests, you can execute:: - $ nox -s system-3.7 + # Run all system tests + $ nox -s system-3.8 $ nox -s system-2.7 + # Run a single system test + $ nox -s system-3.8 -- -k + + .. note:: System tests are only configured to run under Python 2.7 and - Python 3.7. For expediency, we do not run them in older versions + Python 3.8. For expediency, we do not run them in older versions of Python 3. This alone will not run the tests. You'll need to change some local diff --git a/LICENSE b/LICENSE index a8ee855d..d6456956 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ - Apache License + + Apache License Version 2.0, January 2004 - https://www.apache.org/licenses/ + http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION @@ -192,7 +193,7 @@ you may not use this file except in compliance with the License. You may obtain a copy of the License at - https://www.apache.org/licenses/LICENSE-2.0 + 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, diff --git a/MANIFEST.in b/MANIFEST.in index e9e29d12..e783f4c6 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -16,10 +16,10 @@ # Generated by synthtool. DO NOT EDIT! include README.rst LICENSE -recursive-include google *.json *.proto +recursive-include google *.json *.proto py.typed recursive-include tests * global-exclude *.py[co] global-exclude __pycache__ # Exclude scripts for samples readmegen -prune scripts/readme-gen \ No newline at end of file +prune scripts/readme-gen diff --git a/docs/_static/custom.css b/docs/_static/custom.css index 0abaf229..bcd37bbd 100644 --- a/docs/_static/custom.css +++ b/docs/_static/custom.css @@ -1,4 +1,9 @@ div#python2-eol { border-color: red; border-width: medium; -} \ No newline at end of file +} + +/* Ensure minimum width for 'Parameters' / 'Returns' column */ +dl.field-list > dt { + min-width: 100px +} diff --git a/docs/tasks_v2/cloud_tasks.rst b/docs/tasks_v2/cloud_tasks.rst new file mode 100644 index 00000000..be98d0be --- /dev/null +++ b/docs/tasks_v2/cloud_tasks.rst @@ -0,0 +1,11 @@ +CloudTasks +---------------------------- + +.. automodule:: google.cloud.tasks_v2.services.cloud_tasks + :members: + :inherited-members: + + +.. automodule:: google.cloud.tasks_v2.services.cloud_tasks.pagers + :members: + :inherited-members: diff --git a/docs/tasks_v2/services.rst b/docs/tasks_v2/services.rst index f1767aa7..f24b73b1 100644 --- a/docs/tasks_v2/services.rst +++ b/docs/tasks_v2/services.rst @@ -1,6 +1,6 @@ Services for Google Cloud Tasks v2 API ====================================== +.. toctree:: + :maxdepth: 2 -.. automodule:: google.cloud.tasks_v2.services.cloud_tasks - :members: - :inherited-members: + cloud_tasks diff --git a/docs/tasks_v2/types.rst b/docs/tasks_v2/types.rst index a43c04fd..7a2a9a4b 100644 --- a/docs/tasks_v2/types.rst +++ b/docs/tasks_v2/types.rst @@ -3,4 +3,5 @@ Types for Google Cloud Tasks v2 API .. automodule:: google.cloud.tasks_v2.types :members: + :undoc-members: :show-inheritance: diff --git a/docs/tasks_v2beta2/cloud_tasks.rst b/docs/tasks_v2beta2/cloud_tasks.rst new file mode 100644 index 00000000..1fd4fc11 --- /dev/null +++ b/docs/tasks_v2beta2/cloud_tasks.rst @@ -0,0 +1,11 @@ +CloudTasks +---------------------------- + +.. automodule:: google.cloud.tasks_v2beta2.services.cloud_tasks + :members: + :inherited-members: + + +.. automodule:: google.cloud.tasks_v2beta2.services.cloud_tasks.pagers + :members: + :inherited-members: diff --git a/docs/tasks_v2beta2/services.rst b/docs/tasks_v2beta2/services.rst index 21623446..4273c20e 100644 --- a/docs/tasks_v2beta2/services.rst +++ b/docs/tasks_v2beta2/services.rst @@ -1,6 +1,6 @@ Services for Google Cloud Tasks v2beta2 API =========================================== +.. toctree:: + :maxdepth: 2 -.. automodule:: google.cloud.tasks_v2beta2.services.cloud_tasks - :members: - :inherited-members: + cloud_tasks diff --git a/docs/tasks_v2beta2/types.rst b/docs/tasks_v2beta2/types.rst index 3a8eb123..4a688d27 100644 --- a/docs/tasks_v2beta2/types.rst +++ b/docs/tasks_v2beta2/types.rst @@ -3,4 +3,5 @@ Types for Google Cloud Tasks v2beta2 API .. automodule:: google.cloud.tasks_v2beta2.types :members: + :undoc-members: :show-inheritance: diff --git a/docs/tasks_v2beta3/cloud_tasks.rst b/docs/tasks_v2beta3/cloud_tasks.rst new file mode 100644 index 00000000..dfa0d867 --- /dev/null +++ b/docs/tasks_v2beta3/cloud_tasks.rst @@ -0,0 +1,11 @@ +CloudTasks +---------------------------- + +.. automodule:: google.cloud.tasks_v2beta3.services.cloud_tasks + :members: + :inherited-members: + + +.. automodule:: google.cloud.tasks_v2beta3.services.cloud_tasks.pagers + :members: + :inherited-members: diff --git a/docs/tasks_v2beta3/services.rst b/docs/tasks_v2beta3/services.rst index 9b56326f..bd97721b 100644 --- a/docs/tasks_v2beta3/services.rst +++ b/docs/tasks_v2beta3/services.rst @@ -1,6 +1,6 @@ Services for Google Cloud Tasks v2beta3 API =========================================== +.. toctree:: + :maxdepth: 2 -.. automodule:: google.cloud.tasks_v2beta3.services.cloud_tasks - :members: - :inherited-members: + cloud_tasks diff --git a/docs/tasks_v2beta3/types.rst b/docs/tasks_v2beta3/types.rst index 37d181e6..0f3455d1 100644 --- a/docs/tasks_v2beta3/types.rst +++ b/docs/tasks_v2beta3/types.rst @@ -3,4 +3,5 @@ Types for Google Cloud Tasks v2beta3 API .. automodule:: google.cloud.tasks_v2beta3.types :members: + :undoc-members: :show-inheritance: diff --git a/google/cloud/tasks_v2/services/cloud_tasks/async_client.py b/google/cloud/tasks_v2/services/cloud_tasks/async_client.py index d1673800..11bc924e 100644 --- a/google/cloud/tasks_v2/services/cloud_tasks/async_client.py +++ b/google/cloud/tasks_v2/services/cloud_tasks/async_client.py @@ -84,6 +84,7 @@ class CloudTasksAsyncClient: CloudTasksClient.parse_common_location_path ) + from_service_account_info = CloudTasksClient.from_service_account_info from_service_account_file = CloudTasksClient.from_service_account_file from_service_account_json = from_service_account_file @@ -161,12 +162,13 @@ async def list_queues( Queues are returned in lexicographical order. Args: - request (:class:`~.cloudtasks.ListQueuesRequest`): + request (:class:`google.cloud.tasks_v2.types.ListQueuesRequest`): The request object. Request message for [ListQueues][google.cloud.tasks.v2.CloudTasks.ListQueues]. parent (:class:`str`): Required. The location name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID`` + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -178,7 +180,7 @@ async def list_queues( sent along with the request as metadata. Returns: - ~.pagers.ListQueuesAsyncPager: + google.cloud.tasks_v2.services.cloud_tasks.pagers.ListQueuesAsyncPager: Response message for [ListQueues][google.cloud.tasks.v2.CloudTasks.ListQueues]. @@ -250,12 +252,13 @@ async def get_queue( r"""Gets a queue. Args: - request (:class:`~.cloudtasks.GetQueueRequest`): + request (:class:`google.cloud.tasks_v2.types.GetQueueRequest`): The request object. Request message for [GetQueue][google.cloud.tasks.v2.CloudTasks.GetQueue]. name (:class:`str`): Required. The resource name of the queue. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -267,7 +270,7 @@ async def get_queue( sent along with the request as metadata. Returns: - ~.queue.Queue: + google.cloud.tasks_v2.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -345,7 +348,7 @@ async def create_queue( before using this method. Args: - request (:class:`~.cloudtasks.CreateQueueRequest`): + request (:class:`google.cloud.tasks_v2.types.CreateQueueRequest`): The request object. Request message for [CreateQueue][google.cloud.tasks.v2.CloudTasks.CreateQueue]. parent (:class:`str`): @@ -356,14 +359,16 @@ async def create_queue( The list of allowed locations can be obtained by calling Cloud Tasks' implementation of [ListLocations][google.cloud.location.Locations.ListLocations]. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - queue (:class:`~.gct_queue.Queue`): + queue (:class:`google.cloud.tasks_v2.types.Queue`): Required. The queue to create. [Queue's name][google.cloud.tasks.v2.Queue.name] cannot be the same as an existing queue. + This corresponds to the ``queue`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -375,7 +380,7 @@ async def create_queue( sent along with the request as metadata. Returns: - ~.gct_queue.Queue: + google.cloud.tasks_v2.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -450,10 +455,10 @@ async def update_queue( before using this method. Args: - request (:class:`~.cloudtasks.UpdateQueueRequest`): + request (:class:`google.cloud.tasks_v2.types.UpdateQueueRequest`): The request object. Request message for [UpdateQueue][google.cloud.tasks.v2.CloudTasks.UpdateQueue]. - queue (:class:`~.gct_queue.Queue`): + queue (:class:`google.cloud.tasks_v2.types.Queue`): Required. The queue to create or update. The queue's [name][google.cloud.tasks.v2.Queue.name] @@ -464,14 +469,16 @@ async def update_queue( ignored. The queue's [name][google.cloud.tasks.v2.Queue.name] cannot be changed. + This corresponds to the ``queue`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): A mask used to specify which fields of the queue are being updated. If empty, then all fields will be updated. + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -483,7 +490,7 @@ async def update_queue( sent along with the request as metadata. Returns: - ~.gct_queue.Queue: + google.cloud.tasks_v2.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -557,12 +564,13 @@ async def delete_queue( before using this method. Args: - request (:class:`~.cloudtasks.DeleteQueueRequest`): + request (:class:`google.cloud.tasks_v2.types.DeleteQueueRequest`): The request object. Request message for [DeleteQueue][google.cloud.tasks.v2.CloudTasks.DeleteQueue]. name (:class:`str`): Required. The queue name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -635,12 +643,13 @@ async def purge_queue( effect. A purge is irreversible. Args: - request (:class:`~.cloudtasks.PurgeQueueRequest`): + request (:class:`google.cloud.tasks_v2.types.PurgeQueueRequest`): The request object. Request message for [PurgeQueue][google.cloud.tasks.v2.CloudTasks.PurgeQueue]. name (:class:`str`): Required. The queue name. For example: ``projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -652,7 +661,7 @@ async def purge_queue( sent along with the request as metadata. Returns: - ~.queue.Queue: + google.cloud.tasks_v2.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -718,12 +727,13 @@ async def pause_queue( [PAUSED][google.cloud.tasks.v2.Queue.State.PAUSED]. Args: - request (:class:`~.cloudtasks.PauseQueueRequest`): + request (:class:`google.cloud.tasks_v2.types.PauseQueueRequest`): The request object. Request message for [PauseQueue][google.cloud.tasks.v2.CloudTasks.PauseQueue]. name (:class:`str`): Required. The queue name. For example: ``projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -735,7 +745,7 @@ async def pause_queue( sent along with the request as metadata. Returns: - ~.queue.Queue: + google.cloud.tasks_v2.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -808,12 +818,13 @@ async def resume_queue( Risks `__. Args: - request (:class:`~.cloudtasks.ResumeQueueRequest`): + request (:class:`google.cloud.tasks_v2.types.ResumeQueueRequest`): The request object. Request message for [ResumeQueue][google.cloud.tasks.v2.CloudTasks.ResumeQueue]. name (:class:`str`): Required. The queue name. For example: ``projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -825,7 +836,7 @@ async def resume_queue( sent along with the request as metadata. Returns: - ~.queue.Queue: + google.cloud.tasks_v2.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -892,7 +903,7 @@ async def get_iam_policy( - ``cloudtasks.queues.getIamPolicy`` Args: - request (:class:`~.iam_policy.GetIamPolicyRequest`): + request (:class:`google.iam.v1.iam_policy_pb2.GetIamPolicyRequest`): The request object. Request message for `GetIamPolicy` method. resource (:class:`str`): @@ -900,6 +911,7 @@ async def get_iam_policy( policy is being requested. See the operation documentation for the appropriate value for this field. + This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -911,72 +923,62 @@ async def get_iam_policy( sent along with the request as metadata. Returns: - ~.policy.Policy: - Defines an Identity and Access Management (IAM) policy. - It is used to specify access control policies for Cloud - Platform resources. - - A ``Policy`` is a collection of ``bindings``. A - ``binding`` binds one or more ``members`` to a single - ``role``. Members can be user accounts, service - accounts, Google groups, and domains (such as G Suite). - A ``role`` is a named list of permissions (defined by - IAM or configured by users). A ``binding`` can - optionally specify a ``condition``, which is a logic - expression that further constrains the role binding - based on attributes about the request and/or target - resource. - - **JSON Example** - - :: - - { - "bindings": [ - { - "role": "roles/resourcemanager.organizationAdmin", - "members": [ - "user:mike@example.com", - "group:admins@example.com", - "domain:google.com", - "serviceAccount:my-project-id@appspot.gserviceaccount.com" - ] - }, - { - "role": "roles/resourcemanager.organizationViewer", - "members": ["user:eve@example.com"], - "condition": { - "title": "expirable access", - "description": "Does not grant access after Sep 2020", - "expression": "request.time < - timestamp('2020-10-01T00:00:00.000Z')", - } - } - ] - } - - **YAML Example** - - :: - - bindings: - - members: - - user:mike@example.com - - group:admins@example.com - - domain:google.com - - serviceAccount:my-project-id@appspot.gserviceaccount.com - role: roles/resourcemanager.organizationAdmin - - members: - - user:eve@example.com - role: roles/resourcemanager.organizationViewer - condition: - title: expirable access - description: Does not grant access after Sep 2020 - expression: request.time < timestamp('2020-10-01T00:00:00.000Z') - - For a description of IAM and its features, see the `IAM - developer's - guide `__. + google.iam.v1.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. It is used to + specify access control policies for Cloud Platform + resources. + + A Policy is a collection of bindings. A binding binds + one or more members to a single role. Members can be + user accounts, service accounts, Google groups, and + domains (such as G Suite). A role is a named list of + permissions (defined by IAM or configured by users). + A binding can optionally specify a condition, which + is a logic expression that further constrains the + role binding based on attributes about the request + and/or target resource. + + **JSON Example** + + { + "bindings": [ + { + "role": + "roles/resourcemanager.organizationAdmin", + "members": [ "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + + }, { "role": + "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { "title": "expirable access", + "description": "Does not grant access after + Sep 2020", "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", } } + + ] + + } + + **YAML Example** + + bindings: - members: - user:\ mike@example.com - + group:\ admins@example.com - domain:google.com - + serviceAccount:\ my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin - + members: - user:\ eve@example.com role: + roles/resourcemanager.organizationViewer + condition: title: expirable access description: + Does not grant access after Sep 2020 expression: + request.time < + timestamp('2020-10-01T00:00:00.000Z') + + For a description of IAM and its features, see the + [IAM developer's + guide](\ https://cloud.google.com/iam/docs). """ # Create or coerce a protobuf request object. @@ -1049,7 +1051,7 @@ async def set_iam_policy( - ``cloudtasks.queues.setIamPolicy`` Args: - request (:class:`~.iam_policy.SetIamPolicyRequest`): + request (:class:`google.iam.v1.iam_policy_pb2.SetIamPolicyRequest`): The request object. Request message for `SetIamPolicy` method. resource (:class:`str`): @@ -1057,6 +1059,7 @@ async def set_iam_policy( policy is being specified. See the operation documentation for the appropriate value for this field. + This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1068,72 +1071,62 @@ async def set_iam_policy( sent along with the request as metadata. Returns: - ~.policy.Policy: - Defines an Identity and Access Management (IAM) policy. - It is used to specify access control policies for Cloud - Platform resources. - - A ``Policy`` is a collection of ``bindings``. A - ``binding`` binds one or more ``members`` to a single - ``role``. Members can be user accounts, service - accounts, Google groups, and domains (such as G Suite). - A ``role`` is a named list of permissions (defined by - IAM or configured by users). A ``binding`` can - optionally specify a ``condition``, which is a logic - expression that further constrains the role binding - based on attributes about the request and/or target - resource. - - **JSON Example** - - :: - - { - "bindings": [ - { - "role": "roles/resourcemanager.organizationAdmin", - "members": [ - "user:mike@example.com", - "group:admins@example.com", - "domain:google.com", - "serviceAccount:my-project-id@appspot.gserviceaccount.com" - ] - }, - { - "role": "roles/resourcemanager.organizationViewer", - "members": ["user:eve@example.com"], - "condition": { - "title": "expirable access", - "description": "Does not grant access after Sep 2020", - "expression": "request.time < - timestamp('2020-10-01T00:00:00.000Z')", - } - } - ] - } - - **YAML Example** - - :: - - bindings: - - members: - - user:mike@example.com - - group:admins@example.com - - domain:google.com - - serviceAccount:my-project-id@appspot.gserviceaccount.com - role: roles/resourcemanager.organizationAdmin - - members: - - user:eve@example.com - role: roles/resourcemanager.organizationViewer - condition: - title: expirable access - description: Does not grant access after Sep 2020 - expression: request.time < timestamp('2020-10-01T00:00:00.000Z') - - For a description of IAM and its features, see the `IAM - developer's - guide `__. + google.iam.v1.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. It is used to + specify access control policies for Cloud Platform + resources. + + A Policy is a collection of bindings. A binding binds + one or more members to a single role. Members can be + user accounts, service accounts, Google groups, and + domains (such as G Suite). A role is a named list of + permissions (defined by IAM or configured by users). + A binding can optionally specify a condition, which + is a logic expression that further constrains the + role binding based on attributes about the request + and/or target resource. + + **JSON Example** + + { + "bindings": [ + { + "role": + "roles/resourcemanager.organizationAdmin", + "members": [ "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + + }, { "role": + "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { "title": "expirable access", + "description": "Does not grant access after + Sep 2020", "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", } } + + ] + + } + + **YAML Example** + + bindings: - members: - user:\ mike@example.com - + group:\ admins@example.com - domain:google.com - + serviceAccount:\ my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin - + members: - user:\ eve@example.com role: + roles/resourcemanager.organizationViewer + condition: title: expirable access description: + Does not grant access after Sep 2020 expression: + request.time < + timestamp('2020-10-01T00:00:00.000Z') + + For a description of IAM and its features, see the + [IAM developer's + guide](\ https://cloud.google.com/iam/docs). """ # Create or coerce a protobuf request object. @@ -1195,7 +1188,7 @@ async def test_iam_permissions( warning. Args: - request (:class:`~.iam_policy.TestIamPermissionsRequest`): + request (:class:`google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest`): The request object. Request message for `TestIamPermissions` method. resource (:class:`str`): @@ -1203,6 +1196,7 @@ async def test_iam_permissions( policy detail is being requested. See the operation documentation for the appropriate value for this field. + This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1211,6 +1205,7 @@ async def test_iam_permissions( Permissions with wildcards (such as '*' or 'storage.*') are not allowed. For more information see `IAM Overview `__. + This corresponds to the ``permissions`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1222,8 +1217,8 @@ async def test_iam_permissions( sent along with the request as metadata. Returns: - ~.iam_policy.TestIamPermissionsResponse: - Response message for ``TestIamPermissions`` method. + google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: + Response message for TestIamPermissions method. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have @@ -1294,13 +1289,14 @@ async def list_tasks( at any time. Args: - request (:class:`~.cloudtasks.ListTasksRequest`): + request (:class:`google.cloud.tasks_v2.types.ListTasksRequest`): The request object. Request message for listing tasks using [ListTasks][google.cloud.tasks.v2.CloudTasks.ListTasks]. parent (:class:`str`): Required. The queue name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1312,7 +1308,7 @@ async def list_tasks( sent along with the request as metadata. Returns: - ~.pagers.ListTasksAsyncPager: + google.cloud.tasks_v2.services.cloud_tasks.pagers.ListTasksAsyncPager: Response message for listing tasks using [ListTasks][google.cloud.tasks.v2.CloudTasks.ListTasks]. @@ -1384,13 +1380,14 @@ async def get_task( r"""Gets a task. Args: - request (:class:`~.cloudtasks.GetTaskRequest`): + request (:class:`google.cloud.tasks_v2.types.GetTaskRequest`): The request object. Request message for getting a task using [GetTask][google.cloud.tasks.v2.CloudTasks.GetTask]. name (:class:`str`): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1402,7 +1399,7 @@ async def get_task( sent along with the request as metadata. Returns: - ~.task.Task: + google.cloud.tasks_v2.types.Task: A unit of scheduled work. """ # Create or coerce a protobuf request object. @@ -1469,7 +1466,7 @@ async def create_task( - The maximum task size is 100KB. Args: - request (:class:`~.cloudtasks.CreateTaskRequest`): + request (:class:`google.cloud.tasks_v2.types.CreateTaskRequest`): The request object. Request message for [CreateTask][google.cloud.tasks.v2.CloudTasks.CreateTask]. parent (:class:`str`): @@ -1477,10 +1474,11 @@ async def create_task( ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` The queue must already exist. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - task (:class:`~.gct_task.Task`): + task (:class:`google.cloud.tasks_v2.types.Task`): Required. The task to add. Task names have the following format: @@ -1522,6 +1520,7 @@ async def create_task( task commands. The infrastructure relies on an approximately uniform distribution of task ids to store and serve tasks efficiently. + This corresponds to the ``task`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1533,7 +1532,7 @@ async def create_task( sent along with the request as metadata. Returns: - ~.gct_task.Task: + google.cloud.tasks_v2.types.Task: A unit of scheduled work. """ # Create or coerce a protobuf request object. @@ -1591,13 +1590,14 @@ async def delete_task( or permanently failed. Args: - request (:class:`~.cloudtasks.DeleteTaskRequest`): + request (:class:`google.cloud.tasks_v2.types.DeleteTaskRequest`): The request object. Request message for deleting a task using [DeleteTask][google.cloud.tasks.v2.CloudTasks.DeleteTask]. name (:class:`str`): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1691,13 +1691,14 @@ async def run_task( task that has already succeeded or permanently failed. Args: - request (:class:`~.cloudtasks.RunTaskRequest`): + request (:class:`google.cloud.tasks_v2.types.RunTaskRequest`): The request object. Request message for forcing a task to run now using [RunTask][google.cloud.tasks.v2.CloudTasks.RunTask]. name (:class:`str`): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1709,7 +1710,7 @@ async def run_task( sent along with the request as metadata. Returns: - ~.task.Task: + google.cloud.tasks_v2.types.Task: A unit of scheduled work. """ # Create or coerce a protobuf request object. diff --git a/google/cloud/tasks_v2/services/cloud_tasks/client.py b/google/cloud/tasks_v2/services/cloud_tasks/client.py index ecd5a566..7015960a 100644 --- a/google/cloud/tasks_v2/services/cloud_tasks/client.py +++ b/google/cloud/tasks_v2/services/cloud_tasks/client.py @@ -120,6 +120,22 @@ def _get_default_mtls_endpoint(api_endpoint): DEFAULT_ENDPOINT ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + CloudTasksClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials @@ -132,7 +148,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): kwargs: Additional arguments to pass to the constructor. Returns: - {@api.name}: The constructed client. + CloudTasksClient: The constructed client. """ credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials @@ -256,10 +272,10 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.CloudTasksTransport]): The + transport (Union[str, CloudTasksTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (client_options_lib.ClientOptions): Custom options for the + client_options (google.api_core.client_options.ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -295,21 +311,17 @@ def __init__( util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) ) - ssl_credentials = None + client_cert_source_func = None is_mtls = False if use_client_cert: if client_options.client_cert_source: - import grpc # type: ignore - - cert, key = client_options.client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) is_mtls = True + client_cert_source_func = client_options.client_cert_source else: - creds = SslCredentials() - is_mtls = creds.is_mtls - ssl_credentials = creds.ssl_credentials if is_mtls else None + is_mtls = mtls.has_default_client_cert_source() + client_cert_source_func = ( + mtls.default_client_cert_source() if is_mtls else None + ) # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -352,7 +364,7 @@ def __init__( credentials_file=client_options.credentials_file, host=api_endpoint, scopes=client_options.scopes, - ssl_channel_credentials=ssl_credentials, + client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, ) @@ -370,12 +382,13 @@ def list_queues( Queues are returned in lexicographical order. Args: - request (:class:`~.cloudtasks.ListQueuesRequest`): + request (google.cloud.tasks_v2.types.ListQueuesRequest): The request object. Request message for [ListQueues][google.cloud.tasks.v2.CloudTasks.ListQueues]. - parent (:class:`str`): + parent (str): Required. The location name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID`` + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -387,7 +400,7 @@ def list_queues( sent along with the request as metadata. Returns: - ~.pagers.ListQueuesPager: + google.cloud.tasks_v2.services.cloud_tasks.pagers.ListQueuesPager: Response message for [ListQueues][google.cloud.tasks.v2.CloudTasks.ListQueues]. @@ -452,12 +465,13 @@ def get_queue( r"""Gets a queue. Args: - request (:class:`~.cloudtasks.GetQueueRequest`): + request (google.cloud.tasks_v2.types.GetQueueRequest): The request object. Request message for [GetQueue][google.cloud.tasks.v2.CloudTasks.GetQueue]. - name (:class:`str`): + name (str): Required. The resource name of the queue. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -469,7 +483,7 @@ def get_queue( sent along with the request as metadata. Returns: - ~.queue.Queue: + google.cloud.tasks_v2.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -540,10 +554,10 @@ def create_queue( before using this method. Args: - request (:class:`~.cloudtasks.CreateQueueRequest`): + request (google.cloud.tasks_v2.types.CreateQueueRequest): The request object. Request message for [CreateQueue][google.cloud.tasks.v2.CloudTasks.CreateQueue]. - parent (:class:`str`): + parent (str): Required. The location name in which the queue will be created. For example: ``projects/PROJECT_ID/locations/LOCATION_ID`` @@ -551,14 +565,16 @@ def create_queue( The list of allowed locations can be obtained by calling Cloud Tasks' implementation of [ListLocations][google.cloud.location.Locations.ListLocations]. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - queue (:class:`~.gct_queue.Queue`): + queue (google.cloud.tasks_v2.types.Queue): Required. The queue to create. [Queue's name][google.cloud.tasks.v2.Queue.name] cannot be the same as an existing queue. + This corresponds to the ``queue`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -570,7 +586,7 @@ def create_queue( sent along with the request as metadata. Returns: - ~.gct_queue.Queue: + google.cloud.tasks_v2.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -646,10 +662,10 @@ def update_queue( before using this method. Args: - request (:class:`~.cloudtasks.UpdateQueueRequest`): + request (google.cloud.tasks_v2.types.UpdateQueueRequest): The request object. Request message for [UpdateQueue][google.cloud.tasks.v2.CloudTasks.UpdateQueue]. - queue (:class:`~.gct_queue.Queue`): + queue (google.cloud.tasks_v2.types.Queue): Required. The queue to create or update. The queue's [name][google.cloud.tasks.v2.Queue.name] @@ -660,14 +676,16 @@ def update_queue( ignored. The queue's [name][google.cloud.tasks.v2.Queue.name] cannot be changed. + This corresponds to the ``queue`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (google.protobuf.field_mask_pb2.FieldMask): A mask used to specify which fields of the queue are being updated. If empty, then all fields will be updated. + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -679,7 +697,7 @@ def update_queue( sent along with the request as metadata. Returns: - ~.gct_queue.Queue: + google.cloud.tasks_v2.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -754,12 +772,13 @@ def delete_queue( before using this method. Args: - request (:class:`~.cloudtasks.DeleteQueueRequest`): + request (google.cloud.tasks_v2.types.DeleteQueueRequest): The request object. Request message for [DeleteQueue][google.cloud.tasks.v2.CloudTasks.DeleteQueue]. - name (:class:`str`): + name (str): Required. The queue name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -825,12 +844,13 @@ def purge_queue( effect. A purge is irreversible. Args: - request (:class:`~.cloudtasks.PurgeQueueRequest`): + request (google.cloud.tasks_v2.types.PurgeQueueRequest): The request object. Request message for [PurgeQueue][google.cloud.tasks.v2.CloudTasks.PurgeQueue]. - name (:class:`str`): + name (str): Required. The queue name. For example: ``projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -842,7 +862,7 @@ def purge_queue( sent along with the request as metadata. Returns: - ~.queue.Queue: + google.cloud.tasks_v2.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -909,12 +929,13 @@ def pause_queue( [PAUSED][google.cloud.tasks.v2.Queue.State.PAUSED]. Args: - request (:class:`~.cloudtasks.PauseQueueRequest`): + request (google.cloud.tasks_v2.types.PauseQueueRequest): The request object. Request message for [PauseQueue][google.cloud.tasks.v2.CloudTasks.PauseQueue]. - name (:class:`str`): + name (str): Required. The queue name. For example: ``projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -926,7 +947,7 @@ def pause_queue( sent along with the request as metadata. Returns: - ~.queue.Queue: + google.cloud.tasks_v2.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -1000,12 +1021,13 @@ def resume_queue( Risks `__. Args: - request (:class:`~.cloudtasks.ResumeQueueRequest`): + request (google.cloud.tasks_v2.types.ResumeQueueRequest): The request object. Request message for [ResumeQueue][google.cloud.tasks.v2.CloudTasks.ResumeQueue]. - name (:class:`str`): + name (str): Required. The queue name. For example: ``projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1017,7 +1039,7 @@ def resume_queue( sent along with the request as metadata. Returns: - ~.queue.Queue: + google.cloud.tasks_v2.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -1085,14 +1107,15 @@ def get_iam_policy( - ``cloudtasks.queues.getIamPolicy`` Args: - request (:class:`~.iam_policy.GetIamPolicyRequest`): + request (google.iam.v1.iam_policy_pb2.GetIamPolicyRequest): The request object. Request message for `GetIamPolicy` method. - resource (:class:`str`): + resource (str): REQUIRED: The resource for which the policy is being requested. See the operation documentation for the appropriate value for this field. + This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1104,72 +1127,62 @@ def get_iam_policy( sent along with the request as metadata. Returns: - ~.policy.Policy: - Defines an Identity and Access Management (IAM) policy. - It is used to specify access control policies for Cloud - Platform resources. - - A ``Policy`` is a collection of ``bindings``. A - ``binding`` binds one or more ``members`` to a single - ``role``. Members can be user accounts, service - accounts, Google groups, and domains (such as G Suite). - A ``role`` is a named list of permissions (defined by - IAM or configured by users). A ``binding`` can - optionally specify a ``condition``, which is a logic - expression that further constrains the role binding - based on attributes about the request and/or target - resource. - - **JSON Example** - - :: - - { - "bindings": [ - { - "role": "roles/resourcemanager.organizationAdmin", - "members": [ - "user:mike@example.com", - "group:admins@example.com", - "domain:google.com", - "serviceAccount:my-project-id@appspot.gserviceaccount.com" - ] - }, - { - "role": "roles/resourcemanager.organizationViewer", - "members": ["user:eve@example.com"], - "condition": { - "title": "expirable access", - "description": "Does not grant access after Sep 2020", - "expression": "request.time < - timestamp('2020-10-01T00:00:00.000Z')", - } - } - ] - } - - **YAML Example** - - :: - - bindings: - - members: - - user:mike@example.com - - group:admins@example.com - - domain:google.com - - serviceAccount:my-project-id@appspot.gserviceaccount.com - role: roles/resourcemanager.organizationAdmin - - members: - - user:eve@example.com - role: roles/resourcemanager.organizationViewer - condition: - title: expirable access - description: Does not grant access after Sep 2020 - expression: request.time < timestamp('2020-10-01T00:00:00.000Z') - - For a description of IAM and its features, see the `IAM - developer's - guide `__. + google.iam.v1.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. It is used to + specify access control policies for Cloud Platform + resources. + + A Policy is a collection of bindings. A binding binds + one or more members to a single role. Members can be + user accounts, service accounts, Google groups, and + domains (such as G Suite). A role is a named list of + permissions (defined by IAM or configured by users). + A binding can optionally specify a condition, which + is a logic expression that further constrains the + role binding based on attributes about the request + and/or target resource. + + **JSON Example** + + { + "bindings": [ + { + "role": + "roles/resourcemanager.organizationAdmin", + "members": [ "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + + }, { "role": + "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { "title": "expirable access", + "description": "Does not grant access after + Sep 2020", "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", } } + + ] + + } + + **YAML Example** + + bindings: - members: - user:\ mike@example.com - + group:\ admins@example.com - domain:google.com - + serviceAccount:\ my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin - + members: - user:\ eve@example.com role: + roles/resourcemanager.organizationViewer + condition: title: expirable access description: + Does not grant access after Sep 2020 expression: + request.time < + timestamp('2020-10-01T00:00:00.000Z') + + For a description of IAM and its features, see the + [IAM developer's + guide](\ https://cloud.google.com/iam/docs). """ # Create or coerce a protobuf request object. @@ -1190,6 +1203,9 @@ def get_iam_policy( elif not request: request = iam_policy.GetIamPolicyRequest(resource=resource,) + if resource is not None: + request.resource = resource + # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_iam_policy] @@ -1230,14 +1246,15 @@ def set_iam_policy( - ``cloudtasks.queues.setIamPolicy`` Args: - request (:class:`~.iam_policy.SetIamPolicyRequest`): + request (google.iam.v1.iam_policy_pb2.SetIamPolicyRequest): The request object. Request message for `SetIamPolicy` method. - resource (:class:`str`): + resource (str): REQUIRED: The resource for which the policy is being specified. See the operation documentation for the appropriate value for this field. + This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1249,72 +1266,62 @@ def set_iam_policy( sent along with the request as metadata. Returns: - ~.policy.Policy: - Defines an Identity and Access Management (IAM) policy. - It is used to specify access control policies for Cloud - Platform resources. - - A ``Policy`` is a collection of ``bindings``. A - ``binding`` binds one or more ``members`` to a single - ``role``. Members can be user accounts, service - accounts, Google groups, and domains (such as G Suite). - A ``role`` is a named list of permissions (defined by - IAM or configured by users). A ``binding`` can - optionally specify a ``condition``, which is a logic - expression that further constrains the role binding - based on attributes about the request and/or target - resource. - - **JSON Example** - - :: - - { - "bindings": [ - { - "role": "roles/resourcemanager.organizationAdmin", - "members": [ - "user:mike@example.com", - "group:admins@example.com", - "domain:google.com", - "serviceAccount:my-project-id@appspot.gserviceaccount.com" - ] - }, - { - "role": "roles/resourcemanager.organizationViewer", - "members": ["user:eve@example.com"], - "condition": { - "title": "expirable access", - "description": "Does not grant access after Sep 2020", - "expression": "request.time < - timestamp('2020-10-01T00:00:00.000Z')", - } - } - ] - } - - **YAML Example** - - :: - - bindings: - - members: - - user:mike@example.com - - group:admins@example.com - - domain:google.com - - serviceAccount:my-project-id@appspot.gserviceaccount.com - role: roles/resourcemanager.organizationAdmin - - members: - - user:eve@example.com - role: roles/resourcemanager.organizationViewer - condition: - title: expirable access - description: Does not grant access after Sep 2020 - expression: request.time < timestamp('2020-10-01T00:00:00.000Z') - - For a description of IAM and its features, see the `IAM - developer's - guide `__. + google.iam.v1.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. It is used to + specify access control policies for Cloud Platform + resources. + + A Policy is a collection of bindings. A binding binds + one or more members to a single role. Members can be + user accounts, service accounts, Google groups, and + domains (such as G Suite). A role is a named list of + permissions (defined by IAM or configured by users). + A binding can optionally specify a condition, which + is a logic expression that further constrains the + role binding based on attributes about the request + and/or target resource. + + **JSON Example** + + { + "bindings": [ + { + "role": + "roles/resourcemanager.organizationAdmin", + "members": [ "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + + }, { "role": + "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { "title": "expirable access", + "description": "Does not grant access after + Sep 2020", "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", } } + + ] + + } + + **YAML Example** + + bindings: - members: - user:\ mike@example.com - + group:\ admins@example.com - domain:google.com - + serviceAccount:\ my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin - + members: - user:\ eve@example.com role: + roles/resourcemanager.organizationViewer + condition: title: expirable access description: + Does not grant access after Sep 2020 expression: + request.time < + timestamp('2020-10-01T00:00:00.000Z') + + For a description of IAM and its features, see the + [IAM developer's + guide](\ https://cloud.google.com/iam/docs). """ # Create or coerce a protobuf request object. @@ -1335,6 +1342,9 @@ def set_iam_policy( elif not request: request = iam_policy.SetIamPolicyRequest(resource=resource,) + if resource is not None: + request.resource = resource + # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.set_iam_policy] @@ -1372,22 +1382,24 @@ def test_iam_permissions( warning. Args: - request (:class:`~.iam_policy.TestIamPermissionsRequest`): + request (google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest): The request object. Request message for `TestIamPermissions` method. - resource (:class:`str`): + resource (str): REQUIRED: The resource for which the policy detail is being requested. See the operation documentation for the appropriate value for this field. + This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - permissions (:class:`Sequence[str]`): + permissions (Sequence[str]): The set of permissions to check for the ``resource``. Permissions with wildcards (such as '*' or 'storage.*') are not allowed. For more information see `IAM Overview `__. + This corresponds to the ``permissions`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1399,8 +1411,8 @@ def test_iam_permissions( sent along with the request as metadata. Returns: - ~.iam_policy.TestIamPermissionsResponse: - Response message for ``TestIamPermissions`` method. + google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: + Response message for TestIamPermissions method. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have @@ -1422,6 +1434,9 @@ def test_iam_permissions( resource=resource, permissions=permissions, ) + if resource is not None: + request.resource = resource + # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.test_iam_permissions] @@ -1459,13 +1474,14 @@ def list_tasks( at any time. Args: - request (:class:`~.cloudtasks.ListTasksRequest`): + request (google.cloud.tasks_v2.types.ListTasksRequest): The request object. Request message for listing tasks using [ListTasks][google.cloud.tasks.v2.CloudTasks.ListTasks]. - parent (:class:`str`): + parent (str): Required. The queue name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1477,7 +1493,7 @@ def list_tasks( sent along with the request as metadata. Returns: - ~.pagers.ListTasksPager: + google.cloud.tasks_v2.services.cloud_tasks.pagers.ListTasksPager: Response message for listing tasks using [ListTasks][google.cloud.tasks.v2.CloudTasks.ListTasks]. @@ -1542,13 +1558,14 @@ def get_task( r"""Gets a task. Args: - request (:class:`~.cloudtasks.GetTaskRequest`): + request (google.cloud.tasks_v2.types.GetTaskRequest): The request object. Request message for getting a task using [GetTask][google.cloud.tasks.v2.CloudTasks.GetTask]. - name (:class:`str`): + name (str): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1560,7 +1577,7 @@ def get_task( sent along with the request as metadata. Returns: - ~.task.Task: + google.cloud.tasks_v2.types.Task: A unit of scheduled work. """ # Create or coerce a protobuf request object. @@ -1620,18 +1637,19 @@ def create_task( - The maximum task size is 100KB. Args: - request (:class:`~.cloudtasks.CreateTaskRequest`): + request (google.cloud.tasks_v2.types.CreateTaskRequest): The request object. Request message for [CreateTask][google.cloud.tasks.v2.CloudTasks.CreateTask]. - parent (:class:`str`): + parent (str): Required. The queue name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` The queue must already exist. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - task (:class:`~.gct_task.Task`): + task (google.cloud.tasks_v2.types.Task): Required. The task to add. Task names have the following format: @@ -1673,6 +1691,7 @@ def create_task( task commands. The infrastructure relies on an approximately uniform distribution of task ids to store and serve tasks efficiently. + This corresponds to the ``task`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1684,7 +1703,7 @@ def create_task( sent along with the request as metadata. Returns: - ~.gct_task.Task: + google.cloud.tasks_v2.types.Task: A unit of scheduled work. """ # Create or coerce a protobuf request object. @@ -1743,13 +1762,14 @@ def delete_task( or permanently failed. Args: - request (:class:`~.cloudtasks.DeleteTaskRequest`): + request (google.cloud.tasks_v2.types.DeleteTaskRequest): The request object. Request message for deleting a task using [DeleteTask][google.cloud.tasks.v2.CloudTasks.DeleteTask]. - name (:class:`str`): + name (str): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1836,13 +1856,14 @@ def run_task( task that has already succeeded or permanently failed. Args: - request (:class:`~.cloudtasks.RunTaskRequest`): + request (google.cloud.tasks_v2.types.RunTaskRequest): The request object. Request message for forcing a task to run now using [RunTask][google.cloud.tasks.v2.CloudTasks.RunTask]. - name (:class:`str`): + name (str): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1854,7 +1875,7 @@ def run_task( sent along with the request as metadata. Returns: - ~.task.Task: + google.cloud.tasks_v2.types.Task: A unit of scheduled work. """ # Create or coerce a protobuf request object. diff --git a/google/cloud/tasks_v2/services/cloud_tasks/pagers.py b/google/cloud/tasks_v2/services/cloud_tasks/pagers.py index 466a8d25..8d77668d 100644 --- a/google/cloud/tasks_v2/services/cloud_tasks/pagers.py +++ b/google/cloud/tasks_v2/services/cloud_tasks/pagers.py @@ -15,7 +15,16 @@ # limitations under the License. # -from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple +from typing import ( + Any, + AsyncIterable, + Awaitable, + Callable, + Iterable, + Sequence, + Tuple, + Optional, +) from google.cloud.tasks_v2.types import cloudtasks from google.cloud.tasks_v2.types import queue @@ -26,7 +35,7 @@ class ListQueuesPager: """A pager for iterating through ``list_queues`` requests. This class thinly wraps an initial - :class:`~.cloudtasks.ListQueuesResponse` object, and + :class:`google.cloud.tasks_v2.types.ListQueuesResponse` object, and provides an ``__iter__`` method to iterate through its ``queues`` field. @@ -35,7 +44,7 @@ class ListQueuesPager: through the ``queues`` field on the corresponding responses. - All the usual :class:`~.cloudtasks.ListQueuesResponse` + All the usual :class:`google.cloud.tasks_v2.types.ListQueuesResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -53,9 +62,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.cloudtasks.ListQueuesRequest`): + request (google.cloud.tasks_v2.types.ListQueuesRequest): The initial request object. - response (:class:`~.cloudtasks.ListQueuesResponse`): + response (google.cloud.tasks_v2.types.ListQueuesResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -88,7 +97,7 @@ class ListQueuesAsyncPager: """A pager for iterating through ``list_queues`` requests. This class thinly wraps an initial - :class:`~.cloudtasks.ListQueuesResponse` object, and + :class:`google.cloud.tasks_v2.types.ListQueuesResponse` object, and provides an ``__aiter__`` method to iterate through its ``queues`` field. @@ -97,7 +106,7 @@ class ListQueuesAsyncPager: through the ``queues`` field on the corresponding responses. - All the usual :class:`~.cloudtasks.ListQueuesResponse` + All the usual :class:`google.cloud.tasks_v2.types.ListQueuesResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -115,9 +124,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.cloudtasks.ListQueuesRequest`): + request (google.cloud.tasks_v2.types.ListQueuesRequest): The initial request object. - response (:class:`~.cloudtasks.ListQueuesResponse`): + response (google.cloud.tasks_v2.types.ListQueuesResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -154,7 +163,7 @@ class ListTasksPager: """A pager for iterating through ``list_tasks`` requests. This class thinly wraps an initial - :class:`~.cloudtasks.ListTasksResponse` object, and + :class:`google.cloud.tasks_v2.types.ListTasksResponse` object, and provides an ``__iter__`` method to iterate through its ``tasks`` field. @@ -163,7 +172,7 @@ class ListTasksPager: through the ``tasks`` field on the corresponding responses. - All the usual :class:`~.cloudtasks.ListTasksResponse` + All the usual :class:`google.cloud.tasks_v2.types.ListTasksResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -181,9 +190,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.cloudtasks.ListTasksRequest`): + request (google.cloud.tasks_v2.types.ListTasksRequest): The initial request object. - response (:class:`~.cloudtasks.ListTasksResponse`): + response (google.cloud.tasks_v2.types.ListTasksResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -216,7 +225,7 @@ class ListTasksAsyncPager: """A pager for iterating through ``list_tasks`` requests. This class thinly wraps an initial - :class:`~.cloudtasks.ListTasksResponse` object, and + :class:`google.cloud.tasks_v2.types.ListTasksResponse` object, and provides an ``__aiter__`` method to iterate through its ``tasks`` field. @@ -225,7 +234,7 @@ class ListTasksAsyncPager: through the ``tasks`` field on the corresponding responses. - All the usual :class:`~.cloudtasks.ListTasksResponse` + All the usual :class:`google.cloud.tasks_v2.types.ListTasksResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -243,9 +252,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.cloudtasks.ListTasksRequest`): + request (google.cloud.tasks_v2.types.ListTasksRequest): The initial request object. - response (:class:`~.cloudtasks.ListTasksResponse`): + response (google.cloud.tasks_v2.types.ListTasksResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. diff --git a/google/cloud/tasks_v2/services/cloud_tasks/transports/grpc.py b/google/cloud/tasks_v2/services/cloud_tasks/transports/grpc.py index 05345f65..c6fa24ef 100644 --- a/google/cloud/tasks_v2/services/cloud_tasks/transports/grpc.py +++ b/google/cloud/tasks_v2/services/cloud_tasks/transports/grpc.py @@ -65,6 +65,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -95,6 +96,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -111,6 +116,11 @@ def __init__( """ self._ssl_channel_credentials = ssl_channel_credentials + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -120,11 +130,6 @@ def __init__( self._grpc_channel = channel self._ssl_channel_credentials = None elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -168,12 +173,18 @@ def __init__( scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id ) + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + # create a new channel. The provided one is ignored. self._grpc_channel = type(self).create_channel( host, credentials=credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, + ssl_credentials=self._ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ diff --git a/google/cloud/tasks_v2/services/cloud_tasks/transports/grpc_asyncio.py b/google/cloud/tasks_v2/services/cloud_tasks/transports/grpc_asyncio.py index 570a432c..aab98e3a 100644 --- a/google/cloud/tasks_v2/services/cloud_tasks/transports/grpc_asyncio.py +++ b/google/cloud/tasks_v2/services/cloud_tasks/transports/grpc_asyncio.py @@ -109,6 +109,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -140,6 +141,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -156,6 +161,11 @@ def __init__( """ self._ssl_channel_credentials = ssl_channel_credentials + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -165,11 +175,6 @@ def __init__( self._grpc_channel = channel self._ssl_channel_credentials = None elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -213,12 +218,18 @@ def __init__( scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id ) + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + # create a new channel. The provided one is ignored. self._grpc_channel = type(self).create_channel( host, credentials=credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, + ssl_credentials=self._ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ diff --git a/google/cloud/tasks_v2/types/cloudtasks.py b/google/cloud/tasks_v2/types/cloudtasks.py index aff86f04..7354ffde 100644 --- a/google/cloud/tasks_v2/types/cloudtasks.py +++ b/google/cloud/tasks_v2/types/cloudtasks.py @@ -101,7 +101,7 @@ class ListQueuesResponse(proto.Message): [ListQueues][google.cloud.tasks.v2.CloudTasks.ListQueues]. Attributes: - queues (Sequence[~.gct_queue.Queue]): + queues (Sequence[google.cloud.tasks_v2.types.Queue]): The list of queues. next_page_token (str): A token to retrieve next page of results. @@ -151,7 +151,7 @@ class CreateQueueRequest(proto.Message): The list of allowed locations can be obtained by calling Cloud Tasks' implementation of [ListLocations][google.cloud.location.Locations.ListLocations]. - queue (~.gct_queue.Queue): + queue (google.cloud.tasks_v2.types.Queue): Required. The queue to create. [Queue's name][google.cloud.tasks.v2.Queue.name] cannot be @@ -168,7 +168,7 @@ class UpdateQueueRequest(proto.Message): [UpdateQueue][google.cloud.tasks.v2.CloudTasks.UpdateQueue]. Attributes: - queue (~.gct_queue.Queue): + queue (google.cloud.tasks_v2.types.Queue): Required. The queue to create or update. The queue's [name][google.cloud.tasks.v2.Queue.name] must be @@ -178,7 +178,7 @@ class UpdateQueueRequest(proto.Message): value specified for an output only field will be ignored. The queue's [name][google.cloud.tasks.v2.Queue.name] cannot be changed. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): A mask used to specify which fields of the queue are being updated. If empty, then all fields will be updated. @@ -249,7 +249,7 @@ class ListTasksRequest(proto.Message): parent (str): Required. The queue name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` - response_view (~.gct_task.Task.View): + response_view (google.cloud.tasks_v2.types.Task.View): The response_view specifies which subset of the [Task][google.cloud.tasks.v2.Task] will be returned. @@ -303,7 +303,7 @@ class ListTasksResponse(proto.Message): [ListTasks][google.cloud.tasks.v2.CloudTasks.ListTasks]. Attributes: - tasks (Sequence[~.gct_task.Task]): + tasks (Sequence[google.cloud.tasks_v2.types.Task]): The list of tasks. next_page_token (str): A token to retrieve next page of results. @@ -333,7 +333,7 @@ class GetTaskRequest(proto.Message): name (str): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` - response_view (~.gct_task.Task.View): + response_view (google.cloud.tasks_v2.types.Task.View): The response_view specifies which subset of the [Task][google.cloud.tasks.v2.Task] will be returned. @@ -366,7 +366,7 @@ class CreateTaskRequest(proto.Message): ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` The queue must already exist. - task (~.gct_task.Task): + task (google.cloud.tasks_v2.types.Task): Required. The task to add. Task names have the following format: @@ -406,7 +406,7 @@ class CreateTaskRequest(proto.Message): The infrastructure relies on an approximately uniform distribution of task ids to store and serve tasks efficiently. - response_view (~.gct_task.Task.View): + response_view (google.cloud.tasks_v2.types.Task.View): The response_view specifies which subset of the [Task][google.cloud.tasks.v2.Task] will be returned. @@ -452,7 +452,7 @@ class RunTaskRequest(proto.Message): name (str): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` - response_view (~.gct_task.Task.View): + response_view (google.cloud.tasks_v2.types.Task.View): The response_view specifies which subset of the [Task][google.cloud.tasks.v2.Task] will be returned. diff --git a/google/cloud/tasks_v2/types/queue.py b/google/cloud/tasks_v2/types/queue.py index cbc051bd..32127b78 100644 --- a/google/cloud/tasks_v2/types/queue.py +++ b/google/cloud/tasks_v2/types/queue.py @@ -59,7 +59,7 @@ class Queue(proto.Message): - ``QUEUE_ID`` can contain letters ([A-Za-z]), numbers ([0-9]), or hyphens (-). The maximum length is 100 characters. - app_engine_routing_override (~.target.AppEngineRouting): + app_engine_routing_override (google.cloud.tasks_v2.types.AppEngineRouting): Overrides for [task-level app_engine_routing][google.cloud.tasks.v2.AppEngineHttpRequest.app_engine_routing]. These settings apply only to [App Engine @@ -71,7 +71,7 @@ class Queue(proto.Message): Engine tasks][google.cloud.tasks.v2.AppEngineHttpRequest] in the queue, no matter what the setting is for the [task-level app_engine_routing][google.cloud.tasks.v2.AppEngineHttpRequest.app_engine_routing]. - rate_limits (~.queue.RateLimits): + rate_limits (google.cloud.tasks_v2.types.RateLimits): Rate limits for task dispatches. [rate_limits][google.cloud.tasks.v2.Queue.rate_limits] and @@ -102,7 +102,7 @@ class Queue(proto.Message): ``503`` (Service Unavailable) responses from the worker, high error rates, or to smooth sudden large traffic spikes. - retry_config (~.queue.RetryConfig): + retry_config (google.cloud.tasks_v2.types.RetryConfig): Settings that determine the retry behavior. - For tasks created using Cloud Tasks: the queue-level @@ -115,7 +115,7 @@ class Queue(proto.Message): the task and were created by the App Engine SDK. See `App Engine documentation `__. - state (~.queue.Queue.State): + state (google.cloud.tasks_v2.types.Queue.State): Output only. The state of the queue. ``state`` can only be changed by called @@ -125,7 +125,7 @@ class Queue(proto.Message): `queue.yaml/xml `__. [UpdateQueue][google.cloud.tasks.v2.CloudTasks.UpdateQueue] cannot be used to change ``state``. - purge_time (~.timestamp.Timestamp): + purge_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The last time this queue was purged. All tasks that were @@ -139,7 +139,7 @@ class Queue(proto.Message): Purge time will be truncated to the nearest microsecond. Purge time will be unset if the queue has never been purged. - stackdriver_logging_config (~.queue.StackdriverLoggingConfig): + stackdriver_logging_config (google.cloud.tasks_v2.types.StackdriverLoggingConfig): Configuration options for writing logs to `Stackdriver Logging `__. If this field is unset, then no logs are written. @@ -273,7 +273,7 @@ class RetryConfig(proto.Message): This field has the same meaning as `task_retry_limit in queue.yaml/xml `__. - max_retry_duration (~.duration.Duration): + max_retry_duration (google.protobuf.duration_pb2.Duration): If positive, ``max_retry_duration`` specifies the time limit for retrying a failed task, measured from when the task was first attempted. Once ``max_retry_duration`` time has passed @@ -292,7 +292,7 @@ class RetryConfig(proto.Message): This field has the same meaning as `task_age_limit in queue.yaml/xml `__. - min_backoff (~.duration.Duration): + min_backoff (google.protobuf.duration_pb2.Duration): A task will be [scheduled][google.cloud.tasks.v2.Task.schedule_time] for retry between @@ -310,7 +310,7 @@ class RetryConfig(proto.Message): This field has the same meaning as `min_backoff_seconds in queue.yaml/xml `__. - max_backoff (~.duration.Duration): + max_backoff (google.protobuf.duration_pb2.Duration): A task will be [scheduled][google.cloud.tasks.v2.Task.schedule_time] for retry between diff --git a/google/cloud/tasks_v2/types/target.py b/google/cloud/tasks_v2/types/target.py index 5b71f458..6f61465f 100644 --- a/google/cloud/tasks_v2/types/target.py +++ b/google/cloud/tasks_v2/types/target.py @@ -93,10 +93,10 @@ class HttpRequest(proto.Message): The ``Location`` header response from a redirect response [``300`` - ``399``] may be followed. The redirect is not counted as a separate attempt. - http_method (~.target.HttpMethod): + http_method (google.cloud.tasks_v2.types.HttpMethod): The HTTP method to use for the request. The default is POST. - headers (Sequence[~.target.HttpRequest.HeadersEntry]): + headers (Sequence[google.cloud.tasks_v2.types.HttpRequest.HeadersEntry]): HTTP request headers. This map contains the header field names and values. Headers @@ -137,7 +137,7 @@ class HttpRequest(proto.Message): POST, PUT, or PATCH. It is an error to set body on a task with an incompatible [HttpMethod][google.cloud.tasks.v2.HttpMethod]. - oauth_token (~.target.OAuthToken): + oauth_token (google.cloud.tasks_v2.types.OAuthToken): If specified, an `OAuth token `__ will be generated and attached as an ``Authorization`` @@ -145,7 +145,7 @@ class HttpRequest(proto.Message): This type of authorization should generally only be used when calling Google APIs hosted on \*.googleapis.com. - oidc_token (~.target.OidcToken): + oidc_token (google.cloud.tasks_v2.types.OidcToken): If specified, an `OIDC `__ token will be generated and attached as an ``Authorization`` @@ -238,7 +238,7 @@ class AppEngineHttpRequest(proto.Message): control to throttle the queue. Attributes: - http_method (~.target.HttpMethod): + http_method (google.cloud.tasks_v2.types.HttpMethod): The HTTP method to use for the request. The default is POST. The app's request handler for the task's target URL must be @@ -249,7 +249,7 @@ class AppEngineHttpRequest(proto.Message): and the documentation for the request handlers in the language your app is written in e.g. `Python Request Handler `__. - app_engine_routing (~.target.AppEngineRouting): + app_engine_routing (google.cloud.tasks_v2.types.AppEngineRouting): Task-level setting for App Engine routing. - If [app_engine_routing_override is set on the @@ -265,7 +265,7 @@ class AppEngineHttpRequest(proto.Message): is empty, then the root path "/" will be used. No spaces are allowed, and the maximum length allowed is 2083 characters. - headers (Sequence[~.target.AppEngineHttpRequest.HeadersEntry]): + headers (Sequence[google.cloud.tasks_v2.types.AppEngineHttpRequest.HeadersEntry]): HTTP request headers. This map contains the header field names and values. Headers diff --git a/google/cloud/tasks_v2/types/task.py b/google/cloud/tasks_v2/types/task.py index fe676567..c7e8f903 100644 --- a/google/cloud/tasks_v2/types/task.py +++ b/google/cloud/tasks_v2/types/task.py @@ -58,28 +58,28 @@ class Task(proto.Message): - ``TASK_ID`` can contain only letters ([A-Za-z]), numbers ([0-9]), hyphens (-), or underscores (_). The maximum length is 500 characters. - app_engine_http_request (~.target.AppEngineHttpRequest): + app_engine_http_request (google.cloud.tasks_v2.types.AppEngineHttpRequest): HTTP request that is sent to the App Engine app handler. An App Engine task is a task that has [AppEngineHttpRequest][google.cloud.tasks.v2.AppEngineHttpRequest] set. - http_request (~.target.HttpRequest): + http_request (google.cloud.tasks_v2.types.HttpRequest): HTTP request that is sent to the worker. An HTTP task is a task that has [HttpRequest][google.cloud.tasks.v2.HttpRequest] set. - schedule_time (~.timestamp.Timestamp): + schedule_time (google.protobuf.timestamp_pb2.Timestamp): The time when the task is scheduled to be attempted or retried. ``schedule_time`` will be truncated to the nearest microsecond. - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The time that the task was created. ``create_time`` will be truncated to the nearest second. - dispatch_deadline (~.duration.Duration): + dispatch_deadline (google.protobuf.duration_pb2.Duration): The deadline for requests sent to the worker. If the worker does not respond by this deadline then the request is cancelled and the attempt is marked as a @@ -126,7 +126,7 @@ class Task(proto.Message): response_count (int): Output only. The number of attempts which have received a response. - first_attempt (~.task.Attempt): + first_attempt (google.cloud.tasks_v2.types.Attempt): Output only. The status of the task's first attempt. Only @@ -134,10 +134,10 @@ class Task(proto.Message): will be set. The other [Attempt][google.cloud.tasks.v2.Attempt] information is not retained by Cloud Tasks. - last_attempt (~.task.Attempt): + last_attempt (google.cloud.tasks_v2.types.Attempt): Output only. The status of the task's last attempt. - view (~.task.Task.View): + view (google.cloud.tasks_v2.types.Task.View): Output only. The view specifies which subset of the [Task][google.cloud.tasks.v2.Task] has been returned. """ @@ -189,23 +189,23 @@ class Attempt(proto.Message): r"""The status of a task attempt. Attributes: - schedule_time (~.timestamp.Timestamp): + schedule_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The time that this attempt was scheduled. ``schedule_time`` will be truncated to the nearest microsecond. - dispatch_time (~.timestamp.Timestamp): + dispatch_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The time that this attempt was dispatched. ``dispatch_time`` will be truncated to the nearest microsecond. - response_time (~.timestamp.Timestamp): + response_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The time that this attempt response was received. ``response_time`` will be truncated to the nearest microsecond. - response_status (~.status.Status): + response_status (google.rpc.status_pb2.Status): Output only. The response from the worker for this attempt. If ``response_time`` is unset, then the task has not been diff --git a/google/cloud/tasks_v2beta2/__init__.py b/google/cloud/tasks_v2beta2/__init__.py index 532b3358..9b0b1201 100644 --- a/google/cloud/tasks_v2beta2/__init__.py +++ b/google/cloud/tasks_v2beta2/__init__.py @@ -37,6 +37,7 @@ from .types.cloudtasks import RunTaskRequest from .types.cloudtasks import UpdateQueueRequest from .types.queue import Queue +from .types.queue import QueueStats from .types.queue import RateLimits from .types.queue import RetryConfig from .types.target import AppEngineHttpRequest @@ -75,6 +76,7 @@ "PullTarget", "PurgeQueueRequest", "Queue", + "QueueStats", "RateLimits", "RenewLeaseRequest", "ResumeQueueRequest", diff --git a/google/cloud/tasks_v2beta2/proto/cloudtasks.proto b/google/cloud/tasks_v2beta2/proto/cloudtasks.proto index afea6919..8b2fa57e 100644 --- a/google/cloud/tasks_v2beta2/proto/cloudtasks.proto +++ b/google/cloud/tasks_v2beta2/proto/cloudtasks.proto @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC. +// Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -11,7 +11,6 @@ // 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. -// syntax = "proto3"; @@ -431,6 +430,12 @@ message ListQueuesRequest { // method. It is an error to switch the value of the // [filter][google.cloud.tasks.v2beta2.ListQueuesRequest.filter] while iterating through pages. string page_token = 4; + + // Optional. Read mask is used for a more granular control over what the API returns. + // If the mask is not present all fields will be returned except + // [Queue.stats]. [Queue.stats] will be returned only if it was explicitly + // specified in the mask. + google.protobuf.FieldMask read_mask = 5 [(google.api.field_behavior) = OPTIONAL]; } // Response message for [ListQueues][google.cloud.tasks.v2beta2.CloudTasks.ListQueues]. @@ -460,6 +465,12 @@ message GetQueueRequest { type: "cloudtasks.googleapis.com/Queue" } ]; + + // Optional. Read mask is used for a more granular control over what the API returns. + // If the mask is not present all fields will be returned except + // [Queue.stats]. [Queue.stats] will be returned only if it was explicitly + // specified in the mask. + google.protobuf.FieldMask read_mask = 2 [(google.api.field_behavior) = OPTIONAL]; } // Request message for [CreateQueue][google.cloud.tasks.v2beta2.CloudTasks.CreateQueue]. diff --git a/google/cloud/tasks_v2beta2/proto/old_target.proto b/google/cloud/tasks_v2beta2/proto/old_target.proto new file mode 100644 index 00000000..5b5c095c --- /dev/null +++ b/google/cloud/tasks_v2beta2/proto/old_target.proto @@ -0,0 +1,25 @@ +// Copyright 2020 Google LLC +// +// 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. + +syntax = "proto3"; + +package google.cloud.tasks.v2beta2; + +import "google/cloud/tasks/v2beta2/target.proto"; +import "google/api/annotations.proto"; + +option go_package = "google.golang.org/genproto/googleapis/cloud/tasks/v2beta2;tasks"; +option java_multiple_files = true; +option java_outer_classname = "OldTargetProto"; +option java_package = "com.google.cloud.tasks.v2beta2"; diff --git a/google/cloud/tasks_v2beta2/proto/queue.proto b/google/cloud/tasks_v2beta2/proto/queue.proto index 212ab738..1cc44651 100644 --- a/google/cloud/tasks_v2beta2/proto/queue.proto +++ b/google/cloud/tasks_v2beta2/proto/queue.proto @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC. +// Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -11,12 +11,12 @@ // 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. -// syntax = "proto3"; package google.cloud.tasks.v2beta2; +import "google/api/field_behavior.proto"; import "google/api/resource.proto"; import "google/cloud/tasks/v2beta2/target.proto"; import "google/protobuf/duration.proto"; @@ -168,6 +168,37 @@ message Queue { // Purge time will be truncated to the nearest microsecond. Purge // time will be unset if the queue has never been purged. google.protobuf.Timestamp purge_time = 8; + + // The maximum amount of time that a task will be retained in + // this queue. + // + // Queues created by Cloud Tasks have a default `task_ttl` of 31 days. + // After a task has lived for `task_ttl`, the task will be deleted + // regardless of whether it was dispatched or not. + // + // The `task_ttl` for queues created via queue.yaml/xml is equal to the + // maximum duration because there is a + // [storage quota](https://cloud.google.com/appengine/quotas#Task_Queue) for + // these queues. To view the maximum valid duration, see the documentation for + // [Duration][google.protobuf.Duration]. + google.protobuf.Duration task_ttl = 9; + + // The task tombstone time to live (TTL). + // + // After a task is deleted or completed, the task's tombstone is + // retained for the length of time specified by `tombstone_ttl`. + // The tombstone is used by task de-duplication; another task with the same + // name can't be created until the tombstone has expired. For more information + // about task de-duplication, see the documentation for + // [CreateTaskRequest][google.cloud.tasks.v2beta2.CreateTaskRequest.task]. + // + // Queues created by Cloud Tasks have a default `tombstone_ttl` of 1 hour. + google.protobuf.Duration tombstone_ttl = 10; + + // Output only. The realtime, informational statistics for a queue. In order + // to receive the statistics the caller should include this field in the + // FieldMask. + QueueStats stats = 16 [(google.api.field_behavior) = OUTPUT_ONLY]; } // Rate limits. @@ -195,7 +226,7 @@ message RateLimits { // queue.yaml/xml](https://cloud.google.com/appengine/docs/standard/python/config/queueref#rate). double max_tasks_dispatched_per_second = 1; - // Output only. The max burst size. + // The max burst size. // // Max burst size limits how fast tasks in queue are processed when // many tasks are in the queue and the rate is high. This field @@ -210,23 +241,23 @@ message RateLimits { // token is removed from the bucket. Tasks will be dispatched until // the queue's bucket runs out of tokens. The bucket will be // continuously refilled with new tokens based on - // [max_tasks_dispatched_per_second][google.cloud.tasks.v2beta2.RateLimits.max_tasks_dispatched_per_second]. + // [max_dispatches_per_second][RateLimits.max_dispatches_per_second]. + // + // The default value of `max_burst_size` is picked by Cloud Tasks + // based on the value of + // [max_dispatches_per_second][RateLimits.max_dispatches_per_second]. // - // Cloud Tasks will pick the value of `max_burst_size` based on the - // value of - // [max_tasks_dispatched_per_second][google.cloud.tasks.v2beta2.RateLimits.max_tasks_dispatched_per_second]. + // The maximum value of `max_burst_size` is 500. // // For App Engine queues that were created or updated using // `queue.yaml/xml`, `max_burst_size` is equal to // [bucket_size](https://cloud.google.com/appengine/docs/standard/python/config/queueref#bucket_size). - // Since `max_burst_size` is output only, if - // [UpdateQueue][google.cloud.tasks.v2beta2.CloudTasks.UpdateQueue] is called on a queue - // created by `queue.yaml/xml`, `max_burst_size` will be reset based - // on the value of - // [max_tasks_dispatched_per_second][google.cloud.tasks.v2beta2.RateLimits.max_tasks_dispatched_per_second], - // regardless of whether - // [max_tasks_dispatched_per_second][google.cloud.tasks.v2beta2.RateLimits.max_tasks_dispatched_per_second] - // is updated. + // If + // [UpdateQueue][google.cloud.tasks.v2beta2.CloudTasks.UpdateQueue] is called on a queue without + // explicitly setting a value for `max_burst_size`, + // `max_burst_size` value will get updated if + // [UpdateQueue][google.cloud.tasks.v2beta2.CloudTasks.UpdateQueue] is updating + // [max_dispatches_per_second][RateLimits.max_dispatches_per_second]. // int32 max_burst_size = 2; @@ -343,7 +374,7 @@ message RetryConfig { // A task's retry interval starts at // [min_backoff][google.cloud.tasks.v2beta2.RetryConfig.min_backoff], then doubles // `max_doublings` times, then increases linearly, and finally - // retries retries at intervals of + // retries at intervals of // [max_backoff][google.cloud.tasks.v2beta2.RetryConfig.max_backoff] up to // [max_attempts][google.cloud.tasks.v2beta2.RetryConfig.max_attempts] times. // @@ -368,3 +399,31 @@ message RetryConfig { // queue.yaml/xml](https://cloud.google.com/appengine/docs/standard/python/config/queueref#retry_parameters). int32 max_doublings = 6; } + +// Statistics for a queue. +message QueueStats { + // Output only. An estimation of the number of tasks in the queue, that is, the tasks in + // the queue that haven't been executed, the tasks in the queue which the + // queue has dispatched but has not yet received a reply for, and the failed + // tasks that the queue is retrying. + int64 tasks_count = 1 [(google.api.field_behavior) = OUTPUT_ONLY]; + + // Output only. An estimation of the nearest time in the future where a task in the queue + // is scheduled to be executed. + google.protobuf.Timestamp oldest_estimated_arrival_time = 2 [(google.api.field_behavior) = OUTPUT_ONLY]; + + // Output only. The number of tasks that the queue has dispatched and received a reply for + // during the last minute. This variable counts both successful and + // non-successful executions. + int64 executed_last_minute_count = 3 [(google.api.field_behavior) = OUTPUT_ONLY]; + + // Output only. The number of requests that the queue has dispatched but has not received + // a reply for yet. + int64 concurrent_dispatches_count = 4 [(google.api.field_behavior) = OUTPUT_ONLY]; + + // Output only. The current maximum number of tasks per second executed by the queue. + // The maximum value of this variable is controlled by the RateLimits of the + // Queue. However, this value could be less to avoid overloading the endpoints + // tasks in the queue are targeting. + double effective_execution_rate = 5 [(google.api.field_behavior) = OUTPUT_ONLY]; +} diff --git a/google/cloud/tasks_v2beta2/proto/target.proto b/google/cloud/tasks_v2beta2/proto/target.proto index decdbaf8..09c8fd78 100644 --- a/google/cloud/tasks_v2beta2/proto/target.proto +++ b/google/cloud/tasks_v2beta2/proto/target.proto @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC. +// Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -11,7 +11,6 @@ // 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. -// syntax = "proto3"; @@ -115,10 +114,10 @@ message AppEngineHttpTarget { // delivered to can be set at the queue-level or task-level: // // * If set, -// [app_engine_routing_override][google.cloud.tasks.v2beta2.AppEngineHttpTarget.app_engine_routing_override] -// is used for all tasks in the queue, no matter what the setting -// is for the -// [task-level app_engine_routing][google.cloud.tasks.v2beta2.AppEngineHttpRequest.app_engine_routing]. +// [app_engine_routing_override][google.cloud.tasks.v2beta2.AppEngineHttpTarget.app_engine_routing_override] +// is used for all tasks in the queue, no matter what the setting +// is for the +// [task-level app_engine_routing][google.cloud.tasks.v2beta2.AppEngineHttpRequest.app_engine_routing]. // // // The `url` that the task will be sent to is: @@ -151,14 +150,11 @@ message AppEngineHttpRequest { // The HTTP method to use for the request. The default is POST. // // The app's request handler for the task's target URL must be able to handle - // HTTP requests with this http_method, otherwise the task attempt will fail - // with error code 405 (Method Not Allowed). See - // [Writing a push task request + // HTTP requests with this http_method, otherwise the task attempt fails with + // error code 405 (Method Not Allowed). See [Writing a push task request // handler](https://cloud.google.com/appengine/docs/java/taskqueue/push/creating-handlers#writing_a_push_task_request_handler) - // and the documentation for the request handlers in the language your app is - // written in e.g. - // [Python Request - // Handler](https://cloud.google.com/appengine/docs/python/tools/webapp/requesthandlerclass). + // and the App Engine documentation for your runtime on [How Requests are + // Handled](https://cloud.google.com/appengine/docs/standard/python3/how-requests-are-handled). HttpMethod http_method = 1; // Task-level setting for App Engine routing. diff --git a/google/cloud/tasks_v2beta2/proto/task.proto b/google/cloud/tasks_v2beta2/proto/task.proto index 9a927462..873a6f93 100644 --- a/google/cloud/tasks_v2beta2/proto/task.proto +++ b/google/cloud/tasks_v2beta2/proto/task.proto @@ -1,4 +1,4 @@ -// Copyright 2019 Google LLC. +// Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -11,7 +11,6 @@ // 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. -// syntax = "proto3"; diff --git a/google/cloud/tasks_v2beta2/services/cloud_tasks/async_client.py b/google/cloud/tasks_v2beta2/services/cloud_tasks/async_client.py index ce6cf5a7..dfd2f03e 100644 --- a/google/cloud/tasks_v2beta2/services/cloud_tasks/async_client.py +++ b/google/cloud/tasks_v2beta2/services/cloud_tasks/async_client.py @@ -84,6 +84,7 @@ class CloudTasksAsyncClient: CloudTasksClient.parse_common_location_path ) + from_service_account_info = CloudTasksClient.from_service_account_info from_service_account_file = CloudTasksClient.from_service_account_file from_service_account_json = from_service_account_file @@ -161,12 +162,13 @@ async def list_queues( Queues are returned in lexicographical order. Args: - request (:class:`~.cloudtasks.ListQueuesRequest`): + request (:class:`google.cloud.tasks_v2beta2.types.ListQueuesRequest`): The request object. Request message for [ListQueues][google.cloud.tasks.v2beta2.CloudTasks.ListQueues]. parent (:class:`str`): Required. The location name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID`` + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -178,7 +180,7 @@ async def list_queues( sent along with the request as metadata. Returns: - ~.pagers.ListQueuesAsyncPager: + google.cloud.tasks_v2beta2.services.cloud_tasks.pagers.ListQueuesAsyncPager: Response message for [ListQueues][google.cloud.tasks.v2beta2.CloudTasks.ListQueues]. @@ -216,7 +218,7 @@ async def list_queues( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -250,12 +252,13 @@ async def get_queue( r"""Gets a queue. Args: - request (:class:`~.cloudtasks.GetQueueRequest`): + request (:class:`google.cloud.tasks_v2beta2.types.GetQueueRequest`): The request object. Request message for [GetQueue][google.cloud.tasks.v2beta2.CloudTasks.GetQueue]. name (:class:`str`): Required. The resource name of the queue. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -267,7 +270,7 @@ async def get_queue( sent along with the request as metadata. Returns: - ~.queue.Queue: + google.cloud.tasks_v2beta2.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -306,7 +309,7 @@ async def get_queue( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -345,7 +348,7 @@ async def create_queue( before using this method. Args: - request (:class:`~.cloudtasks.CreateQueueRequest`): + request (:class:`google.cloud.tasks_v2beta2.types.CreateQueueRequest`): The request object. Request message for [CreateQueue][google.cloud.tasks.v2beta2.CloudTasks.CreateQueue]. parent (:class:`str`): @@ -356,14 +359,16 @@ async def create_queue( The list of allowed locations can be obtained by calling Cloud Tasks' implementation of [ListLocations][google.cloud.location.Locations.ListLocations]. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - queue (:class:`~.gct_queue.Queue`): + queue (:class:`google.cloud.tasks_v2beta2.types.Queue`): Required. The queue to create. [Queue's name][google.cloud.tasks.v2beta2.Queue.name] cannot be the same as an existing queue. + This corresponds to the ``queue`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -375,7 +380,7 @@ async def create_queue( sent along with the request as metadata. Returns: - ~.gct_queue.Queue: + google.cloud.tasks_v2beta2.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -408,7 +413,7 @@ async def create_queue( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_queue, - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -450,10 +455,10 @@ async def update_queue( before using this method. Args: - request (:class:`~.cloudtasks.UpdateQueueRequest`): + request (:class:`google.cloud.tasks_v2beta2.types.UpdateQueueRequest`): The request object. Request message for [UpdateQueue][google.cloud.tasks.v2beta2.CloudTasks.UpdateQueue]. - queue (:class:`~.gct_queue.Queue`): + queue (:class:`google.cloud.tasks_v2beta2.types.Queue`): Required. The queue to create or update. The queue's @@ -465,14 +470,16 @@ async def update_queue( ignored. The queue's [name][google.cloud.tasks.v2beta2.Queue.name] cannot be changed. + This corresponds to the ``queue`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): A mask used to specify which fields of the queue are being updated. If empty, then all fields will be updated. + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -484,7 +491,7 @@ async def update_queue( sent along with the request as metadata. Returns: - ~.gct_queue.Queue: + google.cloud.tasks_v2beta2.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -517,7 +524,7 @@ async def update_queue( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.update_queue, - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -558,12 +565,13 @@ async def delete_queue( before using this method. Args: - request (:class:`~.cloudtasks.DeleteQueueRequest`): + request (:class:`google.cloud.tasks_v2beta2.types.DeleteQueueRequest`): The request object. Request message for [DeleteQueue][google.cloud.tasks.v2beta2.CloudTasks.DeleteQueue]. name (:class:`str`): Required. The queue name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -604,7 +612,7 @@ async def delete_queue( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -636,12 +644,13 @@ async def purge_queue( effect. A purge is irreversible. Args: - request (:class:`~.cloudtasks.PurgeQueueRequest`): + request (:class:`google.cloud.tasks_v2beta2.types.PurgeQueueRequest`): The request object. Request message for [PurgeQueue][google.cloud.tasks.v2beta2.CloudTasks.PurgeQueue]. name (:class:`str`): Required. The queue name. For example: ``projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -653,7 +662,7 @@ async def purge_queue( sent along with the request as metadata. Returns: - ~.queue.Queue: + google.cloud.tasks_v2beta2.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -684,7 +693,7 @@ async def purge_queue( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.purge_queue, - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -719,12 +728,13 @@ async def pause_queue( [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED]. Args: - request (:class:`~.cloudtasks.PauseQueueRequest`): + request (:class:`google.cloud.tasks_v2beta2.types.PauseQueueRequest`): The request object. Request message for [PauseQueue][google.cloud.tasks.v2beta2.CloudTasks.PauseQueue]. name (:class:`str`): Required. The queue name. For example: ``projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -736,7 +746,7 @@ async def pause_queue( sent along with the request as metadata. Returns: - ~.queue.Queue: + google.cloud.tasks_v2beta2.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -767,7 +777,7 @@ async def pause_queue( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.pause_queue, - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -809,12 +819,13 @@ async def resume_queue( Risks `__. Args: - request (:class:`~.cloudtasks.ResumeQueueRequest`): + request (:class:`google.cloud.tasks_v2beta2.types.ResumeQueueRequest`): The request object. Request message for [ResumeQueue][google.cloud.tasks.v2beta2.CloudTasks.ResumeQueue]. name (:class:`str`): Required. The queue name. For example: ``projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -826,7 +837,7 @@ async def resume_queue( sent along with the request as metadata. Returns: - ~.queue.Queue: + google.cloud.tasks_v2beta2.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -857,7 +868,7 @@ async def resume_queue( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.resume_queue, - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -893,7 +904,7 @@ async def get_iam_policy( - ``cloudtasks.queues.getIamPolicy`` Args: - request (:class:`~.iam_policy.GetIamPolicyRequest`): + request (:class:`google.iam.v1.iam_policy_pb2.GetIamPolicyRequest`): The request object. Request message for `GetIamPolicy` method. resource (:class:`str`): @@ -901,6 +912,7 @@ async def get_iam_policy( policy is being requested. See the operation documentation for the appropriate value for this field. + This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -912,72 +924,62 @@ async def get_iam_policy( sent along with the request as metadata. Returns: - ~.policy.Policy: - Defines an Identity and Access Management (IAM) policy. - It is used to specify access control policies for Cloud - Platform resources. - - A ``Policy`` is a collection of ``bindings``. A - ``binding`` binds one or more ``members`` to a single - ``role``. Members can be user accounts, service - accounts, Google groups, and domains (such as G Suite). - A ``role`` is a named list of permissions (defined by - IAM or configured by users). A ``binding`` can - optionally specify a ``condition``, which is a logic - expression that further constrains the role binding - based on attributes about the request and/or target - resource. - - **JSON Example** - - :: - - { - "bindings": [ - { - "role": "roles/resourcemanager.organizationAdmin", - "members": [ - "user:mike@example.com", - "group:admins@example.com", - "domain:google.com", - "serviceAccount:my-project-id@appspot.gserviceaccount.com" - ] - }, - { - "role": "roles/resourcemanager.organizationViewer", - "members": ["user:eve@example.com"], - "condition": { - "title": "expirable access", - "description": "Does not grant access after Sep 2020", - "expression": "request.time < - timestamp('2020-10-01T00:00:00.000Z')", - } - } - ] - } - - **YAML Example** - - :: - - bindings: - - members: - - user:mike@example.com - - group:admins@example.com - - domain:google.com - - serviceAccount:my-project-id@appspot.gserviceaccount.com - role: roles/resourcemanager.organizationAdmin - - members: - - user:eve@example.com - role: roles/resourcemanager.organizationViewer - condition: - title: expirable access - description: Does not grant access after Sep 2020 - expression: request.time < timestamp('2020-10-01T00:00:00.000Z') - - For a description of IAM and its features, see the `IAM - developer's - guide `__. + google.iam.v1.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. It is used to + specify access control policies for Cloud Platform + resources. + + A Policy is a collection of bindings. A binding binds + one or more members to a single role. Members can be + user accounts, service accounts, Google groups, and + domains (such as G Suite). A role is a named list of + permissions (defined by IAM or configured by users). + A binding can optionally specify a condition, which + is a logic expression that further constrains the + role binding based on attributes about the request + and/or target resource. + + **JSON Example** + + { + "bindings": [ + { + "role": + "roles/resourcemanager.organizationAdmin", + "members": [ "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + + }, { "role": + "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { "title": "expirable access", + "description": "Does not grant access after + Sep 2020", "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", } } + + ] + + } + + **YAML Example** + + bindings: - members: - user:\ mike@example.com - + group:\ admins@example.com - domain:google.com - + serviceAccount:\ my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin - + members: - user:\ eve@example.com role: + roles/resourcemanager.organizationViewer + condition: title: expirable access description: + Does not grant access after Sep 2020 expression: + request.time < + timestamp('2020-10-01T00:00:00.000Z') + + For a description of IAM and its features, see the + [IAM developer's + guide](\ https://cloud.google.com/iam/docs). """ # Create or coerce a protobuf request object. @@ -1010,7 +1012,7 @@ async def get_iam_policy( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -1050,7 +1052,7 @@ async def set_iam_policy( - ``cloudtasks.queues.setIamPolicy`` Args: - request (:class:`~.iam_policy.SetIamPolicyRequest`): + request (:class:`google.iam.v1.iam_policy_pb2.SetIamPolicyRequest`): The request object. Request message for `SetIamPolicy` method. resource (:class:`str`): @@ -1058,6 +1060,7 @@ async def set_iam_policy( policy is being specified. See the operation documentation for the appropriate value for this field. + This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1069,72 +1072,62 @@ async def set_iam_policy( sent along with the request as metadata. Returns: - ~.policy.Policy: - Defines an Identity and Access Management (IAM) policy. - It is used to specify access control policies for Cloud - Platform resources. - - A ``Policy`` is a collection of ``bindings``. A - ``binding`` binds one or more ``members`` to a single - ``role``. Members can be user accounts, service - accounts, Google groups, and domains (such as G Suite). - A ``role`` is a named list of permissions (defined by - IAM or configured by users). A ``binding`` can - optionally specify a ``condition``, which is a logic - expression that further constrains the role binding - based on attributes about the request and/or target - resource. - - **JSON Example** - - :: - - { - "bindings": [ - { - "role": "roles/resourcemanager.organizationAdmin", - "members": [ - "user:mike@example.com", - "group:admins@example.com", - "domain:google.com", - "serviceAccount:my-project-id@appspot.gserviceaccount.com" - ] - }, - { - "role": "roles/resourcemanager.organizationViewer", - "members": ["user:eve@example.com"], - "condition": { - "title": "expirable access", - "description": "Does not grant access after Sep 2020", - "expression": "request.time < - timestamp('2020-10-01T00:00:00.000Z')", - } - } - ] - } - - **YAML Example** - - :: - - bindings: - - members: - - user:mike@example.com - - group:admins@example.com - - domain:google.com - - serviceAccount:my-project-id@appspot.gserviceaccount.com - role: roles/resourcemanager.organizationAdmin - - members: - - user:eve@example.com - role: roles/resourcemanager.organizationViewer - condition: - title: expirable access - description: Does not grant access after Sep 2020 - expression: request.time < timestamp('2020-10-01T00:00:00.000Z') - - For a description of IAM and its features, see the `IAM - developer's - guide `__. + google.iam.v1.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. It is used to + specify access control policies for Cloud Platform + resources. + + A Policy is a collection of bindings. A binding binds + one or more members to a single role. Members can be + user accounts, service accounts, Google groups, and + domains (such as G Suite). A role is a named list of + permissions (defined by IAM or configured by users). + A binding can optionally specify a condition, which + is a logic expression that further constrains the + role binding based on attributes about the request + and/or target resource. + + **JSON Example** + + { + "bindings": [ + { + "role": + "roles/resourcemanager.organizationAdmin", + "members": [ "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + + }, { "role": + "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { "title": "expirable access", + "description": "Does not grant access after + Sep 2020", "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", } } + + ] + + } + + **YAML Example** + + bindings: - members: - user:\ mike@example.com - + group:\ admins@example.com - domain:google.com - + serviceAccount:\ my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin - + members: - user:\ eve@example.com role: + roles/resourcemanager.organizationViewer + condition: title: expirable access description: + Does not grant access after Sep 2020 expression: + request.time < + timestamp('2020-10-01T00:00:00.000Z') + + For a description of IAM and its features, see the + [IAM developer's + guide](\ https://cloud.google.com/iam/docs). """ # Create or coerce a protobuf request object. @@ -1159,7 +1152,7 @@ async def set_iam_policy( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.set_iam_policy, - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -1196,7 +1189,7 @@ async def test_iam_permissions( warning. Args: - request (:class:`~.iam_policy.TestIamPermissionsRequest`): + request (:class:`google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest`): The request object. Request message for `TestIamPermissions` method. resource (:class:`str`): @@ -1204,6 +1197,7 @@ async def test_iam_permissions( policy detail is being requested. See the operation documentation for the appropriate value for this field. + This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1212,6 +1206,7 @@ async def test_iam_permissions( Permissions with wildcards (such as '*' or 'storage.*') are not allowed. For more information see `IAM Overview `__. + This corresponds to the ``permissions`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1223,8 +1218,8 @@ async def test_iam_permissions( sent along with the request as metadata. Returns: - ~.iam_policy.TestIamPermissionsResponse: - Response message for ``TestIamPermissions`` method. + google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: + Response message for TestIamPermissions method. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have @@ -1258,7 +1253,7 @@ async def test_iam_permissions( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -1295,13 +1290,14 @@ async def list_tasks( at any time. Args: - request (:class:`~.cloudtasks.ListTasksRequest`): + request (:class:`google.cloud.tasks_v2beta2.types.ListTasksRequest`): The request object. Request message for listing tasks using [ListTasks][google.cloud.tasks.v2beta2.CloudTasks.ListTasks]. parent (:class:`str`): Required. The queue name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1313,7 +1309,7 @@ async def list_tasks( sent along with the request as metadata. Returns: - ~.pagers.ListTasksAsyncPager: + google.cloud.tasks_v2beta2.services.cloud_tasks.pagers.ListTasksAsyncPager: Response message for listing tasks using [ListTasks][google.cloud.tasks.v2beta2.CloudTasks.ListTasks]. @@ -1351,7 +1347,7 @@ async def list_tasks( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -1385,13 +1381,14 @@ async def get_task( r"""Gets a task. Args: - request (:class:`~.cloudtasks.GetTaskRequest`): + request (:class:`google.cloud.tasks_v2beta2.types.GetTaskRequest`): The request object. Request message for getting a task using [GetTask][google.cloud.tasks.v2beta2.CloudTasks.GetTask]. name (:class:`str`): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1403,7 +1400,7 @@ async def get_task( sent along with the request as metadata. Returns: - ~.task.Task: + google.cloud.tasks_v2beta2.types.Task: A unit of scheduled work. """ # Create or coerce a protobuf request object. @@ -1436,7 +1433,7 @@ async def get_task( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -1474,7 +1471,7 @@ async def create_task( maximum task size is 1MB. Args: - request (:class:`~.cloudtasks.CreateTaskRequest`): + request (:class:`google.cloud.tasks_v2beta2.types.CreateTaskRequest`): The request object. Request message for [CreateTask][google.cloud.tasks.v2beta2.CloudTasks.CreateTask]. parent (:class:`str`): @@ -1482,10 +1479,11 @@ async def create_task( ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` The queue must already exist. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - task (:class:`~.gct_task.Task`): + task (:class:`google.cloud.tasks_v2beta2.types.Task`): Required. The task to add. Task names have the following format: @@ -1527,6 +1525,7 @@ async def create_task( task commands. The infrastructure relies on an approximately uniform distribution of task ids to store and serve tasks efficiently. + This corresponds to the ``task`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1538,7 +1537,7 @@ async def create_task( sent along with the request as metadata. Returns: - ~.gct_task.Task: + google.cloud.tasks_v2beta2.types.Task: A unit of scheduled work. """ # Create or coerce a protobuf request object. @@ -1565,7 +1564,7 @@ async def create_task( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_task, - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -1596,13 +1595,14 @@ async def delete_task( successfully or permanently failed. Args: - request (:class:`~.cloudtasks.DeleteTaskRequest`): + request (:class:`google.cloud.tasks_v2beta2.types.DeleteTaskRequest`): The request object. Request message for deleting a task using [DeleteTask][google.cloud.tasks.v2beta2.CloudTasks.DeleteTask]. name (:class:`str`): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1643,7 +1643,7 @@ async def delete_task( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -1694,17 +1694,18 @@ async def lease_tasks( is exceeded. Args: - request (:class:`~.cloudtasks.LeaseTasksRequest`): + request (:class:`google.cloud.tasks_v2beta2.types.LeaseTasksRequest`): The request object. Request message for leasing tasks using [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks]. parent (:class:`str`): Required. The queue name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - lease_duration (:class:`~.duration.Duration`): + lease_duration (:class:`google.protobuf.duration_pb2.Duration`): Required. The duration of the lease. Each task returned in the @@ -1730,6 +1731,7 @@ async def lease_tasks( The maximum lease duration is 1 week. ``lease_duration`` will be truncated to the nearest second. + This corresponds to the ``lease_duration`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1741,7 +1743,7 @@ async def lease_tasks( sent along with the request as metadata. Returns: - ~.cloudtasks.LeaseTasksResponse: + google.cloud.tasks_v2beta2.types.LeaseTasksResponse: Response message for leasing tasks using [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks]. @@ -1770,7 +1772,7 @@ async def lease_tasks( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.lease_tasks, - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -1813,17 +1815,18 @@ async def acknowledge_task( [ListTasks][google.cloud.tasks.v2beta2.CloudTasks.ListTasks]. Args: - request (:class:`~.cloudtasks.AcknowledgeTaskRequest`): + request (:class:`google.cloud.tasks_v2beta2.types.AcknowledgeTaskRequest`): The request object. Request message for acknowledging a task using [AcknowledgeTask][google.cloud.tasks.v2beta2.CloudTasks.AcknowledgeTask]. name (:class:`str`): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - schedule_time (:class:`~.timestamp.Timestamp`): + schedule_time (:class:`google.protobuf.timestamp_pb2.Timestamp`): Required. The task's current schedule time, available in the [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] @@ -1833,6 +1836,7 @@ async def acknowledge_task( [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction is to ensure that your worker currently holds the lease. + This corresponds to the ``schedule_time`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1867,7 +1871,7 @@ async def acknowledge_task( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.acknowledge_task, - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -1901,17 +1905,18 @@ async def renew_lease( [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time]. Args: - request (:class:`~.cloudtasks.RenewLeaseRequest`): + request (:class:`google.cloud.tasks_v2beta2.types.RenewLeaseRequest`): The request object. Request message for renewing a lease using [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease]. name (:class:`str`): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - schedule_time (:class:`~.timestamp.Timestamp`): + schedule_time (:class:`google.protobuf.timestamp_pb2.Timestamp`): Required. The task's current schedule time, available in the [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] @@ -1921,15 +1926,17 @@ async def renew_lease( [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction is to ensure that your worker currently holds the lease. + This corresponds to the ``schedule_time`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - lease_duration (:class:`~.duration.Duration`): + lease_duration (:class:`google.protobuf.duration_pb2.Duration`): Required. The desired new lease duration, starting from now. The maximum lease duration is 1 week. ``lease_duration`` will be truncated to the nearest second. + This corresponds to the ``lease_duration`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1941,7 +1948,7 @@ async def renew_lease( sent along with the request as metadata. Returns: - ~.task.Task: + google.cloud.tasks_v2beta2.types.Task: A unit of scheduled work. """ # Create or coerce a protobuf request object. @@ -1970,7 +1977,7 @@ async def renew_lease( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.renew_lease, - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -2006,17 +2013,18 @@ async def cancel_lease( [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks]. Args: - request (:class:`~.cloudtasks.CancelLeaseRequest`): + request (:class:`google.cloud.tasks_v2beta2.types.CancelLeaseRequest`): The request object. Request message for canceling a lease using [CancelLease][google.cloud.tasks.v2beta2.CloudTasks.CancelLease]. name (:class:`str`): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - schedule_time (:class:`~.timestamp.Timestamp`): + schedule_time (:class:`google.protobuf.timestamp_pb2.Timestamp`): Required. The task's current schedule time, available in the [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] @@ -2026,6 +2034,7 @@ async def cancel_lease( [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction is to ensure that your worker currently holds the lease. + This corresponds to the ``schedule_time`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -2037,7 +2046,7 @@ async def cancel_lease( sent along with the request as metadata. Returns: - ~.task.Task: + google.cloud.tasks_v2beta2.types.Task: A unit of scheduled work. """ # Create or coerce a protobuf request object. @@ -2064,7 +2073,7 @@ async def cancel_lease( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.cancel_lease, - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -2124,13 +2133,14 @@ async def run_task( task][google.cloud.tasks.v2beta2.PullMessage]. Args: - request (:class:`~.cloudtasks.RunTaskRequest`): + request (:class:`google.cloud.tasks_v2beta2.types.RunTaskRequest`): The request object. Request message for forcing a task to run now using [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask]. name (:class:`str`): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -2142,7 +2152,7 @@ async def run_task( sent along with the request as metadata. Returns: - ~.task.Task: + google.cloud.tasks_v2beta2.types.Task: A unit of scheduled work. """ # Create or coerce a protobuf request object. @@ -2167,7 +2177,7 @@ async def run_task( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.run_task, - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) diff --git a/google/cloud/tasks_v2beta2/services/cloud_tasks/client.py b/google/cloud/tasks_v2beta2/services/cloud_tasks/client.py index 133b77c9..47a1a809 100644 --- a/google/cloud/tasks_v2beta2/services/cloud_tasks/client.py +++ b/google/cloud/tasks_v2beta2/services/cloud_tasks/client.py @@ -120,6 +120,22 @@ def _get_default_mtls_endpoint(api_endpoint): DEFAULT_ENDPOINT ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + CloudTasksClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials @@ -132,7 +148,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): kwargs: Additional arguments to pass to the constructor. Returns: - {@api.name}: The constructed client. + CloudTasksClient: The constructed client. """ credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials @@ -256,10 +272,10 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.CloudTasksTransport]): The + transport (Union[str, CloudTasksTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (client_options_lib.ClientOptions): Custom options for the + client_options (google.api_core.client_options.ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -295,21 +311,17 @@ def __init__( util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) ) - ssl_credentials = None + client_cert_source_func = None is_mtls = False if use_client_cert: if client_options.client_cert_source: - import grpc # type: ignore - - cert, key = client_options.client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) is_mtls = True + client_cert_source_func = client_options.client_cert_source else: - creds = SslCredentials() - is_mtls = creds.is_mtls - ssl_credentials = creds.ssl_credentials if is_mtls else None + is_mtls = mtls.has_default_client_cert_source() + client_cert_source_func = ( + mtls.default_client_cert_source() if is_mtls else None + ) # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -352,7 +364,7 @@ def __init__( credentials_file=client_options.credentials_file, host=api_endpoint, scopes=client_options.scopes, - ssl_channel_credentials=ssl_credentials, + client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, ) @@ -370,12 +382,13 @@ def list_queues( Queues are returned in lexicographical order. Args: - request (:class:`~.cloudtasks.ListQueuesRequest`): + request (google.cloud.tasks_v2beta2.types.ListQueuesRequest): The request object. Request message for [ListQueues][google.cloud.tasks.v2beta2.CloudTasks.ListQueues]. - parent (:class:`str`): + parent (str): Required. The location name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID`` + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -387,7 +400,7 @@ def list_queues( sent along with the request as metadata. Returns: - ~.pagers.ListQueuesPager: + google.cloud.tasks_v2beta2.services.cloud_tasks.pagers.ListQueuesPager: Response message for [ListQueues][google.cloud.tasks.v2beta2.CloudTasks.ListQueues]. @@ -452,12 +465,13 @@ def get_queue( r"""Gets a queue. Args: - request (:class:`~.cloudtasks.GetQueueRequest`): + request (google.cloud.tasks_v2beta2.types.GetQueueRequest): The request object. Request message for [GetQueue][google.cloud.tasks.v2beta2.CloudTasks.GetQueue]. - name (:class:`str`): + name (str): Required. The resource name of the queue. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -469,7 +483,7 @@ def get_queue( sent along with the request as metadata. Returns: - ~.queue.Queue: + google.cloud.tasks_v2beta2.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -540,10 +554,10 @@ def create_queue( before using this method. Args: - request (:class:`~.cloudtasks.CreateQueueRequest`): + request (google.cloud.tasks_v2beta2.types.CreateQueueRequest): The request object. Request message for [CreateQueue][google.cloud.tasks.v2beta2.CloudTasks.CreateQueue]. - parent (:class:`str`): + parent (str): Required. The location name in which the queue will be created. For example: ``projects/PROJECT_ID/locations/LOCATION_ID`` @@ -551,14 +565,16 @@ def create_queue( The list of allowed locations can be obtained by calling Cloud Tasks' implementation of [ListLocations][google.cloud.location.Locations.ListLocations]. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - queue (:class:`~.gct_queue.Queue`): + queue (google.cloud.tasks_v2beta2.types.Queue): Required. The queue to create. [Queue's name][google.cloud.tasks.v2beta2.Queue.name] cannot be the same as an existing queue. + This corresponds to the ``queue`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -570,7 +586,7 @@ def create_queue( sent along with the request as metadata. Returns: - ~.gct_queue.Queue: + google.cloud.tasks_v2beta2.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -646,10 +662,10 @@ def update_queue( before using this method. Args: - request (:class:`~.cloudtasks.UpdateQueueRequest`): + request (google.cloud.tasks_v2beta2.types.UpdateQueueRequest): The request object. Request message for [UpdateQueue][google.cloud.tasks.v2beta2.CloudTasks.UpdateQueue]. - queue (:class:`~.gct_queue.Queue`): + queue (google.cloud.tasks_v2beta2.types.Queue): Required. The queue to create or update. The queue's @@ -661,14 +677,16 @@ def update_queue( ignored. The queue's [name][google.cloud.tasks.v2beta2.Queue.name] cannot be changed. + This corresponds to the ``queue`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (google.protobuf.field_mask_pb2.FieldMask): A mask used to specify which fields of the queue are being updated. If empty, then all fields will be updated. + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -680,7 +698,7 @@ def update_queue( sent along with the request as metadata. Returns: - ~.gct_queue.Queue: + google.cloud.tasks_v2beta2.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -755,12 +773,13 @@ def delete_queue( before using this method. Args: - request (:class:`~.cloudtasks.DeleteQueueRequest`): + request (google.cloud.tasks_v2beta2.types.DeleteQueueRequest): The request object. Request message for [DeleteQueue][google.cloud.tasks.v2beta2.CloudTasks.DeleteQueue]. - name (:class:`str`): + name (str): Required. The queue name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -826,12 +845,13 @@ def purge_queue( effect. A purge is irreversible. Args: - request (:class:`~.cloudtasks.PurgeQueueRequest`): + request (google.cloud.tasks_v2beta2.types.PurgeQueueRequest): The request object. Request message for [PurgeQueue][google.cloud.tasks.v2beta2.CloudTasks.PurgeQueue]. - name (:class:`str`): + name (str): Required. The queue name. For example: ``projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -843,7 +863,7 @@ def purge_queue( sent along with the request as metadata. Returns: - ~.queue.Queue: + google.cloud.tasks_v2beta2.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -910,12 +930,13 @@ def pause_queue( [PAUSED][google.cloud.tasks.v2beta2.Queue.State.PAUSED]. Args: - request (:class:`~.cloudtasks.PauseQueueRequest`): + request (google.cloud.tasks_v2beta2.types.PauseQueueRequest): The request object. Request message for [PauseQueue][google.cloud.tasks.v2beta2.CloudTasks.PauseQueue]. - name (:class:`str`): + name (str): Required. The queue name. For example: ``projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -927,7 +948,7 @@ def pause_queue( sent along with the request as metadata. Returns: - ~.queue.Queue: + google.cloud.tasks_v2beta2.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -1001,12 +1022,13 @@ def resume_queue( Risks `__. Args: - request (:class:`~.cloudtasks.ResumeQueueRequest`): + request (google.cloud.tasks_v2beta2.types.ResumeQueueRequest): The request object. Request message for [ResumeQueue][google.cloud.tasks.v2beta2.CloudTasks.ResumeQueue]. - name (:class:`str`): + name (str): Required. The queue name. For example: ``projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1018,7 +1040,7 @@ def resume_queue( sent along with the request as metadata. Returns: - ~.queue.Queue: + google.cloud.tasks_v2beta2.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -1086,14 +1108,15 @@ def get_iam_policy( - ``cloudtasks.queues.getIamPolicy`` Args: - request (:class:`~.iam_policy.GetIamPolicyRequest`): + request (google.iam.v1.iam_policy_pb2.GetIamPolicyRequest): The request object. Request message for `GetIamPolicy` method. - resource (:class:`str`): + resource (str): REQUIRED: The resource for which the policy is being requested. See the operation documentation for the appropriate value for this field. + This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1105,72 +1128,62 @@ def get_iam_policy( sent along with the request as metadata. Returns: - ~.policy.Policy: - Defines an Identity and Access Management (IAM) policy. - It is used to specify access control policies for Cloud - Platform resources. - - A ``Policy`` is a collection of ``bindings``. A - ``binding`` binds one or more ``members`` to a single - ``role``. Members can be user accounts, service - accounts, Google groups, and domains (such as G Suite). - A ``role`` is a named list of permissions (defined by - IAM or configured by users). A ``binding`` can - optionally specify a ``condition``, which is a logic - expression that further constrains the role binding - based on attributes about the request and/or target - resource. - - **JSON Example** - - :: - - { - "bindings": [ - { - "role": "roles/resourcemanager.organizationAdmin", - "members": [ - "user:mike@example.com", - "group:admins@example.com", - "domain:google.com", - "serviceAccount:my-project-id@appspot.gserviceaccount.com" - ] - }, - { - "role": "roles/resourcemanager.organizationViewer", - "members": ["user:eve@example.com"], - "condition": { - "title": "expirable access", - "description": "Does not grant access after Sep 2020", - "expression": "request.time < - timestamp('2020-10-01T00:00:00.000Z')", - } - } - ] - } - - **YAML Example** - - :: - - bindings: - - members: - - user:mike@example.com - - group:admins@example.com - - domain:google.com - - serviceAccount:my-project-id@appspot.gserviceaccount.com - role: roles/resourcemanager.organizationAdmin - - members: - - user:eve@example.com - role: roles/resourcemanager.organizationViewer - condition: - title: expirable access - description: Does not grant access after Sep 2020 - expression: request.time < timestamp('2020-10-01T00:00:00.000Z') - - For a description of IAM and its features, see the `IAM - developer's - guide `__. + google.iam.v1.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. It is used to + specify access control policies for Cloud Platform + resources. + + A Policy is a collection of bindings. A binding binds + one or more members to a single role. Members can be + user accounts, service accounts, Google groups, and + domains (such as G Suite). A role is a named list of + permissions (defined by IAM or configured by users). + A binding can optionally specify a condition, which + is a logic expression that further constrains the + role binding based on attributes about the request + and/or target resource. + + **JSON Example** + + { + "bindings": [ + { + "role": + "roles/resourcemanager.organizationAdmin", + "members": [ "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + + }, { "role": + "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { "title": "expirable access", + "description": "Does not grant access after + Sep 2020", "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", } } + + ] + + } + + **YAML Example** + + bindings: - members: - user:\ mike@example.com - + group:\ admins@example.com - domain:google.com - + serviceAccount:\ my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin - + members: - user:\ eve@example.com role: + roles/resourcemanager.organizationViewer + condition: title: expirable access description: + Does not grant access after Sep 2020 expression: + request.time < + timestamp('2020-10-01T00:00:00.000Z') + + For a description of IAM and its features, see the + [IAM developer's + guide](\ https://cloud.google.com/iam/docs). """ # Create or coerce a protobuf request object. @@ -1191,6 +1204,9 @@ def get_iam_policy( elif not request: request = iam_policy.GetIamPolicyRequest(resource=resource,) + if resource is not None: + request.resource = resource + # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_iam_policy] @@ -1231,14 +1247,15 @@ def set_iam_policy( - ``cloudtasks.queues.setIamPolicy`` Args: - request (:class:`~.iam_policy.SetIamPolicyRequest`): + request (google.iam.v1.iam_policy_pb2.SetIamPolicyRequest): The request object. Request message for `SetIamPolicy` method. - resource (:class:`str`): + resource (str): REQUIRED: The resource for which the policy is being specified. See the operation documentation for the appropriate value for this field. + This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1250,72 +1267,62 @@ def set_iam_policy( sent along with the request as metadata. Returns: - ~.policy.Policy: - Defines an Identity and Access Management (IAM) policy. - It is used to specify access control policies for Cloud - Platform resources. - - A ``Policy`` is a collection of ``bindings``. A - ``binding`` binds one or more ``members`` to a single - ``role``. Members can be user accounts, service - accounts, Google groups, and domains (such as G Suite). - A ``role`` is a named list of permissions (defined by - IAM or configured by users). A ``binding`` can - optionally specify a ``condition``, which is a logic - expression that further constrains the role binding - based on attributes about the request and/or target - resource. - - **JSON Example** - - :: - - { - "bindings": [ - { - "role": "roles/resourcemanager.organizationAdmin", - "members": [ - "user:mike@example.com", - "group:admins@example.com", - "domain:google.com", - "serviceAccount:my-project-id@appspot.gserviceaccount.com" - ] - }, - { - "role": "roles/resourcemanager.organizationViewer", - "members": ["user:eve@example.com"], - "condition": { - "title": "expirable access", - "description": "Does not grant access after Sep 2020", - "expression": "request.time < - timestamp('2020-10-01T00:00:00.000Z')", - } - } - ] - } - - **YAML Example** - - :: - - bindings: - - members: - - user:mike@example.com - - group:admins@example.com - - domain:google.com - - serviceAccount:my-project-id@appspot.gserviceaccount.com - role: roles/resourcemanager.organizationAdmin - - members: - - user:eve@example.com - role: roles/resourcemanager.organizationViewer - condition: - title: expirable access - description: Does not grant access after Sep 2020 - expression: request.time < timestamp('2020-10-01T00:00:00.000Z') - - For a description of IAM and its features, see the `IAM - developer's - guide `__. + google.iam.v1.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. It is used to + specify access control policies for Cloud Platform + resources. + + A Policy is a collection of bindings. A binding binds + one or more members to a single role. Members can be + user accounts, service accounts, Google groups, and + domains (such as G Suite). A role is a named list of + permissions (defined by IAM or configured by users). + A binding can optionally specify a condition, which + is a logic expression that further constrains the + role binding based on attributes about the request + and/or target resource. + + **JSON Example** + + { + "bindings": [ + { + "role": + "roles/resourcemanager.organizationAdmin", + "members": [ "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + + }, { "role": + "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { "title": "expirable access", + "description": "Does not grant access after + Sep 2020", "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", } } + + ] + + } + + **YAML Example** + + bindings: - members: - user:\ mike@example.com - + group:\ admins@example.com - domain:google.com - + serviceAccount:\ my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin - + members: - user:\ eve@example.com role: + roles/resourcemanager.organizationViewer + condition: title: expirable access description: + Does not grant access after Sep 2020 expression: + request.time < + timestamp('2020-10-01T00:00:00.000Z') + + For a description of IAM and its features, see the + [IAM developer's + guide](\ https://cloud.google.com/iam/docs). """ # Create or coerce a protobuf request object. @@ -1336,6 +1343,9 @@ def set_iam_policy( elif not request: request = iam_policy.SetIamPolicyRequest(resource=resource,) + if resource is not None: + request.resource = resource + # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.set_iam_policy] @@ -1373,22 +1383,24 @@ def test_iam_permissions( warning. Args: - request (:class:`~.iam_policy.TestIamPermissionsRequest`): + request (google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest): The request object. Request message for `TestIamPermissions` method. - resource (:class:`str`): + resource (str): REQUIRED: The resource for which the policy detail is being requested. See the operation documentation for the appropriate value for this field. + This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - permissions (:class:`Sequence[str]`): + permissions (Sequence[str]): The set of permissions to check for the ``resource``. Permissions with wildcards (such as '*' or 'storage.*') are not allowed. For more information see `IAM Overview `__. + This corresponds to the ``permissions`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1400,8 +1412,8 @@ def test_iam_permissions( sent along with the request as metadata. Returns: - ~.iam_policy.TestIamPermissionsResponse: - Response message for ``TestIamPermissions`` method. + google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: + Response message for TestIamPermissions method. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have @@ -1423,6 +1435,9 @@ def test_iam_permissions( resource=resource, permissions=permissions, ) + if resource is not None: + request.resource = resource + # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.test_iam_permissions] @@ -1460,13 +1475,14 @@ def list_tasks( at any time. Args: - request (:class:`~.cloudtasks.ListTasksRequest`): + request (google.cloud.tasks_v2beta2.types.ListTasksRequest): The request object. Request message for listing tasks using [ListTasks][google.cloud.tasks.v2beta2.CloudTasks.ListTasks]. - parent (:class:`str`): + parent (str): Required. The queue name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1478,7 +1494,7 @@ def list_tasks( sent along with the request as metadata. Returns: - ~.pagers.ListTasksPager: + google.cloud.tasks_v2beta2.services.cloud_tasks.pagers.ListTasksPager: Response message for listing tasks using [ListTasks][google.cloud.tasks.v2beta2.CloudTasks.ListTasks]. @@ -1543,13 +1559,14 @@ def get_task( r"""Gets a task. Args: - request (:class:`~.cloudtasks.GetTaskRequest`): + request (google.cloud.tasks_v2beta2.types.GetTaskRequest): The request object. Request message for getting a task using [GetTask][google.cloud.tasks.v2beta2.CloudTasks.GetTask]. - name (:class:`str`): + name (str): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1561,7 +1578,7 @@ def get_task( sent along with the request as metadata. Returns: - ~.task.Task: + google.cloud.tasks_v2beta2.types.Task: A unit of scheduled work. """ # Create or coerce a protobuf request object. @@ -1625,18 +1642,19 @@ def create_task( maximum task size is 1MB. Args: - request (:class:`~.cloudtasks.CreateTaskRequest`): + request (google.cloud.tasks_v2beta2.types.CreateTaskRequest): The request object. Request message for [CreateTask][google.cloud.tasks.v2beta2.CloudTasks.CreateTask]. - parent (:class:`str`): + parent (str): Required. The queue name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` The queue must already exist. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - task (:class:`~.gct_task.Task`): + task (google.cloud.tasks_v2beta2.types.Task): Required. The task to add. Task names have the following format: @@ -1678,6 +1696,7 @@ def create_task( task commands. The infrastructure relies on an approximately uniform distribution of task ids to store and serve tasks efficiently. + This corresponds to the ``task`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1689,7 +1708,7 @@ def create_task( sent along with the request as metadata. Returns: - ~.gct_task.Task: + google.cloud.tasks_v2beta2.types.Task: A unit of scheduled work. """ # Create or coerce a protobuf request object. @@ -1748,13 +1767,14 @@ def delete_task( successfully or permanently failed. Args: - request (:class:`~.cloudtasks.DeleteTaskRequest`): + request (google.cloud.tasks_v2beta2.types.DeleteTaskRequest): The request object. Request message for deleting a task using [DeleteTask][google.cloud.tasks.v2beta2.CloudTasks.DeleteTask]. - name (:class:`str`): + name (str): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1839,17 +1859,18 @@ def lease_tasks( is exceeded. Args: - request (:class:`~.cloudtasks.LeaseTasksRequest`): + request (google.cloud.tasks_v2beta2.types.LeaseTasksRequest): The request object. Request message for leasing tasks using [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks]. - parent (:class:`str`): + parent (str): Required. The queue name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - lease_duration (:class:`~.duration.Duration`): + lease_duration (google.protobuf.duration_pb2.Duration): Required. The duration of the lease. Each task returned in the @@ -1875,6 +1896,7 @@ def lease_tasks( The maximum lease duration is 1 week. ``lease_duration`` will be truncated to the nearest second. + This corresponds to the ``lease_duration`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1886,7 +1908,7 @@ def lease_tasks( sent along with the request as metadata. Returns: - ~.cloudtasks.LeaseTasksResponse: + google.cloud.tasks_v2beta2.types.LeaseTasksResponse: Response message for leasing tasks using [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks]. @@ -1959,17 +1981,18 @@ def acknowledge_task( [ListTasks][google.cloud.tasks.v2beta2.CloudTasks.ListTasks]. Args: - request (:class:`~.cloudtasks.AcknowledgeTaskRequest`): + request (google.cloud.tasks_v2beta2.types.AcknowledgeTaskRequest): The request object. Request message for acknowledging a task using [AcknowledgeTask][google.cloud.tasks.v2beta2.CloudTasks.AcknowledgeTask]. - name (:class:`str`): + name (str): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - schedule_time (:class:`~.timestamp.Timestamp`): + schedule_time (google.protobuf.timestamp_pb2.Timestamp): Required. The task's current schedule time, available in the [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] @@ -1979,6 +2002,7 @@ def acknowledge_task( [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction is to ensure that your worker currently holds the lease. + This corresponds to the ``schedule_time`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -2048,17 +2072,18 @@ def renew_lease( [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time]. Args: - request (:class:`~.cloudtasks.RenewLeaseRequest`): + request (google.cloud.tasks_v2beta2.types.RenewLeaseRequest): The request object. Request message for renewing a lease using [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease]. - name (:class:`str`): + name (str): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - schedule_time (:class:`~.timestamp.Timestamp`): + schedule_time (google.protobuf.timestamp_pb2.Timestamp): Required. The task's current schedule time, available in the [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] @@ -2068,15 +2093,17 @@ def renew_lease( [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction is to ensure that your worker currently holds the lease. + This corresponds to the ``schedule_time`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - lease_duration (:class:`~.duration.Duration`): + lease_duration (google.protobuf.duration_pb2.Duration): Required. The desired new lease duration, starting from now. The maximum lease duration is 1 week. ``lease_duration`` will be truncated to the nearest second. + This corresponds to the ``lease_duration`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -2088,7 +2115,7 @@ def renew_lease( sent along with the request as metadata. Returns: - ~.task.Task: + google.cloud.tasks_v2beta2.types.Task: A unit of scheduled work. """ # Create or coerce a protobuf request object. @@ -2154,17 +2181,18 @@ def cancel_lease( [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks]. Args: - request (:class:`~.cloudtasks.CancelLeaseRequest`): + request (google.cloud.tasks_v2beta2.types.CancelLeaseRequest): The request object. Request message for canceling a lease using [CancelLease][google.cloud.tasks.v2beta2.CloudTasks.CancelLease]. - name (:class:`str`): + name (str): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - schedule_time (:class:`~.timestamp.Timestamp`): + schedule_time (google.protobuf.timestamp_pb2.Timestamp): Required. The task's current schedule time, available in the [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] @@ -2174,6 +2202,7 @@ def cancel_lease( [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction is to ensure that your worker currently holds the lease. + This corresponds to the ``schedule_time`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -2185,7 +2214,7 @@ def cancel_lease( sent along with the request as metadata. Returns: - ~.task.Task: + google.cloud.tasks_v2beta2.types.Task: A unit of scheduled work. """ # Create or coerce a protobuf request object. @@ -2273,13 +2302,14 @@ def run_task( task][google.cloud.tasks.v2beta2.PullMessage]. Args: - request (:class:`~.cloudtasks.RunTaskRequest`): + request (google.cloud.tasks_v2beta2.types.RunTaskRequest): The request object. Request message for forcing a task to run now using [RunTask][google.cloud.tasks.v2beta2.CloudTasks.RunTask]. - name (:class:`str`): + name (str): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -2291,7 +2321,7 @@ def run_task( sent along with the request as metadata. Returns: - ~.task.Task: + google.cloud.tasks_v2beta2.types.Task: A unit of scheduled work. """ # Create or coerce a protobuf request object. diff --git a/google/cloud/tasks_v2beta2/services/cloud_tasks/pagers.py b/google/cloud/tasks_v2beta2/services/cloud_tasks/pagers.py index 6a5b4ad7..f7b1a01d 100644 --- a/google/cloud/tasks_v2beta2/services/cloud_tasks/pagers.py +++ b/google/cloud/tasks_v2beta2/services/cloud_tasks/pagers.py @@ -15,7 +15,16 @@ # limitations under the License. # -from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple +from typing import ( + Any, + AsyncIterable, + Awaitable, + Callable, + Iterable, + Sequence, + Tuple, + Optional, +) from google.cloud.tasks_v2beta2.types import cloudtasks from google.cloud.tasks_v2beta2.types import queue @@ -26,7 +35,7 @@ class ListQueuesPager: """A pager for iterating through ``list_queues`` requests. This class thinly wraps an initial - :class:`~.cloudtasks.ListQueuesResponse` object, and + :class:`google.cloud.tasks_v2beta2.types.ListQueuesResponse` object, and provides an ``__iter__`` method to iterate through its ``queues`` field. @@ -35,7 +44,7 @@ class ListQueuesPager: through the ``queues`` field on the corresponding responses. - All the usual :class:`~.cloudtasks.ListQueuesResponse` + All the usual :class:`google.cloud.tasks_v2beta2.types.ListQueuesResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -53,9 +62,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.cloudtasks.ListQueuesRequest`): + request (google.cloud.tasks_v2beta2.types.ListQueuesRequest): The initial request object. - response (:class:`~.cloudtasks.ListQueuesResponse`): + response (google.cloud.tasks_v2beta2.types.ListQueuesResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -88,7 +97,7 @@ class ListQueuesAsyncPager: """A pager for iterating through ``list_queues`` requests. This class thinly wraps an initial - :class:`~.cloudtasks.ListQueuesResponse` object, and + :class:`google.cloud.tasks_v2beta2.types.ListQueuesResponse` object, and provides an ``__aiter__`` method to iterate through its ``queues`` field. @@ -97,7 +106,7 @@ class ListQueuesAsyncPager: through the ``queues`` field on the corresponding responses. - All the usual :class:`~.cloudtasks.ListQueuesResponse` + All the usual :class:`google.cloud.tasks_v2beta2.types.ListQueuesResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -115,9 +124,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.cloudtasks.ListQueuesRequest`): + request (google.cloud.tasks_v2beta2.types.ListQueuesRequest): The initial request object. - response (:class:`~.cloudtasks.ListQueuesResponse`): + response (google.cloud.tasks_v2beta2.types.ListQueuesResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -154,7 +163,7 @@ class ListTasksPager: """A pager for iterating through ``list_tasks`` requests. This class thinly wraps an initial - :class:`~.cloudtasks.ListTasksResponse` object, and + :class:`google.cloud.tasks_v2beta2.types.ListTasksResponse` object, and provides an ``__iter__`` method to iterate through its ``tasks`` field. @@ -163,7 +172,7 @@ class ListTasksPager: through the ``tasks`` field on the corresponding responses. - All the usual :class:`~.cloudtasks.ListTasksResponse` + All the usual :class:`google.cloud.tasks_v2beta2.types.ListTasksResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -181,9 +190,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.cloudtasks.ListTasksRequest`): + request (google.cloud.tasks_v2beta2.types.ListTasksRequest): The initial request object. - response (:class:`~.cloudtasks.ListTasksResponse`): + response (google.cloud.tasks_v2beta2.types.ListTasksResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -216,7 +225,7 @@ class ListTasksAsyncPager: """A pager for iterating through ``list_tasks`` requests. This class thinly wraps an initial - :class:`~.cloudtasks.ListTasksResponse` object, and + :class:`google.cloud.tasks_v2beta2.types.ListTasksResponse` object, and provides an ``__aiter__`` method to iterate through its ``tasks`` field. @@ -225,7 +234,7 @@ class ListTasksAsyncPager: through the ``tasks`` field on the corresponding responses. - All the usual :class:`~.cloudtasks.ListTasksResponse` + All the usual :class:`google.cloud.tasks_v2beta2.types.ListTasksResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -243,9 +252,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.cloudtasks.ListTasksRequest`): + request (google.cloud.tasks_v2beta2.types.ListTasksRequest): The initial request object. - response (:class:`~.cloudtasks.ListTasksResponse`): + response (google.cloud.tasks_v2beta2.types.ListTasksResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. diff --git a/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/base.py b/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/base.py index a2107f27..eecfe295 100644 --- a/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/base.py +++ b/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/base.py @@ -121,7 +121,7 @@ def _prep_wrapped_messages(self, client_info): exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=client_info, ), self.get_queue: gapic_v1.method.wrap_method( @@ -134,14 +134,14 @@ def _prep_wrapped_messages(self, client_info): exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=client_info, ), self.create_queue: gapic_v1.method.wrap_method( - self.create_queue, default_timeout=10.0, client_info=client_info, + self.create_queue, default_timeout=20.0, client_info=client_info, ), self.update_queue: gapic_v1.method.wrap_method( - self.update_queue, default_timeout=10.0, client_info=client_info, + self.update_queue, default_timeout=20.0, client_info=client_info, ), self.delete_queue: gapic_v1.method.wrap_method( self.delete_queue, @@ -153,17 +153,17 @@ def _prep_wrapped_messages(self, client_info): exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=client_info, ), self.purge_queue: gapic_v1.method.wrap_method( - self.purge_queue, default_timeout=10.0, client_info=client_info, + self.purge_queue, default_timeout=20.0, client_info=client_info, ), self.pause_queue: gapic_v1.method.wrap_method( - self.pause_queue, default_timeout=10.0, client_info=client_info, + self.pause_queue, default_timeout=20.0, client_info=client_info, ), self.resume_queue: gapic_v1.method.wrap_method( - self.resume_queue, default_timeout=10.0, client_info=client_info, + self.resume_queue, default_timeout=20.0, client_info=client_info, ), self.get_iam_policy: gapic_v1.method.wrap_method( self.get_iam_policy, @@ -175,11 +175,11 @@ def _prep_wrapped_messages(self, client_info): exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=client_info, ), self.set_iam_policy: gapic_v1.method.wrap_method( - self.set_iam_policy, default_timeout=10.0, client_info=client_info, + self.set_iam_policy, default_timeout=20.0, client_info=client_info, ), self.test_iam_permissions: gapic_v1.method.wrap_method( self.test_iam_permissions, @@ -191,7 +191,7 @@ def _prep_wrapped_messages(self, client_info): exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=client_info, ), self.list_tasks: gapic_v1.method.wrap_method( @@ -204,7 +204,7 @@ def _prep_wrapped_messages(self, client_info): exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=client_info, ), self.get_task: gapic_v1.method.wrap_method( @@ -217,11 +217,11 @@ def _prep_wrapped_messages(self, client_info): exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=client_info, ), self.create_task: gapic_v1.method.wrap_method( - self.create_task, default_timeout=10.0, client_info=client_info, + self.create_task, default_timeout=20.0, client_info=client_info, ), self.delete_task: gapic_v1.method.wrap_method( self.delete_task, @@ -233,23 +233,23 @@ def _prep_wrapped_messages(self, client_info): exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=client_info, ), self.lease_tasks: gapic_v1.method.wrap_method( - self.lease_tasks, default_timeout=10.0, client_info=client_info, + self.lease_tasks, default_timeout=20.0, client_info=client_info, ), self.acknowledge_task: gapic_v1.method.wrap_method( - self.acknowledge_task, default_timeout=10.0, client_info=client_info, + self.acknowledge_task, default_timeout=20.0, client_info=client_info, ), self.renew_lease: gapic_v1.method.wrap_method( - self.renew_lease, default_timeout=10.0, client_info=client_info, + self.renew_lease, default_timeout=20.0, client_info=client_info, ), self.cancel_lease: gapic_v1.method.wrap_method( - self.cancel_lease, default_timeout=10.0, client_info=client_info, + self.cancel_lease, default_timeout=20.0, client_info=client_info, ), self.run_task: gapic_v1.method.wrap_method( - self.run_task, default_timeout=10.0, client_info=client_info, + self.run_task, default_timeout=20.0, client_info=client_info, ), } diff --git a/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/grpc.py b/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/grpc.py index fcba2038..5534bead 100644 --- a/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/grpc.py +++ b/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/grpc.py @@ -65,6 +65,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -95,6 +96,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -111,6 +116,11 @@ def __init__( """ self._ssl_channel_credentials = ssl_channel_credentials + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -120,11 +130,6 @@ def __init__( self._grpc_channel = channel self._ssl_channel_credentials = None elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -168,12 +173,18 @@ def __init__( scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id ) + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + # create a new channel. The provided one is ignored. self._grpc_channel = type(self).create_channel( host, credentials=credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, + ssl_credentials=self._ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ diff --git a/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/grpc_asyncio.py b/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/grpc_asyncio.py index 62f13489..3fe7a075 100644 --- a/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/grpc_asyncio.py +++ b/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/grpc_asyncio.py @@ -109,6 +109,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -140,6 +141,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -156,6 +161,11 @@ def __init__( """ self._ssl_channel_credentials = ssl_channel_credentials + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -165,11 +175,6 @@ def __init__( self._grpc_channel = channel self._ssl_channel_credentials = None elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -213,12 +218,18 @@ def __init__( scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id ) + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + # create a new channel. The provided one is ignored. self._grpc_channel = type(self).create_channel( host, credentials=credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, + ssl_credentials=self._ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ diff --git a/google/cloud/tasks_v2beta2/types/__init__.py b/google/cloud/tasks_v2beta2/types/__init__.py index a1fb8b0b..7407d142 100644 --- a/google/cloud/tasks_v2beta2/types/__init__.py +++ b/google/cloud/tasks_v2beta2/types/__init__.py @@ -27,6 +27,7 @@ Queue, RateLimits, RetryConfig, + QueueStats, ) from .task import ( Task, @@ -66,6 +67,7 @@ "Queue", "RateLimits", "RetryConfig", + "QueueStats", "Task", "TaskStatus", "AttemptStatus", diff --git a/google/cloud/tasks_v2beta2/types/cloudtasks.py b/google/cloud/tasks_v2beta2/types/cloudtasks.py index 7edb20d1..e216e819 100644 --- a/google/cloud/tasks_v2beta2/types/cloudtasks.py +++ b/google/cloud/tasks_v2beta2/types/cloudtasks.py @@ -92,6 +92,11 @@ class ListQueuesRequest(proto.Message): method. It is an error to switch the value of the [filter][google.cloud.tasks.v2beta2.ListQueuesRequest.filter] while iterating through pages. + read_mask (google.protobuf.field_mask_pb2.FieldMask): + Optional. Read mask is used for a more granular control over + what the API returns. If the mask is not present all fields + will be returned except [Queue.stats]. [Queue.stats] will be + returned only if it was explicitly specified in the mask. """ parent = proto.Field(proto.STRING, number=1) @@ -102,13 +107,15 @@ class ListQueuesRequest(proto.Message): page_token = proto.Field(proto.STRING, number=4) + read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask.FieldMask,) + class ListQueuesResponse(proto.Message): r"""Response message for [ListQueues][google.cloud.tasks.v2beta2.CloudTasks.ListQueues]. Attributes: - queues (Sequence[~.gct_queue.Queue]): + queues (Sequence[google.cloud.tasks_v2beta2.types.Queue]): The list of queues. next_page_token (str): A token to retrieve next page of results. @@ -140,10 +147,17 @@ class GetQueueRequest(proto.Message): name (str): Required. The resource name of the queue. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` + read_mask (google.protobuf.field_mask_pb2.FieldMask): + Optional. Read mask is used for a more granular control over + what the API returns. If the mask is not present all fields + will be returned except [Queue.stats]. [Queue.stats] will be + returned only if it was explicitly specified in the mask. """ name = proto.Field(proto.STRING, number=1) + read_mask = proto.Field(proto.MESSAGE, number=2, message=field_mask.FieldMask,) + class CreateQueueRequest(proto.Message): r"""Request message for @@ -158,7 +172,7 @@ class CreateQueueRequest(proto.Message): The list of allowed locations can be obtained by calling Cloud Tasks' implementation of [ListLocations][google.cloud.location.Locations.ListLocations]. - queue (~.gct_queue.Queue): + queue (google.cloud.tasks_v2beta2.types.Queue): Required. The queue to create. [Queue's name][google.cloud.tasks.v2beta2.Queue.name] cannot @@ -175,7 +189,7 @@ class UpdateQueueRequest(proto.Message): [UpdateQueue][google.cloud.tasks.v2beta2.CloudTasks.UpdateQueue]. Attributes: - queue (~.gct_queue.Queue): + queue (google.cloud.tasks_v2beta2.types.Queue): Required. The queue to create or update. The queue's [name][google.cloud.tasks.v2beta2.Queue.name] @@ -185,7 +199,7 @@ class UpdateQueueRequest(proto.Message): value specified for an output only field will be ignored. The queue's [name][google.cloud.tasks.v2beta2.Queue.name] cannot be changed. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): A mask used to specify which fields of the queue are being updated. If empty, then all fields will be updated. @@ -256,7 +270,7 @@ class ListTasksRequest(proto.Message): parent (str): Required. The queue name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` - response_view (~.gct_task.Task.View): + response_view (google.cloud.tasks_v2beta2.types.Task.View): The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be returned. @@ -310,7 +324,7 @@ class ListTasksResponse(proto.Message): [ListTasks][google.cloud.tasks.v2beta2.CloudTasks.ListTasks]. Attributes: - tasks (Sequence[~.gct_task.Task]): + tasks (Sequence[google.cloud.tasks_v2beta2.types.Task]): The list of tasks. next_page_token (str): A token to retrieve next page of results. @@ -340,7 +354,7 @@ class GetTaskRequest(proto.Message): name (str): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` - response_view (~.gct_task.Task.View): + response_view (google.cloud.tasks_v2beta2.types.Task.View): The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be returned. @@ -373,7 +387,7 @@ class CreateTaskRequest(proto.Message): ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` The queue must already exist. - task (~.gct_task.Task): + task (google.cloud.tasks_v2beta2.types.Task): Required. The task to add. Task names have the following format: @@ -414,7 +428,7 @@ class CreateTaskRequest(proto.Message): The infrastructure relies on an approximately uniform distribution of task ids to store and serve tasks efficiently. - response_view (~.gct_task.Task.View): + response_view (google.cloud.tasks_v2beta2.types.Task.View): The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be returned. @@ -472,7 +486,7 @@ class LeaseTasksRequest(proto.Message): response][google.cloud.tasks.v2beta2.LeaseTasksResponse] is 32 MB. If the sum of all task sizes requested reaches this limit, fewer tasks than requested are returned. - lease_duration (~.duration.Duration): + lease_duration (google.protobuf.duration_pb2.Duration): Required. The duration of the lease. Each task returned in the @@ -498,7 +512,7 @@ class LeaseTasksRequest(proto.Message): The maximum lease duration is 1 week. ``lease_duration`` will be truncated to the nearest second. - response_view (~.gct_task.Task.View): + response_view (google.cloud.tasks_v2beta2.types.Task.View): The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be returned. @@ -569,7 +583,7 @@ class LeaseTasksResponse(proto.Message): [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks]. Attributes: - tasks (Sequence[~.gct_task.Task]): + tasks (Sequence[google.cloud.tasks_v2beta2.types.Task]): The leased tasks. """ @@ -584,7 +598,7 @@ class AcknowledgeTaskRequest(proto.Message): name (str): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` - schedule_time (~.timestamp.Timestamp): + schedule_time (google.protobuf.timestamp_pb2.Timestamp): Required. The task's current schedule time, available in the [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] returned by @@ -608,7 +622,7 @@ class RenewLeaseRequest(proto.Message): name (str): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` - schedule_time (~.timestamp.Timestamp): + schedule_time (google.protobuf.timestamp_pb2.Timestamp): Required. The task's current schedule time, available in the [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] returned by @@ -617,12 +631,12 @@ class RenewLeaseRequest(proto.Message): [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction is to ensure that your worker currently holds the lease. - lease_duration (~.duration.Duration): + lease_duration (google.protobuf.duration_pb2.Duration): Required. The desired new lease duration, starting from now. The maximum lease duration is 1 week. ``lease_duration`` will be truncated to the nearest second. - response_view (~.gct_task.Task.View): + response_view (google.cloud.tasks_v2beta2.types.Task.View): The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be returned. @@ -657,7 +671,7 @@ class CancelLeaseRequest(proto.Message): name (str): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` - schedule_time (~.timestamp.Timestamp): + schedule_time (google.protobuf.timestamp_pb2.Timestamp): Required. The task's current schedule time, available in the [schedule_time][google.cloud.tasks.v2beta2.Task.schedule_time] returned by @@ -666,7 +680,7 @@ class CancelLeaseRequest(proto.Message): [RenewLease][google.cloud.tasks.v2beta2.CloudTasks.RenewLease] response. This restriction is to ensure that your worker currently holds the lease. - response_view (~.gct_task.Task.View): + response_view (google.cloud.tasks_v2beta2.types.Task.View): The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be returned. @@ -699,7 +713,7 @@ class RunTaskRequest(proto.Message): name (str): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` - response_view (~.gct_task.Task.View): + response_view (google.cloud.tasks_v2beta2.types.Task.View): The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] will be returned. diff --git a/google/cloud/tasks_v2beta2/types/queue.py b/google/cloud/tasks_v2beta2/types/queue.py index 2d43a321..093e1400 100644 --- a/google/cloud/tasks_v2beta2/types/queue.py +++ b/google/cloud/tasks_v2beta2/types/queue.py @@ -25,7 +25,7 @@ __protobuf__ = proto.module( package="google.cloud.tasks.v2beta2", - manifest={"Queue", "RateLimits", "RetryConfig",}, + manifest={"Queue", "RateLimits", "RetryConfig", "QueueStats",}, ) @@ -59,17 +59,17 @@ class Queue(proto.Message): - ``QUEUE_ID`` can contain letters ([A-Za-z]), numbers ([0-9]), or hyphens (-). The maximum length is 100 characters. - app_engine_http_target (~.target.AppEngineHttpTarget): + app_engine_http_target (google.cloud.tasks_v2beta2.types.AppEngineHttpTarget): App Engine HTTP target. An App Engine queue is a queue that has an [AppEngineHttpTarget][google.cloud.tasks.v2beta2.AppEngineHttpTarget]. - pull_target (~.target.PullTarget): + pull_target (google.cloud.tasks_v2beta2.types.PullTarget): Pull target. A pull queue is a queue that has a [PullTarget][google.cloud.tasks.v2beta2.PullTarget]. - rate_limits (~.queue.RateLimits): + rate_limits (google.cloud.tasks_v2beta2.types.RateLimits): Rate limits for task dispatches. [rate_limits][google.cloud.tasks.v2beta2.Queue.rate_limits] @@ -88,7 +88,7 @@ class Queue(proto.Message): [retry_config][google.cloud.tasks.v2beta2.Queue.retry_config] controls task retries (the second attempt, third attempt, etc). - retry_config (~.queue.RetryConfig): + retry_config (google.cloud.tasks_v2beta2.types.RetryConfig): Settings that determine the retry behavior. - For tasks created using Cloud Tasks: the queue-level @@ -101,7 +101,7 @@ class Queue(proto.Message): the task and were created by the App Engine SDK. See `App Engine documentation `__. - state (~.queue.Queue.State): + state (google.cloud.tasks_v2beta2.types.Queue.State): Output only. The state of the queue. ``state`` can only be changed by called @@ -111,7 +111,7 @@ class Queue(proto.Message): `queue.yaml/xml `__. [UpdateQueue][google.cloud.tasks.v2beta2.CloudTasks.UpdateQueue] cannot be used to change ``state``. - purge_time (~.timestamp.Timestamp): + purge_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The last time this queue was purged. All tasks that were @@ -125,6 +125,39 @@ class Queue(proto.Message): Purge time will be truncated to the nearest microsecond. Purge time will be unset if the queue has never been purged. + task_ttl (google.protobuf.duration_pb2.Duration): + The maximum amount of time that a task will be retained in + this queue. + + Queues created by Cloud Tasks have a default ``task_ttl`` of + 31 days. After a task has lived for ``task_ttl``, the task + will be deleted regardless of whether it was dispatched or + not. + + The ``task_ttl`` for queues created via queue.yaml/xml is + equal to the maximum duration because there is a `storage + quota `__ + for these queues. To view the maximum valid duration, see + the documentation for [Duration][google.protobuf.Duration]. + tombstone_ttl (google.protobuf.duration_pb2.Duration): + The task tombstone time to live (TTL). + + After a task is deleted or completed, the task's tombstone + is retained for the length of time specified by + ``tombstone_ttl``. The tombstone is used by task + de-duplication; another task with the same name can't be + created until the tombstone has expired. For more + information about task de-duplication, see the documentation + for + [CreateTaskRequest][google.cloud.tasks.v2beta2.CreateTaskRequest.task]. + + Queues created by Cloud Tasks have a default + ``tombstone_ttl`` of 1 hour. + stats (google.cloud.tasks_v2beta2.types.QueueStats): + Output only. The realtime, informational + statistics for a queue. In order to receive the + statistics the caller should include this field + in the FieldMask. """ class State(proto.Enum): @@ -155,6 +188,12 @@ class State(proto.Enum): purge_time = proto.Field(proto.MESSAGE, number=8, message=timestamp.Timestamp,) + task_ttl = proto.Field(proto.MESSAGE, number=9, message=duration.Duration,) + + tombstone_ttl = proto.Field(proto.MESSAGE, number=10, message=duration.Duration,) + + stats = proto.Field(proto.MESSAGE, number=16, message="QueueStats",) + class RateLimits(proto.Message): r"""Rate limits. @@ -189,7 +228,7 @@ class RateLimits(proto.Message): This field has the same meaning as `rate in queue.yaml/xml `__. max_burst_size (int): - Output only. The max burst size. + The max burst size. Max burst size limits how fast tasks in queue are processed when many tasks are in the queue and the rate is high. This @@ -207,23 +246,25 @@ class RateLimits(proto.Message): be dispatched until the queue's bucket runs out of tokens. The bucket will be continuously refilled with new tokens based on - [max_tasks_dispatched_per_second][google.cloud.tasks.v2beta2.RateLimits.max_tasks_dispatched_per_second]. + [max_dispatches_per_second][RateLimits.max_dispatches_per_second]. + + The default value of ``max_burst_size`` is picked by Cloud + Tasks based on the value of + [max_dispatches_per_second][RateLimits.max_dispatches_per_second]. - Cloud Tasks will pick the value of ``max_burst_size`` based - on the value of - [max_tasks_dispatched_per_second][google.cloud.tasks.v2beta2.RateLimits.max_tasks_dispatched_per_second]. + The maximum value of ``max_burst_size`` is 500. For App Engine queues that were created or updated using ``queue.yaml/xml``, ``max_burst_size`` is equal to `bucket_size `__. - Since ``max_burst_size`` is output only, if + If [UpdateQueue][google.cloud.tasks.v2beta2.CloudTasks.UpdateQueue] - is called on a queue created by ``queue.yaml/xml``, - ``max_burst_size`` will be reset based on the value of - [max_tasks_dispatched_per_second][google.cloud.tasks.v2beta2.RateLimits.max_tasks_dispatched_per_second], - regardless of whether - [max_tasks_dispatched_per_second][google.cloud.tasks.v2beta2.RateLimits.max_tasks_dispatched_per_second] - is updated. + is called on a queue without explicitly setting a value for + ``max_burst_size``, ``max_burst_size`` value will get + updated if + [UpdateQueue][google.cloud.tasks.v2beta2.CloudTasks.UpdateQueue] + is updating + [max_dispatches_per_second][RateLimits.max_dispatches_per_second]. max_concurrent_tasks (int): The maximum number of concurrent tasks that Cloud Tasks allows to be dispatched for this queue. After this threshold @@ -266,7 +307,7 @@ class RetryConfig(proto.Message): unlimited_attempts (bool): If true, then the number of attempts is unlimited. - max_retry_duration (~.duration.Duration): + max_retry_duration (google.protobuf.duration_pb2.Duration): If positive, ``max_retry_duration`` specifies the time limit for retrying a failed task, measured from when the task was first attempted. Once ``max_retry_duration`` time has passed @@ -288,7 +329,7 @@ class RetryConfig(proto.Message): This field has the same meaning as `task_age_limit in queue.yaml/xml `__. - min_backoff (~.duration.Duration): + min_backoff (google.protobuf.duration_pb2.Duration): A task will be [scheduled][google.cloud.tasks.v2beta2.Task.schedule_time] for retry between @@ -309,7 +350,7 @@ class RetryConfig(proto.Message): This field has the same meaning as `min_backoff_seconds in queue.yaml/xml `__. - max_backoff (~.duration.Duration): + max_backoff (google.protobuf.duration_pb2.Duration): A task will be [scheduled][google.cloud.tasks.v2beta2.Task.schedule_time] for retry between @@ -337,7 +378,7 @@ class RetryConfig(proto.Message): A task's retry interval starts at [min_backoff][google.cloud.tasks.v2beta2.RetryConfig.min_backoff], then doubles ``max_doublings`` times, then increases - linearly, and finally retries retries at intervals of + linearly, and finally retries at intervals of [max_backoff][google.cloud.tasks.v2beta2.RetryConfig.max_backoff] up to [max_attempts][google.cloud.tasks.v2beta2.RetryConfig.max_attempts] @@ -382,4 +423,50 @@ class RetryConfig(proto.Message): max_doublings = proto.Field(proto.INT32, number=6) +class QueueStats(proto.Message): + r"""Statistics for a queue. + + Attributes: + tasks_count (int): + Output only. An estimation of the number of + tasks in the queue, that is, the tasks in the + queue that haven't been executed, the tasks in + the queue which the queue has dispatched but has + not yet received a reply for, and the failed + tasks that the queue is retrying. + oldest_estimated_arrival_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. An estimation of the nearest + time in the future where a task in the queue is + scheduled to be executed. + executed_last_minute_count (int): + Output only. The number of tasks that the + queue has dispatched and received a reply for + during the last minute. This variable counts + both successful and non-successful executions. + concurrent_dispatches_count (int): + Output only. The number of requests that the + queue has dispatched but has not received a + reply for yet. + effective_execution_rate (float): + Output only. The current maximum number of + tasks per second executed by the queue. The + maximum value of this variable is controlled by + the RateLimits of the Queue. However, this value + could be less to avoid overloading the endpoints + tasks in the queue are targeting. + """ + + tasks_count = proto.Field(proto.INT64, number=1) + + oldest_estimated_arrival_time = proto.Field( + proto.MESSAGE, number=2, message=timestamp.Timestamp, + ) + + executed_last_minute_count = proto.Field(proto.INT64, number=3) + + concurrent_dispatches_count = proto.Field(proto.INT64, number=4) + + effective_execution_rate = proto.Field(proto.DOUBLE, number=5) + + __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/tasks_v2beta2/types/target.py b/google/cloud/tasks_v2beta2/types/target.py index d1d717e9..5c976b10 100644 --- a/google/cloud/tasks_v2beta2/types/target.py +++ b/google/cloud/tasks_v2beta2/types/target.py @@ -108,7 +108,7 @@ class AppEngineHttpTarget(proto.Message): ``https://www.googleapis.com/auth/cloud-platform`` Attributes: - app_engine_routing_override (~.target.AppEngineRouting): + app_engine_routing_override (google.cloud.tasks_v2beta2.types.AppEngineRouting): Overrides for the [task-level app_engine_routing][google.cloud.tasks.v2beta2.AppEngineHttpRequest.app_engine_routing]. @@ -192,18 +192,18 @@ class AppEngineHttpRequest(proto.Message): congestion control to throttle the queue. Attributes: - http_method (~.target.HttpMethod): + http_method (google.cloud.tasks_v2beta2.types.HttpMethod): The HTTP method to use for the request. The default is POST. The app's request handler for the task's target URL must be able to handle HTTP requests with this http_method, - otherwise the task attempt will fail with error code 405 - (Method Not Allowed). See `Writing a push task request + otherwise the task attempt fails with error code 405 (Method + Not Allowed). See `Writing a push task request handler `__ - and the documentation for the request handlers in the - language your app is written in e.g. `Python Request - Handler `__. - app_engine_routing (~.target.AppEngineRouting): + and the App Engine documentation for your runtime on `How + Requests are + Handled `__. + app_engine_routing (google.cloud.tasks_v2beta2.types.AppEngineRouting): Task-level setting for App Engine routing. If set, @@ -219,7 +219,7 @@ class AppEngineHttpRequest(proto.Message): is empty, then the root path "/" will be used. No spaces are allowed, and the maximum length allowed is 2083 characters. - headers (Sequence[~.target.AppEngineHttpRequest.HeadersEntry]): + headers (Sequence[google.cloud.tasks_v2beta2.types.AppEngineHttpRequest.HeadersEntry]): HTTP request headers. This map contains the header field names and values. Headers diff --git a/google/cloud/tasks_v2beta2/types/task.py b/google/cloud/tasks_v2beta2/types/task.py index ad7cd4e0..3d009018 100644 --- a/google/cloud/tasks_v2beta2/types/task.py +++ b/google/cloud/tasks_v2beta2/types/task.py @@ -58,7 +58,7 @@ class Task(proto.Message): - ``TASK_ID`` can contain only letters ([A-Za-z]), numbers ([0-9]), hyphens (-), or underscores (_). The maximum length is 500 characters. - app_engine_http_request (~.target.AppEngineHttpRequest): + app_engine_http_request (google.cloud.tasks_v2beta2.types.AppEngineHttpRequest): App Engine HTTP request that is sent to the task's target. Can be set only if [app_engine_http_target][google.cloud.tasks.v2beta2.Queue.app_engine_http_target] @@ -67,7 +67,7 @@ class Task(proto.Message): An App Engine task is a task that has [AppEngineHttpRequest][google.cloud.tasks.v2beta2.AppEngineHttpRequest] set. - pull_message (~.target.PullMessage): + pull_message (google.cloud.tasks_v2beta2.types.PullMessage): [LeaseTasks][google.cloud.tasks.v2beta2.CloudTasks.LeaseTasks] to process the task. Can be set only if [pull_target][google.cloud.tasks.v2beta2.Queue.pull_target] @@ -75,7 +75,7 @@ class Task(proto.Message): A pull task is a task that has [PullMessage][google.cloud.tasks.v2beta2.PullMessage] set. - schedule_time (~.timestamp.Timestamp): + schedule_time (google.protobuf.timestamp_pb2.Timestamp): The time when the task is scheduled to be attempted. For App Engine queues, this is when the task will be @@ -89,13 +89,13 @@ class Task(proto.Message): ``schedule_time`` will be truncated to the nearest microsecond. - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The time that the task was created. ``create_time`` will be truncated to the nearest second. - status (~.task.TaskStatus): + status (google.cloud.tasks_v2beta2.types.TaskStatus): Output only. The task status. - view (~.task.Task.View): + view (google.cloud.tasks_v2beta2.types.Task.View): Output only. The view specifies which subset of the [Task][google.cloud.tasks.v2beta2.Task] has been returned. """ @@ -150,7 +150,7 @@ class TaskStatus(proto.Message): This field is not calculated for [pull tasks][google.cloud.tasks.v2beta2.PullMessage]. - first_attempt_status (~.task.AttemptStatus): + first_attempt_status (google.cloud.tasks_v2beta2.types.AttemptStatus): Output only. The status of the task's first attempt. Only @@ -161,7 +161,7 @@ class TaskStatus(proto.Message): This field is not calculated for [pull tasks][google.cloud.tasks.v2beta2.PullMessage]. - last_attempt_status (~.task.AttemptStatus): + last_attempt_status (google.cloud.tasks_v2beta2.types.AttemptStatus): Output only. The status of the task's last attempt. This field is not calculated for [pull @@ -183,23 +183,23 @@ class AttemptStatus(proto.Message): r"""The status of a task attempt. Attributes: - schedule_time (~.timestamp.Timestamp): + schedule_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The time that this attempt was scheduled. ``schedule_time`` will be truncated to the nearest microsecond. - dispatch_time (~.timestamp.Timestamp): + dispatch_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The time that this attempt was dispatched. ``dispatch_time`` will be truncated to the nearest microsecond. - response_time (~.timestamp.Timestamp): + response_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The time that this attempt response was received. ``response_time`` will be truncated to the nearest microsecond. - response_status (~.gr_status.Status): + response_status (google.rpc.status_pb2.Status): Output only. The response from the target for this attempt. If the task has not been attempted or the task diff --git a/google/cloud/tasks_v2beta3/__init__.py b/google/cloud/tasks_v2beta3/__init__.py index 9371d755..143c0ff3 100644 --- a/google/cloud/tasks_v2beta3/__init__.py +++ b/google/cloud/tasks_v2beta3/__init__.py @@ -32,6 +32,7 @@ from .types.cloudtasks import RunTaskRequest from .types.cloudtasks import UpdateQueueRequest from .types.queue import Queue +from .types.queue import QueueStats from .types.queue import RateLimits from .types.queue import RetryConfig from .types.queue import StackdriverLoggingConfig @@ -42,6 +43,7 @@ from .types.target import HttpRequest from .types.target import OAuthToken from .types.target import OidcToken +from .types.target import PullMessage from .types.task import Attempt from .types.task import Task @@ -66,8 +68,10 @@ "OAuthToken", "OidcToken", "PauseQueueRequest", + "PullMessage", "PurgeQueueRequest", "Queue", + "QueueStats", "RateLimits", "ResumeQueueRequest", "RetryConfig", diff --git a/google/cloud/tasks_v2beta3/proto/cloudtasks.proto b/google/cloud/tasks_v2beta3/proto/cloudtasks.proto index de3460f6..81e2098d 100644 --- a/google/cloud/tasks_v2beta3/proto/cloudtasks.proto +++ b/google/cloud/tasks_v2beta3/proto/cloudtasks.proto @@ -345,6 +345,12 @@ message ListQueuesRequest { // method. It is an error to switch the value of the // [filter][google.cloud.tasks.v2beta3.ListQueuesRequest.filter] while iterating through pages. string page_token = 4; + + // Optional. Read mask is used for a more granular control over what the API returns. + // If the mask is not present all fields will be returned except + // [Queue.stats]. [Queue.stats] will be returned only if it was explicitly + // specified in the mask. + google.protobuf.FieldMask read_mask = 5 [(google.api.field_behavior) = OPTIONAL]; } // Response message for [ListQueues][google.cloud.tasks.v2beta3.CloudTasks.ListQueues]. @@ -374,6 +380,12 @@ message GetQueueRequest { type: "cloudtasks.googleapis.com/Queue" } ]; + + // Optional. Read mask is used for a more granular control over what the API returns. + // If the mask is not present all fields will be returned except + // [Queue.stats]. [Queue.stats] will be returned only if it was explicitly + // specified in the mask. + google.protobuf.FieldMask read_mask = 2 [(google.api.field_behavior) = OPTIONAL]; } // Request message for [CreateQueue][google.cloud.tasks.v2beta3.CloudTasks.CreateQueue]. diff --git a/google/cloud/tasks_v2beta3/proto/queue.proto b/google/cloud/tasks_v2beta3/proto/queue.proto index b24b7063..2b042a12 100644 --- a/google/cloud/tasks_v2beta3/proto/queue.proto +++ b/google/cloud/tasks_v2beta3/proto/queue.proto @@ -174,6 +174,32 @@ message Queue { // time will be unset if the queue has never been purged. google.protobuf.Timestamp purge_time = 7; + // The maximum amount of time that a task will be retained in + // this queue. + // + // Queues created by Cloud Tasks have a default `task_ttl` of 31 days. + // After a task has lived for `task_ttl`, the task will be deleted + // regardless of whether it was dispatched or not. + // + // The `task_ttl` for queues created via queue.yaml/xml is equal to the + // maximum duration because there is a + // [storage quota](https://cloud.google.com/appengine/quotas#Task_Queue) for + // these queues. To view the maximum valid duration, see the documentation for + // [Duration][google.protobuf.Duration]. + google.protobuf.Duration task_ttl = 8; + + // The task tombstone time to live (TTL). + // + // After a task is deleted or executed, the task's tombstone is + // retained for the length of time specified by `tombstone_ttl`. + // The tombstone is used by task de-duplication; another task with the same + // name can't be created until the tombstone has expired. For more information + // about task de-duplication, see the documentation for + // [CreateTaskRequest][google.cloud.tasks.v2beta3.CreateTaskRequest.task]. + // + // Queues created by Cloud Tasks have a default `tombstone_ttl` of 1 hour. + google.protobuf.Duration tombstone_ttl = 9; + // Configuration options for writing logs to // [Stackdriver Logging](https://cloud.google.com/logging/docs/). If this // field is unset, then no logs are written. @@ -185,6 +211,11 @@ message Queue { // creation time. When left unspecified, the default value of `PUSH` is // selected. Type type = 11 [(google.api.field_behavior) = IMMUTABLE]; + + // Output only. The realtime, informational statistics for a queue. In order + // to receive the statistics the caller should include this field in the + // FieldMask. + QueueStats stats = 12 [(google.api.field_behavior) = OUTPUT_ONLY]; } // Rate limits. @@ -209,7 +240,7 @@ message RateLimits { // queue.yaml/xml](https://cloud.google.com/appengine/docs/standard/python/config/queueref#rate). double max_dispatches_per_second = 1; - // Output only. The max burst size. + // The max burst size. // // Max burst size limits how fast tasks in queue are processed when // many tasks are in the queue and the rate is high. This field @@ -226,21 +257,21 @@ message RateLimits { // continuously refilled with new tokens based on // [max_dispatches_per_second][google.cloud.tasks.v2beta3.RateLimits.max_dispatches_per_second]. // - // Cloud Tasks will pick the value of `max_burst_size` based on the - // value of + // The default value of `max_burst_size` is picked by Cloud Tasks + // based on the value of // [max_dispatches_per_second][google.cloud.tasks.v2beta3.RateLimits.max_dispatches_per_second]. // + // The maximum value of `max_burst_size` is 500. + // // For App Engine queues that were created or updated using // `queue.yaml/xml`, `max_burst_size` is equal to // [bucket_size](https://cloud.google.com/appengine/docs/standard/python/config/queueref#bucket_size). - // Since `max_burst_size` is output only, if - // [UpdateQueue][google.cloud.tasks.v2beta3.CloudTasks.UpdateQueue] is called on a queue - // created by `queue.yaml/xml`, `max_burst_size` will be reset based - // on the value of - // [max_dispatches_per_second][google.cloud.tasks.v2beta3.RateLimits.max_dispatches_per_second], - // regardless of whether - // [max_dispatches_per_second][google.cloud.tasks.v2beta3.RateLimits.max_dispatches_per_second] - // is updated. + // If + // [UpdateQueue][google.cloud.tasks.v2beta3.CloudTasks.UpdateQueue] is called on a queue without + // explicitly setting a value for `max_burst_size`, + // `max_burst_size` value will get updated if + // [UpdateQueue][google.cloud.tasks.v2beta3.CloudTasks.UpdateQueue] is updating + // [max_dispatches_per_second][google.cloud.tasks.v2beta3.RateLimits.max_dispatches_per_second]. // int32 max_burst_size = 2; @@ -374,3 +405,31 @@ message StackdriverLoggingConfig { // 0.0 is the default and means that no operations are logged. double sampling_ratio = 1; } + +// Statistics for a queue. +message QueueStats { + // Output only. An estimation of the number of tasks in the queue, that is, the tasks in + // the queue that haven't been executed, the tasks in the queue which the + // queue has dispatched but has not yet received a reply for, and the failed + // tasks that the queue is retrying. + int64 tasks_count = 1 [(google.api.field_behavior) = OUTPUT_ONLY]; + + // Output only. An estimation of the nearest time in the future where a task in the queue + // is scheduled to be executed. + google.protobuf.Timestamp oldest_estimated_arrival_time = 2 [(google.api.field_behavior) = OUTPUT_ONLY]; + + // Output only. The number of tasks that the queue has dispatched and received a reply for + // during the last minute. This variable counts both successful and + // non-successful executions. + int64 executed_last_minute_count = 3 [(google.api.field_behavior) = OUTPUT_ONLY]; + + // Output only. The number of requests that the queue has dispatched but has not received + // a reply for yet. + int64 concurrent_dispatches_count = 4 [(google.api.field_behavior) = OUTPUT_ONLY]; + + // Output only. The current maximum number of tasks per second executed by the queue. + // The maximum value of this variable is controlled by the RateLimits of the + // Queue. However, this value could be less to avoid overloading the endpoints + // tasks in the queue are targeting. + double effective_execution_rate = 5 [(google.api.field_behavior) = OUTPUT_ONLY]; +} diff --git a/google/cloud/tasks_v2beta3/proto/target.proto b/google/cloud/tasks_v2beta3/proto/target.proto index cc0c5cfe..5ef1ee08 100644 --- a/google/cloud/tasks_v2beta3/proto/target.proto +++ b/google/cloud/tasks_v2beta3/proto/target.proto @@ -23,6 +23,30 @@ option java_multiple_files = true; option java_outer_classname = "TargetProto"; option java_package = "com.google.cloud.tasks.v2beta3"; +// Pull Message. +// +// This proto can only be used for tasks in a queue which has +// [PULL][google.cloud.tasks.v2beta3.Queue.type] type. It currently exists for backwards compatibility with +// the App Engine Task Queue SDK. This message type maybe returned with methods +// [list][google.cloud.tasks.v2beta3.CloudTask.ListTasks] and +// [get][google.cloud.tasks.v2beta3.CloudTask.ListTasks], when the response view +// is [FULL][google.cloud.tasks.v2beta3.Task.View.Full]. +message PullMessage { + // A data payload consumed by the worker to execute the task. + bytes payload = 1; + + // The tasks's tag. + // + // The tag is less than 500 characters. + // + // SDK compatibility: Although the SDK allows tags to be either + // string or + // [bytes](https://cloud.google.com/appengine/docs/standard/java/javadoc/com/google/appengine/api/taskqueue/TaskOptions.html#tag-byte:A-), + // only UTF-8 encoded tags can be used in Cloud Tasks. If a tag isn't UTF-8 + // encoded, the tag will be empty when the task is returned by Cloud Tasks. + string tag = 2; +} + // HTTP request. // // The task will be pushed to the worker as an HTTP request. If the worker diff --git a/google/cloud/tasks_v2beta3/proto/task.proto b/google/cloud/tasks_v2beta3/proto/task.proto index 96d552e0..8a652566 100644 --- a/google/cloud/tasks_v2beta3/proto/task.proto +++ b/google/cloud/tasks_v2beta3/proto/task.proto @@ -97,6 +97,15 @@ message Task { // // An HTTP task is a task that has [HttpRequest][google.cloud.tasks.v2beta3.HttpRequest] set. HttpRequest http_request = 11; + + // Pull Message contained in a task in a [PULL][google.cloud.tasks.v2beta3.Queue.type] queue type. This + // payload type cannot be explicitly set through Cloud Tasks API. Its + // purpose, currently is to provide backward compatibility with App Engine + // Task Queue + // [pull](https://cloud.google.com/appengine/docs/standard/java/taskqueue/pull/) + // queues to provide a way to inspect contents of pull tasks through the + // [CloudTasks.GetTask][google.cloud.tasks.v2beta3.CloudTasks.GetTask]. + PullMessage pull_message = 13; } // The time when the task is scheduled to be attempted. diff --git a/google/cloud/tasks_v2beta3/services/cloud_tasks/async_client.py b/google/cloud/tasks_v2beta3/services/cloud_tasks/async_client.py index 8ef25925..2107df3f 100644 --- a/google/cloud/tasks_v2beta3/services/cloud_tasks/async_client.py +++ b/google/cloud/tasks_v2beta3/services/cloud_tasks/async_client.py @@ -84,6 +84,7 @@ class CloudTasksAsyncClient: CloudTasksClient.parse_common_location_path ) + from_service_account_info = CloudTasksClient.from_service_account_info from_service_account_file = CloudTasksClient.from_service_account_file from_service_account_json = from_service_account_file @@ -161,12 +162,13 @@ async def list_queues( Queues are returned in lexicographical order. Args: - request (:class:`~.cloudtasks.ListQueuesRequest`): + request (:class:`google.cloud.tasks_v2beta3.types.ListQueuesRequest`): The request object. Request message for [ListQueues][google.cloud.tasks.v2beta3.CloudTasks.ListQueues]. parent (:class:`str`): Required. The location name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID`` + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -178,7 +180,7 @@ async def list_queues( sent along with the request as metadata. Returns: - ~.pagers.ListQueuesAsyncPager: + google.cloud.tasks_v2beta3.services.cloud_tasks.pagers.ListQueuesAsyncPager: Response message for [ListQueues][google.cloud.tasks.v2beta3.CloudTasks.ListQueues]. @@ -216,7 +218,7 @@ async def list_queues( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -250,12 +252,13 @@ async def get_queue( r"""Gets a queue. Args: - request (:class:`~.cloudtasks.GetQueueRequest`): + request (:class:`google.cloud.tasks_v2beta3.types.GetQueueRequest`): The request object. Request message for [GetQueue][google.cloud.tasks.v2beta3.CloudTasks.GetQueue]. name (:class:`str`): Required. The resource name of the queue. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -267,7 +270,7 @@ async def get_queue( sent along with the request as metadata. Returns: - ~.queue.Queue: + google.cloud.tasks_v2beta3.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -306,7 +309,7 @@ async def get_queue( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -345,7 +348,7 @@ async def create_queue( before using this method. Args: - request (:class:`~.cloudtasks.CreateQueueRequest`): + request (:class:`google.cloud.tasks_v2beta3.types.CreateQueueRequest`): The request object. Request message for [CreateQueue][google.cloud.tasks.v2beta3.CloudTasks.CreateQueue]. parent (:class:`str`): @@ -356,14 +359,16 @@ async def create_queue( The list of allowed locations can be obtained by calling Cloud Tasks' implementation of [ListLocations][google.cloud.location.Locations.ListLocations]. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - queue (:class:`~.gct_queue.Queue`): + queue (:class:`google.cloud.tasks_v2beta3.types.Queue`): Required. The queue to create. [Queue's name][google.cloud.tasks.v2beta3.Queue.name] cannot be the same as an existing queue. + This corresponds to the ``queue`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -375,7 +380,7 @@ async def create_queue( sent along with the request as metadata. Returns: - ~.gct_queue.Queue: + google.cloud.tasks_v2beta3.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -408,7 +413,7 @@ async def create_queue( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_queue, - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -450,10 +455,10 @@ async def update_queue( before using this method. Args: - request (:class:`~.cloudtasks.UpdateQueueRequest`): + request (:class:`google.cloud.tasks_v2beta3.types.UpdateQueueRequest`): The request object. Request message for [UpdateQueue][google.cloud.tasks.v2beta3.CloudTasks.UpdateQueue]. - queue (:class:`~.gct_queue.Queue`): + queue (:class:`google.cloud.tasks_v2beta3.types.Queue`): Required. The queue to create or update. The queue's @@ -465,14 +470,16 @@ async def update_queue( ignored. The queue's [name][google.cloud.tasks.v2beta3.Queue.name] cannot be changed. + This corresponds to the ``queue`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): A mask used to specify which fields of the queue are being updated. If empty, then all fields will be updated. + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -484,7 +491,7 @@ async def update_queue( sent along with the request as metadata. Returns: - ~.gct_queue.Queue: + google.cloud.tasks_v2beta3.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -517,7 +524,7 @@ async def update_queue( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.update_queue, - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -558,12 +565,13 @@ async def delete_queue( before using this method. Args: - request (:class:`~.cloudtasks.DeleteQueueRequest`): + request (:class:`google.cloud.tasks_v2beta3.types.DeleteQueueRequest`): The request object. Request message for [DeleteQueue][google.cloud.tasks.v2beta3.CloudTasks.DeleteQueue]. name (:class:`str`): Required. The queue name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -604,7 +612,7 @@ async def delete_queue( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -636,12 +644,13 @@ async def purge_queue( effect. A purge is irreversible. Args: - request (:class:`~.cloudtasks.PurgeQueueRequest`): + request (:class:`google.cloud.tasks_v2beta3.types.PurgeQueueRequest`): The request object. Request message for [PurgeQueue][google.cloud.tasks.v2beta3.CloudTasks.PurgeQueue]. name (:class:`str`): Required. The queue name. For example: ``projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -653,7 +662,7 @@ async def purge_queue( sent along with the request as metadata. Returns: - ~.queue.Queue: + google.cloud.tasks_v2beta3.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -684,7 +693,7 @@ async def purge_queue( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.purge_queue, - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -719,12 +728,13 @@ async def pause_queue( [PAUSED][google.cloud.tasks.v2beta3.Queue.State.PAUSED]. Args: - request (:class:`~.cloudtasks.PauseQueueRequest`): + request (:class:`google.cloud.tasks_v2beta3.types.PauseQueueRequest`): The request object. Request message for [PauseQueue][google.cloud.tasks.v2beta3.CloudTasks.PauseQueue]. name (:class:`str`): Required. The queue name. For example: ``projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -736,7 +746,7 @@ async def pause_queue( sent along with the request as metadata. Returns: - ~.queue.Queue: + google.cloud.tasks_v2beta3.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -767,7 +777,7 @@ async def pause_queue( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.pause_queue, - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -809,12 +819,13 @@ async def resume_queue( Risks `__. Args: - request (:class:`~.cloudtasks.ResumeQueueRequest`): + request (:class:`google.cloud.tasks_v2beta3.types.ResumeQueueRequest`): The request object. Request message for [ResumeQueue][google.cloud.tasks.v2beta3.CloudTasks.ResumeQueue]. name (:class:`str`): Required. The queue name. For example: ``projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -826,7 +837,7 @@ async def resume_queue( sent along with the request as metadata. Returns: - ~.queue.Queue: + google.cloud.tasks_v2beta3.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -857,7 +868,7 @@ async def resume_queue( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.resume_queue, - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -893,7 +904,7 @@ async def get_iam_policy( - ``cloudtasks.queues.getIamPolicy`` Args: - request (:class:`~.iam_policy.GetIamPolicyRequest`): + request (:class:`google.iam.v1.iam_policy_pb2.GetIamPolicyRequest`): The request object. Request message for `GetIamPolicy` method. resource (:class:`str`): @@ -901,6 +912,7 @@ async def get_iam_policy( policy is being requested. See the operation documentation for the appropriate value for this field. + This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -912,72 +924,62 @@ async def get_iam_policy( sent along with the request as metadata. Returns: - ~.policy.Policy: - Defines an Identity and Access Management (IAM) policy. - It is used to specify access control policies for Cloud - Platform resources. - - A ``Policy`` is a collection of ``bindings``. A - ``binding`` binds one or more ``members`` to a single - ``role``. Members can be user accounts, service - accounts, Google groups, and domains (such as G Suite). - A ``role`` is a named list of permissions (defined by - IAM or configured by users). A ``binding`` can - optionally specify a ``condition``, which is a logic - expression that further constrains the role binding - based on attributes about the request and/or target - resource. - - **JSON Example** - - :: - - { - "bindings": [ - { - "role": "roles/resourcemanager.organizationAdmin", - "members": [ - "user:mike@example.com", - "group:admins@example.com", - "domain:google.com", - "serviceAccount:my-project-id@appspot.gserviceaccount.com" - ] - }, - { - "role": "roles/resourcemanager.organizationViewer", - "members": ["user:eve@example.com"], - "condition": { - "title": "expirable access", - "description": "Does not grant access after Sep 2020", - "expression": "request.time < - timestamp('2020-10-01T00:00:00.000Z')", - } - } - ] - } - - **YAML Example** - - :: - - bindings: - - members: - - user:mike@example.com - - group:admins@example.com - - domain:google.com - - serviceAccount:my-project-id@appspot.gserviceaccount.com - role: roles/resourcemanager.organizationAdmin - - members: - - user:eve@example.com - role: roles/resourcemanager.organizationViewer - condition: - title: expirable access - description: Does not grant access after Sep 2020 - expression: request.time < timestamp('2020-10-01T00:00:00.000Z') - - For a description of IAM and its features, see the `IAM - developer's - guide `__. + google.iam.v1.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. It is used to + specify access control policies for Cloud Platform + resources. + + A Policy is a collection of bindings. A binding binds + one or more members to a single role. Members can be + user accounts, service accounts, Google groups, and + domains (such as G Suite). A role is a named list of + permissions (defined by IAM or configured by users). + A binding can optionally specify a condition, which + is a logic expression that further constrains the + role binding based on attributes about the request + and/or target resource. + + **JSON Example** + + { + "bindings": [ + { + "role": + "roles/resourcemanager.organizationAdmin", + "members": [ "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + + }, { "role": + "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { "title": "expirable access", + "description": "Does not grant access after + Sep 2020", "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", } } + + ] + + } + + **YAML Example** + + bindings: - members: - user:\ mike@example.com - + group:\ admins@example.com - domain:google.com - + serviceAccount:\ my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin - + members: - user:\ eve@example.com role: + roles/resourcemanager.organizationViewer + condition: title: expirable access description: + Does not grant access after Sep 2020 expression: + request.time < + timestamp('2020-10-01T00:00:00.000Z') + + For a description of IAM and its features, see the + [IAM developer's + guide](\ https://cloud.google.com/iam/docs). """ # Create or coerce a protobuf request object. @@ -1010,7 +1012,7 @@ async def get_iam_policy( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -1050,7 +1052,7 @@ async def set_iam_policy( - ``cloudtasks.queues.setIamPolicy`` Args: - request (:class:`~.iam_policy.SetIamPolicyRequest`): + request (:class:`google.iam.v1.iam_policy_pb2.SetIamPolicyRequest`): The request object. Request message for `SetIamPolicy` method. resource (:class:`str`): @@ -1058,6 +1060,7 @@ async def set_iam_policy( policy is being specified. See the operation documentation for the appropriate value for this field. + This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1069,72 +1072,62 @@ async def set_iam_policy( sent along with the request as metadata. Returns: - ~.policy.Policy: - Defines an Identity and Access Management (IAM) policy. - It is used to specify access control policies for Cloud - Platform resources. - - A ``Policy`` is a collection of ``bindings``. A - ``binding`` binds one or more ``members`` to a single - ``role``. Members can be user accounts, service - accounts, Google groups, and domains (such as G Suite). - A ``role`` is a named list of permissions (defined by - IAM or configured by users). A ``binding`` can - optionally specify a ``condition``, which is a logic - expression that further constrains the role binding - based on attributes about the request and/or target - resource. - - **JSON Example** - - :: - - { - "bindings": [ - { - "role": "roles/resourcemanager.organizationAdmin", - "members": [ - "user:mike@example.com", - "group:admins@example.com", - "domain:google.com", - "serviceAccount:my-project-id@appspot.gserviceaccount.com" - ] - }, - { - "role": "roles/resourcemanager.organizationViewer", - "members": ["user:eve@example.com"], - "condition": { - "title": "expirable access", - "description": "Does not grant access after Sep 2020", - "expression": "request.time < - timestamp('2020-10-01T00:00:00.000Z')", - } - } - ] - } - - **YAML Example** - - :: - - bindings: - - members: - - user:mike@example.com - - group:admins@example.com - - domain:google.com - - serviceAccount:my-project-id@appspot.gserviceaccount.com - role: roles/resourcemanager.organizationAdmin - - members: - - user:eve@example.com - role: roles/resourcemanager.organizationViewer - condition: - title: expirable access - description: Does not grant access after Sep 2020 - expression: request.time < timestamp('2020-10-01T00:00:00.000Z') - - For a description of IAM and its features, see the `IAM - developer's - guide `__. + google.iam.v1.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. It is used to + specify access control policies for Cloud Platform + resources. + + A Policy is a collection of bindings. A binding binds + one or more members to a single role. Members can be + user accounts, service accounts, Google groups, and + domains (such as G Suite). A role is a named list of + permissions (defined by IAM or configured by users). + A binding can optionally specify a condition, which + is a logic expression that further constrains the + role binding based on attributes about the request + and/or target resource. + + **JSON Example** + + { + "bindings": [ + { + "role": + "roles/resourcemanager.organizationAdmin", + "members": [ "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + + }, { "role": + "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { "title": "expirable access", + "description": "Does not grant access after + Sep 2020", "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", } } + + ] + + } + + **YAML Example** + + bindings: - members: - user:\ mike@example.com - + group:\ admins@example.com - domain:google.com - + serviceAccount:\ my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin - + members: - user:\ eve@example.com role: + roles/resourcemanager.organizationViewer + condition: title: expirable access description: + Does not grant access after Sep 2020 expression: + request.time < + timestamp('2020-10-01T00:00:00.000Z') + + For a description of IAM and its features, see the + [IAM developer's + guide](\ https://cloud.google.com/iam/docs). """ # Create or coerce a protobuf request object. @@ -1159,7 +1152,7 @@ async def set_iam_policy( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.set_iam_policy, - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -1196,7 +1189,7 @@ async def test_iam_permissions( warning. Args: - request (:class:`~.iam_policy.TestIamPermissionsRequest`): + request (:class:`google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest`): The request object. Request message for `TestIamPermissions` method. resource (:class:`str`): @@ -1204,6 +1197,7 @@ async def test_iam_permissions( policy detail is being requested. See the operation documentation for the appropriate value for this field. + This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1212,6 +1206,7 @@ async def test_iam_permissions( Permissions with wildcards (such as '*' or 'storage.*') are not allowed. For more information see `IAM Overview `__. + This corresponds to the ``permissions`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1223,8 +1218,8 @@ async def test_iam_permissions( sent along with the request as metadata. Returns: - ~.iam_policy.TestIamPermissionsResponse: - Response message for ``TestIamPermissions`` method. + google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: + Response message for TestIamPermissions method. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have @@ -1258,7 +1253,7 @@ async def test_iam_permissions( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -1295,13 +1290,14 @@ async def list_tasks( at any time. Args: - request (:class:`~.cloudtasks.ListTasksRequest`): + request (:class:`google.cloud.tasks_v2beta3.types.ListTasksRequest`): The request object. Request message for listing tasks using [ListTasks][google.cloud.tasks.v2beta3.CloudTasks.ListTasks]. parent (:class:`str`): Required. The queue name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1313,7 +1309,7 @@ async def list_tasks( sent along with the request as metadata. Returns: - ~.pagers.ListTasksAsyncPager: + google.cloud.tasks_v2beta3.services.cloud_tasks.pagers.ListTasksAsyncPager: Response message for listing tasks using [ListTasks][google.cloud.tasks.v2beta3.CloudTasks.ListTasks]. @@ -1351,7 +1347,7 @@ async def list_tasks( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -1385,13 +1381,14 @@ async def get_task( r"""Gets a task. Args: - request (:class:`~.cloudtasks.GetTaskRequest`): + request (:class:`google.cloud.tasks_v2beta3.types.GetTaskRequest`): The request object. Request message for getting a task using [GetTask][google.cloud.tasks.v2beta3.CloudTasks.GetTask]. name (:class:`str`): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1403,7 +1400,7 @@ async def get_task( sent along with the request as metadata. Returns: - ~.task.Task: + google.cloud.tasks_v2beta3.types.Task: A unit of scheduled work. """ # Create or coerce a protobuf request object. @@ -1436,7 +1433,7 @@ async def get_task( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -1470,7 +1467,7 @@ async def create_task( - The maximum task size is 100KB. Args: - request (:class:`~.cloudtasks.CreateTaskRequest`): + request (:class:`google.cloud.tasks_v2beta3.types.CreateTaskRequest`): The request object. Request message for [CreateTask][google.cloud.tasks.v2beta3.CloudTasks.CreateTask]. parent (:class:`str`): @@ -1478,10 +1475,11 @@ async def create_task( ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` The queue must already exist. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - task (:class:`~.gct_task.Task`): + task (:class:`google.cloud.tasks_v2beta3.types.Task`): Required. The task to add. Task names have the following format: @@ -1523,6 +1521,7 @@ async def create_task( task commands. The infrastructure relies on an approximately uniform distribution of task ids to store and serve tasks efficiently. + This corresponds to the ``task`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1534,7 +1533,7 @@ async def create_task( sent along with the request as metadata. Returns: - ~.gct_task.Task: + google.cloud.tasks_v2beta3.types.Task: A unit of scheduled work. """ # Create or coerce a protobuf request object. @@ -1561,7 +1560,7 @@ async def create_task( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_task, - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -1592,13 +1591,14 @@ async def delete_task( or permanently failed. Args: - request (:class:`~.cloudtasks.DeleteTaskRequest`): + request (:class:`google.cloud.tasks_v2beta3.types.DeleteTaskRequest`): The request object. Request message for deleting a task using [DeleteTask][google.cloud.tasks.v2beta3.CloudTasks.DeleteTask]. name (:class:`str`): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1639,7 +1639,7 @@ async def delete_task( exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -1693,13 +1693,14 @@ async def run_task( task that has already succeeded or permanently failed. Args: - request (:class:`~.cloudtasks.RunTaskRequest`): + request (:class:`google.cloud.tasks_v2beta3.types.RunTaskRequest`): The request object. Request message for forcing a task to run now using [RunTask][google.cloud.tasks.v2beta3.CloudTasks.RunTask]. name (:class:`str`): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1711,7 +1712,7 @@ async def run_task( sent along with the request as metadata. Returns: - ~.task.Task: + google.cloud.tasks_v2beta3.types.Task: A unit of scheduled work. """ # Create or coerce a protobuf request object. @@ -1736,7 +1737,7 @@ async def run_task( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.run_task, - default_timeout=10.0, + default_timeout=20.0, client_info=DEFAULT_CLIENT_INFO, ) diff --git a/google/cloud/tasks_v2beta3/services/cloud_tasks/client.py b/google/cloud/tasks_v2beta3/services/cloud_tasks/client.py index c26eb4fa..0dd8eacd 100644 --- a/google/cloud/tasks_v2beta3/services/cloud_tasks/client.py +++ b/google/cloud/tasks_v2beta3/services/cloud_tasks/client.py @@ -120,6 +120,22 @@ def _get_default_mtls_endpoint(api_endpoint): DEFAULT_ENDPOINT ) + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + CloudTasksClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials @@ -132,7 +148,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): kwargs: Additional arguments to pass to the constructor. Returns: - {@api.name}: The constructed client. + CloudTasksClient: The constructed client. """ credentials = service_account.Credentials.from_service_account_file(filename) kwargs["credentials"] = credentials @@ -256,10 +272,10 @@ def __init__( credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - transport (Union[str, ~.CloudTasksTransport]): The + transport (Union[str, CloudTasksTransport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (client_options_lib.ClientOptions): Custom options for the + client_options (google.api_core.client_options.ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -295,21 +311,17 @@ def __init__( util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) ) - ssl_credentials = None + client_cert_source_func = None is_mtls = False if use_client_cert: if client_options.client_cert_source: - import grpc # type: ignore - - cert, key = client_options.client_cert_source() - ssl_credentials = grpc.ssl_channel_credentials( - certificate_chain=cert, private_key=key - ) is_mtls = True + client_cert_source_func = client_options.client_cert_source else: - creds = SslCredentials() - is_mtls = creds.is_mtls - ssl_credentials = creds.ssl_credentials if is_mtls else None + is_mtls = mtls.has_default_client_cert_source() + client_cert_source_func = ( + mtls.default_client_cert_source() if is_mtls else None + ) # Figure out which api endpoint to use. if client_options.api_endpoint is not None: @@ -352,7 +364,7 @@ def __init__( credentials_file=client_options.credentials_file, host=api_endpoint, scopes=client_options.scopes, - ssl_channel_credentials=ssl_credentials, + client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, ) @@ -370,12 +382,13 @@ def list_queues( Queues are returned in lexicographical order. Args: - request (:class:`~.cloudtasks.ListQueuesRequest`): + request (google.cloud.tasks_v2beta3.types.ListQueuesRequest): The request object. Request message for [ListQueues][google.cloud.tasks.v2beta3.CloudTasks.ListQueues]. - parent (:class:`str`): + parent (str): Required. The location name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID`` + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -387,7 +400,7 @@ def list_queues( sent along with the request as metadata. Returns: - ~.pagers.ListQueuesPager: + google.cloud.tasks_v2beta3.services.cloud_tasks.pagers.ListQueuesPager: Response message for [ListQueues][google.cloud.tasks.v2beta3.CloudTasks.ListQueues]. @@ -452,12 +465,13 @@ def get_queue( r"""Gets a queue. Args: - request (:class:`~.cloudtasks.GetQueueRequest`): + request (google.cloud.tasks_v2beta3.types.GetQueueRequest): The request object. Request message for [GetQueue][google.cloud.tasks.v2beta3.CloudTasks.GetQueue]. - name (:class:`str`): + name (str): Required. The resource name of the queue. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -469,7 +483,7 @@ def get_queue( sent along with the request as metadata. Returns: - ~.queue.Queue: + google.cloud.tasks_v2beta3.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -540,10 +554,10 @@ def create_queue( before using this method. Args: - request (:class:`~.cloudtasks.CreateQueueRequest`): + request (google.cloud.tasks_v2beta3.types.CreateQueueRequest): The request object. Request message for [CreateQueue][google.cloud.tasks.v2beta3.CloudTasks.CreateQueue]. - parent (:class:`str`): + parent (str): Required. The location name in which the queue will be created. For example: ``projects/PROJECT_ID/locations/LOCATION_ID`` @@ -551,14 +565,16 @@ def create_queue( The list of allowed locations can be obtained by calling Cloud Tasks' implementation of [ListLocations][google.cloud.location.Locations.ListLocations]. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - queue (:class:`~.gct_queue.Queue`): + queue (google.cloud.tasks_v2beta3.types.Queue): Required. The queue to create. [Queue's name][google.cloud.tasks.v2beta3.Queue.name] cannot be the same as an existing queue. + This corresponds to the ``queue`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -570,7 +586,7 @@ def create_queue( sent along with the request as metadata. Returns: - ~.gct_queue.Queue: + google.cloud.tasks_v2beta3.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -646,10 +662,10 @@ def update_queue( before using this method. Args: - request (:class:`~.cloudtasks.UpdateQueueRequest`): + request (google.cloud.tasks_v2beta3.types.UpdateQueueRequest): The request object. Request message for [UpdateQueue][google.cloud.tasks.v2beta3.CloudTasks.UpdateQueue]. - queue (:class:`~.gct_queue.Queue`): + queue (google.cloud.tasks_v2beta3.types.Queue): Required. The queue to create or update. The queue's @@ -661,14 +677,16 @@ def update_queue( ignored. The queue's [name][google.cloud.tasks.v2beta3.Queue.name] cannot be changed. + This corresponds to the ``queue`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - update_mask (:class:`~.field_mask.FieldMask`): + update_mask (google.protobuf.field_mask_pb2.FieldMask): A mask used to specify which fields of the queue are being updated. If empty, then all fields will be updated. + This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -680,7 +698,7 @@ def update_queue( sent along with the request as metadata. Returns: - ~.gct_queue.Queue: + google.cloud.tasks_v2beta3.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -755,12 +773,13 @@ def delete_queue( before using this method. Args: - request (:class:`~.cloudtasks.DeleteQueueRequest`): + request (google.cloud.tasks_v2beta3.types.DeleteQueueRequest): The request object. Request message for [DeleteQueue][google.cloud.tasks.v2beta3.CloudTasks.DeleteQueue]. - name (:class:`str`): + name (str): Required. The queue name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -826,12 +845,13 @@ def purge_queue( effect. A purge is irreversible. Args: - request (:class:`~.cloudtasks.PurgeQueueRequest`): + request (google.cloud.tasks_v2beta3.types.PurgeQueueRequest): The request object. Request message for [PurgeQueue][google.cloud.tasks.v2beta3.CloudTasks.PurgeQueue]. - name (:class:`str`): + name (str): Required. The queue name. For example: ``projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -843,7 +863,7 @@ def purge_queue( sent along with the request as metadata. Returns: - ~.queue.Queue: + google.cloud.tasks_v2beta3.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -910,12 +930,13 @@ def pause_queue( [PAUSED][google.cloud.tasks.v2beta3.Queue.State.PAUSED]. Args: - request (:class:`~.cloudtasks.PauseQueueRequest`): + request (google.cloud.tasks_v2beta3.types.PauseQueueRequest): The request object. Request message for [PauseQueue][google.cloud.tasks.v2beta3.CloudTasks.PauseQueue]. - name (:class:`str`): + name (str): Required. The queue name. For example: ``projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -927,7 +948,7 @@ def pause_queue( sent along with the request as metadata. Returns: - ~.queue.Queue: + google.cloud.tasks_v2beta3.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -1001,12 +1022,13 @@ def resume_queue( Risks `__. Args: - request (:class:`~.cloudtasks.ResumeQueueRequest`): + request (google.cloud.tasks_v2beta3.types.ResumeQueueRequest): The request object. Request message for [ResumeQueue][google.cloud.tasks.v2beta3.CloudTasks.ResumeQueue]. - name (:class:`str`): + name (str): Required. The queue name. For example: ``projects/PROJECT_ID/location/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1018,7 +1040,7 @@ def resume_queue( sent along with the request as metadata. Returns: - ~.queue.Queue: + google.cloud.tasks_v2beta3.types.Queue: A queue is a container of related tasks. Queues are configured to manage how those tasks are dispatched. @@ -1086,14 +1108,15 @@ def get_iam_policy( - ``cloudtasks.queues.getIamPolicy`` Args: - request (:class:`~.iam_policy.GetIamPolicyRequest`): + request (google.iam.v1.iam_policy_pb2.GetIamPolicyRequest): The request object. Request message for `GetIamPolicy` method. - resource (:class:`str`): + resource (str): REQUIRED: The resource for which the policy is being requested. See the operation documentation for the appropriate value for this field. + This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1105,72 +1128,62 @@ def get_iam_policy( sent along with the request as metadata. Returns: - ~.policy.Policy: - Defines an Identity and Access Management (IAM) policy. - It is used to specify access control policies for Cloud - Platform resources. - - A ``Policy`` is a collection of ``bindings``. A - ``binding`` binds one or more ``members`` to a single - ``role``. Members can be user accounts, service - accounts, Google groups, and domains (such as G Suite). - A ``role`` is a named list of permissions (defined by - IAM or configured by users). A ``binding`` can - optionally specify a ``condition``, which is a logic - expression that further constrains the role binding - based on attributes about the request and/or target - resource. - - **JSON Example** - - :: - - { - "bindings": [ - { - "role": "roles/resourcemanager.organizationAdmin", - "members": [ - "user:mike@example.com", - "group:admins@example.com", - "domain:google.com", - "serviceAccount:my-project-id@appspot.gserviceaccount.com" - ] - }, - { - "role": "roles/resourcemanager.organizationViewer", - "members": ["user:eve@example.com"], - "condition": { - "title": "expirable access", - "description": "Does not grant access after Sep 2020", - "expression": "request.time < - timestamp('2020-10-01T00:00:00.000Z')", - } - } - ] - } - - **YAML Example** - - :: - - bindings: - - members: - - user:mike@example.com - - group:admins@example.com - - domain:google.com - - serviceAccount:my-project-id@appspot.gserviceaccount.com - role: roles/resourcemanager.organizationAdmin - - members: - - user:eve@example.com - role: roles/resourcemanager.organizationViewer - condition: - title: expirable access - description: Does not grant access after Sep 2020 - expression: request.time < timestamp('2020-10-01T00:00:00.000Z') - - For a description of IAM and its features, see the `IAM - developer's - guide `__. + google.iam.v1.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. It is used to + specify access control policies for Cloud Platform + resources. + + A Policy is a collection of bindings. A binding binds + one or more members to a single role. Members can be + user accounts, service accounts, Google groups, and + domains (such as G Suite). A role is a named list of + permissions (defined by IAM or configured by users). + A binding can optionally specify a condition, which + is a logic expression that further constrains the + role binding based on attributes about the request + and/or target resource. + + **JSON Example** + + { + "bindings": [ + { + "role": + "roles/resourcemanager.organizationAdmin", + "members": [ "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + + }, { "role": + "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { "title": "expirable access", + "description": "Does not grant access after + Sep 2020", "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", } } + + ] + + } + + **YAML Example** + + bindings: - members: - user:\ mike@example.com - + group:\ admins@example.com - domain:google.com - + serviceAccount:\ my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin - + members: - user:\ eve@example.com role: + roles/resourcemanager.organizationViewer + condition: title: expirable access description: + Does not grant access after Sep 2020 expression: + request.time < + timestamp('2020-10-01T00:00:00.000Z') + + For a description of IAM and its features, see the + [IAM developer's + guide](\ https://cloud.google.com/iam/docs). """ # Create or coerce a protobuf request object. @@ -1191,6 +1204,9 @@ def get_iam_policy( elif not request: request = iam_policy.GetIamPolicyRequest(resource=resource,) + if resource is not None: + request.resource = resource + # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_iam_policy] @@ -1231,14 +1247,15 @@ def set_iam_policy( - ``cloudtasks.queues.setIamPolicy`` Args: - request (:class:`~.iam_policy.SetIamPolicyRequest`): + request (google.iam.v1.iam_policy_pb2.SetIamPolicyRequest): The request object. Request message for `SetIamPolicy` method. - resource (:class:`str`): + resource (str): REQUIRED: The resource for which the policy is being specified. See the operation documentation for the appropriate value for this field. + This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1250,72 +1267,62 @@ def set_iam_policy( sent along with the request as metadata. Returns: - ~.policy.Policy: - Defines an Identity and Access Management (IAM) policy. - It is used to specify access control policies for Cloud - Platform resources. - - A ``Policy`` is a collection of ``bindings``. A - ``binding`` binds one or more ``members`` to a single - ``role``. Members can be user accounts, service - accounts, Google groups, and domains (such as G Suite). - A ``role`` is a named list of permissions (defined by - IAM or configured by users). A ``binding`` can - optionally specify a ``condition``, which is a logic - expression that further constrains the role binding - based on attributes about the request and/or target - resource. - - **JSON Example** - - :: - - { - "bindings": [ - { - "role": "roles/resourcemanager.organizationAdmin", - "members": [ - "user:mike@example.com", - "group:admins@example.com", - "domain:google.com", - "serviceAccount:my-project-id@appspot.gserviceaccount.com" - ] - }, - { - "role": "roles/resourcemanager.organizationViewer", - "members": ["user:eve@example.com"], - "condition": { - "title": "expirable access", - "description": "Does not grant access after Sep 2020", - "expression": "request.time < - timestamp('2020-10-01T00:00:00.000Z')", - } - } - ] - } - - **YAML Example** - - :: - - bindings: - - members: - - user:mike@example.com - - group:admins@example.com - - domain:google.com - - serviceAccount:my-project-id@appspot.gserviceaccount.com - role: roles/resourcemanager.organizationAdmin - - members: - - user:eve@example.com - role: roles/resourcemanager.organizationViewer - condition: - title: expirable access - description: Does not grant access after Sep 2020 - expression: request.time < timestamp('2020-10-01T00:00:00.000Z') - - For a description of IAM and its features, see the `IAM - developer's - guide `__. + google.iam.v1.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. It is used to + specify access control policies for Cloud Platform + resources. + + A Policy is a collection of bindings. A binding binds + one or more members to a single role. Members can be + user accounts, service accounts, Google groups, and + domains (such as G Suite). A role is a named list of + permissions (defined by IAM or configured by users). + A binding can optionally specify a condition, which + is a logic expression that further constrains the + role binding based on attributes about the request + and/or target resource. + + **JSON Example** + + { + "bindings": [ + { + "role": + "roles/resourcemanager.organizationAdmin", + "members": [ "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + + }, { "role": + "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { "title": "expirable access", + "description": "Does not grant access after + Sep 2020", "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", } } + + ] + + } + + **YAML Example** + + bindings: - members: - user:\ mike@example.com - + group:\ admins@example.com - domain:google.com - + serviceAccount:\ my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin - + members: - user:\ eve@example.com role: + roles/resourcemanager.organizationViewer + condition: title: expirable access description: + Does not grant access after Sep 2020 expression: + request.time < + timestamp('2020-10-01T00:00:00.000Z') + + For a description of IAM and its features, see the + [IAM developer's + guide](\ https://cloud.google.com/iam/docs). """ # Create or coerce a protobuf request object. @@ -1336,6 +1343,9 @@ def set_iam_policy( elif not request: request = iam_policy.SetIamPolicyRequest(resource=resource,) + if resource is not None: + request.resource = resource + # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.set_iam_policy] @@ -1373,22 +1383,24 @@ def test_iam_permissions( warning. Args: - request (:class:`~.iam_policy.TestIamPermissionsRequest`): + request (google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest): The request object. Request message for `TestIamPermissions` method. - resource (:class:`str`): + resource (str): REQUIRED: The resource for which the policy detail is being requested. See the operation documentation for the appropriate value for this field. + This corresponds to the ``resource`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - permissions (:class:`Sequence[str]`): + permissions (Sequence[str]): The set of permissions to check for the ``resource``. Permissions with wildcards (such as '*' or 'storage.*') are not allowed. For more information see `IAM Overview `__. + This corresponds to the ``permissions`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1400,8 +1412,8 @@ def test_iam_permissions( sent along with the request as metadata. Returns: - ~.iam_policy.TestIamPermissionsResponse: - Response message for ``TestIamPermissions`` method. + google.iam.v1.iam_policy_pb2.TestIamPermissionsResponse: + Response message for TestIamPermissions method. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have @@ -1423,6 +1435,9 @@ def test_iam_permissions( resource=resource, permissions=permissions, ) + if resource is not None: + request.resource = resource + # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.test_iam_permissions] @@ -1460,13 +1475,14 @@ def list_tasks( at any time. Args: - request (:class:`~.cloudtasks.ListTasksRequest`): + request (google.cloud.tasks_v2beta3.types.ListTasksRequest): The request object. Request message for listing tasks using [ListTasks][google.cloud.tasks.v2beta3.CloudTasks.ListTasks]. - parent (:class:`str`): + parent (str): Required. The queue name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1478,7 +1494,7 @@ def list_tasks( sent along with the request as metadata. Returns: - ~.pagers.ListTasksPager: + google.cloud.tasks_v2beta3.services.cloud_tasks.pagers.ListTasksPager: Response message for listing tasks using [ListTasks][google.cloud.tasks.v2beta3.CloudTasks.ListTasks]. @@ -1543,13 +1559,14 @@ def get_task( r"""Gets a task. Args: - request (:class:`~.cloudtasks.GetTaskRequest`): + request (google.cloud.tasks_v2beta3.types.GetTaskRequest): The request object. Request message for getting a task using [GetTask][google.cloud.tasks.v2beta3.CloudTasks.GetTask]. - name (:class:`str`): + name (str): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1561,7 +1578,7 @@ def get_task( sent along with the request as metadata. Returns: - ~.task.Task: + google.cloud.tasks_v2beta3.types.Task: A unit of scheduled work. """ # Create or coerce a protobuf request object. @@ -1621,18 +1638,19 @@ def create_task( - The maximum task size is 100KB. Args: - request (:class:`~.cloudtasks.CreateTaskRequest`): + request (google.cloud.tasks_v2beta3.types.CreateTaskRequest): The request object. Request message for [CreateTask][google.cloud.tasks.v2beta3.CloudTasks.CreateTask]. - parent (:class:`str`): + parent (str): Required. The queue name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` The queue must already exist. + This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - task (:class:`~.gct_task.Task`): + task (google.cloud.tasks_v2beta3.types.Task): Required. The task to add. Task names have the following format: @@ -1674,6 +1692,7 @@ def create_task( task commands. The infrastructure relies on an approximately uniform distribution of task ids to store and serve tasks efficiently. + This corresponds to the ``task`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1685,7 +1704,7 @@ def create_task( sent along with the request as metadata. Returns: - ~.gct_task.Task: + google.cloud.tasks_v2beta3.types.Task: A unit of scheduled work. """ # Create or coerce a protobuf request object. @@ -1744,13 +1763,14 @@ def delete_task( or permanently failed. Args: - request (:class:`~.cloudtasks.DeleteTaskRequest`): + request (google.cloud.tasks_v2beta3.types.DeleteTaskRequest): The request object. Request message for deleting a task using [DeleteTask][google.cloud.tasks.v2beta3.CloudTasks.DeleteTask]. - name (:class:`str`): + name (str): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1838,13 +1858,14 @@ def run_task( task that has already succeeded or permanently failed. Args: - request (:class:`~.cloudtasks.RunTaskRequest`): + request (google.cloud.tasks_v2beta3.types.RunTaskRequest): The request object. Request message for forcing a task to run now using [RunTask][google.cloud.tasks.v2beta3.CloudTasks.RunTask]. - name (:class:`str`): + name (str): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -1856,7 +1877,7 @@ def run_task( sent along with the request as metadata. Returns: - ~.task.Task: + google.cloud.tasks_v2beta3.types.Task: A unit of scheduled work. """ # Create or coerce a protobuf request object. diff --git a/google/cloud/tasks_v2beta3/services/cloud_tasks/pagers.py b/google/cloud/tasks_v2beta3/services/cloud_tasks/pagers.py index 1f0f543f..eeb07fe4 100644 --- a/google/cloud/tasks_v2beta3/services/cloud_tasks/pagers.py +++ b/google/cloud/tasks_v2beta3/services/cloud_tasks/pagers.py @@ -15,7 +15,16 @@ # limitations under the License. # -from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple +from typing import ( + Any, + AsyncIterable, + Awaitable, + Callable, + Iterable, + Sequence, + Tuple, + Optional, +) from google.cloud.tasks_v2beta3.types import cloudtasks from google.cloud.tasks_v2beta3.types import queue @@ -26,7 +35,7 @@ class ListQueuesPager: """A pager for iterating through ``list_queues`` requests. This class thinly wraps an initial - :class:`~.cloudtasks.ListQueuesResponse` object, and + :class:`google.cloud.tasks_v2beta3.types.ListQueuesResponse` object, and provides an ``__iter__`` method to iterate through its ``queues`` field. @@ -35,7 +44,7 @@ class ListQueuesPager: through the ``queues`` field on the corresponding responses. - All the usual :class:`~.cloudtasks.ListQueuesResponse` + All the usual :class:`google.cloud.tasks_v2beta3.types.ListQueuesResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -53,9 +62,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.cloudtasks.ListQueuesRequest`): + request (google.cloud.tasks_v2beta3.types.ListQueuesRequest): The initial request object. - response (:class:`~.cloudtasks.ListQueuesResponse`): + response (google.cloud.tasks_v2beta3.types.ListQueuesResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -88,7 +97,7 @@ class ListQueuesAsyncPager: """A pager for iterating through ``list_queues`` requests. This class thinly wraps an initial - :class:`~.cloudtasks.ListQueuesResponse` object, and + :class:`google.cloud.tasks_v2beta3.types.ListQueuesResponse` object, and provides an ``__aiter__`` method to iterate through its ``queues`` field. @@ -97,7 +106,7 @@ class ListQueuesAsyncPager: through the ``queues`` field on the corresponding responses. - All the usual :class:`~.cloudtasks.ListQueuesResponse` + All the usual :class:`google.cloud.tasks_v2beta3.types.ListQueuesResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -115,9 +124,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.cloudtasks.ListQueuesRequest`): + request (google.cloud.tasks_v2beta3.types.ListQueuesRequest): The initial request object. - response (:class:`~.cloudtasks.ListQueuesResponse`): + response (google.cloud.tasks_v2beta3.types.ListQueuesResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -154,7 +163,7 @@ class ListTasksPager: """A pager for iterating through ``list_tasks`` requests. This class thinly wraps an initial - :class:`~.cloudtasks.ListTasksResponse` object, and + :class:`google.cloud.tasks_v2beta3.types.ListTasksResponse` object, and provides an ``__iter__`` method to iterate through its ``tasks`` field. @@ -163,7 +172,7 @@ class ListTasksPager: through the ``tasks`` field on the corresponding responses. - All the usual :class:`~.cloudtasks.ListTasksResponse` + All the usual :class:`google.cloud.tasks_v2beta3.types.ListTasksResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -181,9 +190,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.cloudtasks.ListTasksRequest`): + request (google.cloud.tasks_v2beta3.types.ListTasksRequest): The initial request object. - response (:class:`~.cloudtasks.ListTasksResponse`): + response (google.cloud.tasks_v2beta3.types.ListTasksResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. @@ -216,7 +225,7 @@ class ListTasksAsyncPager: """A pager for iterating through ``list_tasks`` requests. This class thinly wraps an initial - :class:`~.cloudtasks.ListTasksResponse` object, and + :class:`google.cloud.tasks_v2beta3.types.ListTasksResponse` object, and provides an ``__aiter__`` method to iterate through its ``tasks`` field. @@ -225,7 +234,7 @@ class ListTasksAsyncPager: through the ``tasks`` field on the corresponding responses. - All the usual :class:`~.cloudtasks.ListTasksResponse` + All the usual :class:`google.cloud.tasks_v2beta3.types.ListTasksResponse` attributes are available on the pager. If multiple requests are made, only the most recent response is retained, and thus used for attribute lookup. """ @@ -243,9 +252,9 @@ def __init__( Args: method (Callable): The method that was originally called, and which instantiated this pager. - request (:class:`~.cloudtasks.ListTasksRequest`): + request (google.cloud.tasks_v2beta3.types.ListTasksRequest): The initial request object. - response (:class:`~.cloudtasks.ListTasksResponse`): + response (google.cloud.tasks_v2beta3.types.ListTasksResponse): The initial response object. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. diff --git a/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/base.py b/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/base.py index 6a16a22d..d5c25b51 100644 --- a/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/base.py +++ b/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/base.py @@ -121,7 +121,7 @@ def _prep_wrapped_messages(self, client_info): exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=client_info, ), self.get_queue: gapic_v1.method.wrap_method( @@ -134,14 +134,14 @@ def _prep_wrapped_messages(self, client_info): exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=client_info, ), self.create_queue: gapic_v1.method.wrap_method( - self.create_queue, default_timeout=10.0, client_info=client_info, + self.create_queue, default_timeout=20.0, client_info=client_info, ), self.update_queue: gapic_v1.method.wrap_method( - self.update_queue, default_timeout=10.0, client_info=client_info, + self.update_queue, default_timeout=20.0, client_info=client_info, ), self.delete_queue: gapic_v1.method.wrap_method( self.delete_queue, @@ -153,17 +153,17 @@ def _prep_wrapped_messages(self, client_info): exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=client_info, ), self.purge_queue: gapic_v1.method.wrap_method( - self.purge_queue, default_timeout=10.0, client_info=client_info, + self.purge_queue, default_timeout=20.0, client_info=client_info, ), self.pause_queue: gapic_v1.method.wrap_method( - self.pause_queue, default_timeout=10.0, client_info=client_info, + self.pause_queue, default_timeout=20.0, client_info=client_info, ), self.resume_queue: gapic_v1.method.wrap_method( - self.resume_queue, default_timeout=10.0, client_info=client_info, + self.resume_queue, default_timeout=20.0, client_info=client_info, ), self.get_iam_policy: gapic_v1.method.wrap_method( self.get_iam_policy, @@ -175,11 +175,11 @@ def _prep_wrapped_messages(self, client_info): exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=client_info, ), self.set_iam_policy: gapic_v1.method.wrap_method( - self.set_iam_policy, default_timeout=10.0, client_info=client_info, + self.set_iam_policy, default_timeout=20.0, client_info=client_info, ), self.test_iam_permissions: gapic_v1.method.wrap_method( self.test_iam_permissions, @@ -191,7 +191,7 @@ def _prep_wrapped_messages(self, client_info): exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=client_info, ), self.list_tasks: gapic_v1.method.wrap_method( @@ -204,7 +204,7 @@ def _prep_wrapped_messages(self, client_info): exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=client_info, ), self.get_task: gapic_v1.method.wrap_method( @@ -217,11 +217,11 @@ def _prep_wrapped_messages(self, client_info): exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=client_info, ), self.create_task: gapic_v1.method.wrap_method( - self.create_task, default_timeout=10.0, client_info=client_info, + self.create_task, default_timeout=20.0, client_info=client_info, ), self.delete_task: gapic_v1.method.wrap_method( self.delete_task, @@ -233,11 +233,11 @@ def _prep_wrapped_messages(self, client_info): exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, ), ), - default_timeout=10.0, + default_timeout=20.0, client_info=client_info, ), self.run_task: gapic_v1.method.wrap_method( - self.run_task, default_timeout=10.0, client_info=client_info, + self.run_task, default_timeout=20.0, client_info=client_info, ), } diff --git a/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/grpc.py b/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/grpc.py index af80f7c1..fe4b8a2b 100644 --- a/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/grpc.py +++ b/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/grpc.py @@ -65,6 +65,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -95,6 +96,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -111,6 +116,11 @@ def __init__( """ self._ssl_channel_credentials = ssl_channel_credentials + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -120,11 +130,6 @@ def __init__( self._grpc_channel = channel self._ssl_channel_credentials = None elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -168,12 +173,18 @@ def __init__( scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id ) + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + # create a new channel. The provided one is ignored. self._grpc_channel = type(self).create_channel( host, credentials=credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, + ssl_credentials=self._ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ diff --git a/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/grpc_asyncio.py b/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/grpc_asyncio.py index a3e5247b..8b5c85db 100644 --- a/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/grpc_asyncio.py +++ b/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/grpc_asyncio.py @@ -109,6 +109,7 @@ def __init__( api_mtls_endpoint: str = None, client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: @@ -140,6 +141,10 @@ def __init__( ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials for grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. client_info (google.api_core.gapic_v1.client_info.ClientInfo): @@ -156,6 +161,11 @@ def __init__( """ self._ssl_channel_credentials = ssl_channel_credentials + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -165,11 +175,6 @@ def __init__( self._grpc_channel = channel self._ssl_channel_credentials = None elif api_mtls_endpoint: - warnings.warn( - "api_mtls_endpoint and client_cert_source are deprecated", - DeprecationWarning, - ) - host = ( api_mtls_endpoint if ":" in api_mtls_endpoint @@ -213,12 +218,18 @@ def __init__( scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id ) + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + # create a new channel. The provided one is ignored. self._grpc_channel = type(self).create_channel( host, credentials=credentials, credentials_file=credentials_file, - ssl_credentials=ssl_channel_credentials, + ssl_credentials=self._ssl_channel_credentials, scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, options=[ diff --git a/google/cloud/tasks_v2beta3/types/__init__.py b/google/cloud/tasks_v2beta3/types/__init__.py index 9c2b2f3c..1e26bdf8 100644 --- a/google/cloud/tasks_v2beta3/types/__init__.py +++ b/google/cloud/tasks_v2beta3/types/__init__.py @@ -16,6 +16,7 @@ # from .target import ( + PullMessage, HttpRequest, AppEngineHttpQueue, AppEngineHttpRequest, @@ -29,6 +30,7 @@ RateLimits, RetryConfig, StackdriverLoggingConfig, + QueueStats, ) from .task import ( Task, @@ -53,6 +55,7 @@ ) __all__ = ( + "PullMessage", "HttpRequest", "AppEngineHttpQueue", "AppEngineHttpRequest", @@ -64,6 +67,7 @@ "RateLimits", "RetryConfig", "StackdriverLoggingConfig", + "QueueStats", "Task", "Attempt", "ListQueuesRequest", diff --git a/google/cloud/tasks_v2beta3/types/cloudtasks.py b/google/cloud/tasks_v2beta3/types/cloudtasks.py index e469298c..ec659ea1 100644 --- a/google/cloud/tasks_v2beta3/types/cloudtasks.py +++ b/google/cloud/tasks_v2beta3/types/cloudtasks.py @@ -85,6 +85,11 @@ class ListQueuesRequest(proto.Message): method. It is an error to switch the value of the [filter][google.cloud.tasks.v2beta3.ListQueuesRequest.filter] while iterating through pages. + read_mask (google.protobuf.field_mask_pb2.FieldMask): + Optional. Read mask is used for a more granular control over + what the API returns. If the mask is not present all fields + will be returned except [Queue.stats]. [Queue.stats] will be + returned only if it was explicitly specified in the mask. """ parent = proto.Field(proto.STRING, number=1) @@ -95,13 +100,15 @@ class ListQueuesRequest(proto.Message): page_token = proto.Field(proto.STRING, number=4) + read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask.FieldMask,) + class ListQueuesResponse(proto.Message): r"""Response message for [ListQueues][google.cloud.tasks.v2beta3.CloudTasks.ListQueues]. Attributes: - queues (Sequence[~.gct_queue.Queue]): + queues (Sequence[google.cloud.tasks_v2beta3.types.Queue]): The list of queues. next_page_token (str): A token to retrieve next page of results. @@ -133,10 +140,17 @@ class GetQueueRequest(proto.Message): name (str): Required. The resource name of the queue. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` + read_mask (google.protobuf.field_mask_pb2.FieldMask): + Optional. Read mask is used for a more granular control over + what the API returns. If the mask is not present all fields + will be returned except [Queue.stats]. [Queue.stats] will be + returned only if it was explicitly specified in the mask. """ name = proto.Field(proto.STRING, number=1) + read_mask = proto.Field(proto.MESSAGE, number=2, message=field_mask.FieldMask,) + class CreateQueueRequest(proto.Message): r"""Request message for @@ -151,7 +165,7 @@ class CreateQueueRequest(proto.Message): The list of allowed locations can be obtained by calling Cloud Tasks' implementation of [ListLocations][google.cloud.location.Locations.ListLocations]. - queue (~.gct_queue.Queue): + queue (google.cloud.tasks_v2beta3.types.Queue): Required. The queue to create. [Queue's name][google.cloud.tasks.v2beta3.Queue.name] cannot @@ -168,7 +182,7 @@ class UpdateQueueRequest(proto.Message): [UpdateQueue][google.cloud.tasks.v2beta3.CloudTasks.UpdateQueue]. Attributes: - queue (~.gct_queue.Queue): + queue (google.cloud.tasks_v2beta3.types.Queue): Required. The queue to create or update. The queue's [name][google.cloud.tasks.v2beta3.Queue.name] @@ -178,7 +192,7 @@ class UpdateQueueRequest(proto.Message): value specified for an output only field will be ignored. The queue's [name][google.cloud.tasks.v2beta3.Queue.name] cannot be changed. - update_mask (~.field_mask.FieldMask): + update_mask (google.protobuf.field_mask_pb2.FieldMask): A mask used to specify which fields of the queue are being updated. If empty, then all fields will be updated. @@ -249,7 +263,7 @@ class ListTasksRequest(proto.Message): parent (str): Required. The queue name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` - response_view (~.gct_task.Task.View): + response_view (google.cloud.tasks_v2beta3.types.Task.View): The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta3.Task] will be returned. @@ -303,7 +317,7 @@ class ListTasksResponse(proto.Message): [ListTasks][google.cloud.tasks.v2beta3.CloudTasks.ListTasks]. Attributes: - tasks (Sequence[~.gct_task.Task]): + tasks (Sequence[google.cloud.tasks_v2beta3.types.Task]): The list of tasks. next_page_token (str): A token to retrieve next page of results. @@ -333,7 +347,7 @@ class GetTaskRequest(proto.Message): name (str): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` - response_view (~.gct_task.Task.View): + response_view (google.cloud.tasks_v2beta3.types.Task.View): The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta3.Task] will be returned. @@ -366,7 +380,7 @@ class CreateTaskRequest(proto.Message): ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID`` The queue must already exist. - task (~.gct_task.Task): + task (google.cloud.tasks_v2beta3.types.Task): Required. The task to add. Task names have the following format: @@ -407,7 +421,7 @@ class CreateTaskRequest(proto.Message): The infrastructure relies on an approximately uniform distribution of task ids to store and serve tasks efficiently. - response_view (~.gct_task.Task.View): + response_view (google.cloud.tasks_v2beta3.types.Task.View): The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta3.Task] will be returned. @@ -453,7 +467,7 @@ class RunTaskRequest(proto.Message): name (str): Required. The task name. For example: ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`` - response_view (~.gct_task.Task.View): + response_view (google.cloud.tasks_v2beta3.types.Task.View): The response_view specifies which subset of the [Task][google.cloud.tasks.v2beta3.Task] will be returned. diff --git a/google/cloud/tasks_v2beta3/types/queue.py b/google/cloud/tasks_v2beta3/types/queue.py index 4da1b48d..13e9fc82 100644 --- a/google/cloud/tasks_v2beta3/types/queue.py +++ b/google/cloud/tasks_v2beta3/types/queue.py @@ -25,7 +25,13 @@ __protobuf__ = proto.module( package="google.cloud.tasks.v2beta3", - manifest={"Queue", "RateLimits", "RetryConfig", "StackdriverLoggingConfig",}, + manifest={ + "Queue", + "RateLimits", + "RetryConfig", + "StackdriverLoggingConfig", + "QueueStats", + }, ) @@ -59,14 +65,14 @@ class Queue(proto.Message): - ``QUEUE_ID`` can contain letters ([A-Za-z]), numbers ([0-9]), or hyphens (-). The maximum length is 100 characters. - app_engine_http_queue (~.target.AppEngineHttpQueue): + app_engine_http_queue (google.cloud.tasks_v2beta3.types.AppEngineHttpQueue): [AppEngineHttpQueue][google.cloud.tasks.v2beta3.AppEngineHttpQueue] settings apply only to [App Engine tasks][google.cloud.tasks.v2beta3.AppEngineHttpRequest] in this queue. [Http tasks][google.cloud.tasks.v2beta3.HttpRequest] are not affected by this proto. - rate_limits (~.queue.RateLimits): + rate_limits (google.cloud.tasks_v2beta3.types.RateLimits): Rate limits for task dispatches. [rate_limits][google.cloud.tasks.v2beta3.Queue.rate_limits] @@ -98,7 +104,7 @@ class Queue(proto.Message): ``503`` (Service Unavailable) responses from the worker, high error rates, or to smooth sudden large traffic spikes. - retry_config (~.queue.RetryConfig): + retry_config (google.cloud.tasks_v2beta3.types.RetryConfig): Settings that determine the retry behavior. - For tasks created using Cloud Tasks: the queue-level @@ -111,7 +117,7 @@ class Queue(proto.Message): the task and were created by the App Engine SDK. See `App Engine documentation `__. - state (~.queue.Queue.State): + state (google.cloud.tasks_v2beta3.types.Queue.State): Output only. The state of the queue. ``state`` can only be changed by called @@ -121,7 +127,7 @@ class Queue(proto.Message): `queue.yaml/xml `__. [UpdateQueue][google.cloud.tasks.v2beta3.CloudTasks.UpdateQueue] cannot be used to change ``state``. - purge_time (~.timestamp.Timestamp): + purge_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The last time this queue was purged. All tasks that were @@ -135,16 +141,49 @@ class Queue(proto.Message): Purge time will be truncated to the nearest microsecond. Purge time will be unset if the queue has never been purged. - stackdriver_logging_config (~.queue.StackdriverLoggingConfig): + task_ttl (google.protobuf.duration_pb2.Duration): + The maximum amount of time that a task will be retained in + this queue. + + Queues created by Cloud Tasks have a default ``task_ttl`` of + 31 days. After a task has lived for ``task_ttl``, the task + will be deleted regardless of whether it was dispatched or + not. + + The ``task_ttl`` for queues created via queue.yaml/xml is + equal to the maximum duration because there is a `storage + quota `__ + for these queues. To view the maximum valid duration, see + the documentation for [Duration][google.protobuf.Duration]. + tombstone_ttl (google.protobuf.duration_pb2.Duration): + The task tombstone time to live (TTL). + + After a task is deleted or executed, the task's tombstone is + retained for the length of time specified by + ``tombstone_ttl``. The tombstone is used by task + de-duplication; another task with the same name can't be + created until the tombstone has expired. For more + information about task de-duplication, see the documentation + for + [CreateTaskRequest][google.cloud.tasks.v2beta3.CreateTaskRequest.task]. + + Queues created by Cloud Tasks have a default + ``tombstone_ttl`` of 1 hour. + stackdriver_logging_config (google.cloud.tasks_v2beta3.types.StackdriverLoggingConfig): Configuration options for writing logs to `Stackdriver Logging `__. If this field is unset, then no logs are written. - type_ (~.queue.Queue.Type): + type_ (google.cloud.tasks_v2beta3.types.Queue.Type): Immutable. The type of a queue (push or pull). ``Queue.type`` is an immutable property of the queue that is set at the queue creation time. When left unspecified, the default value of ``PUSH`` is selected. + stats (google.cloud.tasks_v2beta3.types.QueueStats): + Output only. The realtime, informational + statistics for a queue. In order to receive the + statistics the caller should include this field + in the FieldMask. """ class State(proto.Enum): @@ -174,12 +213,18 @@ class Type(proto.Enum): purge_time = proto.Field(proto.MESSAGE, number=7, message=timestamp.Timestamp,) + task_ttl = proto.Field(proto.MESSAGE, number=8, message=duration.Duration,) + + tombstone_ttl = proto.Field(proto.MESSAGE, number=9, message=duration.Duration,) + stackdriver_logging_config = proto.Field( proto.MESSAGE, number=10, message="StackdriverLoggingConfig", ) type_ = proto.Field(proto.ENUM, number=11, enum=Type,) + stats = proto.Field(proto.MESSAGE, number=12, message="QueueStats",) + class RateLimits(proto.Message): r"""Rate limits. @@ -208,7 +253,7 @@ class RateLimits(proto.Message): This field has the same meaning as `rate in queue.yaml/xml `__. max_burst_size (int): - Output only. The max burst size. + The max burst size. Max burst size limits how fast tasks in queue are processed when many tasks are in the queue and the rate is high. This @@ -228,21 +273,23 @@ class RateLimits(proto.Message): based on [max_dispatches_per_second][google.cloud.tasks.v2beta3.RateLimits.max_dispatches_per_second]. - Cloud Tasks will pick the value of ``max_burst_size`` based - on the value of + The default value of ``max_burst_size`` is picked by Cloud + Tasks based on the value of [max_dispatches_per_second][google.cloud.tasks.v2beta3.RateLimits.max_dispatches_per_second]. + The maximum value of ``max_burst_size`` is 500. + For App Engine queues that were created or updated using ``queue.yaml/xml``, ``max_burst_size`` is equal to `bucket_size `__. - Since ``max_burst_size`` is output only, if + If + [UpdateQueue][google.cloud.tasks.v2beta3.CloudTasks.UpdateQueue] + is called on a queue without explicitly setting a value for + ``max_burst_size``, ``max_burst_size`` value will get + updated if [UpdateQueue][google.cloud.tasks.v2beta3.CloudTasks.UpdateQueue] - is called on a queue created by ``queue.yaml/xml``, - ``max_burst_size`` will be reset based on the value of - [max_dispatches_per_second][google.cloud.tasks.v2beta3.RateLimits.max_dispatches_per_second], - regardless of whether - [max_dispatches_per_second][google.cloud.tasks.v2beta3.RateLimits.max_dispatches_per_second] - is updated. + is updating + [max_dispatches_per_second][google.cloud.tasks.v2beta3.RateLimits.max_dispatches_per_second]. max_concurrent_dispatches (int): The maximum number of concurrent tasks that Cloud Tasks allows to be dispatched for this queue. After this threshold @@ -285,7 +332,7 @@ class RetryConfig(proto.Message): This field has the same meaning as `task_retry_limit in queue.yaml/xml `__. - max_retry_duration (~.duration.Duration): + max_retry_duration (google.protobuf.duration_pb2.Duration): If positive, ``max_retry_duration`` specifies the time limit for retrying a failed task, measured from when the task was first attempted. Once ``max_retry_duration`` time has passed @@ -304,7 +351,7 @@ class RetryConfig(proto.Message): This field has the same meaning as `task_age_limit in queue.yaml/xml `__. - min_backoff (~.duration.Duration): + min_backoff (google.protobuf.duration_pb2.Duration): A task will be [scheduled][google.cloud.tasks.v2beta3.Task.schedule_time] for retry between @@ -322,7 +369,7 @@ class RetryConfig(proto.Message): This field has the same meaning as `min_backoff_seconds in queue.yaml/xml `__. - max_backoff (~.duration.Duration): + max_backoff (google.protobuf.duration_pb2.Duration): A task will be [scheduled][google.cloud.tasks.v2beta3.Task.schedule_time] for retry between @@ -403,4 +450,50 @@ class StackdriverLoggingConfig(proto.Message): sampling_ratio = proto.Field(proto.DOUBLE, number=1) +class QueueStats(proto.Message): + r"""Statistics for a queue. + + Attributes: + tasks_count (int): + Output only. An estimation of the number of + tasks in the queue, that is, the tasks in the + queue that haven't been executed, the tasks in + the queue which the queue has dispatched but has + not yet received a reply for, and the failed + tasks that the queue is retrying. + oldest_estimated_arrival_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. An estimation of the nearest + time in the future where a task in the queue is + scheduled to be executed. + executed_last_minute_count (int): + Output only. The number of tasks that the + queue has dispatched and received a reply for + during the last minute. This variable counts + both successful and non-successful executions. + concurrent_dispatches_count (int): + Output only. The number of requests that the + queue has dispatched but has not received a + reply for yet. + effective_execution_rate (float): + Output only. The current maximum number of + tasks per second executed by the queue. The + maximum value of this variable is controlled by + the RateLimits of the Queue. However, this value + could be less to avoid overloading the endpoints + tasks in the queue are targeting. + """ + + tasks_count = proto.Field(proto.INT64, number=1) + + oldest_estimated_arrival_time = proto.Field( + proto.MESSAGE, number=2, message=timestamp.Timestamp, + ) + + executed_last_minute_count = proto.Field(proto.INT64, number=3) + + concurrent_dispatches_count = proto.Field(proto.INT64, number=4) + + effective_execution_rate = proto.Field(proto.DOUBLE, number=5) + + __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/tasks_v2beta3/types/target.py b/google/cloud/tasks_v2beta3/types/target.py index 69379e33..938f6413 100644 --- a/google/cloud/tasks_v2beta3/types/target.py +++ b/google/cloud/tasks_v2beta3/types/target.py @@ -22,6 +22,7 @@ package="google.cloud.tasks.v2beta3", manifest={ "HttpMethod", + "PullMessage", "HttpRequest", "AppEngineHttpQueue", "AppEngineHttpRequest", @@ -44,6 +45,39 @@ class HttpMethod(proto.Enum): OPTIONS = 7 +class PullMessage(proto.Message): + r"""Pull Message. + + This proto can only be used for tasks in a queue which has + [PULL][google.cloud.tasks.v2beta3.Queue.type] type. It currently + exists for backwards compatibility with the App Engine Task Queue + SDK. This message type maybe returned with methods + [list][google.cloud.tasks.v2beta3.CloudTask.ListTasks] and + [get][google.cloud.tasks.v2beta3.CloudTask.ListTasks], when the + response view is [FULL][google.cloud.tasks.v2beta3.Task.View.Full]. + + Attributes: + payload (bytes): + A data payload consumed by the worker to + execute the task. + tag (str): + The tasks's tag. + + The tag is less than 500 characters. + + SDK compatibility: Although the SDK allows tags to be either + string or + `bytes `__, + only UTF-8 encoded tags can be used in Cloud Tasks. If a tag + isn't UTF-8 encoded, the tag will be empty when the task is + returned by Cloud Tasks. + """ + + payload = proto.Field(proto.BYTES, number=1) + + tag = proto.Field(proto.STRING, number=2) + + class HttpRequest(proto.Message): r"""HTTP request. @@ -94,10 +128,10 @@ class HttpRequest(proto.Message): The ``Location`` header response from a redirect response [``300`` - ``399``] may be followed. The redirect is not counted as a separate attempt. - http_method (~.target.HttpMethod): + http_method (google.cloud.tasks_v2beta3.types.HttpMethod): The HTTP method to use for the request. The default is POST. - headers (Sequence[~.target.HttpRequest.HeadersEntry]): + headers (Sequence[google.cloud.tasks_v2beta3.types.HttpRequest.HeadersEntry]): HTTP request headers. This map contains the header field names and values. Headers @@ -138,7 +172,7 @@ class HttpRequest(proto.Message): is POST, PUT, or PATCH. It is an error to set body on a task with an incompatible [HttpMethod][google.cloud.tasks.v2beta3.HttpMethod]. - oauth_token (~.target.OAuthToken): + oauth_token (google.cloud.tasks_v2beta3.types.OAuthToken): If specified, an `OAuth token `__ will be generated and attached as an ``Authorization`` @@ -146,7 +180,7 @@ class HttpRequest(proto.Message): This type of authorization should generally only be used when calling Google APIs hosted on \*.googleapis.com. - oidc_token (~.target.OidcToken): + oidc_token (google.cloud.tasks_v2beta3.types.OidcToken): If specified, an `OIDC `__ token will be generated and attached as an ``Authorization`` @@ -195,7 +229,7 @@ class AppEngineHttpQueue(proto.Message): ``https://www.googleapis.com/auth/cloud-platform`` Attributes: - app_engine_routing_override (~.target.AppEngineRouting): + app_engine_routing_override (google.cloud.tasks_v2beta3.types.AppEngineRouting): Overrides for the [task-level app_engine_routing][google.cloud.tasks.v2beta3.AppEngineHttpRequest.app_engine_routing]. @@ -275,7 +309,7 @@ class AppEngineHttpRequest(proto.Message): congestion control to throttle the queue. Attributes: - http_method (~.target.HttpMethod): + http_method (google.cloud.tasks_v2beta3.types.HttpMethod): The HTTP method to use for the request. The default is POST. The app's request handler for the task's target URL must be @@ -286,7 +320,7 @@ class AppEngineHttpRequest(proto.Message): and the App Engine documentation for your runtime on `How Requests are Handled `__. - app_engine_routing (~.target.AppEngineRouting): + app_engine_routing (google.cloud.tasks_v2beta3.types.AppEngineRouting): Task-level setting for App Engine routing. If set, @@ -302,7 +336,7 @@ class AppEngineHttpRequest(proto.Message): is empty, then the root path "/" will be used. No spaces are allowed, and the maximum length allowed is 2083 characters. - headers (Sequence[~.target.AppEngineHttpRequest.HeadersEntry]): + headers (Sequence[google.cloud.tasks_v2beta3.types.AppEngineHttpRequest.HeadersEntry]): HTTP request headers. This map contains the header field names and values. Headers diff --git a/google/cloud/tasks_v2beta3/types/task.py b/google/cloud/tasks_v2beta3/types/task.py index 518cd8b4..1ec2700e 100644 --- a/google/cloud/tasks_v2beta3/types/task.py +++ b/google/cloud/tasks_v2beta3/types/task.py @@ -58,18 +58,28 @@ class Task(proto.Message): - ``TASK_ID`` can contain only letters ([A-Za-z]), numbers ([0-9]), hyphens (-), or underscores (_). The maximum length is 500 characters. - app_engine_http_request (~.target.AppEngineHttpRequest): + app_engine_http_request (google.cloud.tasks_v2beta3.types.AppEngineHttpRequest): HTTP request that is sent to the App Engine app handler. An App Engine task is a task that has [AppEngineHttpRequest][google.cloud.tasks.v2beta3.AppEngineHttpRequest] set. - http_request (~.target.HttpRequest): + http_request (google.cloud.tasks_v2beta3.types.HttpRequest): HTTP request that is sent to the task's target. An HTTP task is a task that has [HttpRequest][google.cloud.tasks.v2beta3.HttpRequest] set. - schedule_time (~.timestamp.Timestamp): + pull_message (google.cloud.tasks_v2beta3.types.PullMessage): + Pull Message contained in a task in a + [PULL][google.cloud.tasks.v2beta3.Queue.type] queue type. + This payload type cannot be explicitly set through Cloud + Tasks API. Its purpose, currently is to provide backward + compatibility with App Engine Task Queue + `pull `__ + queues to provide a way to inspect contents of pull tasks + through the + [CloudTasks.GetTask][google.cloud.tasks.v2beta3.CloudTasks.GetTask]. + schedule_time (google.protobuf.timestamp_pb2.Timestamp): The time when the task is scheduled to be attempted. For App Engine queues, this is when the task will be @@ -77,11 +87,11 @@ class Task(proto.Message): ``schedule_time`` will be truncated to the nearest microsecond. - create_time (~.timestamp.Timestamp): + create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The time that the task was created. ``create_time`` will be truncated to the nearest second. - dispatch_deadline (~.duration.Duration): + dispatch_deadline (google.protobuf.duration_pb2.Duration): The deadline for requests sent to the worker. If the worker does not respond by this deadline then the request is cancelled and the attempt is marked as a @@ -128,7 +138,7 @@ class Task(proto.Message): response_count (int): Output only. The number of attempts which have received a response. - first_attempt (~.task.Attempt): + first_attempt (google.cloud.tasks_v2beta3.types.Attempt): Output only. The status of the task's first attempt. Only @@ -136,10 +146,10 @@ class Task(proto.Message): will be set. The other [Attempt][google.cloud.tasks.v2beta3.Attempt] information is not retained by Cloud Tasks. - last_attempt (~.task.Attempt): + last_attempt (google.cloud.tasks_v2beta3.types.Attempt): Output only. The status of the task's last attempt. - view (~.task.Task.View): + view (google.cloud.tasks_v2beta3.types.Task.View): Output only. The view specifies which subset of the [Task][google.cloud.tasks.v2beta3.Task] has been returned. """ @@ -170,6 +180,10 @@ class View(proto.Enum): proto.MESSAGE, number=11, oneof="payload_type", message=target.HttpRequest, ) + pull_message = proto.Field( + proto.MESSAGE, number=13, oneof="payload_type", message=target.PullMessage, + ) + schedule_time = proto.Field(proto.MESSAGE, number=4, message=timestamp.Timestamp,) create_time = proto.Field(proto.MESSAGE, number=5, message=timestamp.Timestamp,) @@ -193,23 +207,23 @@ class Attempt(proto.Message): r"""The status of a task attempt. Attributes: - schedule_time (~.timestamp.Timestamp): + schedule_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The time that this attempt was scheduled. ``schedule_time`` will be truncated to the nearest microsecond. - dispatch_time (~.timestamp.Timestamp): + dispatch_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The time that this attempt was dispatched. ``dispatch_time`` will be truncated to the nearest microsecond. - response_time (~.timestamp.Timestamp): + response_time (google.protobuf.timestamp_pb2.Timestamp): Output only. The time that this attempt response was received. ``response_time`` will be truncated to the nearest microsecond. - response_status (~.status.Status): + response_status (google.rpc.status_pb2.Status): Output only. The response from the worker for this attempt. If ``response_time`` is unset, then the task has not been diff --git a/noxfile.py b/noxfile.py index a57e24be..6e69bfe0 100644 --- a/noxfile.py +++ b/noxfile.py @@ -30,6 +30,17 @@ SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"] UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] +# 'docfx' is excluded since it only needs to run in 'docs-presubmit' +nox.options.sessions = [ + "unit", + "system", + "cover", + "lint", + "lint_setup_py", + "blacken", + "docs", +] + @nox.session(python=DEFAULT_PYTHON_VERSION) def lint(session): @@ -75,12 +86,14 @@ def default(session): session.install( "mock", "pytest", "pytest-cov", ) + session.install("-e", ".") # Run py.test against the unit tests. session.run( "py.test", "--quiet", + f"--junitxml=unit_{session.python}_sponge_log.xml", "--cov=google/cloud", "--cov=tests/unit", "--cov-append", @@ -129,9 +142,21 @@ def system(session): # Run py.test against the system tests. if system_test_exists: - session.run("py.test", "--quiet", system_test_path, *session.posargs) + session.run( + "py.test", + "--quiet", + f"--junitxml=system_{session.python}_sponge_log.xml", + system_test_path, + *session.posargs, + ) if system_test_folder_exists: - session.run("py.test", "--quiet", system_test_folder_path, *session.posargs) + session.run( + "py.test", + "--quiet", + f"--junitxml=system_{session.python}_sponge_log.xml", + system_test_folder_path, + *session.posargs, + ) @nox.session(python=DEFAULT_PYTHON_VERSION) diff --git a/samples/snippets/noxfile.py b/samples/snippets/noxfile.py index bca0522e..97bf7da8 100644 --- a/samples/snippets/noxfile.py +++ b/samples/snippets/noxfile.py @@ -85,7 +85,7 @@ def get_pytest_env_vars() -> Dict[str, str]: # DO NOT EDIT - automatically generated. # All versions used to tested samples. -ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8"] +ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8", "3.9"] # Any default versions that should be ignored. IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] diff --git a/scripts/fixup_tasks_v2beta2_keywords.py b/scripts/fixup_tasks_v2beta2_keywords.py index 7277f4ab..4f910267 100644 --- a/scripts/fixup_tasks_v2beta2_keywords.py +++ b/scripts/fixup_tasks_v2beta2_keywords.py @@ -48,10 +48,10 @@ class tasksCallTransformer(cst.CSTTransformer): 'delete_queue': ('name', ), 'delete_task': ('name', ), 'get_iam_policy': ('resource', 'options', ), - 'get_queue': ('name', ), + 'get_queue': ('name', 'read_mask', ), 'get_task': ('name', 'response_view', ), 'lease_tasks': ('parent', 'lease_duration', 'max_tasks', 'response_view', 'filter', ), - 'list_queues': ('parent', 'filter', 'page_size', 'page_token', ), + 'list_queues': ('parent', 'filter', 'page_size', 'page_token', 'read_mask', ), 'list_tasks': ('parent', 'response_view', 'page_size', 'page_token', ), 'pause_queue': ('name', ), 'purge_queue': ('name', ), diff --git a/scripts/fixup_tasks_v2beta3_keywords.py b/scripts/fixup_tasks_v2beta3_keywords.py index 30997b65..b8e151d0 100644 --- a/scripts/fixup_tasks_v2beta3_keywords.py +++ b/scripts/fixup_tasks_v2beta3_keywords.py @@ -46,9 +46,9 @@ class tasksCallTransformer(cst.CSTTransformer): 'delete_queue': ('name', ), 'delete_task': ('name', ), 'get_iam_policy': ('resource', 'options', ), - 'get_queue': ('name', ), + 'get_queue': ('name', 'read_mask', ), 'get_task': ('name', 'response_view', ), - 'list_queues': ('parent', 'filter', 'page_size', 'page_token', ), + 'list_queues': ('parent', 'filter', 'page_size', 'page_token', 'read_mask', ), 'list_tasks': ('parent', 'response_view', 'page_size', 'page_token', ), 'pause_queue': ('name', ), 'purge_queue': ('name', ), diff --git a/synth.metadata b/synth.metadata index b8feb39f..57c8e0c2 100644 --- a/synth.metadata +++ b/synth.metadata @@ -3,30 +3,30 @@ { "git": { "name": ".", - "remote": "https://github.com/googleapis/python-tasks.git", - "sha": "6a5bfaf63b46567897c36907772b10ea4b0dff43" + "remote": "git@github.com:googleapis/python-tasks", + "sha": "7e720ed97e5ea978d6e1a0aaf2ae508cccb6ff90" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "dd372aa22ded7a8ba6f0e03a80e06358a3fa0907", - "internalRef": "347055288" + "sha": "eabec5a21219401bad79e1cc7d900c1658aee5fd", + "internalRef": "359130387" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "373861061648b5fe5e0ac4f8a38b32d639ee93e4" + "sha": "79ab0b44a2cc7d803d07c107f9faf07729fc4012" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "373861061648b5fe5e0ac4f8a38b32d639ee93e4" + "sha": "79ab0b44a2cc7d803d07c107f9faf07729fc4012" } } ], @@ -58,152 +58,5 @@ "generator": "bazel" } } - ], - "generatedFiles": [ - ".flake8", - ".github/CONTRIBUTING.md", - ".github/ISSUE_TEMPLATE/bug_report.md", - ".github/ISSUE_TEMPLATE/feature_request.md", - ".github/ISSUE_TEMPLATE/support_request.md", - ".github/PULL_REQUEST_TEMPLATE.md", - ".github/release-please.yml", - ".github/snippet-bot.yml", - ".gitignore", - ".kokoro/build.sh", - ".kokoro/continuous/common.cfg", - ".kokoro/continuous/continuous.cfg", - ".kokoro/docker/docs/Dockerfile", - ".kokoro/docker/docs/fetch_gpg_keys.sh", - ".kokoro/docs/common.cfg", - ".kokoro/docs/docs-presubmit.cfg", - ".kokoro/docs/docs.cfg", - ".kokoro/populate-secrets.sh", - ".kokoro/presubmit/common.cfg", - ".kokoro/presubmit/presubmit.cfg", - ".kokoro/publish-docs.sh", - ".kokoro/release.sh", - ".kokoro/release/common.cfg", - ".kokoro/release/release.cfg", - ".kokoro/samples/lint/common.cfg", - ".kokoro/samples/lint/continuous.cfg", - ".kokoro/samples/lint/periodic.cfg", - ".kokoro/samples/lint/presubmit.cfg", - ".kokoro/samples/python3.6/common.cfg", - ".kokoro/samples/python3.6/continuous.cfg", - ".kokoro/samples/python3.6/periodic.cfg", - ".kokoro/samples/python3.6/presubmit.cfg", - ".kokoro/samples/python3.7/common.cfg", - ".kokoro/samples/python3.7/continuous.cfg", - ".kokoro/samples/python3.7/periodic.cfg", - ".kokoro/samples/python3.7/presubmit.cfg", - ".kokoro/samples/python3.8/common.cfg", - ".kokoro/samples/python3.8/continuous.cfg", - ".kokoro/samples/python3.8/periodic.cfg", - ".kokoro/samples/python3.8/presubmit.cfg", - ".kokoro/test-samples.sh", - ".kokoro/trampoline.sh", - ".kokoro/trampoline_v2.sh", - ".pre-commit-config.yaml", - ".trampolinerc", - "CODE_OF_CONDUCT.md", - "CONTRIBUTING.rst", - "LICENSE", - "MANIFEST.in", - "docs/_static/custom.css", - "docs/_templates/layout.html", - "docs/conf.py", - "docs/multiprocessing.rst", - "docs/tasks_v2/services.rst", - "docs/tasks_v2/types.rst", - "docs/tasks_v2beta2/services.rst", - "docs/tasks_v2beta2/types.rst", - "docs/tasks_v2beta3/services.rst", - "docs/tasks_v2beta3/types.rst", - "google/cloud/tasks/__init__.py", - "google/cloud/tasks/py.typed", - "google/cloud/tasks_v2/__init__.py", - "google/cloud/tasks_v2/proto/cloudtasks.proto", - "google/cloud/tasks_v2/proto/queue.proto", - "google/cloud/tasks_v2/proto/target.proto", - "google/cloud/tasks_v2/proto/task.proto", - "google/cloud/tasks_v2/py.typed", - "google/cloud/tasks_v2/services/__init__.py", - "google/cloud/tasks_v2/services/cloud_tasks/__init__.py", - "google/cloud/tasks_v2/services/cloud_tasks/async_client.py", - "google/cloud/tasks_v2/services/cloud_tasks/client.py", - "google/cloud/tasks_v2/services/cloud_tasks/pagers.py", - "google/cloud/tasks_v2/services/cloud_tasks/transports/__init__.py", - "google/cloud/tasks_v2/services/cloud_tasks/transports/base.py", - "google/cloud/tasks_v2/services/cloud_tasks/transports/grpc.py", - "google/cloud/tasks_v2/services/cloud_tasks/transports/grpc_asyncio.py", - "google/cloud/tasks_v2/types/__init__.py", - "google/cloud/tasks_v2/types/cloudtasks.py", - "google/cloud/tasks_v2/types/queue.py", - "google/cloud/tasks_v2/types/target.py", - "google/cloud/tasks_v2/types/task.py", - "google/cloud/tasks_v2beta2/__init__.py", - "google/cloud/tasks_v2beta2/proto/cloudtasks.proto", - "google/cloud/tasks_v2beta2/proto/queue.proto", - "google/cloud/tasks_v2beta2/proto/target.proto", - "google/cloud/tasks_v2beta2/proto/task.proto", - "google/cloud/tasks_v2beta2/py.typed", - "google/cloud/tasks_v2beta2/services/__init__.py", - "google/cloud/tasks_v2beta2/services/cloud_tasks/__init__.py", - "google/cloud/tasks_v2beta2/services/cloud_tasks/async_client.py", - "google/cloud/tasks_v2beta2/services/cloud_tasks/client.py", - "google/cloud/tasks_v2beta2/services/cloud_tasks/pagers.py", - "google/cloud/tasks_v2beta2/services/cloud_tasks/transports/__init__.py", - "google/cloud/tasks_v2beta2/services/cloud_tasks/transports/base.py", - "google/cloud/tasks_v2beta2/services/cloud_tasks/transports/grpc.py", - "google/cloud/tasks_v2beta2/services/cloud_tasks/transports/grpc_asyncio.py", - "google/cloud/tasks_v2beta2/types/__init__.py", - "google/cloud/tasks_v2beta2/types/cloudtasks.py", - "google/cloud/tasks_v2beta2/types/queue.py", - "google/cloud/tasks_v2beta2/types/target.py", - "google/cloud/tasks_v2beta2/types/task.py", - "google/cloud/tasks_v2beta3/__init__.py", - "google/cloud/tasks_v2beta3/proto/cloudtasks.proto", - "google/cloud/tasks_v2beta3/proto/queue.proto", - "google/cloud/tasks_v2beta3/proto/target.proto", - "google/cloud/tasks_v2beta3/proto/task.proto", - "google/cloud/tasks_v2beta3/py.typed", - "google/cloud/tasks_v2beta3/services/__init__.py", - "google/cloud/tasks_v2beta3/services/cloud_tasks/__init__.py", - "google/cloud/tasks_v2beta3/services/cloud_tasks/async_client.py", - "google/cloud/tasks_v2beta3/services/cloud_tasks/client.py", - "google/cloud/tasks_v2beta3/services/cloud_tasks/pagers.py", - "google/cloud/tasks_v2beta3/services/cloud_tasks/transports/__init__.py", - "google/cloud/tasks_v2beta3/services/cloud_tasks/transports/base.py", - "google/cloud/tasks_v2beta3/services/cloud_tasks/transports/grpc.py", - "google/cloud/tasks_v2beta3/services/cloud_tasks/transports/grpc_asyncio.py", - "google/cloud/tasks_v2beta3/types/__init__.py", - "google/cloud/tasks_v2beta3/types/cloudtasks.py", - "google/cloud/tasks_v2beta3/types/queue.py", - "google/cloud/tasks_v2beta3/types/target.py", - "google/cloud/tasks_v2beta3/types/task.py", - "mypy.ini", - "noxfile.py", - "renovate.json", - "samples/AUTHORING_GUIDE.md", - "samples/CONTRIBUTING.md", - "samples/snippets/noxfile.py", - "scripts/decrypt-secrets.sh", - "scripts/fixup_tasks_v2_keywords.py", - "scripts/fixup_tasks_v2beta2_keywords.py", - "scripts/fixup_tasks_v2beta3_keywords.py", - "scripts/readme-gen/readme_gen.py", - "scripts/readme-gen/templates/README.tmpl.rst", - "scripts/readme-gen/templates/auth.tmpl.rst", - "scripts/readme-gen/templates/auth_api_key.tmpl.rst", - "scripts/readme-gen/templates/install_deps.tmpl.rst", - "scripts/readme-gen/templates/install_portaudio.tmpl.rst", - "setup.cfg", - "testing/.gitignore", - "tests/unit/gapic/tasks_v2/__init__.py", - "tests/unit/gapic/tasks_v2/test_cloud_tasks.py", - "tests/unit/gapic/tasks_v2beta2/__init__.py", - "tests/unit/gapic/tasks_v2beta2/test_cloud_tasks.py", - "tests/unit/gapic/tasks_v2beta3/__init__.py", - "tests/unit/gapic/tasks_v2beta3/test_cloud_tasks.py" ] } \ No newline at end of file diff --git a/synth.py b/synth.py index f01a891b..7781cb99 100644 --- a/synth.py +++ b/synth.py @@ -42,6 +42,15 @@ s.replace("google/cloud/*/types/target.py", "X-Google-\*", "X-Google-\\*") s.replace("google/cloud/*/types/target.py", "X-AppEngine-\*", "X-AppEngine-\\*") +# Bug with test_iam_permissions adding permissions twice +# https://github.com/googleapis/gapic-generator-python/issues/778 +s.replace( + "google/cloud/**/client.py", + """\s+if permissions: +\s+request\.permissions\.extend\(permissions\)""", + "", +) + # ---------------------------------------------------------------------------- # Add templated files # ---------------------------------------------------------------------------- @@ -50,7 +59,9 @@ microgenerator=True, cov_level=99, ) -s.move(templated_files, excludes=[".coveragerc"]) # microgenerator has a good .coveragerc file +s.move( + templated_files, excludes=[".coveragerc"] +) # microgenerator has a good .coveragerc file # ---------------------------------------------------------------------------- # Samples templates diff --git a/tasks-v2beta2-py.tar.gz b/tasks-v2beta2-py.tar.gz new file mode 100644 index 00000000..e69de29b diff --git a/tests/unit/gapic/tasks_v2/test_cloud_tasks.py b/tests/unit/gapic/tasks_v2/test_cloud_tasks.py index 5306eb25..573bfa7b 100644 --- a/tests/unit/gapic/tasks_v2/test_cloud_tasks.py +++ b/tests/unit/gapic/tasks_v2/test_cloud_tasks.py @@ -95,7 +95,20 @@ def test__get_default_mtls_endpoint(): assert CloudTasksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi -@pytest.mark.parametrize("client_class", [CloudTasksClient, CloudTasksAsyncClient]) +def test_cloud_tasks_client_from_service_account_info(): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = CloudTasksClient.from_service_account_info(info) + assert client.transport._credentials == creds + + assert client.transport._host == "cloudtasks.googleapis.com:443" + + +@pytest.mark.parametrize("client_class", [CloudTasksClient, CloudTasksAsyncClient,]) def test_cloud_tasks_client_from_service_account_file(client_class): creds = credentials.AnonymousCredentials() with mock.patch.object( @@ -113,7 +126,10 @@ def test_cloud_tasks_client_from_service_account_file(client_class): def test_cloud_tasks_client_get_transport_class(): transport = CloudTasksClient.get_transport_class() - assert transport == transports.CloudTasksGrpcTransport + available_transports = [ + transports.CloudTasksGrpcTransport, + ] + assert transport in available_transports transport = CloudTasksClient.get_transport_class("grpc") assert transport == transports.CloudTasksGrpcTransport @@ -162,7 +178,7 @@ def test_cloud_tasks_client_client_options( credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -178,7 +194,7 @@ def test_cloud_tasks_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -194,7 +210,7 @@ def test_cloud_tasks_client_client_options( credentials_file=None, host=client.DEFAULT_MTLS_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -222,7 +238,7 @@ def test_cloud_tasks_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -271,29 +287,25 @@ def test_cloud_tasks_client_mtls_env_auto( client_cert_source=client_cert_source_callback ) with mock.patch.object(transport_class, "__init__") as patched: - ssl_channel_creds = mock.Mock() - with mock.patch( - "grpc.ssl_channel_credentials", return_value=ssl_channel_creds - ): - patched.return_value = None - client = client_class(client_options=options) + patched.return_value = None + client = client_class(client_options=options) - if use_client_cert_env == "false": - expected_ssl_channel_creds = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_ssl_channel_creds = ssl_channel_creds - expected_host = client.DEFAULT_MTLS_ENDPOINT + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) # Check the case ADC client cert is provided. Whether client cert is used depends on # GOOGLE_API_USE_CLIENT_CERTIFICATE value. @@ -302,66 +314,53 @@ def test_cloud_tasks_client_mtls_env_auto( ): with mock.patch.object(transport_class, "__init__") as patched: with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, ): with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.ssl_credentials", - new_callable=mock.PropertyMock, - ) as ssl_credentials_mock: - if use_client_cert_env == "false": - is_mtls_mock.return_value = False - ssl_credentials_mock.return_value = None - expected_host = client.DEFAULT_ENDPOINT - expected_ssl_channel_creds = None - else: - is_mtls_mock.return_value = True - ssl_credentials_mock.return_value = mock.Mock() - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_ssl_channel_creds = ( - ssl_credentials_mock.return_value - ) - - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict( - os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} - ): - with mock.patch.object(transport_class, "__init__") as patched: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None - ): - with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - is_mtls_mock.return_value = False patched.return_value = None client = client_class() patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=expected_host, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -387,7 +386,7 @@ def test_cloud_tasks_client_client_options_scopes( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=["1", "2"], - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -417,7 +416,7 @@ def test_cloud_tasks_client_client_options_credentials_file( credentials_file="credentials.json", host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -434,7 +433,7 @@ def test_cloud_tasks_client_client_options_from_dict(): credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -3931,7 +3930,7 @@ def test_transport_get_channel(): @pytest.mark.parametrize( "transport_class", - [transports.CloudTasksGrpcTransport, transports.CloudTasksGrpcAsyncIOTransport], + [transports.CloudTasksGrpcTransport, transports.CloudTasksGrpcAsyncIOTransport,], ) def test_transport_adc(transport_class): # Test default credentials are used if not provided. @@ -4046,6 +4045,48 @@ def test_cloud_tasks_transport_auth_adc(): ) +@pytest.mark.parametrize( + "transport_class", + [transports.CloudTasksGrpcTransport, transports.CloudTasksGrpcAsyncIOTransport], +) +def test_cloud_tasks_grpc_transport_client_cert_source_for_mtls(transport_class): + cred = credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + def test_cloud_tasks_host_no_port(): client = CloudTasksClient( credentials=credentials.AnonymousCredentials(), @@ -4067,7 +4108,7 @@ def test_cloud_tasks_host_with_port(): def test_cloud_tasks_grpc_transport_channel(): - channel = grpc.insecure_channel("http://localhost/") + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.CloudTasksGrpcTransport( @@ -4079,7 +4120,7 @@ def test_cloud_tasks_grpc_transport_channel(): def test_cloud_tasks_grpc_asyncio_transport_channel(): - channel = aio.insecure_channel("http://localhost/") + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.CloudTasksGrpcAsyncIOTransport( @@ -4090,6 +4131,8 @@ def test_cloud_tasks_grpc_asyncio_transport_channel(): assert transport._ssl_channel_credentials == None +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [transports.CloudTasksGrpcTransport, transports.CloudTasksGrpcAsyncIOTransport], @@ -4099,7 +4142,7 @@ def test_cloud_tasks_transport_channel_mtls_with_client_cert_source(transport_cl "grpc.ssl_channel_credentials", autospec=True ) as grpc_ssl_channel_cred: with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -4137,6 +4180,8 @@ def test_cloud_tasks_transport_channel_mtls_with_client_cert_source(transport_cl assert transport._ssl_channel_credentials == mock_ssl_cred +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [transports.CloudTasksGrpcTransport, transports.CloudTasksGrpcAsyncIOTransport], @@ -4149,7 +4194,7 @@ def test_cloud_tasks_transport_channel_mtls_with_adc(transport_class): ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel diff --git a/tests/unit/gapic/tasks_v2beta2/test_cloud_tasks.py b/tests/unit/gapic/tasks_v2beta2/test_cloud_tasks.py index eabbc9bc..555e14aa 100644 --- a/tests/unit/gapic/tasks_v2beta2/test_cloud_tasks.py +++ b/tests/unit/gapic/tasks_v2beta2/test_cloud_tasks.py @@ -95,7 +95,20 @@ def test__get_default_mtls_endpoint(): assert CloudTasksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi -@pytest.mark.parametrize("client_class", [CloudTasksClient, CloudTasksAsyncClient]) +def test_cloud_tasks_client_from_service_account_info(): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = CloudTasksClient.from_service_account_info(info) + assert client.transport._credentials == creds + + assert client.transport._host == "cloudtasks.googleapis.com:443" + + +@pytest.mark.parametrize("client_class", [CloudTasksClient, CloudTasksAsyncClient,]) def test_cloud_tasks_client_from_service_account_file(client_class): creds = credentials.AnonymousCredentials() with mock.patch.object( @@ -113,7 +126,10 @@ def test_cloud_tasks_client_from_service_account_file(client_class): def test_cloud_tasks_client_get_transport_class(): transport = CloudTasksClient.get_transport_class() - assert transport == transports.CloudTasksGrpcTransport + available_transports = [ + transports.CloudTasksGrpcTransport, + ] + assert transport in available_transports transport = CloudTasksClient.get_transport_class("grpc") assert transport == transports.CloudTasksGrpcTransport @@ -162,7 +178,7 @@ def test_cloud_tasks_client_client_options( credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -178,7 +194,7 @@ def test_cloud_tasks_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -194,7 +210,7 @@ def test_cloud_tasks_client_client_options( credentials_file=None, host=client.DEFAULT_MTLS_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -222,7 +238,7 @@ def test_cloud_tasks_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -271,29 +287,25 @@ def test_cloud_tasks_client_mtls_env_auto( client_cert_source=client_cert_source_callback ) with mock.patch.object(transport_class, "__init__") as patched: - ssl_channel_creds = mock.Mock() - with mock.patch( - "grpc.ssl_channel_credentials", return_value=ssl_channel_creds - ): - patched.return_value = None - client = client_class(client_options=options) + patched.return_value = None + client = client_class(client_options=options) - if use_client_cert_env == "false": - expected_ssl_channel_creds = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_ssl_channel_creds = ssl_channel_creds - expected_host = client.DEFAULT_MTLS_ENDPOINT + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) # Check the case ADC client cert is provided. Whether client cert is used depends on # GOOGLE_API_USE_CLIENT_CERTIFICATE value. @@ -302,66 +314,53 @@ def test_cloud_tasks_client_mtls_env_auto( ): with mock.patch.object(transport_class, "__init__") as patched: with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, ): with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.ssl_credentials", - new_callable=mock.PropertyMock, - ) as ssl_credentials_mock: - if use_client_cert_env == "false": - is_mtls_mock.return_value = False - ssl_credentials_mock.return_value = None - expected_host = client.DEFAULT_ENDPOINT - expected_ssl_channel_creds = None - else: - is_mtls_mock.return_value = True - ssl_credentials_mock.return_value = mock.Mock() - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_ssl_channel_creds = ( - ssl_credentials_mock.return_value - ) - - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict( - os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} - ): - with mock.patch.object(transport_class, "__init__") as patched: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None - ): - with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - is_mtls_mock.return_value = False patched.return_value = None client = client_class() patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=expected_host, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -387,7 +386,7 @@ def test_cloud_tasks_client_client_options_scopes( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=["1", "2"], - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -417,7 +416,7 @@ def test_cloud_tasks_client_client_options_credentials_file( credentials_file="credentials.json", host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -434,7 +433,7 @@ def test_cloud_tasks_client_client_options_from_dict(): credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -4761,7 +4760,7 @@ def test_transport_get_channel(): @pytest.mark.parametrize( "transport_class", - [transports.CloudTasksGrpcTransport, transports.CloudTasksGrpcAsyncIOTransport], + [transports.CloudTasksGrpcTransport, transports.CloudTasksGrpcAsyncIOTransport,], ) def test_transport_adc(transport_class): # Test default credentials are used if not provided. @@ -4880,6 +4879,48 @@ def test_cloud_tasks_transport_auth_adc(): ) +@pytest.mark.parametrize( + "transport_class", + [transports.CloudTasksGrpcTransport, transports.CloudTasksGrpcAsyncIOTransport], +) +def test_cloud_tasks_grpc_transport_client_cert_source_for_mtls(transport_class): + cred = credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + def test_cloud_tasks_host_no_port(): client = CloudTasksClient( credentials=credentials.AnonymousCredentials(), @@ -4901,7 +4942,7 @@ def test_cloud_tasks_host_with_port(): def test_cloud_tasks_grpc_transport_channel(): - channel = grpc.insecure_channel("http://localhost/") + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.CloudTasksGrpcTransport( @@ -4913,7 +4954,7 @@ def test_cloud_tasks_grpc_transport_channel(): def test_cloud_tasks_grpc_asyncio_transport_channel(): - channel = aio.insecure_channel("http://localhost/") + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.CloudTasksGrpcAsyncIOTransport( @@ -4924,6 +4965,8 @@ def test_cloud_tasks_grpc_asyncio_transport_channel(): assert transport._ssl_channel_credentials == None +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [transports.CloudTasksGrpcTransport, transports.CloudTasksGrpcAsyncIOTransport], @@ -4933,7 +4976,7 @@ def test_cloud_tasks_transport_channel_mtls_with_client_cert_source(transport_cl "grpc.ssl_channel_credentials", autospec=True ) as grpc_ssl_channel_cred: with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -4971,6 +5014,8 @@ def test_cloud_tasks_transport_channel_mtls_with_client_cert_source(transport_cl assert transport._ssl_channel_credentials == mock_ssl_cred +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [transports.CloudTasksGrpcTransport, transports.CloudTasksGrpcAsyncIOTransport], @@ -4983,7 +5028,7 @@ def test_cloud_tasks_transport_channel_mtls_with_adc(transport_class): ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel diff --git a/tests/unit/gapic/tasks_v2beta3/test_cloud_tasks.py b/tests/unit/gapic/tasks_v2beta3/test_cloud_tasks.py index 8d3e059c..99157ca3 100644 --- a/tests/unit/gapic/tasks_v2beta3/test_cloud_tasks.py +++ b/tests/unit/gapic/tasks_v2beta3/test_cloud_tasks.py @@ -95,7 +95,20 @@ def test__get_default_mtls_endpoint(): assert CloudTasksClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi -@pytest.mark.parametrize("client_class", [CloudTasksClient, CloudTasksAsyncClient]) +def test_cloud_tasks_client_from_service_account_info(): + creds = credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = CloudTasksClient.from_service_account_info(info) + assert client.transport._credentials == creds + + assert client.transport._host == "cloudtasks.googleapis.com:443" + + +@pytest.mark.parametrize("client_class", [CloudTasksClient, CloudTasksAsyncClient,]) def test_cloud_tasks_client_from_service_account_file(client_class): creds = credentials.AnonymousCredentials() with mock.patch.object( @@ -113,7 +126,10 @@ def test_cloud_tasks_client_from_service_account_file(client_class): def test_cloud_tasks_client_get_transport_class(): transport = CloudTasksClient.get_transport_class() - assert transport == transports.CloudTasksGrpcTransport + available_transports = [ + transports.CloudTasksGrpcTransport, + ] + assert transport in available_transports transport = CloudTasksClient.get_transport_class("grpc") assert transport == transports.CloudTasksGrpcTransport @@ -162,7 +178,7 @@ def test_cloud_tasks_client_client_options( credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -178,7 +194,7 @@ def test_cloud_tasks_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -194,7 +210,7 @@ def test_cloud_tasks_client_client_options( credentials_file=None, host=client.DEFAULT_MTLS_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -222,7 +238,7 @@ def test_cloud_tasks_client_client_options( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -271,29 +287,25 @@ def test_cloud_tasks_client_mtls_env_auto( client_cert_source=client_cert_source_callback ) with mock.patch.object(transport_class, "__init__") as patched: - ssl_channel_creds = mock.Mock() - with mock.patch( - "grpc.ssl_channel_credentials", return_value=ssl_channel_creds - ): - patched.return_value = None - client = client_class(client_options=options) + patched.return_value = None + client = client_class(client_options=options) - if use_client_cert_env == "false": - expected_ssl_channel_creds = None - expected_host = client.DEFAULT_ENDPOINT - else: - expected_ssl_channel_creds = ssl_channel_creds - expected_host = client.DEFAULT_MTLS_ENDPOINT + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) # Check the case ADC client cert is provided. Whether client cert is used depends on # GOOGLE_API_USE_CLIENT_CERTIFICATE value. @@ -302,66 +314,53 @@ def test_cloud_tasks_client_mtls_env_auto( ): with mock.patch.object(transport_class, "__init__") as patched: with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, ): with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.ssl_credentials", - new_callable=mock.PropertyMock, - ) as ssl_credentials_mock: - if use_client_cert_env == "false": - is_mtls_mock.return_value = False - ssl_credentials_mock.return_value = None - expected_host = client.DEFAULT_ENDPOINT - expected_ssl_channel_creds = None - else: - is_mtls_mock.return_value = True - ssl_credentials_mock.return_value = mock.Mock() - expected_host = client.DEFAULT_MTLS_ENDPOINT - expected_ssl_channel_creds = ( - ssl_credentials_mock.return_value - ) - - patched.return_value = None - client = client_class() - patched.assert_called_once_with( - credentials=None, - credentials_file=None, - host=expected_host, - scopes=None, - ssl_channel_credentials=expected_ssl_channel_creds, - quota_project_id=None, - client_info=transports.base.DEFAULT_CLIENT_INFO, - ) + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback - # Check the case client_cert_source and ADC client cert are not provided. - with mock.patch.dict( - os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} - ): - with mock.patch.object(transport_class, "__init__") as patched: - with mock.patch( - "google.auth.transport.grpc.SslCredentials.__init__", return_value=None - ): - with mock.patch( - "google.auth.transport.grpc.SslCredentials.is_mtls", - new_callable=mock.PropertyMock, - ) as is_mtls_mock: - is_mtls_mock.return_value = False patched.return_value = None client = client_class() patched.assert_called_once_with( credentials=None, credentials_file=None, - host=client.DEFAULT_ENDPOINT, + host=expected_host, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class() + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + ) + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -387,7 +386,7 @@ def test_cloud_tasks_client_client_options_scopes( credentials_file=None, host=client.DEFAULT_ENDPOINT, scopes=["1", "2"], - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -417,7 +416,7 @@ def test_cloud_tasks_client_client_options_credentials_file( credentials_file="credentials.json", host=client.DEFAULT_ENDPOINT, scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -434,7 +433,7 @@ def test_cloud_tasks_client_client_options_from_dict(): credentials_file=None, host="squid.clam.whelk", scopes=None, - ssl_channel_credentials=None, + client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, ) @@ -4021,7 +4020,7 @@ def test_transport_get_channel(): @pytest.mark.parametrize( "transport_class", - [transports.CloudTasksGrpcTransport, transports.CloudTasksGrpcAsyncIOTransport], + [transports.CloudTasksGrpcTransport, transports.CloudTasksGrpcAsyncIOTransport,], ) def test_transport_adc(transport_class): # Test default credentials are used if not provided. @@ -4136,6 +4135,48 @@ def test_cloud_tasks_transport_auth_adc(): ) +@pytest.mark.parametrize( + "transport_class", + [transports.CloudTasksGrpcTransport, transports.CloudTasksGrpcAsyncIOTransport], +) +def test_cloud_tasks_grpc_transport_client_cert_source_for_mtls(transport_class): + cred = credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=("https://www.googleapis.com/auth/cloud-platform",), + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + def test_cloud_tasks_host_no_port(): client = CloudTasksClient( credentials=credentials.AnonymousCredentials(), @@ -4157,7 +4198,7 @@ def test_cloud_tasks_host_with_port(): def test_cloud_tasks_grpc_transport_channel(): - channel = grpc.insecure_channel("http://localhost/") + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.CloudTasksGrpcTransport( @@ -4169,7 +4210,7 @@ def test_cloud_tasks_grpc_transport_channel(): def test_cloud_tasks_grpc_asyncio_transport_channel(): - channel = aio.insecure_channel("http://localhost/") + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.CloudTasksGrpcAsyncIOTransport( @@ -4180,6 +4221,8 @@ def test_cloud_tasks_grpc_asyncio_transport_channel(): assert transport._ssl_channel_credentials == None +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [transports.CloudTasksGrpcTransport, transports.CloudTasksGrpcAsyncIOTransport], @@ -4189,7 +4232,7 @@ def test_cloud_tasks_transport_channel_mtls_with_client_cert_source(transport_cl "grpc.ssl_channel_credentials", autospec=True ) as grpc_ssl_channel_cred: with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -4227,6 +4270,8 @@ def test_cloud_tasks_transport_channel_mtls_with_client_cert_source(transport_cl assert transport._ssl_channel_credentials == mock_ssl_cred +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [transports.CloudTasksGrpcTransport, transports.CloudTasksGrpcAsyncIOTransport], @@ -4239,7 +4284,7 @@ def test_cloud_tasks_transport_channel_mtls_with_adc(transport_class): ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): with mock.patch.object( - transport_class, "create_channel", autospec=True + transport_class, "create_channel" ) as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel