diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 108063d..39ad3ce 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,16 @@ +# Copyright 2022 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. docker: image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest - digest: sha256:4ee57a76a176ede9087c14330c625a71553cf9c72828b2c0ca12f5338171ba60 + digest: sha256:d22cd2ddce65fdac6986f115563faf2fc81482b09dfbea83ac2808c92ecfdff0 diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 319e311..e446644 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -3,9 +3,10 @@ # # For syntax help see: # https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners#codeowners-syntax +# Note: This file is autogenerated. To make changes to the codeowner team, please update .repo-metadata.json. -# The @googleapis/yoshi-python is the default owner for changes in this repo -* @googleapis/yoshi-python +# @googleapis/yoshi-python is the default owner for changes in this repo +* @googleapis/yoshi-python -# The python-samples-reviewers team is the default owner for samples changes -/samples/ @googleapis/python-samples-owner \ No newline at end of file +# @googleapis/python-samples-reviewers is the default owner for samples changes +/samples/ @googleapis/python-samples-reviewers diff --git a/.github/release-please.yml b/.github/release-please.yml index 4507ad0..466597e 100644 --- a/.github/release-please.yml +++ b/.github/release-please.yml @@ -1 +1,2 @@ releaseType: python +handleGHRelease: true diff --git a/.github/release-trigger.yml b/.github/release-trigger.yml new file mode 100644 index 0000000..d4ca941 --- /dev/null +++ b/.github/release-trigger.yml @@ -0,0 +1 @@ +enabled: true diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..f7b8344 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,38 @@ +on: + pull_request: + branches: + - main +name: docs +jobs: + docs: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.10" + - name: Install nox + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install nox + - name: Run docs + run: | + nox -s docs + docfx: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.10" + - name: Install nox + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install nox + - name: Run docfx + run: | + nox -s docfx diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..1e8b05c --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,25 @@ +on: + pull_request: + branches: + - main +name: lint +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.10" + - name: Install nox + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install nox + - name: Run lint + run: | + nox -s lint + - name: Run lint_setup_py + run: | + nox -s lint_setup_py diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml new file mode 100644 index 0000000..074ee25 --- /dev/null +++ b/.github/workflows/unittest.yml @@ -0,0 +1,57 @@ +on: + pull_request: + branches: + - main +name: unittest +jobs: + unit: + runs-on: ubuntu-latest + strategy: + matrix: + python: ['3.6', '3.7', '3.8', '3.9', '3.10'] + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python }} + - name: Install nox + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install nox + - name: Run unit tests + env: + COVERAGE_FILE: .coverage-${{ matrix.python }} + run: | + nox -s unit-${{ matrix.python }} + - name: Upload coverage results + uses: actions/upload-artifact@v2 + with: + name: coverage-artifacts + path: .coverage-${{ matrix.python }} + + cover: + runs-on: ubuntu-latest + needs: + - unit + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.10" + - name: Install coverage + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install coverage + - name: Download coverage results + uses: actions/download-artifact@v2 + with: + name: coverage-artifacts + path: .coverage-results/ + - name: Report coverage results + run: | + coverage combine .coverage-results/.coverage* + coverage report --show-missing --fail-under=100 diff --git a/.kokoro/release.sh b/.kokoro/release.sh index 702d228..33b8a0f 100755 --- a/.kokoro/release.sh +++ b/.kokoro/release.sh @@ -26,7 +26,7 @@ python3 -m pip install --upgrade twine wheel setuptools export PYTHONUNBUFFERED=1 # Move into the package, build the distribution and upload. -TWINE_PASSWORD=$(cat "${KOKORO_GFILE_DIR}/secret_manager/google-cloud-pypi-token") +TWINE_PASSWORD=$(cat "${KOKORO_KEYSTORE_DIR}/73713_google-cloud-pypi-token-keystore-1") cd github/python-workflows python3 setup.py sdist bdist_wheel twine upload --username __token__ --password "${TWINE_PASSWORD}" dist/* diff --git a/.kokoro/release/common.cfg b/.kokoro/release/common.cfg index 215173b..34a74d8 100644 --- a/.kokoro/release/common.cfg +++ b/.kokoro/release/common.cfg @@ -23,8 +23,18 @@ env_vars: { value: "github/python-workflows/.kokoro/release.sh" } +# Fetch PyPI password +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 73713 + keyname: "google-cloud-pypi-token-keystore-1" + } + } +} + # Tokens needed to report release status back to GitHub env_vars: { key: "SECRET_MANAGER_KEYS" - value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem,google-cloud-pypi-token" + value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem" } diff --git a/.repo-metadata.json b/.repo-metadata.json index f2661e2..79616a6 100644 --- a/.repo-metadata.json +++ b/.repo-metadata.json @@ -2,14 +2,15 @@ "name": "workflows", "name_pretty": "Cloud Workflows", "product_documentation": "https://cloud.google.com/workflows/", - "client_documentation": "https://googleapis.dev/python/workflows/latest", + "client_documentation": "https://cloud.google.com/python/docs/reference/workflows/latest", "issue_tracker": "https://issuetracker.google.com/savedsearches/559729", - "release_level": "ga", + "release_level": "stable", "language": "python", "library_type": "GAPIC_AUTO", "repo": "googleapis/python-workflows", "distribution_name": "google-cloud-workflows", "api_id": "workflows.googleapis.com", "default_version": "v1", - "codeowner_team": "" + "codeowner_team": "", + "api_shortname": "workflows" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 759129e..9860359 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +## [1.6.0](https://github.com/googleapis/python-workflows/compare/v1.5.0...v1.6.0) (2022-02-15) + + +### Features + +* add api key support ([#127](https://github.com/googleapis/python-workflows/issues/127)) ([9db415f](https://github.com/googleapis/python-workflows/commit/9db415fdcc3ac7372e07b060a06751d0c8804ba8)) + + +### Bug Fixes + +* **deps:** remove unused dependency libcst ([#133](https://github.com/googleapis/python-workflows/issues/133)) ([bfadb79](https://github.com/googleapis/python-workflows/commit/bfadb7946d7960996a7d371c5b60b47057009eb5)) +* resolve DuplicateCredentialArgs error when using credentials_file ([57614ee](https://github.com/googleapis/python-workflows/commit/57614eeac59b09bcbbb8bdf50369934c73802ae3)) + ## [1.5.0](https://www.github.com/googleapis/python-workflows/compare/v1.4.1...v1.5.0) (2021-11-05) diff --git a/README.rst b/README.rst index 5264ea3..8442a49 100644 --- a/README.rst +++ b/README.rst @@ -16,7 +16,7 @@ API services with serverless workflows. .. |versions| image:: https://img.shields.io/pypi/pyversions/google-cloud-workflows.svg :target: https://pypi.org/project/google-cloud-workflows/ .. _Cloud Workflows API: https://cloud.google.com/workflows/docs -.. _Client Library Documentation: https://googleapis.dev/python/workflows/latest +.. _Client Library Documentation: https://cloud.google.com/python/docs/reference/workflows/latest .. _Product Documentation: https://cloud.google.com/workflows/docs Quick Start diff --git a/google/cloud/workflows/executions_v1/services/executions/async_client.py b/google/cloud/workflows/executions_v1/services/executions/async_client.py index ff1605f..403dd5c 100644 --- a/google/cloud/workflows/executions_v1/services/executions/async_client.py +++ b/google/cloud/workflows/executions_v1/services/executions/async_client.py @@ -16,17 +16,20 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core.client_options import ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.cloud.workflows.executions_v1.services.executions import pagers from google.cloud.workflows.executions_v1.types import executions @@ -102,6 +105,42 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return ExecutionsClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> ExecutionsTransport: """Returns the transport used by the client instance. @@ -177,6 +216,27 @@ async def list_executions( executions are ordered by their start time (newest first). + + .. code-block:: + + from google.cloud.workflows import executions_v1 + + def sample_list_executions(): + # Create a client + client = executions_v1.ExecutionsClient() + + # Initialize request argument(s) + request = executions_v1.ListExecutionsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_executions(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.workflows.executions_v1.types.ListExecutionsRequest, dict]): The request object. Request for the @@ -208,7 +268,7 @@ async def list_executions( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: @@ -263,6 +323,26 @@ async def create_execution( r"""Creates a new execution using the latest revision of the given workflow. + + .. code-block:: + + from google.cloud.workflows import executions_v1 + + def sample_create_execution(): + # Create a client + client = executions_v1.ExecutionsClient() + + # Initialize request argument(s) + request = executions_v1.CreateExecutionRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_execution(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows.executions_v1.types.CreateExecutionRequest, dict]): The request object. Request for the @@ -297,7 +377,7 @@ async def create_execution( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, execution]) if request is not None and has_flattened_params: @@ -346,6 +426,25 @@ async def get_execution( ) -> executions.Execution: r"""Returns an execution of the given name. + .. code-block:: + + from google.cloud.workflows import executions_v1 + + def sample_get_execution(): + # Create a client + client = executions_v1.ExecutionsClient() + + # Initialize request argument(s) + request = executions_v1.GetExecutionRequest( + name="name_value", + ) + + # Make the request + response = client.get_execution(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows.executions_v1.types.GetExecutionRequest, dict]): The request object. Request for the @@ -372,7 +471,7 @@ async def get_execution( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -419,6 +518,25 @@ async def cancel_execution( ) -> executions.Execution: r"""Cancels an execution of the given name. + .. code-block:: + + from google.cloud.workflows import executions_v1 + + def sample_cancel_execution(): + # Create a client + client = executions_v1.ExecutionsClient() + + # Initialize request argument(s) + request = executions_v1.CancelExecutionRequest( + name="name_value", + ) + + # Make the request + response = client.cancel_execution(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows.executions_v1.types.CancelExecutionRequest, dict]): The request object. Request for the @@ -445,7 +563,7 @@ async def cancel_execution( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: diff --git a/google/cloud/workflows/executions_v1/services/executions/client.py b/google/cloud/workflows/executions_v1/services/executions/client.py index 584f81a..5d53797 100644 --- a/google/cloud/workflows/executions_v1/services/executions/client.py +++ b/google/cloud/workflows/executions_v1/services/executions/client.py @@ -14,23 +14,25 @@ # limitations under the License. # from collections import OrderedDict -from distutils import util import os import re from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.cloud.workflows.executions_v1.services.executions import pagers from google.cloud.workflows.executions_v1.types import executions @@ -251,6 +253,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -301,50 +370,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - use_client_cert = bool( - util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - if is_mtls: - client_cert_source_func = mtls.default_client_cert_source() - else: - client_cert_source_func = None - - # Figure out which api endpoint to use. - if client_options.api_endpoint is not None: - api_endpoint = client_options.api_endpoint - else: - use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") - if use_mtls_env == "never": - api_endpoint = self.DEFAULT_ENDPOINT - elif use_mtls_env == "always": - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - elif use_mtls_env == "auto": - if is_mtls: - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = self.DEFAULT_ENDPOINT - else: - raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " - "values: never, auto, always" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # Save or instantiate the transport. # Ordinarily, we provide the transport, but allowing a custom transport # instance provides an extensibility point for unusual situations. if isinstance(transport, ExecutionsTransport): # transport is a ExecutionsTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: raise ValueError( "When providing a transport instance, " "provide its credentials directly." @@ -356,6 +397,15 @@ def __init__( ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -383,6 +433,28 @@ def list_executions( executions are ordered by their start time (newest first). + + + .. code-block:: + + from google.cloud.workflows import executions_v1 + + def sample_list_executions(): + # Create a client + client = executions_v1.ExecutionsClient() + + # Initialize request argument(s) + request = executions_v1.ListExecutionsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_executions(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.workflows.executions_v1.types.ListExecutionsRequest, dict]): The request object. Request for the @@ -414,7 +486,7 @@ def list_executions( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: @@ -469,6 +541,27 @@ def create_execution( r"""Creates a new execution using the latest revision of the given workflow. + + + .. code-block:: + + from google.cloud.workflows import executions_v1 + + def sample_create_execution(): + # Create a client + client = executions_v1.ExecutionsClient() + + # Initialize request argument(s) + request = executions_v1.CreateExecutionRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_execution(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows.executions_v1.types.CreateExecutionRequest, dict]): The request object. Request for the @@ -503,7 +596,7 @@ def create_execution( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, execution]) if request is not None and has_flattened_params: @@ -552,6 +645,26 @@ def get_execution( ) -> executions.Execution: r"""Returns an execution of the given name. + + .. code-block:: + + from google.cloud.workflows import executions_v1 + + def sample_get_execution(): + # Create a client + client = executions_v1.ExecutionsClient() + + # Initialize request argument(s) + request = executions_v1.GetExecutionRequest( + name="name_value", + ) + + # Make the request + response = client.get_execution(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows.executions_v1.types.GetExecutionRequest, dict]): The request object. Request for the @@ -578,7 +691,7 @@ def get_execution( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -625,6 +738,26 @@ def cancel_execution( ) -> executions.Execution: r"""Cancels an execution of the given name. + + .. code-block:: + + from google.cloud.workflows import executions_v1 + + def sample_cancel_execution(): + # Create a client + client = executions_v1.ExecutionsClient() + + # Initialize request argument(s) + request = executions_v1.CancelExecutionRequest( + name="name_value", + ) + + # Make the request + response = client.cancel_execution(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows.executions_v1.types.CancelExecutionRequest, dict]): The request object. Request for the @@ -651,7 +784,7 @@ def cancel_execution( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: diff --git a/google/cloud/workflows/executions_v1/services/executions/transports/base.py b/google/cloud/workflows/executions_v1/services/executions/transports/base.py index e06f16a..695830d 100644 --- a/google/cloud/workflows/executions_v1/services/executions/transports/base.py +++ b/google/cloud/workflows/executions_v1/services/executions/transports/base.py @@ -18,10 +18,10 @@ import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore @@ -99,7 +99,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/workflows/executions_v1/services/executions/transports/grpc.py b/google/cloud/workflows/executions_v1/services/executions/transports/grpc.py index 38734e8..fb2899f 100644 --- a/google/cloud/workflows/executions_v1/services/executions/transports/grpc.py +++ b/google/cloud/workflows/executions_v1/services/executions/transports/grpc.py @@ -16,8 +16,8 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -159,8 +159,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, diff --git a/google/cloud/workflows/executions_v1/services/executions/transports/grpc_asyncio.py b/google/cloud/workflows/executions_v1/services/executions/transports/grpc_asyncio.py index 7601fa8..fc043ed 100644 --- a/google/cloud/workflows/executions_v1/services/executions/transports/grpc_asyncio.py +++ b/google/cloud/workflows/executions_v1/services/executions/transports/grpc_asyncio.py @@ -16,8 +16,8 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -204,8 +204,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, diff --git a/google/cloud/workflows/executions_v1beta/services/executions/async_client.py b/google/cloud/workflows/executions_v1beta/services/executions/async_client.py index c0ab2be..02ed703 100644 --- a/google/cloud/workflows/executions_v1beta/services/executions/async_client.py +++ b/google/cloud/workflows/executions_v1beta/services/executions/async_client.py @@ -16,17 +16,20 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core.client_options import ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.cloud.workflows.executions_v1beta.services.executions import pagers from google.cloud.workflows.executions_v1beta.types import executions @@ -103,6 +106,42 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return ExecutionsClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> ExecutionsTransport: """Returns the transport used by the client instance. @@ -178,6 +217,27 @@ async def list_executions( executions are ordered by their start time (newest first). + + .. code-block:: + + from google.cloud.workflows import executions_v1beta + + def sample_list_executions(): + # Create a client + client = executions_v1beta.ExecutionsClient() + + # Initialize request argument(s) + request = executions_v1beta.ListExecutionsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_executions(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.workflows.executions_v1beta.types.ListExecutionsRequest, dict]): The request object. Request for the @@ -209,7 +269,7 @@ async def list_executions( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: @@ -264,6 +324,26 @@ async def create_execution( r"""Creates a new execution using the latest revision of the given workflow. + + .. code-block:: + + from google.cloud.workflows import executions_v1beta + + def sample_create_execution(): + # Create a client + client = executions_v1beta.ExecutionsClient() + + # Initialize request argument(s) + request = executions_v1beta.CreateExecutionRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_execution(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows.executions_v1beta.types.CreateExecutionRequest, dict]): The request object. Request for the @@ -298,7 +378,7 @@ async def create_execution( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, execution]) if request is not None and has_flattened_params: @@ -347,6 +427,25 @@ async def get_execution( ) -> executions.Execution: r"""Returns an execution of the given name. + .. code-block:: + + from google.cloud.workflows import executions_v1beta + + def sample_get_execution(): + # Create a client + client = executions_v1beta.ExecutionsClient() + + # Initialize request argument(s) + request = executions_v1beta.GetExecutionRequest( + name="name_value", + ) + + # Make the request + response = client.get_execution(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows.executions_v1beta.types.GetExecutionRequest, dict]): The request object. Request for the @@ -373,7 +472,7 @@ async def get_execution( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -420,6 +519,25 @@ async def cancel_execution( ) -> executions.Execution: r"""Cancels an execution of the given name. + .. code-block:: + + from google.cloud.workflows import executions_v1beta + + def sample_cancel_execution(): + # Create a client + client = executions_v1beta.ExecutionsClient() + + # Initialize request argument(s) + request = executions_v1beta.CancelExecutionRequest( + name="name_value", + ) + + # Make the request + response = client.cancel_execution(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows.executions_v1beta.types.CancelExecutionRequest, dict]): The request object. Request for the @@ -446,7 +564,7 @@ async def cancel_execution( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: diff --git a/google/cloud/workflows/executions_v1beta/services/executions/client.py b/google/cloud/workflows/executions_v1beta/services/executions/client.py index d294c2b..de14a73 100644 --- a/google/cloud/workflows/executions_v1beta/services/executions/client.py +++ b/google/cloud/workflows/executions_v1beta/services/executions/client.py @@ -14,23 +14,25 @@ # limitations under the License. # from collections import OrderedDict -from distutils import util import os import re from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.cloud.workflows.executions_v1beta.services.executions import pagers from google.cloud.workflows.executions_v1beta.types import executions @@ -252,6 +254,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -302,50 +371,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - use_client_cert = bool( - util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - if is_mtls: - client_cert_source_func = mtls.default_client_cert_source() - else: - client_cert_source_func = None - - # Figure out which api endpoint to use. - if client_options.api_endpoint is not None: - api_endpoint = client_options.api_endpoint - else: - use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") - if use_mtls_env == "never": - api_endpoint = self.DEFAULT_ENDPOINT - elif use_mtls_env == "always": - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - elif use_mtls_env == "auto": - if is_mtls: - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = self.DEFAULT_ENDPOINT - else: - raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " - "values: never, auto, always" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # Save or instantiate the transport. # Ordinarily, we provide the transport, but allowing a custom transport # instance provides an extensibility point for unusual situations. if isinstance(transport, ExecutionsTransport): # transport is a ExecutionsTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: raise ValueError( "When providing a transport instance, " "provide its credentials directly." @@ -357,6 +398,15 @@ def __init__( ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -384,6 +434,28 @@ def list_executions( executions are ordered by their start time (newest first). + + + .. code-block:: + + from google.cloud.workflows import executions_v1beta + + def sample_list_executions(): + # Create a client + client = executions_v1beta.ExecutionsClient() + + # Initialize request argument(s) + request = executions_v1beta.ListExecutionsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_executions(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.workflows.executions_v1beta.types.ListExecutionsRequest, dict]): The request object. Request for the @@ -415,7 +487,7 @@ def list_executions( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: @@ -470,6 +542,27 @@ def create_execution( r"""Creates a new execution using the latest revision of the given workflow. + + + .. code-block:: + + from google.cloud.workflows import executions_v1beta + + def sample_create_execution(): + # Create a client + client = executions_v1beta.ExecutionsClient() + + # Initialize request argument(s) + request = executions_v1beta.CreateExecutionRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_execution(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows.executions_v1beta.types.CreateExecutionRequest, dict]): The request object. Request for the @@ -504,7 +597,7 @@ def create_execution( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, execution]) if request is not None and has_flattened_params: @@ -553,6 +646,26 @@ def get_execution( ) -> executions.Execution: r"""Returns an execution of the given name. + + .. code-block:: + + from google.cloud.workflows import executions_v1beta + + def sample_get_execution(): + # Create a client + client = executions_v1beta.ExecutionsClient() + + # Initialize request argument(s) + request = executions_v1beta.GetExecutionRequest( + name="name_value", + ) + + # Make the request + response = client.get_execution(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows.executions_v1beta.types.GetExecutionRequest, dict]): The request object. Request for the @@ -579,7 +692,7 @@ def get_execution( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -626,6 +739,26 @@ def cancel_execution( ) -> executions.Execution: r"""Cancels an execution of the given name. + + .. code-block:: + + from google.cloud.workflows import executions_v1beta + + def sample_cancel_execution(): + # Create a client + client = executions_v1beta.ExecutionsClient() + + # Initialize request argument(s) + request = executions_v1beta.CancelExecutionRequest( + name="name_value", + ) + + # Make the request + response = client.cancel_execution(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows.executions_v1beta.types.CancelExecutionRequest, dict]): The request object. Request for the @@ -652,7 +785,7 @@ def cancel_execution( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: diff --git a/google/cloud/workflows/executions_v1beta/services/executions/transports/base.py b/google/cloud/workflows/executions_v1beta/services/executions/transports/base.py index 6e779e9..64b4db4 100644 --- a/google/cloud/workflows/executions_v1beta/services/executions/transports/base.py +++ b/google/cloud/workflows/executions_v1beta/services/executions/transports/base.py @@ -18,10 +18,10 @@ import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore @@ -99,7 +99,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/workflows/executions_v1beta/services/executions/transports/grpc.py b/google/cloud/workflows/executions_v1beta/services/executions/transports/grpc.py index d15f045..b692116 100644 --- a/google/cloud/workflows/executions_v1beta/services/executions/transports/grpc.py +++ b/google/cloud/workflows/executions_v1beta/services/executions/transports/grpc.py @@ -16,8 +16,8 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -160,8 +160,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, diff --git a/google/cloud/workflows/executions_v1beta/services/executions/transports/grpc_asyncio.py b/google/cloud/workflows/executions_v1beta/services/executions/transports/grpc_asyncio.py index 4050dae..064e9d4 100644 --- a/google/cloud/workflows/executions_v1beta/services/executions/transports/grpc_asyncio.py +++ b/google/cloud/workflows/executions_v1beta/services/executions/transports/grpc_asyncio.py @@ -16,8 +16,8 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -205,8 +205,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, diff --git a/google/cloud/workflows_v1/services/workflows/async_client.py b/google/cloud/workflows_v1/services/workflows/async_client.py index 5118c7e..c8965a4 100644 --- a/google/cloud/workflows_v1/services/workflows/async_client.py +++ b/google/cloud/workflows_v1/services/workflows/async_client.py @@ -16,17 +16,20 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core.client_options import ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -105,6 +108,42 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return WorkflowsClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> WorkflowsTransport: """Returns the transport used by the client instance. @@ -177,6 +216,27 @@ async def list_workflows( r"""Lists Workflows in a given project and location. The default order is not specified. + + .. code-block:: + + from google.cloud import workflows_v1 + + def sample_list_workflows(): + # Create a client + client = workflows_v1.WorkflowsClient() + + # Initialize request argument(s) + request = workflows_v1.ListWorkflowsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_workflows(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.workflows_v1.types.ListWorkflowsRequest, dict]): The request object. Request for the @@ -208,7 +268,7 @@ async def list_workflows( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: @@ -261,6 +321,25 @@ async def get_workflow( ) -> workflows.Workflow: r"""Gets details of a single Workflow. + .. code-block:: + + from google.cloud import workflows_v1 + + def sample_get_workflow(): + # Create a client + client = workflows_v1.WorkflowsClient() + + # Initialize request argument(s) + request = workflows_v1.GetWorkflowRequest( + name="name_value", + ) + + # Make the request + response = client.get_workflow(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows_v1.types.GetWorkflowRequest, dict]): The request object. Request for the @@ -287,7 +366,7 @@ async def get_workflow( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -339,6 +418,35 @@ async def create_workflow( running operation will return [ALREADY_EXISTS][google.rpc.Code.ALREADY_EXISTS] error. + + .. code-block:: + + from google.cloud import workflows_v1 + + def sample_create_workflow(): + # Create a client + client = workflows_v1.WorkflowsClient() + + # Initialize request argument(s) + workflow = workflows_v1.Workflow() + workflow.source_contents = "source_contents_value" + + request = workflows_v1.CreateWorkflowRequest( + parent="parent_value", + workflow=workflow, + workflow_id="workflow_id_value", + ) + + # Make the request + operation = client.create_workflow(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows_v1.types.CreateWorkflowRequest, dict]): The request object. Request for the @@ -389,7 +497,7 @@ async def create_workflow( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, workflow, workflow_id]) if request is not None and has_flattened_params: @@ -450,6 +558,30 @@ async def delete_workflow( This method also cancels and deletes all running executions of the workflow. + + .. code-block:: + + from google.cloud import workflows_v1 + + def sample_delete_workflow(): + # Create a client + client = workflows_v1.WorkflowsClient() + + # Initialize request argument(s) + request = workflows_v1.DeleteWorkflowRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_workflow(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows_v1.types.DeleteWorkflowRequest, dict]): The request object. Request for the @@ -489,7 +621,7 @@ async def delete_workflow( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -550,6 +682,33 @@ async def update_workflow( update operation. In that case, such revision will be used in new workflow executions. + + .. code-block:: + + from google.cloud import workflows_v1 + + def sample_update_workflow(): + # Create a client + client = workflows_v1.WorkflowsClient() + + # Initialize request argument(s) + workflow = workflows_v1.Workflow() + workflow.source_contents = "source_contents_value" + + request = workflows_v1.UpdateWorkflowRequest( + workflow=workflow, + ) + + # Make the request + operation = client.update_workflow(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows_v1.types.UpdateWorkflowRequest, dict]): The request object. Request for the @@ -584,7 +743,7 @@ async def update_workflow( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([workflow, update_mask]) if request is not None and has_flattened_params: diff --git a/google/cloud/workflows_v1/services/workflows/client.py b/google/cloud/workflows_v1/services/workflows/client.py index 19022d0..3f9e681 100644 --- a/google/cloud/workflows_v1/services/workflows/client.py +++ b/google/cloud/workflows_v1/services/workflows/client.py @@ -14,23 +14,25 @@ # limitations under the License. # from collections import OrderedDict -from distutils import util import os import re from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -238,6 +240,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -288,50 +357,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - use_client_cert = bool( - util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - if is_mtls: - client_cert_source_func = mtls.default_client_cert_source() - else: - client_cert_source_func = None - - # Figure out which api endpoint to use. - if client_options.api_endpoint is not None: - api_endpoint = client_options.api_endpoint - else: - use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") - if use_mtls_env == "never": - api_endpoint = self.DEFAULT_ENDPOINT - elif use_mtls_env == "always": - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - elif use_mtls_env == "auto": - if is_mtls: - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = self.DEFAULT_ENDPOINT - else: - raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " - "values: never, auto, always" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # Save or instantiate the transport. # Ordinarily, we provide the transport, but allowing a custom transport # instance provides an extensibility point for unusual situations. if isinstance(transport, WorkflowsTransport): # transport is a WorkflowsTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: raise ValueError( "When providing a transport instance, " "provide its credentials directly." @@ -343,6 +384,15 @@ def __init__( ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -367,6 +417,28 @@ def list_workflows( r"""Lists Workflows in a given project and location. The default order is not specified. + + + .. code-block:: + + from google.cloud import workflows_v1 + + def sample_list_workflows(): + # Create a client + client = workflows_v1.WorkflowsClient() + + # Initialize request argument(s) + request = workflows_v1.ListWorkflowsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_workflows(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.workflows_v1.types.ListWorkflowsRequest, dict]): The request object. Request for the @@ -398,7 +470,7 @@ def list_workflows( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: @@ -451,6 +523,26 @@ def get_workflow( ) -> workflows.Workflow: r"""Gets details of a single Workflow. + + .. code-block:: + + from google.cloud import workflows_v1 + + def sample_get_workflow(): + # Create a client + client = workflows_v1.WorkflowsClient() + + # Initialize request argument(s) + request = workflows_v1.GetWorkflowRequest( + name="name_value", + ) + + # Make the request + response = client.get_workflow(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows_v1.types.GetWorkflowRequest, dict]): The request object. Request for the @@ -477,7 +569,7 @@ def get_workflow( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -529,6 +621,36 @@ def create_workflow( running operation will return [ALREADY_EXISTS][google.rpc.Code.ALREADY_EXISTS] error. + + + .. code-block:: + + from google.cloud import workflows_v1 + + def sample_create_workflow(): + # Create a client + client = workflows_v1.WorkflowsClient() + + # Initialize request argument(s) + workflow = workflows_v1.Workflow() + workflow.source_contents = "source_contents_value" + + request = workflows_v1.CreateWorkflowRequest( + parent="parent_value", + workflow=workflow, + workflow_id="workflow_id_value", + ) + + # Make the request + operation = client.create_workflow(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows_v1.types.CreateWorkflowRequest, dict]): The request object. Request for the @@ -579,7 +701,7 @@ def create_workflow( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, workflow, workflow_id]) if request is not None and has_flattened_params: @@ -640,6 +762,31 @@ def delete_workflow( This method also cancels and deletes all running executions of the workflow. + + + .. code-block:: + + from google.cloud import workflows_v1 + + def sample_delete_workflow(): + # Create a client + client = workflows_v1.WorkflowsClient() + + # Initialize request argument(s) + request = workflows_v1.DeleteWorkflowRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_workflow(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows_v1.types.DeleteWorkflowRequest, dict]): The request object. Request for the @@ -679,7 +826,7 @@ def delete_workflow( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -740,6 +887,34 @@ def update_workflow( update operation. In that case, such revision will be used in new workflow executions. + + + .. code-block:: + + from google.cloud import workflows_v1 + + def sample_update_workflow(): + # Create a client + client = workflows_v1.WorkflowsClient() + + # Initialize request argument(s) + workflow = workflows_v1.Workflow() + workflow.source_contents = "source_contents_value" + + request = workflows_v1.UpdateWorkflowRequest( + workflow=workflow, + ) + + # Make the request + operation = client.update_workflow(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows_v1.types.UpdateWorkflowRequest, dict]): The request object. Request for the @@ -774,7 +949,7 @@ def update_workflow( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([workflow, update_mask]) if request is not None and has_flattened_params: diff --git a/google/cloud/workflows_v1/services/workflows/transports/base.py b/google/cloud/workflows_v1/services/workflows/transports/base.py index 9a72531..67089ad 100644 --- a/google/cloud/workflows_v1/services/workflows/transports/base.py +++ b/google/cloud/workflows_v1/services/workflows/transports/base.py @@ -18,11 +18,11 @@ import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore @@ -101,7 +101,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/workflows_v1/services/workflows/transports/grpc.py b/google/cloud/workflows_v1/services/workflows/transports/grpc.py index 0404663..e0c3f59 100644 --- a/google/cloud/workflows_v1/services/workflows/transports/grpc.py +++ b/google/cloud/workflows_v1/services/workflows/transports/grpc.py @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -163,8 +163,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -237,7 +240,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) diff --git a/google/cloud/workflows_v1/services/workflows/transports/grpc_asyncio.py b/google/cloud/workflows_v1/services/workflows/transports/grpc_asyncio.py index 0bc50a9..63a5cde 100644 --- a/google/cloud/workflows_v1/services/workflows/transports/grpc_asyncio.py +++ b/google/cloud/workflows_v1/services/workflows/transports/grpc_asyncio.py @@ -16,9 +16,9 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -208,8 +208,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -239,7 +242,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel diff --git a/google/cloud/workflows_v1/types/workflows.py b/google/cloud/workflows_v1/types/workflows.py index 1aaef1f..9cb93a2 100644 --- a/google/cloud/workflows_v1/types/workflows.py +++ b/google/cloud/workflows_v1/types/workflows.py @@ -99,6 +99,7 @@ class Workflow(proto.Message): source_contents (str): Workflow code to be executed. The size limit is 128KB. + This field is a member of `oneof`_ ``source_code``. """ diff --git a/google/cloud/workflows_v1beta/services/workflows/async_client.py b/google/cloud/workflows_v1beta/services/workflows/async_client.py index 088829f..33852d1 100644 --- a/google/cloud/workflows_v1beta/services/workflows/async_client.py +++ b/google/cloud/workflows_v1beta/services/workflows/async_client.py @@ -16,17 +16,20 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core.client_options import ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -105,6 +108,42 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return WorkflowsClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> WorkflowsTransport: """Returns the transport used by the client instance. @@ -177,6 +216,27 @@ async def list_workflows( r"""Lists Workflows in a given project and location. The default order is not specified. + + .. code-block:: + + from google.cloud import workflows_v1beta + + def sample_list_workflows(): + # Create a client + client = workflows_v1beta.WorkflowsClient() + + # Initialize request argument(s) + request = workflows_v1beta.ListWorkflowsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_workflows(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.workflows_v1beta.types.ListWorkflowsRequest, dict]): The request object. Request for the @@ -208,7 +268,7 @@ async def list_workflows( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: @@ -261,6 +321,25 @@ async def get_workflow( ) -> workflows.Workflow: r"""Gets details of a single Workflow. + .. code-block:: + + from google.cloud import workflows_v1beta + + def sample_get_workflow(): + # Create a client + client = workflows_v1beta.WorkflowsClient() + + # Initialize request argument(s) + request = workflows_v1beta.GetWorkflowRequest( + name="name_value", + ) + + # Make the request + response = client.get_workflow(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows_v1beta.types.GetWorkflowRequest, dict]): The request object. Request for the @@ -287,7 +366,7 @@ async def get_workflow( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -339,6 +418,35 @@ async def create_workflow( running operation will return [ALREADY_EXISTS][google.rpc.Code.ALREADY_EXISTS] error. + + .. code-block:: + + from google.cloud import workflows_v1beta + + def sample_create_workflow(): + # Create a client + client = workflows_v1beta.WorkflowsClient() + + # Initialize request argument(s) + workflow = workflows_v1beta.Workflow() + workflow.source_contents = "source_contents_value" + + request = workflows_v1beta.CreateWorkflowRequest( + parent="parent_value", + workflow=workflow, + workflow_id="workflow_id_value", + ) + + # Make the request + operation = client.create_workflow(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows_v1beta.types.CreateWorkflowRequest, dict]): The request object. Request for the @@ -389,7 +497,7 @@ async def create_workflow( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, workflow, workflow_id]) if request is not None and has_flattened_params: @@ -450,6 +558,30 @@ async def delete_workflow( This method also cancels and deletes all running executions of the workflow. + + .. code-block:: + + from google.cloud import workflows_v1beta + + def sample_delete_workflow(): + # Create a client + client = workflows_v1beta.WorkflowsClient() + + # Initialize request argument(s) + request = workflows_v1beta.DeleteWorkflowRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_workflow(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows_v1beta.types.DeleteWorkflowRequest, dict]): The request object. Request for the @@ -489,7 +621,7 @@ async def delete_workflow( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -550,6 +682,33 @@ async def update_workflow( update operation. In that case, such revision will be used in new workflow executions. + + .. code-block:: + + from google.cloud import workflows_v1beta + + def sample_update_workflow(): + # Create a client + client = workflows_v1beta.WorkflowsClient() + + # Initialize request argument(s) + workflow = workflows_v1beta.Workflow() + workflow.source_contents = "source_contents_value" + + request = workflows_v1beta.UpdateWorkflowRequest( + workflow=workflow, + ) + + # Make the request + operation = client.update_workflow(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows_v1beta.types.UpdateWorkflowRequest, dict]): The request object. Request for the @@ -584,7 +743,7 @@ async def update_workflow( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([workflow, update_mask]) if request is not None and has_flattened_params: diff --git a/google/cloud/workflows_v1beta/services/workflows/client.py b/google/cloud/workflows_v1beta/services/workflows/client.py index 1be074a..5f7e510 100644 --- a/google/cloud/workflows_v1beta/services/workflows/client.py +++ b/google/cloud/workflows_v1beta/services/workflows/client.py @@ -14,23 +14,25 @@ # limitations under the License. # from collections import OrderedDict -from distutils import util import os import re from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport import mtls # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore -OptionalRetry = Union[retries.Retry, object] +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -238,6 +240,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -288,50 +357,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - use_client_cert = bool( - util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - if is_mtls: - client_cert_source_func = mtls.default_client_cert_source() - else: - client_cert_source_func = None - - # Figure out which api endpoint to use. - if client_options.api_endpoint is not None: - api_endpoint = client_options.api_endpoint - else: - use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") - if use_mtls_env == "never": - api_endpoint = self.DEFAULT_ENDPOINT - elif use_mtls_env == "always": - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - elif use_mtls_env == "auto": - if is_mtls: - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = self.DEFAULT_ENDPOINT - else: - raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " - "values: never, auto, always" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # Save or instantiate the transport. # Ordinarily, we provide the transport, but allowing a custom transport # instance provides an extensibility point for unusual situations. if isinstance(transport, WorkflowsTransport): # transport is a WorkflowsTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: raise ValueError( "When providing a transport instance, " "provide its credentials directly." @@ -343,6 +384,15 @@ def __init__( ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -367,6 +417,28 @@ def list_workflows( r"""Lists Workflows in a given project and location. The default order is not specified. + + + .. code-block:: + + from google.cloud import workflows_v1beta + + def sample_list_workflows(): + # Create a client + client = workflows_v1beta.WorkflowsClient() + + # Initialize request argument(s) + request = workflows_v1beta.ListWorkflowsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_workflows(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.workflows_v1beta.types.ListWorkflowsRequest, dict]): The request object. Request for the @@ -398,7 +470,7 @@ def list_workflows( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: @@ -451,6 +523,26 @@ def get_workflow( ) -> workflows.Workflow: r"""Gets details of a single Workflow. + + .. code-block:: + + from google.cloud import workflows_v1beta + + def sample_get_workflow(): + # Create a client + client = workflows_v1beta.WorkflowsClient() + + # Initialize request argument(s) + request = workflows_v1beta.GetWorkflowRequest( + name="name_value", + ) + + # Make the request + response = client.get_workflow(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows_v1beta.types.GetWorkflowRequest, dict]): The request object. Request for the @@ -477,7 +569,7 @@ def get_workflow( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -529,6 +621,36 @@ def create_workflow( running operation will return [ALREADY_EXISTS][google.rpc.Code.ALREADY_EXISTS] error. + + + .. code-block:: + + from google.cloud import workflows_v1beta + + def sample_create_workflow(): + # Create a client + client = workflows_v1beta.WorkflowsClient() + + # Initialize request argument(s) + workflow = workflows_v1beta.Workflow() + workflow.source_contents = "source_contents_value" + + request = workflows_v1beta.CreateWorkflowRequest( + parent="parent_value", + workflow=workflow, + workflow_id="workflow_id_value", + ) + + # Make the request + operation = client.create_workflow(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows_v1beta.types.CreateWorkflowRequest, dict]): The request object. Request for the @@ -579,7 +701,7 @@ def create_workflow( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, workflow, workflow_id]) if request is not None and has_flattened_params: @@ -640,6 +762,31 @@ def delete_workflow( This method also cancels and deletes all running executions of the workflow. + + + .. code-block:: + + from google.cloud import workflows_v1beta + + def sample_delete_workflow(): + # Create a client + client = workflows_v1beta.WorkflowsClient() + + # Initialize request argument(s) + request = workflows_v1beta.DeleteWorkflowRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_workflow(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows_v1beta.types.DeleteWorkflowRequest, dict]): The request object. Request for the @@ -679,7 +826,7 @@ def delete_workflow( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -740,6 +887,34 @@ def update_workflow( update operation. In that case, such revision will be used in new workflow executions. + + + .. code-block:: + + from google.cloud import workflows_v1beta + + def sample_update_workflow(): + # Create a client + client = workflows_v1beta.WorkflowsClient() + + # Initialize request argument(s) + workflow = workflows_v1beta.Workflow() + workflow.source_contents = "source_contents_value" + + request = workflows_v1beta.UpdateWorkflowRequest( + workflow=workflow, + ) + + # Make the request + operation = client.update_workflow(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.workflows_v1beta.types.UpdateWorkflowRequest, dict]): The request object. Request for the @@ -774,7 +949,7 @@ def update_workflow( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([workflow, update_mask]) if request is not None and has_flattened_params: diff --git a/google/cloud/workflows_v1beta/services/workflows/transports/base.py b/google/cloud/workflows_v1beta/services/workflows/transports/base.py index 210ab3f..7d98d08 100644 --- a/google/cloud/workflows_v1beta/services/workflows/transports/base.py +++ b/google/cloud/workflows_v1beta/services/workflows/transports/base.py @@ -18,11 +18,11 @@ import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore @@ -101,7 +101,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/google/cloud/workflows_v1beta/services/workflows/transports/grpc.py b/google/cloud/workflows_v1beta/services/workflows/transports/grpc.py index 64e243c..db63aef 100644 --- a/google/cloud/workflows_v1beta/services/workflows/transports/grpc.py +++ b/google/cloud/workflows_v1beta/services/workflows/transports/grpc.py @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -163,8 +163,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -237,7 +240,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) diff --git a/google/cloud/workflows_v1beta/services/workflows/transports/grpc_asyncio.py b/google/cloud/workflows_v1beta/services/workflows/transports/grpc_asyncio.py index c3c56f3..4580f47 100644 --- a/google/cloud/workflows_v1beta/services/workflows/transports/grpc_asyncio.py +++ b/google/cloud/workflows_v1beta/services/workflows/transports/grpc_asyncio.py @@ -16,9 +16,9 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -208,8 +208,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -239,7 +242,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel diff --git a/google/cloud/workflows_v1beta/types/workflows.py b/google/cloud/workflows_v1beta/types/workflows.py index f7d4dda..0bf26fd 100644 --- a/google/cloud/workflows_v1beta/types/workflows.py +++ b/google/cloud/workflows_v1beta/types/workflows.py @@ -96,6 +96,7 @@ class Workflow(proto.Message): source_contents (str): Workflow code to be executed. The size limit is 32KB. + This field is a member of `oneof`_ ``source_code``. """ diff --git a/noxfile.py b/noxfile.py index f041f1f..2a2001c 100644 --- a/noxfile.py +++ b/noxfile.py @@ -175,7 +175,7 @@ def cover(session): test runs (not system test runs), and then erases coverage data. """ session.install("coverage", "pytest-cov") - session.run("coverage", "report", "--show-missing", "--fail-under=98") + session.run("coverage", "report", "--show-missing", "--fail-under=100") session.run("coverage", "erase") diff --git a/owlbot.py b/owlbot.py index 721f0b9..73ef18c 100644 --- a/owlbot.py +++ b/owlbot.py @@ -100,7 +100,7 @@ def get_staging_dirs( # ---------------------------------------------------------------------------- # Add templated files # ---------------------------------------------------------------------------- -templated_files = common.py_library(cov_level=98, microgenerator=True) +templated_files = common.py_library(cov_level=100, microgenerator=True) s.move( templated_files, excludes=[".coveragerc"] diff --git a/samples/generated_samples/snippet_metadata_executions_v1.json b/samples/generated_samples/snippet_metadata_executions_v1.json new file mode 100644 index 0000000..3d3c18b --- /dev/null +++ b/samples/generated_samples/snippet_metadata_executions_v1.json @@ -0,0 +1,360 @@ +{ + "snippets": [ + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Executions" + }, + "shortName": "CancelExecution" + } + }, + "file": "workflowexecutions_generated_executions_v1_executions_cancel_execution_async.py", + "regionTag": "workflowexecutions_generated_executions_v1_Executions_CancelExecution_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Executions" + }, + "shortName": "CancelExecution" + } + }, + "file": "workflowexecutions_generated_executions_v1_executions_cancel_execution_sync.py", + "regionTag": "workflowexecutions_generated_executions_v1_Executions_CancelExecution_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Executions" + }, + "shortName": "CreateExecution" + } + }, + "file": "workflowexecutions_generated_executions_v1_executions_create_execution_async.py", + "regionTag": "workflowexecutions_generated_executions_v1_Executions_CreateExecution_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Executions" + }, + "shortName": "CreateExecution" + } + }, + "file": "workflowexecutions_generated_executions_v1_executions_create_execution_sync.py", + "regionTag": "workflowexecutions_generated_executions_v1_Executions_CreateExecution_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Executions" + }, + "shortName": "GetExecution" + } + }, + "file": "workflowexecutions_generated_executions_v1_executions_get_execution_async.py", + "regionTag": "workflowexecutions_generated_executions_v1_Executions_GetExecution_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Executions" + }, + "shortName": "GetExecution" + } + }, + "file": "workflowexecutions_generated_executions_v1_executions_get_execution_sync.py", + "regionTag": "workflowexecutions_generated_executions_v1_Executions_GetExecution_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Executions" + }, + "shortName": "ListExecutions" + } + }, + "file": "workflowexecutions_generated_executions_v1_executions_list_executions_async.py", + "regionTag": "workflowexecutions_generated_executions_v1_Executions_ListExecutions_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Executions" + }, + "shortName": "ListExecutions" + } + }, + "file": "workflowexecutions_generated_executions_v1_executions_list_executions_sync.py", + "regionTag": "workflowexecutions_generated_executions_v1_Executions_ListExecutions_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + } + ] +} diff --git a/samples/generated_samples/snippet_metadata_executions_v1beta.json b/samples/generated_samples/snippet_metadata_executions_v1beta.json new file mode 100644 index 0000000..1dcee66 --- /dev/null +++ b/samples/generated_samples/snippet_metadata_executions_v1beta.json @@ -0,0 +1,360 @@ +{ + "snippets": [ + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Executions" + }, + "shortName": "CancelExecution" + } + }, + "file": "workflowexecutions_generated_executions_v1beta_executions_cancel_execution_async.py", + "regionTag": "workflowexecutions_generated_executions_v1beta_Executions_CancelExecution_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Executions" + }, + "shortName": "CancelExecution" + } + }, + "file": "workflowexecutions_generated_executions_v1beta_executions_cancel_execution_sync.py", + "regionTag": "workflowexecutions_generated_executions_v1beta_Executions_CancelExecution_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Executions" + }, + "shortName": "CreateExecution" + } + }, + "file": "workflowexecutions_generated_executions_v1beta_executions_create_execution_async.py", + "regionTag": "workflowexecutions_generated_executions_v1beta_Executions_CreateExecution_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Executions" + }, + "shortName": "CreateExecution" + } + }, + "file": "workflowexecutions_generated_executions_v1beta_executions_create_execution_sync.py", + "regionTag": "workflowexecutions_generated_executions_v1beta_Executions_CreateExecution_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Executions" + }, + "shortName": "GetExecution" + } + }, + "file": "workflowexecutions_generated_executions_v1beta_executions_get_execution_async.py", + "regionTag": "workflowexecutions_generated_executions_v1beta_Executions_GetExecution_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Executions" + }, + "shortName": "GetExecution" + } + }, + "file": "workflowexecutions_generated_executions_v1beta_executions_get_execution_sync.py", + "regionTag": "workflowexecutions_generated_executions_v1beta_Executions_GetExecution_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Executions" + }, + "shortName": "ListExecutions" + } + }, + "file": "workflowexecutions_generated_executions_v1beta_executions_list_executions_async.py", + "regionTag": "workflowexecutions_generated_executions_v1beta_Executions_ListExecutions_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Executions" + }, + "shortName": "ListExecutions" + } + }, + "file": "workflowexecutions_generated_executions_v1beta_executions_list_executions_sync.py", + "regionTag": "workflowexecutions_generated_executions_v1beta_Executions_ListExecutions_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + } + ] +} diff --git a/samples/generated_samples/snippet_metadata_workflows_v1.json b/samples/generated_samples/snippet_metadata_workflows_v1.json new file mode 100644 index 0000000..aa06c4d --- /dev/null +++ b/samples/generated_samples/snippet_metadata_workflows_v1.json @@ -0,0 +1,449 @@ +{ + "snippets": [ + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Workflows" + }, + "shortName": "CreateWorkflow" + } + }, + "file": "workflows_generated_workflows_v1_workflows_create_workflow_async.py", + "regionTag": "workflows_generated_workflows_v1_Workflows_CreateWorkflow_async", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Workflows" + }, + "shortName": "CreateWorkflow" + } + }, + "file": "workflows_generated_workflows_v1_workflows_create_workflow_sync.py", + "regionTag": "workflows_generated_workflows_v1_Workflows_CreateWorkflow_sync", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Workflows" + }, + "shortName": "DeleteWorkflow" + } + }, + "file": "workflows_generated_workflows_v1_workflows_delete_workflow_async.py", + "regionTag": "workflows_generated_workflows_v1_Workflows_DeleteWorkflow_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Workflows" + }, + "shortName": "DeleteWorkflow" + } + }, + "file": "workflows_generated_workflows_v1_workflows_delete_workflow_sync.py", + "regionTag": "workflows_generated_workflows_v1_Workflows_DeleteWorkflow_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Workflows" + }, + "shortName": "GetWorkflow" + } + }, + "file": "workflows_generated_workflows_v1_workflows_get_workflow_async.py", + "regionTag": "workflows_generated_workflows_v1_Workflows_GetWorkflow_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Workflows" + }, + "shortName": "GetWorkflow" + } + }, + "file": "workflows_generated_workflows_v1_workflows_get_workflow_sync.py", + "regionTag": "workflows_generated_workflows_v1_Workflows_GetWorkflow_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Workflows" + }, + "shortName": "ListWorkflows" + } + }, + "file": "workflows_generated_workflows_v1_workflows_list_workflows_async.py", + "regionTag": "workflows_generated_workflows_v1_Workflows_ListWorkflows_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Workflows" + }, + "shortName": "ListWorkflows" + } + }, + "file": "workflows_generated_workflows_v1_workflows_list_workflows_sync.py", + "regionTag": "workflows_generated_workflows_v1_Workflows_ListWorkflows_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Workflows" + }, + "shortName": "UpdateWorkflow" + } + }, + "file": "workflows_generated_workflows_v1_workflows_update_workflow_async.py", + "regionTag": "workflows_generated_workflows_v1_Workflows_UpdateWorkflow_async", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Workflows" + }, + "shortName": "UpdateWorkflow" + } + }, + "file": "workflows_generated_workflows_v1_workflows_update_workflow_sync.py", + "regionTag": "workflows_generated_workflows_v1_Workflows_UpdateWorkflow_sync", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ] + } + ] +} diff --git a/samples/generated_samples/snippet_metadata_workflows_v1beta.json b/samples/generated_samples/snippet_metadata_workflows_v1beta.json new file mode 100644 index 0000000..3593c65 --- /dev/null +++ b/samples/generated_samples/snippet_metadata_workflows_v1beta.json @@ -0,0 +1,449 @@ +{ + "snippets": [ + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Workflows" + }, + "shortName": "CreateWorkflow" + } + }, + "file": "workflows_generated_workflows_v1beta_workflows_create_workflow_async.py", + "regionTag": "workflows_generated_workflows_v1beta_Workflows_CreateWorkflow_async", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Workflows" + }, + "shortName": "CreateWorkflow" + } + }, + "file": "workflows_generated_workflows_v1beta_workflows_create_workflow_sync.py", + "regionTag": "workflows_generated_workflows_v1beta_Workflows_CreateWorkflow_sync", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Workflows" + }, + "shortName": "DeleteWorkflow" + } + }, + "file": "workflows_generated_workflows_v1beta_workflows_delete_workflow_async.py", + "regionTag": "workflows_generated_workflows_v1beta_Workflows_DeleteWorkflow_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Workflows" + }, + "shortName": "DeleteWorkflow" + } + }, + "file": "workflows_generated_workflows_v1beta_workflows_delete_workflow_sync.py", + "regionTag": "workflows_generated_workflows_v1beta_Workflows_DeleteWorkflow_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Workflows" + }, + "shortName": "GetWorkflow" + } + }, + "file": "workflows_generated_workflows_v1beta_workflows_get_workflow_async.py", + "regionTag": "workflows_generated_workflows_v1beta_Workflows_GetWorkflow_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Workflows" + }, + "shortName": "GetWorkflow" + } + }, + "file": "workflows_generated_workflows_v1beta_workflows_get_workflow_sync.py", + "regionTag": "workflows_generated_workflows_v1beta_Workflows_GetWorkflow_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Workflows" + }, + "shortName": "ListWorkflows" + } + }, + "file": "workflows_generated_workflows_v1beta_workflows_list_workflows_async.py", + "regionTag": "workflows_generated_workflows_v1beta_Workflows_ListWorkflows_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Workflows" + }, + "shortName": "ListWorkflows" + } + }, + "file": "workflows_generated_workflows_v1beta_workflows_list_workflows_sync.py", + "regionTag": "workflows_generated_workflows_v1beta_Workflows_ListWorkflows_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "Workflows" + }, + "shortName": "UpdateWorkflow" + } + }, + "file": "workflows_generated_workflows_v1beta_workflows_update_workflow_async.py", + "regionTag": "workflows_generated_workflows_v1beta_Workflows_UpdateWorkflow_async", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "Workflows" + }, + "shortName": "UpdateWorkflow" + } + }, + "file": "workflows_generated_workflows_v1beta_workflows_update_workflow_sync.py", + "regionTag": "workflows_generated_workflows_v1beta_Workflows_UpdateWorkflow_sync", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ] + } + ] +} diff --git a/samples/generated_samples/workflowexecutions_generated_executions_v1_executions_cancel_execution_async.py b/samples/generated_samples/workflowexecutions_generated_executions_v1_executions_cancel_execution_async.py new file mode 100644 index 0000000..683cc76 --- /dev/null +++ b/samples/generated_samples/workflowexecutions_generated_executions_v1_executions_cancel_execution_async.py @@ -0,0 +1,45 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows-executions + + +# [START workflowexecutions_generated_executions_v1_Executions_CancelExecution_async] +from google.cloud.workflows import executions_v1 + + +async def sample_cancel_execution(): + # Create a client + client = executions_v1.ExecutionsAsyncClient() + + # Initialize request argument(s) + request = executions_v1.CancelExecutionRequest( + name="name_value", + ) + + # Make the request + response = await client.cancel_execution(request=request) + + # Handle the response + print(response) + +# [END workflowexecutions_generated_executions_v1_Executions_CancelExecution_async] diff --git a/samples/generated_samples/workflowexecutions_generated_executions_v1_executions_cancel_execution_sync.py b/samples/generated_samples/workflowexecutions_generated_executions_v1_executions_cancel_execution_sync.py new file mode 100644 index 0000000..e984f05 --- /dev/null +++ b/samples/generated_samples/workflowexecutions_generated_executions_v1_executions_cancel_execution_sync.py @@ -0,0 +1,45 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows-executions + + +# [START workflowexecutions_generated_executions_v1_Executions_CancelExecution_sync] +from google.cloud.workflows import executions_v1 + + +def sample_cancel_execution(): + # Create a client + client = executions_v1.ExecutionsClient() + + # Initialize request argument(s) + request = executions_v1.CancelExecutionRequest( + name="name_value", + ) + + # Make the request + response = client.cancel_execution(request=request) + + # Handle the response + print(response) + +# [END workflowexecutions_generated_executions_v1_Executions_CancelExecution_sync] diff --git a/samples/generated_samples/workflowexecutions_generated_executions_v1_executions_create_execution_async.py b/samples/generated_samples/workflowexecutions_generated_executions_v1_executions_create_execution_async.py new file mode 100644 index 0000000..e3821fa --- /dev/null +++ b/samples/generated_samples/workflowexecutions_generated_executions_v1_executions_create_execution_async.py @@ -0,0 +1,45 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows-executions + + +# [START workflowexecutions_generated_executions_v1_Executions_CreateExecution_async] +from google.cloud.workflows import executions_v1 + + +async def sample_create_execution(): + # Create a client + client = executions_v1.ExecutionsAsyncClient() + + # Initialize request argument(s) + request = executions_v1.CreateExecutionRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_execution(request=request) + + # Handle the response + print(response) + +# [END workflowexecutions_generated_executions_v1_Executions_CreateExecution_async] diff --git a/samples/generated_samples/workflowexecutions_generated_executions_v1_executions_create_execution_sync.py b/samples/generated_samples/workflowexecutions_generated_executions_v1_executions_create_execution_sync.py new file mode 100644 index 0000000..6812197 --- /dev/null +++ b/samples/generated_samples/workflowexecutions_generated_executions_v1_executions_create_execution_sync.py @@ -0,0 +1,45 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows-executions + + +# [START workflowexecutions_generated_executions_v1_Executions_CreateExecution_sync] +from google.cloud.workflows import executions_v1 + + +def sample_create_execution(): + # Create a client + client = executions_v1.ExecutionsClient() + + # Initialize request argument(s) + request = executions_v1.CreateExecutionRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_execution(request=request) + + # Handle the response + print(response) + +# [END workflowexecutions_generated_executions_v1_Executions_CreateExecution_sync] diff --git a/samples/generated_samples/workflowexecutions_generated_executions_v1_executions_get_execution_async.py b/samples/generated_samples/workflowexecutions_generated_executions_v1_executions_get_execution_async.py new file mode 100644 index 0000000..145c5a3 --- /dev/null +++ b/samples/generated_samples/workflowexecutions_generated_executions_v1_executions_get_execution_async.py @@ -0,0 +1,45 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows-executions + + +# [START workflowexecutions_generated_executions_v1_Executions_GetExecution_async] +from google.cloud.workflows import executions_v1 + + +async def sample_get_execution(): + # Create a client + client = executions_v1.ExecutionsAsyncClient() + + # Initialize request argument(s) + request = executions_v1.GetExecutionRequest( + name="name_value", + ) + + # Make the request + response = await client.get_execution(request=request) + + # Handle the response + print(response) + +# [END workflowexecutions_generated_executions_v1_Executions_GetExecution_async] diff --git a/samples/generated_samples/workflowexecutions_generated_executions_v1_executions_get_execution_sync.py b/samples/generated_samples/workflowexecutions_generated_executions_v1_executions_get_execution_sync.py new file mode 100644 index 0000000..cd3952a --- /dev/null +++ b/samples/generated_samples/workflowexecutions_generated_executions_v1_executions_get_execution_sync.py @@ -0,0 +1,45 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows-executions + + +# [START workflowexecutions_generated_executions_v1_Executions_GetExecution_sync] +from google.cloud.workflows import executions_v1 + + +def sample_get_execution(): + # Create a client + client = executions_v1.ExecutionsClient() + + # Initialize request argument(s) + request = executions_v1.GetExecutionRequest( + name="name_value", + ) + + # Make the request + response = client.get_execution(request=request) + + # Handle the response + print(response) + +# [END workflowexecutions_generated_executions_v1_Executions_GetExecution_sync] diff --git a/samples/generated_samples/workflowexecutions_generated_executions_v1_executions_list_executions_async.py b/samples/generated_samples/workflowexecutions_generated_executions_v1_executions_list_executions_async.py new file mode 100644 index 0000000..709feed --- /dev/null +++ b/samples/generated_samples/workflowexecutions_generated_executions_v1_executions_list_executions_async.py @@ -0,0 +1,46 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows-executions + + +# [START workflowexecutions_generated_executions_v1_Executions_ListExecutions_async] +from google.cloud.workflows import executions_v1 + + +async def sample_list_executions(): + # Create a client + client = executions_v1.ExecutionsAsyncClient() + + # Initialize request argument(s) + request = executions_v1.ListExecutionsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_executions(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END workflowexecutions_generated_executions_v1_Executions_ListExecutions_async] diff --git a/samples/generated_samples/workflowexecutions_generated_executions_v1_executions_list_executions_sync.py b/samples/generated_samples/workflowexecutions_generated_executions_v1_executions_list_executions_sync.py new file mode 100644 index 0000000..c8e7643 --- /dev/null +++ b/samples/generated_samples/workflowexecutions_generated_executions_v1_executions_list_executions_sync.py @@ -0,0 +1,46 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows-executions + + +# [START workflowexecutions_generated_executions_v1_Executions_ListExecutions_sync] +from google.cloud.workflows import executions_v1 + + +def sample_list_executions(): + # Create a client + client = executions_v1.ExecutionsClient() + + # Initialize request argument(s) + request = executions_v1.ListExecutionsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_executions(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END workflowexecutions_generated_executions_v1_Executions_ListExecutions_sync] diff --git a/samples/generated_samples/workflowexecutions_generated_executions_v1beta_executions_cancel_execution_async.py b/samples/generated_samples/workflowexecutions_generated_executions_v1beta_executions_cancel_execution_async.py new file mode 100644 index 0000000..3d20aea --- /dev/null +++ b/samples/generated_samples/workflowexecutions_generated_executions_v1beta_executions_cancel_execution_async.py @@ -0,0 +1,45 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows-executions + + +# [START workflowexecutions_generated_executions_v1beta_Executions_CancelExecution_async] +from google.cloud.workflows import executions_v1beta + + +async def sample_cancel_execution(): + # Create a client + client = executions_v1beta.ExecutionsAsyncClient() + + # Initialize request argument(s) + request = executions_v1beta.CancelExecutionRequest( + name="name_value", + ) + + # Make the request + response = await client.cancel_execution(request=request) + + # Handle the response + print(response) + +# [END workflowexecutions_generated_executions_v1beta_Executions_CancelExecution_async] diff --git a/samples/generated_samples/workflowexecutions_generated_executions_v1beta_executions_cancel_execution_sync.py b/samples/generated_samples/workflowexecutions_generated_executions_v1beta_executions_cancel_execution_sync.py new file mode 100644 index 0000000..c14b842 --- /dev/null +++ b/samples/generated_samples/workflowexecutions_generated_executions_v1beta_executions_cancel_execution_sync.py @@ -0,0 +1,45 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows-executions + + +# [START workflowexecutions_generated_executions_v1beta_Executions_CancelExecution_sync] +from google.cloud.workflows import executions_v1beta + + +def sample_cancel_execution(): + # Create a client + client = executions_v1beta.ExecutionsClient() + + # Initialize request argument(s) + request = executions_v1beta.CancelExecutionRequest( + name="name_value", + ) + + # Make the request + response = client.cancel_execution(request=request) + + # Handle the response + print(response) + +# [END workflowexecutions_generated_executions_v1beta_Executions_CancelExecution_sync] diff --git a/samples/generated_samples/workflowexecutions_generated_executions_v1beta_executions_create_execution_async.py b/samples/generated_samples/workflowexecutions_generated_executions_v1beta_executions_create_execution_async.py new file mode 100644 index 0000000..2adc9ef --- /dev/null +++ b/samples/generated_samples/workflowexecutions_generated_executions_v1beta_executions_create_execution_async.py @@ -0,0 +1,45 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows-executions + + +# [START workflowexecutions_generated_executions_v1beta_Executions_CreateExecution_async] +from google.cloud.workflows import executions_v1beta + + +async def sample_create_execution(): + # Create a client + client = executions_v1beta.ExecutionsAsyncClient() + + # Initialize request argument(s) + request = executions_v1beta.CreateExecutionRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_execution(request=request) + + # Handle the response + print(response) + +# [END workflowexecutions_generated_executions_v1beta_Executions_CreateExecution_async] diff --git a/samples/generated_samples/workflowexecutions_generated_executions_v1beta_executions_create_execution_sync.py b/samples/generated_samples/workflowexecutions_generated_executions_v1beta_executions_create_execution_sync.py new file mode 100644 index 0000000..00a5afe --- /dev/null +++ b/samples/generated_samples/workflowexecutions_generated_executions_v1beta_executions_create_execution_sync.py @@ -0,0 +1,45 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows-executions + + +# [START workflowexecutions_generated_executions_v1beta_Executions_CreateExecution_sync] +from google.cloud.workflows import executions_v1beta + + +def sample_create_execution(): + # Create a client + client = executions_v1beta.ExecutionsClient() + + # Initialize request argument(s) + request = executions_v1beta.CreateExecutionRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_execution(request=request) + + # Handle the response + print(response) + +# [END workflowexecutions_generated_executions_v1beta_Executions_CreateExecution_sync] diff --git a/samples/generated_samples/workflowexecutions_generated_executions_v1beta_executions_get_execution_async.py b/samples/generated_samples/workflowexecutions_generated_executions_v1beta_executions_get_execution_async.py new file mode 100644 index 0000000..f98ac31 --- /dev/null +++ b/samples/generated_samples/workflowexecutions_generated_executions_v1beta_executions_get_execution_async.py @@ -0,0 +1,45 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows-executions + + +# [START workflowexecutions_generated_executions_v1beta_Executions_GetExecution_async] +from google.cloud.workflows import executions_v1beta + + +async def sample_get_execution(): + # Create a client + client = executions_v1beta.ExecutionsAsyncClient() + + # Initialize request argument(s) + request = executions_v1beta.GetExecutionRequest( + name="name_value", + ) + + # Make the request + response = await client.get_execution(request=request) + + # Handle the response + print(response) + +# [END workflowexecutions_generated_executions_v1beta_Executions_GetExecution_async] diff --git a/samples/generated_samples/workflowexecutions_generated_executions_v1beta_executions_get_execution_sync.py b/samples/generated_samples/workflowexecutions_generated_executions_v1beta_executions_get_execution_sync.py new file mode 100644 index 0000000..dee1afa --- /dev/null +++ b/samples/generated_samples/workflowexecutions_generated_executions_v1beta_executions_get_execution_sync.py @@ -0,0 +1,45 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows-executions + + +# [START workflowexecutions_generated_executions_v1beta_Executions_GetExecution_sync] +from google.cloud.workflows import executions_v1beta + + +def sample_get_execution(): + # Create a client + client = executions_v1beta.ExecutionsClient() + + # Initialize request argument(s) + request = executions_v1beta.GetExecutionRequest( + name="name_value", + ) + + # Make the request + response = client.get_execution(request=request) + + # Handle the response + print(response) + +# [END workflowexecutions_generated_executions_v1beta_Executions_GetExecution_sync] diff --git a/samples/generated_samples/workflowexecutions_generated_executions_v1beta_executions_list_executions_async.py b/samples/generated_samples/workflowexecutions_generated_executions_v1beta_executions_list_executions_async.py new file mode 100644 index 0000000..690ad5d --- /dev/null +++ b/samples/generated_samples/workflowexecutions_generated_executions_v1beta_executions_list_executions_async.py @@ -0,0 +1,46 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows-executions + + +# [START workflowexecutions_generated_executions_v1beta_Executions_ListExecutions_async] +from google.cloud.workflows import executions_v1beta + + +async def sample_list_executions(): + # Create a client + client = executions_v1beta.ExecutionsAsyncClient() + + # Initialize request argument(s) + request = executions_v1beta.ListExecutionsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_executions(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END workflowexecutions_generated_executions_v1beta_Executions_ListExecutions_async] diff --git a/samples/generated_samples/workflowexecutions_generated_executions_v1beta_executions_list_executions_sync.py b/samples/generated_samples/workflowexecutions_generated_executions_v1beta_executions_list_executions_sync.py new file mode 100644 index 0000000..99292f7 --- /dev/null +++ b/samples/generated_samples/workflowexecutions_generated_executions_v1beta_executions_list_executions_sync.py @@ -0,0 +1,46 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows-executions + + +# [START workflowexecutions_generated_executions_v1beta_Executions_ListExecutions_sync] +from google.cloud.workflows import executions_v1beta + + +def sample_list_executions(): + # Create a client + client = executions_v1beta.ExecutionsClient() + + # Initialize request argument(s) + request = executions_v1beta.ListExecutionsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_executions(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END workflowexecutions_generated_executions_v1beta_Executions_ListExecutions_sync] diff --git a/samples/generated_samples/workflows_generated_workflows_v1_workflows_create_workflow_async.py b/samples/generated_samples/workflows_generated_workflows_v1_workflows_create_workflow_async.py new file mode 100644 index 0000000..f9de0ae --- /dev/null +++ b/samples/generated_samples/workflows_generated_workflows_v1_workflows_create_workflow_async.py @@ -0,0 +1,54 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateWorkflow +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows + + +# [START workflows_generated_workflows_v1_Workflows_CreateWorkflow_async] +from google.cloud import workflows_v1 + + +async def sample_create_workflow(): + # Create a client + client = workflows_v1.WorkflowsAsyncClient() + + # Initialize request argument(s) + workflow = workflows_v1.Workflow() + workflow.source_contents = "source_contents_value" + + request = workflows_v1.CreateWorkflowRequest( + parent="parent_value", + workflow=workflow, + workflow_id="workflow_id_value", + ) + + # Make the request + operation = client.create_workflow(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END workflows_generated_workflows_v1_Workflows_CreateWorkflow_async] diff --git a/samples/generated_samples/workflows_generated_workflows_v1_workflows_create_workflow_sync.py b/samples/generated_samples/workflows_generated_workflows_v1_workflows_create_workflow_sync.py new file mode 100644 index 0000000..cd09fca --- /dev/null +++ b/samples/generated_samples/workflows_generated_workflows_v1_workflows_create_workflow_sync.py @@ -0,0 +1,54 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateWorkflow +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows + + +# [START workflows_generated_workflows_v1_Workflows_CreateWorkflow_sync] +from google.cloud import workflows_v1 + + +def sample_create_workflow(): + # Create a client + client = workflows_v1.WorkflowsClient() + + # Initialize request argument(s) + workflow = workflows_v1.Workflow() + workflow.source_contents = "source_contents_value" + + request = workflows_v1.CreateWorkflowRequest( + parent="parent_value", + workflow=workflow, + workflow_id="workflow_id_value", + ) + + # Make the request + operation = client.create_workflow(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END workflows_generated_workflows_v1_Workflows_CreateWorkflow_sync] diff --git a/samples/generated_samples/workflows_generated_workflows_v1_workflows_delete_workflow_async.py b/samples/generated_samples/workflows_generated_workflows_v1_workflows_delete_workflow_async.py new file mode 100644 index 0000000..c4485ac --- /dev/null +++ b/samples/generated_samples/workflows_generated_workflows_v1_workflows_delete_workflow_async.py @@ -0,0 +1,49 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteWorkflow +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows + + +# [START workflows_generated_workflows_v1_Workflows_DeleteWorkflow_async] +from google.cloud import workflows_v1 + + +async def sample_delete_workflow(): + # Create a client + client = workflows_v1.WorkflowsAsyncClient() + + # Initialize request argument(s) + request = workflows_v1.DeleteWorkflowRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_workflow(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END workflows_generated_workflows_v1_Workflows_DeleteWorkflow_async] diff --git a/samples/generated_samples/workflows_generated_workflows_v1_workflows_delete_workflow_sync.py b/samples/generated_samples/workflows_generated_workflows_v1_workflows_delete_workflow_sync.py new file mode 100644 index 0000000..e10a6aa --- /dev/null +++ b/samples/generated_samples/workflows_generated_workflows_v1_workflows_delete_workflow_sync.py @@ -0,0 +1,49 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteWorkflow +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows + + +# [START workflows_generated_workflows_v1_Workflows_DeleteWorkflow_sync] +from google.cloud import workflows_v1 + + +def sample_delete_workflow(): + # Create a client + client = workflows_v1.WorkflowsClient() + + # Initialize request argument(s) + request = workflows_v1.DeleteWorkflowRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_workflow(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END workflows_generated_workflows_v1_Workflows_DeleteWorkflow_sync] diff --git a/samples/generated_samples/workflows_generated_workflows_v1_workflows_get_workflow_async.py b/samples/generated_samples/workflows_generated_workflows_v1_workflows_get_workflow_async.py new file mode 100644 index 0000000..796975b --- /dev/null +++ b/samples/generated_samples/workflows_generated_workflows_v1_workflows_get_workflow_async.py @@ -0,0 +1,45 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetWorkflow +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows + + +# [START workflows_generated_workflows_v1_Workflows_GetWorkflow_async] +from google.cloud import workflows_v1 + + +async def sample_get_workflow(): + # Create a client + client = workflows_v1.WorkflowsAsyncClient() + + # Initialize request argument(s) + request = workflows_v1.GetWorkflowRequest( + name="name_value", + ) + + # Make the request + response = await client.get_workflow(request=request) + + # Handle the response + print(response) + +# [END workflows_generated_workflows_v1_Workflows_GetWorkflow_async] diff --git a/samples/generated_samples/workflows_generated_workflows_v1_workflows_get_workflow_sync.py b/samples/generated_samples/workflows_generated_workflows_v1_workflows_get_workflow_sync.py new file mode 100644 index 0000000..d1e6cde --- /dev/null +++ b/samples/generated_samples/workflows_generated_workflows_v1_workflows_get_workflow_sync.py @@ -0,0 +1,45 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetWorkflow +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows + + +# [START workflows_generated_workflows_v1_Workflows_GetWorkflow_sync] +from google.cloud import workflows_v1 + + +def sample_get_workflow(): + # Create a client + client = workflows_v1.WorkflowsClient() + + # Initialize request argument(s) + request = workflows_v1.GetWorkflowRequest( + name="name_value", + ) + + # Make the request + response = client.get_workflow(request=request) + + # Handle the response + print(response) + +# [END workflows_generated_workflows_v1_Workflows_GetWorkflow_sync] diff --git a/samples/generated_samples/workflows_generated_workflows_v1_workflows_list_workflows_async.py b/samples/generated_samples/workflows_generated_workflows_v1_workflows_list_workflows_async.py new file mode 100644 index 0000000..520e2db --- /dev/null +++ b/samples/generated_samples/workflows_generated_workflows_v1_workflows_list_workflows_async.py @@ -0,0 +1,46 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListWorkflows +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows + + +# [START workflows_generated_workflows_v1_Workflows_ListWorkflows_async] +from google.cloud import workflows_v1 + + +async def sample_list_workflows(): + # Create a client + client = workflows_v1.WorkflowsAsyncClient() + + # Initialize request argument(s) + request = workflows_v1.ListWorkflowsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_workflows(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END workflows_generated_workflows_v1_Workflows_ListWorkflows_async] diff --git a/samples/generated_samples/workflows_generated_workflows_v1_workflows_list_workflows_sync.py b/samples/generated_samples/workflows_generated_workflows_v1_workflows_list_workflows_sync.py new file mode 100644 index 0000000..34b50b2 --- /dev/null +++ b/samples/generated_samples/workflows_generated_workflows_v1_workflows_list_workflows_sync.py @@ -0,0 +1,46 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListWorkflows +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows + + +# [START workflows_generated_workflows_v1_Workflows_ListWorkflows_sync] +from google.cloud import workflows_v1 + + +def sample_list_workflows(): + # Create a client + client = workflows_v1.WorkflowsClient() + + # Initialize request argument(s) + request = workflows_v1.ListWorkflowsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_workflows(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END workflows_generated_workflows_v1_Workflows_ListWorkflows_sync] diff --git a/samples/generated_samples/workflows_generated_workflows_v1_workflows_update_workflow_async.py b/samples/generated_samples/workflows_generated_workflows_v1_workflows_update_workflow_async.py new file mode 100644 index 0000000..e0de26d --- /dev/null +++ b/samples/generated_samples/workflows_generated_workflows_v1_workflows_update_workflow_async.py @@ -0,0 +1,52 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateWorkflow +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows + + +# [START workflows_generated_workflows_v1_Workflows_UpdateWorkflow_async] +from google.cloud import workflows_v1 + + +async def sample_update_workflow(): + # Create a client + client = workflows_v1.WorkflowsAsyncClient() + + # Initialize request argument(s) + workflow = workflows_v1.Workflow() + workflow.source_contents = "source_contents_value" + + request = workflows_v1.UpdateWorkflowRequest( + workflow=workflow, + ) + + # Make the request + operation = client.update_workflow(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END workflows_generated_workflows_v1_Workflows_UpdateWorkflow_async] diff --git a/samples/generated_samples/workflows_generated_workflows_v1_workflows_update_workflow_sync.py b/samples/generated_samples/workflows_generated_workflows_v1_workflows_update_workflow_sync.py new file mode 100644 index 0000000..a15d7ae --- /dev/null +++ b/samples/generated_samples/workflows_generated_workflows_v1_workflows_update_workflow_sync.py @@ -0,0 +1,52 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateWorkflow +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows + + +# [START workflows_generated_workflows_v1_Workflows_UpdateWorkflow_sync] +from google.cloud import workflows_v1 + + +def sample_update_workflow(): + # Create a client + client = workflows_v1.WorkflowsClient() + + # Initialize request argument(s) + workflow = workflows_v1.Workflow() + workflow.source_contents = "source_contents_value" + + request = workflows_v1.UpdateWorkflowRequest( + workflow=workflow, + ) + + # Make the request + operation = client.update_workflow(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END workflows_generated_workflows_v1_Workflows_UpdateWorkflow_sync] diff --git a/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_create_workflow_async.py b/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_create_workflow_async.py new file mode 100644 index 0000000..c2ece6c --- /dev/null +++ b/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_create_workflow_async.py @@ -0,0 +1,54 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateWorkflow +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows + + +# [START workflows_generated_workflows_v1beta_Workflows_CreateWorkflow_async] +from google.cloud import workflows_v1beta + + +async def sample_create_workflow(): + # Create a client + client = workflows_v1beta.WorkflowsAsyncClient() + + # Initialize request argument(s) + workflow = workflows_v1beta.Workflow() + workflow.source_contents = "source_contents_value" + + request = workflows_v1beta.CreateWorkflowRequest( + parent="parent_value", + workflow=workflow, + workflow_id="workflow_id_value", + ) + + # Make the request + operation = client.create_workflow(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END workflows_generated_workflows_v1beta_Workflows_CreateWorkflow_async] diff --git a/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_create_workflow_sync.py b/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_create_workflow_sync.py new file mode 100644 index 0000000..1802b26 --- /dev/null +++ b/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_create_workflow_sync.py @@ -0,0 +1,54 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateWorkflow +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows + + +# [START workflows_generated_workflows_v1beta_Workflows_CreateWorkflow_sync] +from google.cloud import workflows_v1beta + + +def sample_create_workflow(): + # Create a client + client = workflows_v1beta.WorkflowsClient() + + # Initialize request argument(s) + workflow = workflows_v1beta.Workflow() + workflow.source_contents = "source_contents_value" + + request = workflows_v1beta.CreateWorkflowRequest( + parent="parent_value", + workflow=workflow, + workflow_id="workflow_id_value", + ) + + # Make the request + operation = client.create_workflow(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END workflows_generated_workflows_v1beta_Workflows_CreateWorkflow_sync] diff --git a/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_delete_workflow_async.py b/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_delete_workflow_async.py new file mode 100644 index 0000000..2260a93 --- /dev/null +++ b/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_delete_workflow_async.py @@ -0,0 +1,49 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteWorkflow +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows + + +# [START workflows_generated_workflows_v1beta_Workflows_DeleteWorkflow_async] +from google.cloud import workflows_v1beta + + +async def sample_delete_workflow(): + # Create a client + client = workflows_v1beta.WorkflowsAsyncClient() + + # Initialize request argument(s) + request = workflows_v1beta.DeleteWorkflowRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_workflow(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END workflows_generated_workflows_v1beta_Workflows_DeleteWorkflow_async] diff --git a/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_delete_workflow_sync.py b/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_delete_workflow_sync.py new file mode 100644 index 0000000..29ff7a6 --- /dev/null +++ b/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_delete_workflow_sync.py @@ -0,0 +1,49 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteWorkflow +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows + + +# [START workflows_generated_workflows_v1beta_Workflows_DeleteWorkflow_sync] +from google.cloud import workflows_v1beta + + +def sample_delete_workflow(): + # Create a client + client = workflows_v1beta.WorkflowsClient() + + # Initialize request argument(s) + request = workflows_v1beta.DeleteWorkflowRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_workflow(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END workflows_generated_workflows_v1beta_Workflows_DeleteWorkflow_sync] diff --git a/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_get_workflow_async.py b/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_get_workflow_async.py new file mode 100644 index 0000000..5f21126 --- /dev/null +++ b/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_get_workflow_async.py @@ -0,0 +1,45 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetWorkflow +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows + + +# [START workflows_generated_workflows_v1beta_Workflows_GetWorkflow_async] +from google.cloud import workflows_v1beta + + +async def sample_get_workflow(): + # Create a client + client = workflows_v1beta.WorkflowsAsyncClient() + + # Initialize request argument(s) + request = workflows_v1beta.GetWorkflowRequest( + name="name_value", + ) + + # Make the request + response = await client.get_workflow(request=request) + + # Handle the response + print(response) + +# [END workflows_generated_workflows_v1beta_Workflows_GetWorkflow_async] diff --git a/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_get_workflow_sync.py b/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_get_workflow_sync.py new file mode 100644 index 0000000..64ab076 --- /dev/null +++ b/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_get_workflow_sync.py @@ -0,0 +1,45 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetWorkflow +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows + + +# [START workflows_generated_workflows_v1beta_Workflows_GetWorkflow_sync] +from google.cloud import workflows_v1beta + + +def sample_get_workflow(): + # Create a client + client = workflows_v1beta.WorkflowsClient() + + # Initialize request argument(s) + request = workflows_v1beta.GetWorkflowRequest( + name="name_value", + ) + + # Make the request + response = client.get_workflow(request=request) + + # Handle the response + print(response) + +# [END workflows_generated_workflows_v1beta_Workflows_GetWorkflow_sync] diff --git a/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_list_workflows_async.py b/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_list_workflows_async.py new file mode 100644 index 0000000..3aaad0e --- /dev/null +++ b/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_list_workflows_async.py @@ -0,0 +1,46 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListWorkflows +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows + + +# [START workflows_generated_workflows_v1beta_Workflows_ListWorkflows_async] +from google.cloud import workflows_v1beta + + +async def sample_list_workflows(): + # Create a client + client = workflows_v1beta.WorkflowsAsyncClient() + + # Initialize request argument(s) + request = workflows_v1beta.ListWorkflowsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_workflows(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END workflows_generated_workflows_v1beta_Workflows_ListWorkflows_async] diff --git a/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_list_workflows_sync.py b/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_list_workflows_sync.py new file mode 100644 index 0000000..43fd78d --- /dev/null +++ b/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_list_workflows_sync.py @@ -0,0 +1,46 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListWorkflows +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows + + +# [START workflows_generated_workflows_v1beta_Workflows_ListWorkflows_sync] +from google.cloud import workflows_v1beta + + +def sample_list_workflows(): + # Create a client + client = workflows_v1beta.WorkflowsClient() + + # Initialize request argument(s) + request = workflows_v1beta.ListWorkflowsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_workflows(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END workflows_generated_workflows_v1beta_Workflows_ListWorkflows_sync] diff --git a/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_update_workflow_async.py b/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_update_workflow_async.py new file mode 100644 index 0000000..badeb54 --- /dev/null +++ b/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_update_workflow_async.py @@ -0,0 +1,52 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateWorkflow +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows + + +# [START workflows_generated_workflows_v1beta_Workflows_UpdateWorkflow_async] +from google.cloud import workflows_v1beta + + +async def sample_update_workflow(): + # Create a client + client = workflows_v1beta.WorkflowsAsyncClient() + + # Initialize request argument(s) + workflow = workflows_v1beta.Workflow() + workflow.source_contents = "source_contents_value" + + request = workflows_v1beta.UpdateWorkflowRequest( + workflow=workflow, + ) + + # Make the request + operation = client.update_workflow(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END workflows_generated_workflows_v1beta_Workflows_UpdateWorkflow_async] diff --git a/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_update_workflow_sync.py b/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_update_workflow_sync.py new file mode 100644 index 0000000..282ab45 --- /dev/null +++ b/samples/generated_samples/workflows_generated_workflows_v1beta_workflows_update_workflow_sync.py @@ -0,0 +1,52 @@ +# -*- 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 +# +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateWorkflow +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-workflows + + +# [START workflows_generated_workflows_v1beta_Workflows_UpdateWorkflow_sync] +from google.cloud import workflows_v1beta + + +def sample_update_workflow(): + # Create a client + client = workflows_v1beta.WorkflowsClient() + + # Initialize request argument(s) + workflow = workflows_v1beta.Workflow() + workflow.source_contents = "source_contents_value" + + request = workflows_v1beta.UpdateWorkflowRequest( + workflow=workflow, + ) + + # Make the request + operation = client.update_workflow(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END workflows_generated_workflows_v1beta_Workflows_UpdateWorkflow_sync] diff --git a/setup.py b/setup.py index 4ebb418..5ee58c9 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ import os import setuptools # type: ignore -version = "1.5.0" +version = "1.6.0" package_root = os.path.abspath(os.path.dirname(__file__)) @@ -50,7 +50,6 @@ # Until this issue is closed # https://github.com/googleapis/google-cloud-python/issues/10566 "google-api-core[grpc] >= 1.28.0, <3.0.0dev", - "libcst >= 0.2.5", "proto-plus >= 1.4.0", ), python_requires=">=3.6", diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index 96d3604..6b451bc 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -6,5 +6,4 @@ # e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", # Then this file should have foo==1.14.0 google-api-core==1.28.0 -libcst==0.2.5 proto-plus==1.4.0 diff --git a/tests/unit/gapic/executions_v1/test_executions.py b/tests/unit/gapic/executions_v1/test_executions.py index 85d2764..065db67 100644 --- a/tests/unit/gapic/executions_v1/test_executions.py +++ b/tests/unit/gapic/executions_v1/test_executions.py @@ -240,20 +240,20 @@ def test_executions_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -310,7 +310,7 @@ def test_executions_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -387,6 +387,83 @@ def test_executions_client_mtls_env_auto( ) +@pytest.mark.parametrize("client_class", [ExecutionsClient, ExecutionsAsyncClient]) +@mock.patch.object( + ExecutionsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ExecutionsClient) +) +@mock.patch.object( + ExecutionsAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(ExecutionsAsyncClient), +) +def test_executions_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -405,7 +482,7 @@ def test_executions_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -419,24 +496,26 @@ def test_executions_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (ExecutionsClient, transports.ExecutionsGrpcTransport, "grpc"), + (ExecutionsClient, transports.ExecutionsGrpcTransport, "grpc", grpc_helpers), ( ExecutionsAsyncClient, transports.ExecutionsGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_executions_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -467,9 +546,69 @@ def test_executions_client_client_options_from_dict(): ) -def test_list_executions( - transport: str = "grpc", request_type=executions.ListExecutionsRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + (ExecutionsClient, transports.ExecutionsGrpcTransport, "grpc", grpc_helpers), + ( + ExecutionsAsyncClient, + transports.ExecutionsGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_executions_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "workflowexecutions.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="workflowexecutions.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("request_type", [executions.ListExecutionsRequest, dict,]) +def test_list_executions(request_type, transport: str = "grpc"): client = ExecutionsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -496,10 +635,6 @@ def test_list_executions( assert response.next_page_token == "next_page_token_value" -def test_list_executions_from_dict(): - test_list_executions(request_type=dict) - - def test_list_executions_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -616,7 +751,9 @@ def test_list_executions_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_executions_flattened_error(): @@ -650,7 +787,9 @@ async def test_list_executions_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -665,8 +804,10 @@ async def test_list_executions_flattened_error_async(): ) -def test_list_executions_pager(): - client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_executions_pager(transport_name: str = "grpc"): + client = ExecutionsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_executions), "__call__") as call: @@ -703,8 +844,10 @@ def test_list_executions_pager(): assert all(isinstance(i, executions.Execution) for i in results) -def test_list_executions_pages(): - client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_executions_pages(transport_name: str = "grpc"): + client = ExecutionsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_executions), "__call__") as call: @@ -803,9 +946,8 @@ async def test_list_executions_async_pages(): assert page_.raw_page.next_page_token == token -def test_create_execution( - transport: str = "grpc", request_type=executions.CreateExecutionRequest -): +@pytest.mark.parametrize("request_type", [executions.CreateExecutionRequest, dict,]) +def test_create_execution(request_type, transport: str = "grpc"): client = ExecutionsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -842,10 +984,6 @@ def test_create_execution( assert response.call_log_level == executions.Execution.CallLogLevel.LOG_ALL_CALLS -def test_create_execution_from_dict(): - test_create_execution(request_type=dict) - - def test_create_execution_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -976,8 +1114,12 @@ def test_create_execution_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].execution == executions.Execution(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].execution + mock_val = executions.Execution(name="name_value") + assert arg == mock_val def test_create_execution_flattened_error(): @@ -1015,8 +1157,12 @@ async def test_create_execution_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].execution == executions.Execution(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].execution + mock_val = executions.Execution(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -1033,9 +1179,8 @@ async def test_create_execution_flattened_error_async(): ) -def test_get_execution( - transport: str = "grpc", request_type=executions.GetExecutionRequest -): +@pytest.mark.parametrize("request_type", [executions.GetExecutionRequest, dict,]) +def test_get_execution(request_type, transport: str = "grpc"): client = ExecutionsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1072,10 +1217,6 @@ def test_get_execution( assert response.call_log_level == executions.Execution.CallLogLevel.LOG_ALL_CALLS -def test_get_execution_from_dict(): - test_get_execution(request_type=dict) - - def test_get_execution_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1204,7 +1345,9 @@ def test_get_execution_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_execution_flattened_error(): @@ -1238,7 +1381,9 @@ async def test_get_execution_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1253,9 +1398,8 @@ async def test_get_execution_flattened_error_async(): ) -def test_cancel_execution( - transport: str = "grpc", request_type=executions.CancelExecutionRequest -): +@pytest.mark.parametrize("request_type", [executions.CancelExecutionRequest, dict,]) +def test_cancel_execution(request_type, transport: str = "grpc"): client = ExecutionsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1292,10 +1436,6 @@ def test_cancel_execution( assert response.call_log_level == executions.Execution.CallLogLevel.LOG_ALL_CALLS -def test_cancel_execution_from_dict(): - test_cancel_execution(request_type=dict) - - def test_cancel_execution_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1424,7 +1564,9 @@ def test_cancel_execution_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_cancel_execution_flattened_error(): @@ -1458,7 +1600,9 @@ async def test_cancel_execution_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1493,6 +1637,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.ExecutionsGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = ExecutionsClient(client_options=options, transport=transport,) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = ExecutionsClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.ExecutionsGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -1999,7 +2160,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( @@ -2064,3 +2225,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (ExecutionsClient, transports.ExecutionsGrpcTransport), + (ExecutionsAsyncClient, transports.ExecutionsGrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + 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, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/executions_v1beta/test_executions.py b/tests/unit/gapic/executions_v1beta/test_executions.py index 520c76a..38116a4 100644 --- a/tests/unit/gapic/executions_v1beta/test_executions.py +++ b/tests/unit/gapic/executions_v1beta/test_executions.py @@ -242,20 +242,20 @@ def test_executions_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -312,7 +312,7 @@ def test_executions_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -389,6 +389,83 @@ def test_executions_client_mtls_env_auto( ) +@pytest.mark.parametrize("client_class", [ExecutionsClient, ExecutionsAsyncClient]) +@mock.patch.object( + ExecutionsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ExecutionsClient) +) +@mock.patch.object( + ExecutionsAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(ExecutionsAsyncClient), +) +def test_executions_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -407,7 +484,7 @@ def test_executions_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -421,24 +498,26 @@ def test_executions_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (ExecutionsClient, transports.ExecutionsGrpcTransport, "grpc"), + (ExecutionsClient, transports.ExecutionsGrpcTransport, "grpc", grpc_helpers), ( ExecutionsAsyncClient, transports.ExecutionsGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_executions_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -469,9 +548,69 @@ def test_executions_client_client_options_from_dict(): ) -def test_list_executions( - transport: str = "grpc", request_type=executions.ListExecutionsRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + (ExecutionsClient, transports.ExecutionsGrpcTransport, "grpc", grpc_helpers), + ( + ExecutionsAsyncClient, + transports.ExecutionsGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_executions_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "workflowexecutions.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="workflowexecutions.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("request_type", [executions.ListExecutionsRequest, dict,]) +def test_list_executions(request_type, transport: str = "grpc"): client = ExecutionsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -498,10 +637,6 @@ def test_list_executions( assert response.next_page_token == "next_page_token_value" -def test_list_executions_from_dict(): - test_list_executions(request_type=dict) - - def test_list_executions_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -618,7 +753,9 @@ def test_list_executions_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_executions_flattened_error(): @@ -652,7 +789,9 @@ async def test_list_executions_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -667,8 +806,10 @@ async def test_list_executions_flattened_error_async(): ) -def test_list_executions_pager(): - client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_executions_pager(transport_name: str = "grpc"): + client = ExecutionsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_executions), "__call__") as call: @@ -705,8 +846,10 @@ def test_list_executions_pager(): assert all(isinstance(i, executions.Execution) for i in results) -def test_list_executions_pages(): - client = ExecutionsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_executions_pages(transport_name: str = "grpc"): + client = ExecutionsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_executions), "__call__") as call: @@ -805,9 +948,8 @@ async def test_list_executions_async_pages(): assert page_.raw_page.next_page_token == token -def test_create_execution( - transport: str = "grpc", request_type=executions.CreateExecutionRequest -): +@pytest.mark.parametrize("request_type", [executions.CreateExecutionRequest, dict,]) +def test_create_execution(request_type, transport: str = "grpc"): client = ExecutionsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -842,10 +984,6 @@ def test_create_execution( assert response.workflow_revision_id == "workflow_revision_id_value" -def test_create_execution_from_dict(): - test_create_execution(request_type=dict) - - def test_create_execution_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -974,8 +1112,12 @@ def test_create_execution_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].execution == executions.Execution(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].execution + mock_val = executions.Execution(name="name_value") + assert arg == mock_val def test_create_execution_flattened_error(): @@ -1013,8 +1155,12 @@ async def test_create_execution_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].execution == executions.Execution(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].execution + mock_val = executions.Execution(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -1031,9 +1177,8 @@ async def test_create_execution_flattened_error_async(): ) -def test_get_execution( - transport: str = "grpc", request_type=executions.GetExecutionRequest -): +@pytest.mark.parametrize("request_type", [executions.GetExecutionRequest, dict,]) +def test_get_execution(request_type, transport: str = "grpc"): client = ExecutionsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1068,10 +1213,6 @@ def test_get_execution( assert response.workflow_revision_id == "workflow_revision_id_value" -def test_get_execution_from_dict(): - test_get_execution(request_type=dict) - - def test_get_execution_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1198,7 +1339,9 @@ def test_get_execution_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_execution_flattened_error(): @@ -1232,7 +1375,9 @@ async def test_get_execution_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1247,9 +1392,8 @@ async def test_get_execution_flattened_error_async(): ) -def test_cancel_execution( - transport: str = "grpc", request_type=executions.CancelExecutionRequest -): +@pytest.mark.parametrize("request_type", [executions.CancelExecutionRequest, dict,]) +def test_cancel_execution(request_type, transport: str = "grpc"): client = ExecutionsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1284,10 +1428,6 @@ def test_cancel_execution( assert response.workflow_revision_id == "workflow_revision_id_value" -def test_cancel_execution_from_dict(): - test_cancel_execution(request_type=dict) - - def test_cancel_execution_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1414,7 +1554,9 @@ def test_cancel_execution_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_cancel_execution_flattened_error(): @@ -1448,7 +1590,9 @@ async def test_cancel_execution_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1483,6 +1627,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.ExecutionsGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = ExecutionsClient(client_options=options, transport=transport,) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = ExecutionsClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.ExecutionsGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -1989,7 +2150,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( @@ -2054,3 +2215,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (ExecutionsClient, transports.ExecutionsGrpcTransport), + (ExecutionsAsyncClient, transports.ExecutionsGrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + 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, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/workflows_v1/test_workflows.py b/tests/unit/gapic/workflows_v1/test_workflows.py index 65eaf88..a48d355 100644 --- a/tests/unit/gapic/workflows_v1/test_workflows.py +++ b/tests/unit/gapic/workflows_v1/test_workflows.py @@ -29,6 +29,7 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 from google.api_core import path_template @@ -239,20 +240,20 @@ def test_workflows_client_client_options(client_class, transport_class, transpor # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -309,7 +310,7 @@ def test_workflows_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -386,6 +387,83 @@ def test_workflows_client_mtls_env_auto( ) +@pytest.mark.parametrize("client_class", [WorkflowsClient, WorkflowsAsyncClient]) +@mock.patch.object( + WorkflowsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(WorkflowsClient) +) +@mock.patch.object( + WorkflowsAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(WorkflowsAsyncClient), +) +def test_workflows_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -404,7 +482,7 @@ def test_workflows_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -418,24 +496,26 @@ def test_workflows_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (WorkflowsClient, transports.WorkflowsGrpcTransport, "grpc"), + (WorkflowsClient, transports.WorkflowsGrpcTransport, "grpc", grpc_helpers), ( WorkflowsAsyncClient, transports.WorkflowsGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_workflows_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -466,9 +546,69 @@ def test_workflows_client_client_options_from_dict(): ) -def test_list_workflows( - transport: str = "grpc", request_type=workflows.ListWorkflowsRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + (WorkflowsClient, transports.WorkflowsGrpcTransport, "grpc", grpc_helpers), + ( + WorkflowsAsyncClient, + transports.WorkflowsGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_workflows_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "workflows.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="workflows.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("request_type", [workflows.ListWorkflowsRequest, dict,]) +def test_list_workflows(request_type, transport: str = "grpc"): client = WorkflowsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -496,10 +636,6 @@ def test_list_workflows( assert response.unreachable == ["unreachable_value"] -def test_list_workflows_from_dict(): - test_list_workflows(request_type=dict) - - def test_list_workflows_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -620,7 +756,9 @@ def test_list_workflows_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_workflows_flattened_error(): @@ -654,7 +792,9 @@ async def test_list_workflows_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -669,8 +809,10 @@ async def test_list_workflows_flattened_error_async(): ) -def test_list_workflows_pager(): - client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_workflows_pager(transport_name: str = "grpc"): + client = WorkflowsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_workflows), "__call__") as call: @@ -707,8 +849,10 @@ def test_list_workflows_pager(): assert all(isinstance(i, workflows.Workflow) for i in results) -def test_list_workflows_pages(): - client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_workflows_pages(transport_name: str = "grpc"): + client = WorkflowsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_workflows), "__call__") as call: @@ -807,9 +951,8 @@ async def test_list_workflows_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_workflow( - transport: str = "grpc", request_type=workflows.GetWorkflowRequest -): +@pytest.mark.parametrize("request_type", [workflows.GetWorkflowRequest, dict,]) +def test_get_workflow(request_type, transport: str = "grpc"): client = WorkflowsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -845,10 +988,6 @@ def test_get_workflow( assert response.service_account == "service_account_value" -def test_get_workflow_from_dict(): - test_get_workflow(request_type=dict) - - def test_get_workflow_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -973,7 +1112,9 @@ def test_get_workflow_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_workflow_flattened_error(): @@ -1005,7 +1146,9 @@ async def test_get_workflow_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1020,9 +1163,8 @@ async def test_get_workflow_flattened_error_async(): ) -def test_create_workflow( - transport: str = "grpc", request_type=workflows.CreateWorkflowRequest -): +@pytest.mark.parametrize("request_type", [workflows.CreateWorkflowRequest, dict,]) +def test_create_workflow(request_type, transport: str = "grpc"): client = WorkflowsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1046,10 +1188,6 @@ def test_create_workflow( assert isinstance(response, future.Future) -def test_create_workflow_from_dict(): - test_create_workflow(request_type=dict) - - def test_create_workflow_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1169,9 +1307,15 @@ def test_create_workflow_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].workflow == workflows.Workflow(name="name_value") - assert args[0].workflow_id == "workflow_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].workflow + mock_val = workflows.Workflow(name="name_value") + assert arg == mock_val + arg = args[0].workflow_id + mock_val = "workflow_id_value" + assert arg == mock_val def test_create_workflow_flattened_error(): @@ -1212,9 +1356,15 @@ async def test_create_workflow_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].workflow == workflows.Workflow(name="name_value") - assert args[0].workflow_id == "workflow_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].workflow + mock_val = workflows.Workflow(name="name_value") + assert arg == mock_val + arg = args[0].workflow_id + mock_val = "workflow_id_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1232,9 +1382,8 @@ async def test_create_workflow_flattened_error_async(): ) -def test_delete_workflow( - transport: str = "grpc", request_type=workflows.DeleteWorkflowRequest -): +@pytest.mark.parametrize("request_type", [workflows.DeleteWorkflowRequest, dict,]) +def test_delete_workflow(request_type, transport: str = "grpc"): client = WorkflowsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1258,10 +1407,6 @@ def test_delete_workflow( assert isinstance(response, future.Future) -def test_delete_workflow_from_dict(): - test_delete_workflow(request_type=dict) - - def test_delete_workflow_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1377,7 +1522,9 @@ def test_delete_workflow_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_workflow_flattened_error(): @@ -1411,7 +1558,9 @@ async def test_delete_workflow_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1426,9 +1575,8 @@ async def test_delete_workflow_flattened_error_async(): ) -def test_update_workflow( - transport: str = "grpc", request_type=workflows.UpdateWorkflowRequest -): +@pytest.mark.parametrize("request_type", [workflows.UpdateWorkflowRequest, dict,]) +def test_update_workflow(request_type, transport: str = "grpc"): client = WorkflowsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1452,10 +1600,6 @@ def test_update_workflow( assert isinstance(response, future.Future) -def test_update_workflow_from_dict(): - test_update_workflow(request_type=dict) - - def test_update_workflow_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1578,8 +1722,12 @@ def test_update_workflow_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].workflow == workflows.Workflow(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].workflow + mock_val = workflows.Workflow(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val def test_update_workflow_flattened_error(): @@ -1618,8 +1766,12 @@ async def test_update_workflow_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].workflow == workflows.Workflow(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].workflow + mock_val = workflows.Workflow(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio @@ -1656,6 +1808,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.WorkflowsGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = WorkflowsClient(client_options=options, transport=transport,) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = WorkflowsClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.WorkflowsGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -2168,7 +2337,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( @@ -2233,3 +2402,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (WorkflowsClient, transports.WorkflowsGrpcTransport), + (WorkflowsAsyncClient, transports.WorkflowsGrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + 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, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/workflows_v1beta/test_workflows.py b/tests/unit/gapic/workflows_v1beta/test_workflows.py index 175ed7f..29f00dd 100644 --- a/tests/unit/gapic/workflows_v1beta/test_workflows.py +++ b/tests/unit/gapic/workflows_v1beta/test_workflows.py @@ -29,6 +29,7 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 from google.api_core import path_template @@ -239,20 +240,20 @@ def test_workflows_client_client_options(client_class, transport_class, transpor # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -309,7 +310,7 @@ def test_workflows_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -386,6 +387,83 @@ def test_workflows_client_mtls_env_auto( ) +@pytest.mark.parametrize("client_class", [WorkflowsClient, WorkflowsAsyncClient]) +@mock.patch.object( + WorkflowsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(WorkflowsClient) +) +@mock.patch.object( + WorkflowsAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(WorkflowsAsyncClient), +) +def test_workflows_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -404,7 +482,7 @@ def test_workflows_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -418,24 +496,26 @@ def test_workflows_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (WorkflowsClient, transports.WorkflowsGrpcTransport, "grpc"), + (WorkflowsClient, transports.WorkflowsGrpcTransport, "grpc", grpc_helpers), ( WorkflowsAsyncClient, transports.WorkflowsGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_workflows_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -466,9 +546,69 @@ def test_workflows_client_client_options_from_dict(): ) -def test_list_workflows( - transport: str = "grpc", request_type=workflows.ListWorkflowsRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + (WorkflowsClient, transports.WorkflowsGrpcTransport, "grpc", grpc_helpers), + ( + WorkflowsAsyncClient, + transports.WorkflowsGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_workflows_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "workflows.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="workflows.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("request_type", [workflows.ListWorkflowsRequest, dict,]) +def test_list_workflows(request_type, transport: str = "grpc"): client = WorkflowsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -496,10 +636,6 @@ def test_list_workflows( assert response.unreachable == ["unreachable_value"] -def test_list_workflows_from_dict(): - test_list_workflows(request_type=dict) - - def test_list_workflows_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -620,7 +756,9 @@ def test_list_workflows_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_workflows_flattened_error(): @@ -654,7 +792,9 @@ async def test_list_workflows_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -669,8 +809,10 @@ async def test_list_workflows_flattened_error_async(): ) -def test_list_workflows_pager(): - client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_workflows_pager(transport_name: str = "grpc"): + client = WorkflowsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_workflows), "__call__") as call: @@ -707,8 +849,10 @@ def test_list_workflows_pager(): assert all(isinstance(i, workflows.Workflow) for i in results) -def test_list_workflows_pages(): - client = WorkflowsClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_workflows_pages(transport_name: str = "grpc"): + client = WorkflowsClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_workflows), "__call__") as call: @@ -807,9 +951,8 @@ async def test_list_workflows_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_workflow( - transport: str = "grpc", request_type=workflows.GetWorkflowRequest -): +@pytest.mark.parametrize("request_type", [workflows.GetWorkflowRequest, dict,]) +def test_get_workflow(request_type, transport: str = "grpc"): client = WorkflowsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -845,10 +988,6 @@ def test_get_workflow( assert response.service_account == "service_account_value" -def test_get_workflow_from_dict(): - test_get_workflow(request_type=dict) - - def test_get_workflow_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -973,7 +1112,9 @@ def test_get_workflow_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_workflow_flattened_error(): @@ -1005,7 +1146,9 @@ async def test_get_workflow_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1020,9 +1163,8 @@ async def test_get_workflow_flattened_error_async(): ) -def test_create_workflow( - transport: str = "grpc", request_type=workflows.CreateWorkflowRequest -): +@pytest.mark.parametrize("request_type", [workflows.CreateWorkflowRequest, dict,]) +def test_create_workflow(request_type, transport: str = "grpc"): client = WorkflowsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1046,10 +1188,6 @@ def test_create_workflow( assert isinstance(response, future.Future) -def test_create_workflow_from_dict(): - test_create_workflow(request_type=dict) - - def test_create_workflow_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1169,9 +1307,15 @@ def test_create_workflow_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].workflow == workflows.Workflow(name="name_value") - assert args[0].workflow_id == "workflow_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].workflow + mock_val = workflows.Workflow(name="name_value") + assert arg == mock_val + arg = args[0].workflow_id + mock_val = "workflow_id_value" + assert arg == mock_val def test_create_workflow_flattened_error(): @@ -1212,9 +1356,15 @@ async def test_create_workflow_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].workflow == workflows.Workflow(name="name_value") - assert args[0].workflow_id == "workflow_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].workflow + mock_val = workflows.Workflow(name="name_value") + assert arg == mock_val + arg = args[0].workflow_id + mock_val = "workflow_id_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1232,9 +1382,8 @@ async def test_create_workflow_flattened_error_async(): ) -def test_delete_workflow( - transport: str = "grpc", request_type=workflows.DeleteWorkflowRequest -): +@pytest.mark.parametrize("request_type", [workflows.DeleteWorkflowRequest, dict,]) +def test_delete_workflow(request_type, transport: str = "grpc"): client = WorkflowsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1258,10 +1407,6 @@ def test_delete_workflow( assert isinstance(response, future.Future) -def test_delete_workflow_from_dict(): - test_delete_workflow(request_type=dict) - - def test_delete_workflow_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1377,7 +1522,9 @@ def test_delete_workflow_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_workflow_flattened_error(): @@ -1411,7 +1558,9 @@ async def test_delete_workflow_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1426,9 +1575,8 @@ async def test_delete_workflow_flattened_error_async(): ) -def test_update_workflow( - transport: str = "grpc", request_type=workflows.UpdateWorkflowRequest -): +@pytest.mark.parametrize("request_type", [workflows.UpdateWorkflowRequest, dict,]) +def test_update_workflow(request_type, transport: str = "grpc"): client = WorkflowsClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1452,10 +1600,6 @@ def test_update_workflow( assert isinstance(response, future.Future) -def test_update_workflow_from_dict(): - test_update_workflow(request_type=dict) - - def test_update_workflow_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1578,8 +1722,12 @@ def test_update_workflow_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].workflow == workflows.Workflow(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].workflow + mock_val = workflows.Workflow(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val def test_update_workflow_flattened_error(): @@ -1618,8 +1766,12 @@ async def test_update_workflow_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].workflow == workflows.Workflow(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].workflow + mock_val = workflows.Workflow(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio @@ -1656,6 +1808,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.WorkflowsGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = WorkflowsClient(client_options=options, transport=transport,) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = WorkflowsClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.WorkflowsGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -2168,7 +2337,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( @@ -2233,3 +2402,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (WorkflowsClient, transports.WorkflowsGrpcTransport), + (WorkflowsAsyncClient, transports.WorkflowsGrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + 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, + always_use_jwt_access=True, + )