diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 108063d..b668c04 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,17 @@ +# 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:ed1f9983d5a935a89fe8085e8bb97d94e41015252c5b6c9771257cf8624367e6 + diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index be888a9..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 - -/samples/ @googleapis/python-samples-owners +# @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 d38c957..cd76ff1 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-dataflow-client 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 86f31ce..6749416 100644 --- a/.kokoro/release/common.cfg +++ b/.kokoro/release/common.cfg @@ -23,8 +23,18 @@ env_vars: { value: "github/python-dataflow-client/.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 e8788e0..ab92278 100644 --- a/.repo-metadata.json +++ b/.repo-metadata.json @@ -2,14 +2,15 @@ "name": "dataflow", "name_pretty": "Dataflow", "product_documentation": "https://cloud.google.com/dataflow/", - "client_documentation": "https://googleapis.dev/python/dataflow/latest", + "client_documentation": "https://cloud.google.com/python/docs/reference/dataflow/latest", "issue_tracker": "", - "release_level": "beta", + "release_level": "preview", "language": "python", "library_type": "GAPIC_AUTO", "repo": "googleapis/python-dataflow-client", "distribution_name": "google-cloud-dataflow-client", "api_id": "dataflow.googleapis.com", "default_version": "v1beta3", - "codeowner_team": "" + "codeowner_team": "", + "api_shortname": "dataflow" } diff --git a/CHANGELOG.md b/CHANGELOG.md index ad2c3a3..e204c9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,23 @@ # Changelog +## [0.4.0](https://github.com/googleapis/python-dataflow-client/compare/v0.3.1...v0.4.0) (2022-02-26) + + +### Features + +* add api key support ([#65](https://github.com/googleapis/python-dataflow-client/issues/65)) ([888664b](https://github.com/googleapis/python-dataflow-client/commit/888664b70baefe7acb7e46c82a06c24e7ba06af2)) +* new parameters in FlexTemplateRuntimeEnvironment ([#69](https://github.com/googleapis/python-dataflow-client/issues/69)) ([f8bd373](https://github.com/googleapis/python-dataflow-client/commit/f8bd3730da138532aa90f6bc90ff3a8c1075fa01)) + + +### Bug Fixes + +* resolve DuplicateCredentialArgs error when using credentials_file ([f8bd373](https://github.com/googleapis/python-dataflow-client/commit/f8bd3730da138532aa90f6bc90ff3a8c1075fa01)) + + +### Documentation + +* remove typo in docstring ([#72](https://github.com/googleapis/python-dataflow-client/issues/72)) ([db91cc2](https://github.com/googleapis/python-dataflow-client/commit/db91cc2c65cf43f766385c0f973dd58c4233c9c7)) + ### [0.3.1](https://www.github.com/googleapis/python-dataflow-client/compare/v0.3.0...v0.3.1) (2021-11-01) diff --git a/README.rst b/README.rst index 77f57f5..130b417 100644 --- a/README.rst +++ b/README.rst @@ -15,7 +15,7 @@ Python Client for Cloud Dataflow .. |versions| image:: https://img.shields.io/pypi/pyversions/google-cloud-dataflow-client.svg :target: https://pypi.org/project/google-cloud-dataflow-client/ .. _Cloud Dataflow: https://cloud.google.com/dataflow/ -.. _Client Library Documentation: https://googleapis.dev/python/dataflow/latest +.. _Client Library Documentation: https://cloud.google.com/python/docs/reference/dataflow/latest .. _Product Documentation: https://cloud.google.com/dataflow/ Quick Start diff --git a/google/cloud/dataflow/__init__.py b/google/cloud/dataflow/__init__.py index 598b957..566f4e8 100644 --- a/google/cloud/dataflow/__init__.py +++ b/google/cloud/dataflow/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. diff --git a/google/cloud/dataflow_v1beta3/__init__.py b/google/cloud/dataflow_v1beta3/__init__.py index caa2daf..0e46e99 100644 --- a/google/cloud/dataflow_v1beta3/__init__.py +++ b/google/cloud/dataflow_v1beta3/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. diff --git a/google/cloud/dataflow_v1beta3/services/__init__.py b/google/cloud/dataflow_v1beta3/services/__init__.py index 4de6597..e8e1c38 100644 --- a/google/cloud/dataflow_v1beta3/services/__init__.py +++ b/google/cloud/dataflow_v1beta3/services/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. diff --git a/google/cloud/dataflow_v1beta3/services/flex_templates_service/__init__.py b/google/cloud/dataflow_v1beta3/services/flex_templates_service/__init__.py index afd8353..abcf4c2 100644 --- a/google/cloud/dataflow_v1beta3/services/flex_templates_service/__init__.py +++ b/google/cloud/dataflow_v1beta3/services/flex_templates_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. diff --git a/google/cloud/dataflow_v1beta3/services/flex_templates_service/async_client.py b/google/cloud/dataflow_v1beta3/services/flex_templates_service/async_client.py index 756a538..3214026 100644 --- a/google/cloud/dataflow_v1beta3/services/flex_templates_service/async_client.py +++ b/google/cloud/dataflow_v1beta3/services/flex_templates_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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.dataflow_v1beta3.types import jobs from google.cloud.dataflow_v1beta3.types import templates @@ -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 FlexTemplatesServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> FlexTemplatesServiceTransport: """Returns the transport used by the client instance. @@ -174,6 +213,24 @@ async def launch_flex_template( ) -> templates.LaunchFlexTemplateResponse: r"""Launch a job with a FlexTemplate. + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_launch_flex_template(): + # Create a client + client = dataflow_v1beta3.FlexTemplatesServiceClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.LaunchFlexTemplateRequest( + ) + + # Make the request + response = client.launch_flex_template(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.LaunchFlexTemplateRequest, dict]): The request object. A request to launch a Cloud Dataflow diff --git a/google/cloud/dataflow_v1beta3/services/flex_templates_service/client.py b/google/cloud/dataflow_v1beta3/services/flex_templates_service/client.py index 8a52e47..83d5cea 100644 --- a/google/cloud/dataflow_v1beta3/services/flex_templates_service/client.py +++ b/google/cloud/dataflow_v1beta3/services/flex_templates_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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.dataflow_v1beta3.types import jobs from google.cloud.dataflow_v1beta3.types import templates @@ -220,6 +222,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, *, @@ -270,50 +339,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, FlexTemplatesServiceTransport): # transport is a FlexTemplatesServiceTransport 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." @@ -325,6 +366,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, @@ -347,6 +397,24 @@ def launch_flex_template( ) -> templates.LaunchFlexTemplateResponse: r"""Launch a job with a FlexTemplate. + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_launch_flex_template(): + # Create a client + client = dataflow_v1beta3.FlexTemplatesServiceClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.LaunchFlexTemplateRequest( + ) + + # Make the request + response = client.launch_flex_template(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.LaunchFlexTemplateRequest, dict]): The request object. A request to launch a Cloud Dataflow diff --git a/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/__init__.py b/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/__init__.py index 2d03f11..103b20d 100644 --- a/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/__init__.py +++ b/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. diff --git a/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/base.py b/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/base.py index 2dfccb1..e252487 100644 --- a/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/base.py +++ b/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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 @@ -106,7 +106,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/dataflow_v1beta3/services/flex_templates_service/transports/grpc.py b/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/grpc.py index 32e2892..9c59826 100644 --- a/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/grpc.py +++ b/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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/dataflow_v1beta3/services/flex_templates_service/transports/grpc_asyncio.py b/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/grpc_asyncio.py index 4da7f19..c24cae1 100644 --- a/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/grpc_asyncio.py +++ b/google/cloud/dataflow_v1beta3/services/flex_templates_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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/dataflow_v1beta3/services/jobs_v1_beta3/__init__.py b/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/__init__.py index 92101f6..cf47b2a 100644 --- a/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/__init__.py +++ b/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. diff --git a/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/async_client.py b/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/async_client.py index 9c651ec..0720a6a 100644 --- a/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/async_client.py +++ b/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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.dataflow_v1beta3.services.jobs_v1_beta3 import pagers from google.cloud.dataflow_v1beta3.types import environment @@ -104,6 +107,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 JobsV1Beta3Client.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> JobsV1Beta3Transport: """Returns the transport used by the client instance. @@ -180,6 +219,25 @@ async def create_job( Using ``projects.jobs.create`` is not recommended, as your job will always start in ``us-central1``. + + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_create_job(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.CreateJobRequest( + ) + + # Make the request + response = client.create_job(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.CreateJobRequest, dict]): The request object. Request to create a Cloud Dataflow @@ -193,7 +251,7 @@ async def create_job( Returns: google.cloud.dataflow_v1beta3.types.Job: Defines a job to be run by the Cloud - Dataflow service. nextID: 26 + Dataflow service. """ # Create or coerce a protobuf request object. @@ -229,6 +287,25 @@ async def get_job( Using ``projects.jobs.get`` is not recommended, as you can only get the state of jobs that are running in ``us-central1``. + + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_get_job(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.GetJobRequest( + ) + + # Make the request + response = client.get_job(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.GetJobRequest, dict]): The request object. Request to get the state of a Cloud @@ -242,7 +319,7 @@ async def get_job( Returns: google.cloud.dataflow_v1beta3.types.Job: Defines a job to be run by the Cloud - Dataflow service. nextID: 26 + Dataflow service. """ # Create or coerce a protobuf request object. @@ -279,6 +356,25 @@ async def update_job( only update the state of jobs that are running in ``us-central1``. + + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_update_job(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.UpdateJobRequest( + ) + + # Make the request + response = client.update_job(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.UpdateJobRequest, dict]): The request object. Request to update a Cloud Dataflow @@ -292,7 +388,7 @@ async def update_job( Returns: google.cloud.dataflow_v1beta3.types.Job: Defines a job to be run by the Cloud - Dataflow service. nextID: 26 + Dataflow service. """ # Create or coerce a protobuf request object. @@ -330,6 +426,26 @@ async def list_jobs( not recommended, as you can only get the list of jobs that are running in ``us-central1``. + + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_list_jobs(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.ListJobsRequest( + ) + + # Make the request + page_result = client.list_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.ListJobsRequest, dict]): The request object. Request to list Cloud Dataflow jobs. @@ -388,6 +504,25 @@ async def aggregated_list_jobs( ) -> pagers.AggregatedListJobsAsyncPager: r"""List the jobs of a project across all regions. + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_aggregated_list_jobs(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.ListJobsRequest( + ) + + # Make the request + page_result = client.aggregated_list_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.ListJobsRequest, dict]): The request object. Request to list Cloud Dataflow jobs. @@ -447,6 +582,25 @@ async def check_active_jobs( r"""Check for existence of active jobs in the given project across all regions. + + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_check_active_jobs(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.CheckActiveJobsRequest( + ) + + # Make the request + response = client.check_active_jobs(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.CheckActiveJobsRequest, dict]): The request object. Request to check is active jobs @@ -488,6 +642,24 @@ async def snapshot_job( ) -> snapshots.Snapshot: r"""Snapshot the state of a streaming job. + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_snapshot_job(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.SnapshotJobRequest( + ) + + # Make the request + response = client.snapshot_job(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.SnapshotJobRequest, dict]): The request object. Request to create a snapshot of a diff --git a/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/client.py b/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/client.py index 8102532..af5658b 100644 --- a/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/client.py +++ b/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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.dataflow_v1beta3.services.jobs_v1_beta3 import pagers from google.cloud.dataflow_v1beta3.types import environment @@ -221,6 +223,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, *, @@ -271,50 +340,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, JobsV1Beta3Transport): # transport is a JobsV1Beta3Transport 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." @@ -326,6 +367,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, @@ -354,6 +404,25 @@ def create_job( Using ``projects.jobs.create`` is not recommended, as your job will always start in ``us-central1``. + + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_create_job(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.CreateJobRequest( + ) + + # Make the request + response = client.create_job(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.CreateJobRequest, dict]): The request object. Request to create a Cloud Dataflow @@ -367,7 +436,7 @@ def create_job( Returns: google.cloud.dataflow_v1beta3.types.Job: Defines a job to be run by the Cloud - Dataflow service. nextID: 26 + Dataflow service. """ # Create or coerce a protobuf request object. @@ -404,6 +473,25 @@ def get_job( Using ``projects.jobs.get`` is not recommended, as you can only get the state of jobs that are running in ``us-central1``. + + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_get_job(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.GetJobRequest( + ) + + # Make the request + response = client.get_job(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.GetJobRequest, dict]): The request object. Request to get the state of a Cloud @@ -417,7 +505,7 @@ def get_job( Returns: google.cloud.dataflow_v1beta3.types.Job: Defines a job to be run by the Cloud - Dataflow service. nextID: 26 + Dataflow service. """ # Create or coerce a protobuf request object. @@ -455,6 +543,25 @@ def update_job( only update the state of jobs that are running in ``us-central1``. + + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_update_job(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.UpdateJobRequest( + ) + + # Make the request + response = client.update_job(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.UpdateJobRequest, dict]): The request object. Request to update a Cloud Dataflow @@ -468,7 +575,7 @@ def update_job( Returns: google.cloud.dataflow_v1beta3.types.Job: Defines a job to be run by the Cloud - Dataflow service. nextID: 26 + Dataflow service. """ # Create or coerce a protobuf request object. @@ -507,6 +614,26 @@ def list_jobs( not recommended, as you can only get the list of jobs that are running in ``us-central1``. + + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_list_jobs(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.ListJobsRequest( + ) + + # Make the request + page_result = client.list_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.ListJobsRequest, dict]): The request object. Request to list Cloud Dataflow jobs. @@ -566,6 +693,25 @@ def aggregated_list_jobs( ) -> pagers.AggregatedListJobsPager: r"""List the jobs of a project across all regions. + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_aggregated_list_jobs(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.ListJobsRequest( + ) + + # Make the request + page_result = client.aggregated_list_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.ListJobsRequest, dict]): The request object. Request to list Cloud Dataflow jobs. @@ -626,6 +772,25 @@ def check_active_jobs( r"""Check for existence of active jobs in the given project across all regions. + + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_check_active_jobs(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.CheckActiveJobsRequest( + ) + + # Make the request + response = client.check_active_jobs(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.CheckActiveJobsRequest, dict]): The request object. Request to check is active jobs @@ -668,6 +833,24 @@ def snapshot_job( ) -> snapshots.Snapshot: r"""Snapshot the state of a streaming job. + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_snapshot_job(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.SnapshotJobRequest( + ) + + # Make the request + response = client.snapshot_job(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.SnapshotJobRequest, dict]): The request object. Request to create a snapshot of a diff --git a/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/pagers.py b/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/pagers.py index c8bad1a..c7364db 100644 --- a/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/pagers.py +++ b/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. diff --git a/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/__init__.py b/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/__init__.py index 04a6783..73dcbbc 100644 --- a/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/__init__.py +++ b/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. diff --git a/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/base.py b/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/base.py index 45e47cb..c7f555e 100644 --- a/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/base.py +++ b/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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 @@ -107,7 +107,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/dataflow_v1beta3/services/jobs_v1_beta3/transports/grpc.py b/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/grpc.py index e522a7d..0cae85d 100644 --- a/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/grpc.py +++ b/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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 @@ -161,8 +161,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/dataflow_v1beta3/services/jobs_v1_beta3/transports/grpc_asyncio.py b/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/grpc_asyncio.py index 6c3d71a..0cb418f 100644 --- a/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/grpc_asyncio.py +++ b/google/cloud/dataflow_v1beta3/services/jobs_v1_beta3/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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 @@ -206,8 +206,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/dataflow_v1beta3/services/messages_v1_beta3/__init__.py b/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/__init__.py index a4018f1..73044f9 100644 --- a/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/__init__.py +++ b/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. diff --git a/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/async_client.py b/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/async_client.py index b7f9b10..41b399f 100644 --- a/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/async_client.py +++ b/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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.dataflow_v1beta3.services.messages_v1_beta3 import pagers from google.cloud.dataflow_v1beta3.types import messages @@ -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 MessagesV1Beta3Client.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> MessagesV1Beta3Transport: """Returns the transport used by the client instance. @@ -181,6 +220,26 @@ async def list_job_messages( can only request the status of jobs that are running in ``us-central1``. + + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_list_job_messages(): + # Create a client + client = dataflow_v1beta3.MessagesV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.ListJobMessagesRequest( + ) + + # Make the request + page_result = client.list_job_messages(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.ListJobMessagesRequest, dict]): The request object. Request to list job messages. diff --git a/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/client.py b/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/client.py index b4b2807..47b6023 100644 --- a/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/client.py +++ b/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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.dataflow_v1beta3.services.messages_v1_beta3 import pagers from google.cloud.dataflow_v1beta3.types import messages @@ -218,6 +220,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, *, @@ -268,50 +337,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, MessagesV1Beta3Transport): # transport is a MessagesV1Beta3Transport 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." @@ -323,6 +364,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, @@ -353,6 +403,26 @@ def list_job_messages( can only request the status of jobs that are running in ``us-central1``. + + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_list_job_messages(): + # Create a client + client = dataflow_v1beta3.MessagesV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.ListJobMessagesRequest( + ) + + # Make the request + page_result = client.list_job_messages(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.ListJobMessagesRequest, dict]): The request object. Request to list job messages. diff --git a/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/pagers.py b/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/pagers.py index 75878de..c6b7807 100644 --- a/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/pagers.py +++ b/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. diff --git a/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/__init__.py b/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/__init__.py index f8cb3f7..80880dc 100644 --- a/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/__init__.py +++ b/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. diff --git a/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/base.py b/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/base.py index 7658ef7..23c97d7 100644 --- a/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/base.py +++ b/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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 @@ -106,7 +106,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/dataflow_v1beta3/services/messages_v1_beta3/transports/grpc.py b/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/grpc.py index 0afbe02..748256e 100644 --- a/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/grpc.py +++ b/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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/dataflow_v1beta3/services/messages_v1_beta3/transports/grpc_asyncio.py b/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/grpc_asyncio.py index 658fa93..b3821e6 100644 --- a/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/grpc_asyncio.py +++ b/google/cloud/dataflow_v1beta3/services/messages_v1_beta3/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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/dataflow_v1beta3/services/metrics_v1_beta3/__init__.py b/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/__init__.py index dc4ea9e..621deb3 100644 --- a/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/__init__.py +++ b/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. diff --git a/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/async_client.py b/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/async_client.py index 4d10eb5..50b6d5c 100644 --- a/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/async_client.py +++ b/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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.dataflow_v1beta3.services.metrics_v1_beta3 import pagers from google.cloud.dataflow_v1beta3.types import metrics @@ -104,6 +107,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 MetricsV1Beta3Client.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> MetricsV1Beta3Transport: """Returns the transport used by the client instance. @@ -182,6 +221,25 @@ async def get_job_metrics( can only request the status of jobs that are running in ``us-central1``. + + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_get_job_metrics(): + # Create a client + client = dataflow_v1beta3.MetricsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.GetJobMetricsRequest( + ) + + # Make the request + response = client.get_job_metrics(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.GetJobMetricsRequest, dict]): The request object. Request to get job metrics. @@ -200,8 +258,8 @@ async def get_job_metrics( in the job. This resource captures only the most - recent values of each metric; time- - series data can be queried for them + recent values of each metric; + time-series data can be queried for them (under the same metric names) from Cloud Monitoring. @@ -236,6 +294,26 @@ async def get_job_execution_details( EXPERIMENTAL. This API is subject to change or removal without notice. + + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_get_job_execution_details(): + # Create a client + client = dataflow_v1beta3.MetricsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.GetJobExecutionDetailsRequest( + ) + + # Make the request + page_result = client.get_job_execution_details(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.GetJobExecutionDetailsRequest, dict]): The request object. Request to get job execution @@ -292,6 +370,26 @@ async def get_stage_execution_details( EXPERIMENTAL. This API is subject to change or removal without notice. + + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_get_stage_execution_details(): + # Create a client + client = dataflow_v1beta3.MetricsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.GetStageExecutionDetailsRequest( + ) + + # Make the request + page_result = client.get_stage_execution_details(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.GetStageExecutionDetailsRequest, dict]): The request object. Request to get information about a diff --git a/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/client.py b/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/client.py index 6532c08..4c10174 100644 --- a/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/client.py +++ b/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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.dataflow_v1beta3.services.metrics_v1_beta3 import pagers from google.cloud.dataflow_v1beta3.types import metrics @@ -219,6 +221,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, *, @@ -269,50 +338,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, MetricsV1Beta3Transport): # transport is a MetricsV1Beta3Transport 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." @@ -324,6 +365,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, @@ -354,6 +404,25 @@ def get_job_metrics( can only request the status of jobs that are running in ``us-central1``. + + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_get_job_metrics(): + # Create a client + client = dataflow_v1beta3.MetricsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.GetJobMetricsRequest( + ) + + # Make the request + response = client.get_job_metrics(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.GetJobMetricsRequest, dict]): The request object. Request to get job metrics. @@ -372,8 +441,8 @@ def get_job_metrics( in the job. This resource captures only the most - recent values of each metric; time- - series data can be queried for them + recent values of each metric; + time-series data can be queried for them (under the same metric names) from Cloud Monitoring. @@ -409,6 +478,26 @@ def get_job_execution_details( EXPERIMENTAL. This API is subject to change or removal without notice. + + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_get_job_execution_details(): + # Create a client + client = dataflow_v1beta3.MetricsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.GetJobExecutionDetailsRequest( + ) + + # Make the request + page_result = client.get_job_execution_details(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.GetJobExecutionDetailsRequest, dict]): The request object. Request to get job execution @@ -468,6 +557,26 @@ def get_stage_execution_details( EXPERIMENTAL. This API is subject to change or removal without notice. + + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_get_stage_execution_details(): + # Create a client + client = dataflow_v1beta3.MetricsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.GetStageExecutionDetailsRequest( + ) + + # Make the request + page_result = client.get_stage_execution_details(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.GetStageExecutionDetailsRequest, dict]): The request object. Request to get information about a diff --git a/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/pagers.py b/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/pagers.py index 499018c..fc77147 100644 --- a/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/pagers.py +++ b/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. diff --git a/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/__init__.py b/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/__init__.py index 94b291d..7e4058d 100644 --- a/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/__init__.py +++ b/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. diff --git a/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/base.py b/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/base.py index e3c21bc..ce1b39b 100644 --- a/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/base.py +++ b/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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 @@ -106,7 +106,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/dataflow_v1beta3/services/metrics_v1_beta3/transports/grpc.py b/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/grpc.py index 7c01ca7..f92f6fa 100644 --- a/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/grpc.py +++ b/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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/dataflow_v1beta3/services/metrics_v1_beta3/transports/grpc_asyncio.py b/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/grpc_asyncio.py index 816bbc3..d92375d 100644 --- a/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/grpc_asyncio.py +++ b/google/cloud/dataflow_v1beta3/services/metrics_v1_beta3/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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/dataflow_v1beta3/services/snapshots_v1_beta3/__init__.py b/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/__init__.py index 23f0594..b18218e 100644 --- a/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/__init__.py +++ b/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. diff --git a/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/async_client.py b/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/async_client.py index 198dcfc..b7623be 100644 --- a/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/async_client.py +++ b/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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.dataflow_v1beta3.types import snapshots from google.protobuf import duration_pb2 # type: ignore @@ -104,6 +107,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 SnapshotsV1Beta3Client.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> SnapshotsV1Beta3Transport: """Returns the transport used by the client instance. @@ -174,6 +213,24 @@ async def get_snapshot( ) -> snapshots.Snapshot: r"""Gets information about a snapshot. + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_get_snapshot(): + # Create a client + client = dataflow_v1beta3.SnapshotsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.GetSnapshotRequest( + ) + + # Make the request + response = client.get_snapshot(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.GetSnapshotRequest, dict]): The request object. Request to get information about a @@ -215,6 +272,24 @@ async def delete_snapshot( ) -> snapshots.DeleteSnapshotResponse: r"""Deletes a snapshot. + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_delete_snapshot(): + # Create a client + client = dataflow_v1beta3.SnapshotsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.DeleteSnapshotRequest( + ) + + # Make the request + response = client.delete_snapshot(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.DeleteSnapshotRequest, dict]): The request object. Request to delete a snapshot. @@ -255,6 +330,24 @@ async def list_snapshots( ) -> snapshots.ListSnapshotsResponse: r"""Lists snapshots. + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_list_snapshots(): + # Create a client + client = dataflow_v1beta3.SnapshotsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.ListSnapshotsRequest( + ) + + # Make the request + response = client.list_snapshots(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.ListSnapshotsRequest, dict]): The request object. Request to list snapshots. diff --git a/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/client.py b/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/client.py index 7540d6c..edf271a 100644 --- a/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/client.py +++ b/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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.dataflow_v1beta3.types import snapshots from google.protobuf import duration_pb2 # type: ignore @@ -219,6 +221,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, *, @@ -269,50 +338,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, SnapshotsV1Beta3Transport): # transport is a SnapshotsV1Beta3Transport 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." @@ -324,6 +365,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, @@ -346,6 +396,24 @@ def get_snapshot( ) -> snapshots.Snapshot: r"""Gets information about a snapshot. + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_get_snapshot(): + # Create a client + client = dataflow_v1beta3.SnapshotsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.GetSnapshotRequest( + ) + + # Make the request + response = client.get_snapshot(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.GetSnapshotRequest, dict]): The request object. Request to get information about a @@ -388,6 +456,24 @@ def delete_snapshot( ) -> snapshots.DeleteSnapshotResponse: r"""Deletes a snapshot. + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_delete_snapshot(): + # Create a client + client = dataflow_v1beta3.SnapshotsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.DeleteSnapshotRequest( + ) + + # Make the request + response = client.delete_snapshot(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.DeleteSnapshotRequest, dict]): The request object. Request to delete a snapshot. @@ -429,6 +515,24 @@ def list_snapshots( ) -> snapshots.ListSnapshotsResponse: r"""Lists snapshots. + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_list_snapshots(): + # Create a client + client = dataflow_v1beta3.SnapshotsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.ListSnapshotsRequest( + ) + + # Make the request + response = client.list_snapshots(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.ListSnapshotsRequest, dict]): The request object. Request to list snapshots. diff --git a/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/__init__.py b/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/__init__.py index d79a295..30bbf23 100644 --- a/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/__init__.py +++ b/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. diff --git a/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/base.py b/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/base.py index 44d6798..9e03199 100644 --- a/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/base.py +++ b/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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 @@ -106,7 +106,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/dataflow_v1beta3/services/snapshots_v1_beta3/transports/grpc.py b/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/grpc.py index 2c32a08..144fbb3 100644 --- a/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/grpc.py +++ b/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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/dataflow_v1beta3/services/snapshots_v1_beta3/transports/grpc_asyncio.py b/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/grpc_asyncio.py index 962f022..593e2c0 100644 --- a/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/grpc_asyncio.py +++ b/google/cloud/dataflow_v1beta3/services/snapshots_v1_beta3/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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/dataflow_v1beta3/services/templates_service/__init__.py b/google/cloud/dataflow_v1beta3/services/templates_service/__init__.py index 7cd41bf..d9320d8 100644 --- a/google/cloud/dataflow_v1beta3/services/templates_service/__init__.py +++ b/google/cloud/dataflow_v1beta3/services/templates_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. diff --git a/google/cloud/dataflow_v1beta3/services/templates_service/async_client.py b/google/cloud/dataflow_v1beta3/services/templates_service/async_client.py index 70de866..3ce2069 100644 --- a/google/cloud/dataflow_v1beta3/services/templates_service/async_client.py +++ b/google/cloud/dataflow_v1beta3/services/templates_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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.dataflow_v1beta3.types import environment from google.cloud.dataflow_v1beta3.types import jobs @@ -106,6 +109,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 TemplatesServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> TemplatesServiceTransport: """Returns the transport used by the client instance. @@ -176,6 +215,25 @@ async def create_job_from_template( ) -> jobs.Job: r"""Creates a Cloud Dataflow job from a template. + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_create_job_from_template(): + # Create a client + client = dataflow_v1beta3.TemplatesServiceClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.CreateJobFromTemplateRequest( + gcs_path="gcs_path_value", + ) + + # Make the request + response = client.create_job_from_template(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.CreateJobFromTemplateRequest, dict]): The request object. A request to create a Cloud Dataflow @@ -189,7 +247,7 @@ async def create_job_from_template( Returns: google.cloud.dataflow_v1beta3.types.Job: Defines a job to be run by the Cloud - Dataflow service. nextID: 26 + Dataflow service. """ # Create or coerce a protobuf request object. @@ -219,6 +277,25 @@ async def launch_template( ) -> templates.LaunchTemplateResponse: r"""Launch a template. + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_launch_template(): + # Create a client + client = dataflow_v1beta3.TemplatesServiceClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.LaunchTemplateRequest( + gcs_path="gcs_path_value", + ) + + # Make the request + response = client.launch_template(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.LaunchTemplateRequest, dict]): The request object. A request to launch a template. @@ -261,6 +338,25 @@ async def get_template( ) -> templates.GetTemplateResponse: r"""Get the template associated with a template. + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_get_template(): + # Create a client + client = dataflow_v1beta3.TemplatesServiceClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.GetTemplateRequest( + gcs_path="gcs_path_value", + ) + + # Make the request + response = client.get_template(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.GetTemplateRequest, dict]): The request object. A request to retrieve a Cloud diff --git a/google/cloud/dataflow_v1beta3/services/templates_service/client.py b/google/cloud/dataflow_v1beta3/services/templates_service/client.py index b4d7814..41ea1e2 100644 --- a/google/cloud/dataflow_v1beta3/services/templates_service/client.py +++ b/google/cloud/dataflow_v1beta3/services/templates_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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.dataflow_v1beta3.types import environment from google.cloud.dataflow_v1beta3.types import jobs @@ -221,6 +223,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, *, @@ -271,50 +340,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, TemplatesServiceTransport): # transport is a TemplatesServiceTransport 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." @@ -326,6 +367,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, @@ -348,6 +398,25 @@ def create_job_from_template( ) -> jobs.Job: r"""Creates a Cloud Dataflow job from a template. + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_create_job_from_template(): + # Create a client + client = dataflow_v1beta3.TemplatesServiceClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.CreateJobFromTemplateRequest( + gcs_path="gcs_path_value", + ) + + # Make the request + response = client.create_job_from_template(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.CreateJobFromTemplateRequest, dict]): The request object. A request to create a Cloud Dataflow @@ -361,7 +430,7 @@ def create_job_from_template( Returns: google.cloud.dataflow_v1beta3.types.Job: Defines a job to be run by the Cloud - Dataflow service. nextID: 26 + Dataflow service. """ # Create or coerce a protobuf request object. @@ -392,6 +461,25 @@ def launch_template( ) -> templates.LaunchTemplateResponse: r"""Launch a template. + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_launch_template(): + # Create a client + client = dataflow_v1beta3.TemplatesServiceClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.LaunchTemplateRequest( + gcs_path="gcs_path_value", + ) + + # Make the request + response = client.launch_template(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.LaunchTemplateRequest, dict]): The request object. A request to launch a template. @@ -435,6 +523,25 @@ def get_template( ) -> templates.GetTemplateResponse: r"""Get the template associated with a template. + .. code-block:: python + + from google.cloud import dataflow_v1beta3 + + def sample_get_template(): + # Create a client + client = dataflow_v1beta3.TemplatesServiceClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.GetTemplateRequest( + gcs_path="gcs_path_value", + ) + + # Make the request + response = client.get_template(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.dataflow_v1beta3.types.GetTemplateRequest, dict]): The request object. A request to retrieve a Cloud diff --git a/google/cloud/dataflow_v1beta3/services/templates_service/transports/__init__.py b/google/cloud/dataflow_v1beta3/services/templates_service/transports/__init__.py index f4ff50c..5deae6e 100644 --- a/google/cloud/dataflow_v1beta3/services/templates_service/transports/__init__.py +++ b/google/cloud/dataflow_v1beta3/services/templates_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. diff --git a/google/cloud/dataflow_v1beta3/services/templates_service/transports/base.py b/google/cloud/dataflow_v1beta3/services/templates_service/transports/base.py index 3b00510..986f587 100644 --- a/google/cloud/dataflow_v1beta3/services/templates_service/transports/base.py +++ b/google/cloud/dataflow_v1beta3/services/templates_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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 @@ -107,7 +107,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/dataflow_v1beta3/services/templates_service/transports/grpc.py b/google/cloud/dataflow_v1beta3/services/templates_service/transports/grpc.py index 729ba13..09f8b89 100644 --- a/google/cloud/dataflow_v1beta3/services/templates_service/transports/grpc.py +++ b/google/cloud/dataflow_v1beta3/services/templates_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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/dataflow_v1beta3/services/templates_service/transports/grpc_asyncio.py b/google/cloud/dataflow_v1beta3/services/templates_service/transports/grpc_asyncio.py index 666d54b..7e2ec76 100644 --- a/google/cloud/dataflow_v1beta3/services/templates_service/transports/grpc_asyncio.py +++ b/google/cloud/dataflow_v1beta3/services/templates_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -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/dataflow_v1beta3/types/__init__.py b/google/cloud/dataflow_v1beta3/types/__init__.py index 569b19d..739c3f0 100644 --- a/google/cloud/dataflow_v1beta3/types/__init__.py +++ b/google/cloud/dataflow_v1beta3/types/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. diff --git a/google/cloud/dataflow_v1beta3/types/environment.py b/google/cloud/dataflow_v1beta3/types/environment.py index 2731689..4641cbf 100644 --- a/google/cloud/dataflow_v1beta3/types/environment.py +++ b/google/cloud/dataflow_v1beta3/types/environment.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -280,8 +280,8 @@ class Disk(proto.Message): default. For example, the standard persistent disk type - is a resource name typically ending in "pd- - standard". If SSD persistent disks are + is a resource name typically ending in + "pd-standard". If SSD persistent disks are available, the resource name typically ends with "pd-ssd". The actual valid values are defined the Google Compute Engine API, not by the Cloud @@ -294,8 +294,7 @@ class Disk(proto.Message): the resource name will typically look something like this: - compute.googleapis.com/projects/project- - id/zones/zone/diskTypes/pd-standard + compute.googleapis.com/projects/project-id/zones/zone/diskTypes/pd-standard mount_point (str): Directory in a VM where disk is mounted. """ diff --git a/google/cloud/dataflow_v1beta3/types/jobs.py b/google/cloud/dataflow_v1beta3/types/jobs.py index ef898aa..68cbece 100644 --- a/google/cloud/dataflow_v1beta3/types/jobs.py +++ b/google/cloud/dataflow_v1beta3/types/jobs.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -101,7 +101,6 @@ class JobView(proto.Enum): class Job(proto.Message): r"""Defines a job to be run by the Cloud Dataflow service. - nextID: 26 Attributes: id (str): @@ -331,7 +330,7 @@ class FileIODetails(proto.Message): class BigTableIODetails(proto.Message): - r"""Metadata for a Cloud BigTable connector used by the job. + r"""Metadata for a Cloud Bigtable connector used by the job. Attributes: project_id (str): @@ -424,11 +423,11 @@ class JobMetadata(proto.Message): Identification of a BigQuery source used in the Dataflow job. big_table_details (Sequence[google.cloud.dataflow_v1beta3.types.BigTableIODetails]): - Identification of a Cloud BigTable source + Identification of a Cloud Bigtable source used in the Dataflow job. pubsub_details (Sequence[google.cloud.dataflow_v1beta3.types.PubSubIODetails]): - Identification of a PubSub source used in the - Dataflow job. + Identification of a Pub/Sub source used in + the Dataflow job. file_details (Sequence[google.cloud.dataflow_v1beta3.types.FileIODetails]): Identification of a File source used in the Dataflow job. @@ -670,28 +669,35 @@ class name or programming language namespace rendering. str_value (str): Contains value if the data is of string type. + This field is a member of `oneof`_ ``Value``. int64_value (int): Contains value if the data is of int64 type. + This field is a member of `oneof`_ ``Value``. float_value (float): Contains value if the data is of float type. + This field is a member of `oneof`_ ``Value``. java_class_value (str): Contains value if the data is of java class type. + This field is a member of `oneof`_ ``Value``. timestamp_value (google.protobuf.timestamp_pb2.Timestamp): Contains value if the data is of timestamp type. + This field is a member of `oneof`_ ``Value``. duration_value (google.protobuf.duration_pb2.Duration): Contains value if the data is of duration type. + This field is a member of `oneof`_ ``Value``. bool_value (bool): Contains value if the data is of a boolean type. + This field is a member of `oneof`_ ``Value``. short_str_value (str): A possible additional shorter value to display. For example diff --git a/google/cloud/dataflow_v1beta3/types/messages.py b/google/cloud/dataflow_v1beta3/types/messages.py index 355ab79..379c0d8 100644 --- a/google/cloud/dataflow_v1beta3/types/messages.py +++ b/google/cloud/dataflow_v1beta3/types/messages.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -118,9 +118,8 @@ class AutoscalingEvent(proto.Message): The time this event was emitted to indicate a new target or current num_workers value. worker_pool (str): - A short and friendly name for the worker pool this event - refers to, populated from the value of - PoolStageRelation::user_pool_name. + A short and friendly name for the worker pool + this event refers to. """ class AutoscalingEventType(proto.Enum): diff --git a/google/cloud/dataflow_v1beta3/types/metrics.py b/google/cloud/dataflow_v1beta3/types/metrics.py index 887470f..ac8ce9d 100644 --- a/google/cloud/dataflow_v1beta3/types/metrics.py +++ b/google/cloud/dataflow_v1beta3/types/metrics.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -86,8 +86,8 @@ class MetricUpdate(proto.Message): Metric aggregation kind. The possible metric aggregation kinds are "Sum", "Max", "Min", "Mean", "Set", "And", "Or", and "Distribution". - The specified aggregation kind is case- - insensitive. + The specified aggregation kind is + case-insensitive. If omitted, this is not an aggregated value but instead a single metric sample value. cumulative (bool): @@ -177,8 +177,8 @@ class GetJobMetricsRequest(proto.Message): class JobMetrics(proto.Message): r"""JobMetrics contains a collection of metrics describing the - detailed progress of a Dataflow job. Metrics correspond to user- - defined and system-defined metrics in the job. + detailed progress of a Dataflow job. Metrics correspond to + user-defined and system-defined metrics in the job. This resource captures only the most recent values of each metric; time-series data can be queried for them (under the same diff --git a/google/cloud/dataflow_v1beta3/types/snapshots.py b/google/cloud/dataflow_v1beta3/types/snapshots.py index 9062c58..5a49790 100644 --- a/google/cloud/dataflow_v1beta3/types/snapshots.py +++ b/google/cloud/dataflow_v1beta3/types/snapshots.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -79,7 +79,7 @@ class Snapshot(proto.Message): state (google.cloud.dataflow_v1beta3.types.SnapshotState): State of the snapshot. pubsub_metadata (Sequence[google.cloud.dataflow_v1beta3.types.PubsubSnapshotMetadata]): - PubSub snapshot metadata. + Pub/Sub snapshot metadata. description (str): User specified description of the snapshot. Maybe empty. diff --git a/google/cloud/dataflow_v1beta3/types/streaming.py b/google/cloud/dataflow_v1beta3/types/streaming.py index 29764bf..bcc2812 100644 --- a/google/cloud/dataflow_v1beta3/types/streaming.py +++ b/google/cloud/dataflow_v1beta3/types/streaming.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -78,12 +78,10 @@ class PubsubLocation(proto.Message): Attributes: topic (str): A pubsub topic, in the form of - "pubsub.googleapis.com/topics//". + "pubsub.googleapis.com/topics//". subscription (str): A pubsub subscription, in the form of - "pubsub.googleapis.com/subscriptions//". + "pubsub.googleapis.com/subscriptions//". timestamp_label (str): If set, contains a pubsub label from which to extract record timestamps. If left empty, record @@ -93,8 +91,8 @@ class PubsubLocation(proto.Message): extract record ids. If left empty, record deduplication will be strictly best effort. drop_late_data (bool): - Indicates whether the pipeline allows late- - rriving data. + Indicates whether the pipeline allows + late-arriving data. tracking_subscription (str): If set, specifies the pubsub subscription that will be used for tracking custom time @@ -168,15 +166,19 @@ class StreamLocation(proto.Message): streaming_stage_location (google.cloud.dataflow_v1beta3.types.StreamingStageLocation): The stream is part of another computation within the current streaming Dataflow job. + This field is a member of `oneof`_ ``location``. pubsub_location (google.cloud.dataflow_v1beta3.types.PubsubLocation): The stream is a pubsub stream. + This field is a member of `oneof`_ ``location``. side_input_location (google.cloud.dataflow_v1beta3.types.StreamingSideInputLocation): The stream is a streaming side input. + This field is a member of `oneof`_ ``location``. custom_source_location (google.cloud.dataflow_v1beta3.types.CustomSourceLocation): The stream is a custom source. + This field is a member of `oneof`_ ``location``. """ diff --git a/google/cloud/dataflow_v1beta3/types/templates.py b/google/cloud/dataflow_v1beta3/types/templates.py index fd7f5ac..5bd9298 100644 --- a/google/cloud/dataflow_v1beta3/types/templates.py +++ b/google/cloud/dataflow_v1beta3/types/templates.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -116,10 +116,12 @@ class LaunchFlexTemplateParameter(proto.Message): same as the existing running job. container_spec (google.cloud.dataflow_v1beta3.types.ContainerSpec): Spec about the container image to launch. + This field is a member of `oneof`_ ``template``. container_spec_gcs_path (str): Cloud Storage path to a file with json serialized ContainerSpec as content. + This field is a member of `oneof`_ ``template``. parameters (Sequence[google.cloud.dataflow_v1beta3.types.LaunchFlexTemplateParameter.ParametersEntry]): The parameters for FlexTemplate. Ex. {"num_workers":"5"} @@ -237,6 +239,24 @@ class FlexTemplateRuntimeEnvironment(proto.Message): to use for the 'worker harness. Default is the container for the version of the SDK. Note this field is only valid for portable pipelines. + disk_size_gb (int): + Worker disk size, in gigabytes. + autoscaling_algorithm (google.cloud.dataflow_v1beta3.types.AutoscalingAlgorithm): + The algorithm to use for autoscaling + dump_heap_on_oom (bool): + If true, save a heap dump before killing a + thread or process which is GC thrashing or out + of memory. The location of the heap file will + either be echoed back to the user, or the user + will be given the opportunity to download the + heap file. + save_heap_dumps_to_gcs_path (str): + Cloud Storage bucket (directory) to upload heap dumps to the + given location. Enabling this implies that heap dumps should + be generated on OOM (dump_heap_on_oom is set to true). + launcher_machine_type (str): + The machine type to use for launching the + job. The default is n1-standard-1. """ num_workers = proto.Field(proto.INT32, number=1,) @@ -261,6 +281,13 @@ class FlexTemplateRuntimeEnvironment(proto.Message): ) staging_location = proto.Field(proto.STRING, number=17,) sdk_container_image = proto.Field(proto.STRING, number=18,) + disk_size_gb = proto.Field(proto.INT32, number=20,) + autoscaling_algorithm = proto.Field( + proto.ENUM, number=21, enum=gd_environment.AutoscalingAlgorithm, + ) + dump_heap_on_oom = proto.Field(proto.BOOL, number=22,) + save_heap_dumps_to_gcs_path = proto.Field(proto.STRING, number=23,) + launcher_machine_type = proto.Field(proto.STRING, number=24,) class LaunchFlexTemplateRequest(proto.Message): @@ -319,7 +346,8 @@ class RuntimeEnvironment(proto.Message): The machine type to use for the job. Defaults to the value from the template if not specified. additional_experiments (Sequence[str]): - Additional experiment flags for the job. + Additional experiment flags for the job, specified with the + ``--experiments`` option. network (str): Network to which VMs will be assigned. If empty or unspecified, the service will use the @@ -492,6 +520,7 @@ class CreateJobFromTemplateRequest(proto.Message): Required. A Cloud Storage path to the template from which to create the job. Must be a valid Cloud Storage URL, beginning with ``gs://``. + This field is a member of `oneof`_ ``template``. parameters (Sequence[google.cloud.dataflow_v1beta3.types.CreateJobFromTemplateRequest.ParametersEntry]): The runtime parameters to pass to the job. @@ -525,6 +554,7 @@ class GetTemplateRequest(proto.Message): template from which to create the job. Must be valid Cloud Storage URL, beginning with 'gs://'. + This field is a member of `oneof`_ ``template``. view (google.cloud.dataflow_v1beta3.types.GetTemplateRequest.TemplateView): The view to retrieve. Defaults to METADATA_ONLY. @@ -624,9 +654,11 @@ class LaunchTemplateRequest(proto.Message): which to create the job. Must be valid Cloud Storage URL, beginning with 'gs://'. + This field is a member of `oneof`_ ``template``. dynamic_template (google.cloud.dataflow_v1beta3.types.DynamicTemplateLaunchParams): Params for launching a dynamic template. + This field is a member of `oneof`_ ``template``. launch_parameters (google.cloud.dataflow_v1beta3.types.LaunchTemplateParameters): The parameters of the template to launch. diff --git a/samples/generated_samples/dataflow_v1beta3_generated_flex_templates_service_launch_flex_template_async.py b/samples/generated_samples/dataflow_v1beta3_generated_flex_templates_service_launch_flex_template_async.py new file mode 100644 index 0000000..5357fdd --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_flex_templates_service_launch_flex_template_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for LaunchFlexTemplate +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_FlexTemplatesService_LaunchFlexTemplate_async] +from google.cloud import dataflow_v1beta3 + + +async def sample_launch_flex_template(): + # Create a client + client = dataflow_v1beta3.FlexTemplatesServiceAsyncClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.LaunchFlexTemplateRequest( + ) + + # Make the request + response = await client.launch_flex_template(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_FlexTemplatesService_LaunchFlexTemplate_async] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_flex_templates_service_launch_flex_template_sync.py b/samples/generated_samples/dataflow_v1beta3_generated_flex_templates_service_launch_flex_template_sync.py new file mode 100644 index 0000000..3f10948 --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_flex_templates_service_launch_flex_template_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for LaunchFlexTemplate +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_FlexTemplatesService_LaunchFlexTemplate_sync] +from google.cloud import dataflow_v1beta3 + + +def sample_launch_flex_template(): + # Create a client + client = dataflow_v1beta3.FlexTemplatesServiceClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.LaunchFlexTemplateRequest( + ) + + # Make the request + response = client.launch_flex_template(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_FlexTemplatesService_LaunchFlexTemplate_sync] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_aggregated_list_jobs_async.py b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_aggregated_list_jobs_async.py new file mode 100644 index 0000000..055273c --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_aggregated_list_jobs_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AggregatedListJobs +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_JobsV1Beta3_AggregatedListJobs_async] +from google.cloud import dataflow_v1beta3 + + +async def sample_aggregated_list_jobs(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3AsyncClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.ListJobsRequest( + ) + + # Make the request + page_result = client.aggregated_list_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END dataflow_v1beta3_generated_JobsV1Beta3_AggregatedListJobs_async] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_aggregated_list_jobs_sync.py b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_aggregated_list_jobs_sync.py new file mode 100644 index 0000000..5c7e8ee --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_aggregated_list_jobs_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AggregatedListJobs +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_JobsV1Beta3_AggregatedListJobs_sync] +from google.cloud import dataflow_v1beta3 + + +def sample_aggregated_list_jobs(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.ListJobsRequest( + ) + + # Make the request + page_result = client.aggregated_list_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END dataflow_v1beta3_generated_JobsV1Beta3_AggregatedListJobs_sync] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_check_active_jobs_async.py b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_check_active_jobs_async.py new file mode 100644 index 0000000..fb98186 --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_check_active_jobs_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CheckActiveJobs +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_JobsV1Beta3_CheckActiveJobs_async] +from google.cloud import dataflow_v1beta3 + + +async def sample_check_active_jobs(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3AsyncClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.CheckActiveJobsRequest( + ) + + # Make the request + response = await client.check_active_jobs(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_JobsV1Beta3_CheckActiveJobs_async] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_check_active_jobs_sync.py b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_check_active_jobs_sync.py new file mode 100644 index 0000000..cc112d4 --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_check_active_jobs_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CheckActiveJobs +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_JobsV1Beta3_CheckActiveJobs_sync] +from google.cloud import dataflow_v1beta3 + + +def sample_check_active_jobs(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.CheckActiveJobsRequest( + ) + + # Make the request + response = client.check_active_jobs(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_JobsV1Beta3_CheckActiveJobs_sync] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_create_job_async.py b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_create_job_async.py new file mode 100644 index 0000000..7ea8825 --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_create_job_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateJob +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_JobsV1Beta3_CreateJob_async] +from google.cloud import dataflow_v1beta3 + + +async def sample_create_job(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3AsyncClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.CreateJobRequest( + ) + + # Make the request + response = await client.create_job(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_JobsV1Beta3_CreateJob_async] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_create_job_sync.py b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_create_job_sync.py new file mode 100644 index 0000000..8336586 --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_create_job_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateJob +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_JobsV1Beta3_CreateJob_sync] +from google.cloud import dataflow_v1beta3 + + +def sample_create_job(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.CreateJobRequest( + ) + + # Make the request + response = client.create_job(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_JobsV1Beta3_CreateJob_sync] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_get_job_async.py b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_get_job_async.py new file mode 100644 index 0000000..bb903dd --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_get_job_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetJob +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_JobsV1Beta3_GetJob_async] +from google.cloud import dataflow_v1beta3 + + +async def sample_get_job(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3AsyncClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.GetJobRequest( + ) + + # Make the request + response = await client.get_job(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_JobsV1Beta3_GetJob_async] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_get_job_sync.py b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_get_job_sync.py new file mode 100644 index 0000000..08c216a --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_get_job_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetJob +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_JobsV1Beta3_GetJob_sync] +from google.cloud import dataflow_v1beta3 + + +def sample_get_job(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.GetJobRequest( + ) + + # Make the request + response = client.get_job(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_JobsV1Beta3_GetJob_sync] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_list_jobs_async.py b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_list_jobs_async.py new file mode 100644 index 0000000..b3d657a --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_list_jobs_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListJobs +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_JobsV1Beta3_ListJobs_async] +from google.cloud import dataflow_v1beta3 + + +async def sample_list_jobs(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3AsyncClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.ListJobsRequest( + ) + + # Make the request + page_result = client.list_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END dataflow_v1beta3_generated_JobsV1Beta3_ListJobs_async] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_list_jobs_sync.py b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_list_jobs_sync.py new file mode 100644 index 0000000..a15e4b5 --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_list_jobs_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListJobs +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_JobsV1Beta3_ListJobs_sync] +from google.cloud import dataflow_v1beta3 + + +def sample_list_jobs(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.ListJobsRequest( + ) + + # Make the request + page_result = client.list_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END dataflow_v1beta3_generated_JobsV1Beta3_ListJobs_sync] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_snapshot_job_async.py b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_snapshot_job_async.py new file mode 100644 index 0000000..db6128d --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_snapshot_job_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SnapshotJob +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_JobsV1Beta3_SnapshotJob_async] +from google.cloud import dataflow_v1beta3 + + +async def sample_snapshot_job(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3AsyncClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.SnapshotJobRequest( + ) + + # Make the request + response = await client.snapshot_job(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_JobsV1Beta3_SnapshotJob_async] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_snapshot_job_sync.py b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_snapshot_job_sync.py new file mode 100644 index 0000000..1cc8d21 --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_snapshot_job_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SnapshotJob +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_JobsV1Beta3_SnapshotJob_sync] +from google.cloud import dataflow_v1beta3 + + +def sample_snapshot_job(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.SnapshotJobRequest( + ) + + # Make the request + response = client.snapshot_job(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_JobsV1Beta3_SnapshotJob_sync] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_update_job_async.py b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_update_job_async.py new file mode 100644 index 0000000..872b840 --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_update_job_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateJob +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_JobsV1Beta3_UpdateJob_async] +from google.cloud import dataflow_v1beta3 + + +async def sample_update_job(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3AsyncClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.UpdateJobRequest( + ) + + # Make the request + response = await client.update_job(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_JobsV1Beta3_UpdateJob_async] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_update_job_sync.py b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_update_job_sync.py new file mode 100644 index 0000000..1808f65 --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_jobs_v1_beta3_update_job_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateJob +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_JobsV1Beta3_UpdateJob_sync] +from google.cloud import dataflow_v1beta3 + + +def sample_update_job(): + # Create a client + client = dataflow_v1beta3.JobsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.UpdateJobRequest( + ) + + # Make the request + response = client.update_job(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_JobsV1Beta3_UpdateJob_sync] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_messages_v1_beta3_list_job_messages_async.py b/samples/generated_samples/dataflow_v1beta3_generated_messages_v1_beta3_list_job_messages_async.py new file mode 100644 index 0000000..5dfa45c --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_messages_v1_beta3_list_job_messages_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListJobMessages +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_MessagesV1Beta3_ListJobMessages_async] +from google.cloud import dataflow_v1beta3 + + +async def sample_list_job_messages(): + # Create a client + client = dataflow_v1beta3.MessagesV1Beta3AsyncClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.ListJobMessagesRequest( + ) + + # Make the request + page_result = client.list_job_messages(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END dataflow_v1beta3_generated_MessagesV1Beta3_ListJobMessages_async] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_messages_v1_beta3_list_job_messages_sync.py b/samples/generated_samples/dataflow_v1beta3_generated_messages_v1_beta3_list_job_messages_sync.py new file mode 100644 index 0000000..18e6b11 --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_messages_v1_beta3_list_job_messages_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListJobMessages +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_MessagesV1Beta3_ListJobMessages_sync] +from google.cloud import dataflow_v1beta3 + + +def sample_list_job_messages(): + # Create a client + client = dataflow_v1beta3.MessagesV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.ListJobMessagesRequest( + ) + + # Make the request + page_result = client.list_job_messages(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END dataflow_v1beta3_generated_MessagesV1Beta3_ListJobMessages_sync] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_metrics_v1_beta3_get_job_execution_details_async.py b/samples/generated_samples/dataflow_v1beta3_generated_metrics_v1_beta3_get_job_execution_details_async.py new file mode 100644 index 0000000..604072a --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_metrics_v1_beta3_get_job_execution_details_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetJobExecutionDetails +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_MetricsV1Beta3_GetJobExecutionDetails_async] +from google.cloud import dataflow_v1beta3 + + +async def sample_get_job_execution_details(): + # Create a client + client = dataflow_v1beta3.MetricsV1Beta3AsyncClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.GetJobExecutionDetailsRequest( + ) + + # Make the request + page_result = client.get_job_execution_details(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END dataflow_v1beta3_generated_MetricsV1Beta3_GetJobExecutionDetails_async] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_metrics_v1_beta3_get_job_execution_details_sync.py b/samples/generated_samples/dataflow_v1beta3_generated_metrics_v1_beta3_get_job_execution_details_sync.py new file mode 100644 index 0000000..a3f3667 --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_metrics_v1_beta3_get_job_execution_details_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetJobExecutionDetails +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_MetricsV1Beta3_GetJobExecutionDetails_sync] +from google.cloud import dataflow_v1beta3 + + +def sample_get_job_execution_details(): + # Create a client + client = dataflow_v1beta3.MetricsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.GetJobExecutionDetailsRequest( + ) + + # Make the request + page_result = client.get_job_execution_details(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END dataflow_v1beta3_generated_MetricsV1Beta3_GetJobExecutionDetails_sync] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_metrics_v1_beta3_get_job_metrics_async.py b/samples/generated_samples/dataflow_v1beta3_generated_metrics_v1_beta3_get_job_metrics_async.py new file mode 100644 index 0000000..19eae53 --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_metrics_v1_beta3_get_job_metrics_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetJobMetrics +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_MetricsV1Beta3_GetJobMetrics_async] +from google.cloud import dataflow_v1beta3 + + +async def sample_get_job_metrics(): + # Create a client + client = dataflow_v1beta3.MetricsV1Beta3AsyncClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.GetJobMetricsRequest( + ) + + # Make the request + response = await client.get_job_metrics(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_MetricsV1Beta3_GetJobMetrics_async] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_metrics_v1_beta3_get_job_metrics_sync.py b/samples/generated_samples/dataflow_v1beta3_generated_metrics_v1_beta3_get_job_metrics_sync.py new file mode 100644 index 0000000..b3681c4 --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_metrics_v1_beta3_get_job_metrics_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetJobMetrics +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_MetricsV1Beta3_GetJobMetrics_sync] +from google.cloud import dataflow_v1beta3 + + +def sample_get_job_metrics(): + # Create a client + client = dataflow_v1beta3.MetricsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.GetJobMetricsRequest( + ) + + # Make the request + response = client.get_job_metrics(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_MetricsV1Beta3_GetJobMetrics_sync] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_metrics_v1_beta3_get_stage_execution_details_async.py b/samples/generated_samples/dataflow_v1beta3_generated_metrics_v1_beta3_get_stage_execution_details_async.py new file mode 100644 index 0000000..b1b620c --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_metrics_v1_beta3_get_stage_execution_details_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetStageExecutionDetails +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_MetricsV1Beta3_GetStageExecutionDetails_async] +from google.cloud import dataflow_v1beta3 + + +async def sample_get_stage_execution_details(): + # Create a client + client = dataflow_v1beta3.MetricsV1Beta3AsyncClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.GetStageExecutionDetailsRequest( + ) + + # Make the request + page_result = client.get_stage_execution_details(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END dataflow_v1beta3_generated_MetricsV1Beta3_GetStageExecutionDetails_async] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_metrics_v1_beta3_get_stage_execution_details_sync.py b/samples/generated_samples/dataflow_v1beta3_generated_metrics_v1_beta3_get_stage_execution_details_sync.py new file mode 100644 index 0000000..9e4ae13 --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_metrics_v1_beta3_get_stage_execution_details_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetStageExecutionDetails +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_MetricsV1Beta3_GetStageExecutionDetails_sync] +from google.cloud import dataflow_v1beta3 + + +def sample_get_stage_execution_details(): + # Create a client + client = dataflow_v1beta3.MetricsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.GetStageExecutionDetailsRequest( + ) + + # Make the request + page_result = client.get_stage_execution_details(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END dataflow_v1beta3_generated_MetricsV1Beta3_GetStageExecutionDetails_sync] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_snapshots_v1_beta3_delete_snapshot_async.py b/samples/generated_samples/dataflow_v1beta3_generated_snapshots_v1_beta3_delete_snapshot_async.py new file mode 100644 index 0000000..f210c6a --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_snapshots_v1_beta3_delete_snapshot_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteSnapshot +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_SnapshotsV1Beta3_DeleteSnapshot_async] +from google.cloud import dataflow_v1beta3 + + +async def sample_delete_snapshot(): + # Create a client + client = dataflow_v1beta3.SnapshotsV1Beta3AsyncClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.DeleteSnapshotRequest( + ) + + # Make the request + response = await client.delete_snapshot(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_SnapshotsV1Beta3_DeleteSnapshot_async] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_snapshots_v1_beta3_delete_snapshot_sync.py b/samples/generated_samples/dataflow_v1beta3_generated_snapshots_v1_beta3_delete_snapshot_sync.py new file mode 100644 index 0000000..2a69716 --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_snapshots_v1_beta3_delete_snapshot_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteSnapshot +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_SnapshotsV1Beta3_DeleteSnapshot_sync] +from google.cloud import dataflow_v1beta3 + + +def sample_delete_snapshot(): + # Create a client + client = dataflow_v1beta3.SnapshotsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.DeleteSnapshotRequest( + ) + + # Make the request + response = client.delete_snapshot(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_SnapshotsV1Beta3_DeleteSnapshot_sync] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_snapshots_v1_beta3_get_snapshot_async.py b/samples/generated_samples/dataflow_v1beta3_generated_snapshots_v1_beta3_get_snapshot_async.py new file mode 100644 index 0000000..f153028 --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_snapshots_v1_beta3_get_snapshot_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetSnapshot +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_SnapshotsV1Beta3_GetSnapshot_async] +from google.cloud import dataflow_v1beta3 + + +async def sample_get_snapshot(): + # Create a client + client = dataflow_v1beta3.SnapshotsV1Beta3AsyncClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.GetSnapshotRequest( + ) + + # Make the request + response = await client.get_snapshot(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_SnapshotsV1Beta3_GetSnapshot_async] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_snapshots_v1_beta3_get_snapshot_sync.py b/samples/generated_samples/dataflow_v1beta3_generated_snapshots_v1_beta3_get_snapshot_sync.py new file mode 100644 index 0000000..c9ac9f9 --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_snapshots_v1_beta3_get_snapshot_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetSnapshot +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_SnapshotsV1Beta3_GetSnapshot_sync] +from google.cloud import dataflow_v1beta3 + + +def sample_get_snapshot(): + # Create a client + client = dataflow_v1beta3.SnapshotsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.GetSnapshotRequest( + ) + + # Make the request + response = client.get_snapshot(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_SnapshotsV1Beta3_GetSnapshot_sync] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_snapshots_v1_beta3_list_snapshots_async.py b/samples/generated_samples/dataflow_v1beta3_generated_snapshots_v1_beta3_list_snapshots_async.py new file mode 100644 index 0000000..db185c6 --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_snapshots_v1_beta3_list_snapshots_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListSnapshots +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_SnapshotsV1Beta3_ListSnapshots_async] +from google.cloud import dataflow_v1beta3 + + +async def sample_list_snapshots(): + # Create a client + client = dataflow_v1beta3.SnapshotsV1Beta3AsyncClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.ListSnapshotsRequest( + ) + + # Make the request + response = await client.list_snapshots(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_SnapshotsV1Beta3_ListSnapshots_async] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_snapshots_v1_beta3_list_snapshots_sync.py b/samples/generated_samples/dataflow_v1beta3_generated_snapshots_v1_beta3_list_snapshots_sync.py new file mode 100644 index 0000000..0bc9dd2 --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_snapshots_v1_beta3_list_snapshots_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListSnapshots +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_SnapshotsV1Beta3_ListSnapshots_sync] +from google.cloud import dataflow_v1beta3 + + +def sample_list_snapshots(): + # Create a client + client = dataflow_v1beta3.SnapshotsV1Beta3Client() + + # Initialize request argument(s) + request = dataflow_v1beta3.ListSnapshotsRequest( + ) + + # Make the request + response = client.list_snapshots(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_SnapshotsV1Beta3_ListSnapshots_sync] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_templates_service_create_job_from_template_async.py b/samples/generated_samples/dataflow_v1beta3_generated_templates_service_create_job_from_template_async.py new file mode 100644 index 0000000..ca4b2c5 --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_templates_service_create_job_from_template_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateJobFromTemplate +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_TemplatesService_CreateJobFromTemplate_async] +from google.cloud import dataflow_v1beta3 + + +async def sample_create_job_from_template(): + # Create a client + client = dataflow_v1beta3.TemplatesServiceAsyncClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.CreateJobFromTemplateRequest( + gcs_path="gcs_path_value", + ) + + # Make the request + response = await client.create_job_from_template(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_TemplatesService_CreateJobFromTemplate_async] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_templates_service_create_job_from_template_sync.py b/samples/generated_samples/dataflow_v1beta3_generated_templates_service_create_job_from_template_sync.py new file mode 100644 index 0000000..3e117b3 --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_templates_service_create_job_from_template_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateJobFromTemplate +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_TemplatesService_CreateJobFromTemplate_sync] +from google.cloud import dataflow_v1beta3 + + +def sample_create_job_from_template(): + # Create a client + client = dataflow_v1beta3.TemplatesServiceClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.CreateJobFromTemplateRequest( + gcs_path="gcs_path_value", + ) + + # Make the request + response = client.create_job_from_template(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_TemplatesService_CreateJobFromTemplate_sync] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_templates_service_get_template_async.py b/samples/generated_samples/dataflow_v1beta3_generated_templates_service_get_template_async.py new file mode 100644 index 0000000..4c17136 --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_templates_service_get_template_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTemplate +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_TemplatesService_GetTemplate_async] +from google.cloud import dataflow_v1beta3 + + +async def sample_get_template(): + # Create a client + client = dataflow_v1beta3.TemplatesServiceAsyncClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.GetTemplateRequest( + gcs_path="gcs_path_value", + ) + + # Make the request + response = await client.get_template(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_TemplatesService_GetTemplate_async] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_templates_service_get_template_sync.py b/samples/generated_samples/dataflow_v1beta3_generated_templates_service_get_template_sync.py new file mode 100644 index 0000000..dfdfece --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_templates_service_get_template_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTemplate +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_TemplatesService_GetTemplate_sync] +from google.cloud import dataflow_v1beta3 + + +def sample_get_template(): + # Create a client + client = dataflow_v1beta3.TemplatesServiceClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.GetTemplateRequest( + gcs_path="gcs_path_value", + ) + + # Make the request + response = client.get_template(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_TemplatesService_GetTemplate_sync] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_templates_service_launch_template_async.py b/samples/generated_samples/dataflow_v1beta3_generated_templates_service_launch_template_async.py new file mode 100644 index 0000000..a7a70a1 --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_templates_service_launch_template_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for LaunchTemplate +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_TemplatesService_LaunchTemplate_async] +from google.cloud import dataflow_v1beta3 + + +async def sample_launch_template(): + # Create a client + client = dataflow_v1beta3.TemplatesServiceAsyncClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.LaunchTemplateRequest( + gcs_path="gcs_path_value", + ) + + # Make the request + response = await client.launch_template(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_TemplatesService_LaunchTemplate_async] diff --git a/samples/generated_samples/dataflow_v1beta3_generated_templates_service_launch_template_sync.py b/samples/generated_samples/dataflow_v1beta3_generated_templates_service_launch_template_sync.py new file mode 100644 index 0000000..9dc8d08 --- /dev/null +++ b/samples/generated_samples/dataflow_v1beta3_generated_templates_service_launch_template_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for LaunchTemplate +# 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-dataflow-client + + +# [START dataflow_v1beta3_generated_TemplatesService_LaunchTemplate_sync] +from google.cloud import dataflow_v1beta3 + + +def sample_launch_template(): + # Create a client + client = dataflow_v1beta3.TemplatesServiceClient() + + # Initialize request argument(s) + request = dataflow_v1beta3.LaunchTemplateRequest( + gcs_path="gcs_path_value", + ) + + # Make the request + response = client.launch_template(request=request) + + # Handle the response + print(response) + +# [END dataflow_v1beta3_generated_TemplatesService_LaunchTemplate_sync] diff --git a/samples/generated_samples/snippet_metadata_dataflow_v1beta3.json b/samples/generated_samples/snippet_metadata_dataflow_v1beta3.json new file mode 100644 index 0000000..47a3472 --- /dev/null +++ b/samples/generated_samples/snippet_metadata_dataflow_v1beta3.json @@ -0,0 +1,1606 @@ +{ + "snippets": [ + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "FlexTemplatesService" + }, + "shortName": "LaunchFlexTemplate" + } + }, + "file": "dataflow_v1beta3_generated_flex_templates_service_launch_flex_template_async.py", + "regionTag": "dataflow_v1beta3_generated_FlexTemplatesService_LaunchFlexTemplate_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "FlexTemplatesService" + }, + "shortName": "LaunchFlexTemplate" + } + }, + "file": "dataflow_v1beta3_generated_flex_templates_service_launch_flex_template_sync.py", + "regionTag": "dataflow_v1beta3_generated_FlexTemplatesService_LaunchFlexTemplate_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "JobsV1Beta3" + }, + "shortName": "AggregatedListJobs" + } + }, + "file": "dataflow_v1beta3_generated_jobs_v1_beta3_aggregated_list_jobs_async.py", + "regionTag": "dataflow_v1beta3_generated_JobsV1Beta3_AggregatedListJobs_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "JobsV1Beta3" + }, + "shortName": "AggregatedListJobs" + } + }, + "file": "dataflow_v1beta3_generated_jobs_v1_beta3_aggregated_list_jobs_sync.py", + "regionTag": "dataflow_v1beta3_generated_JobsV1Beta3_AggregatedListJobs_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "JobsV1Beta3" + }, + "shortName": "CheckActiveJobs" + } + }, + "file": "dataflow_v1beta3_generated_jobs_v1_beta3_check_active_jobs_async.py", + "regionTag": "dataflow_v1beta3_generated_JobsV1Beta3_CheckActiveJobs_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "JobsV1Beta3" + }, + "shortName": "CheckActiveJobs" + } + }, + "file": "dataflow_v1beta3_generated_jobs_v1_beta3_check_active_jobs_sync.py", + "regionTag": "dataflow_v1beta3_generated_JobsV1Beta3_CheckActiveJobs_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "JobsV1Beta3" + }, + "shortName": "CreateJob" + } + }, + "file": "dataflow_v1beta3_generated_jobs_v1_beta3_create_job_async.py", + "regionTag": "dataflow_v1beta3_generated_JobsV1Beta3_CreateJob_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "JobsV1Beta3" + }, + "shortName": "CreateJob" + } + }, + "file": "dataflow_v1beta3_generated_jobs_v1_beta3_create_job_sync.py", + "regionTag": "dataflow_v1beta3_generated_JobsV1Beta3_CreateJob_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "JobsV1Beta3" + }, + "shortName": "GetJob" + } + }, + "file": "dataflow_v1beta3_generated_jobs_v1_beta3_get_job_async.py", + "regionTag": "dataflow_v1beta3_generated_JobsV1Beta3_GetJob_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "JobsV1Beta3" + }, + "shortName": "GetJob" + } + }, + "file": "dataflow_v1beta3_generated_jobs_v1_beta3_get_job_sync.py", + "regionTag": "dataflow_v1beta3_generated_JobsV1Beta3_GetJob_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "JobsV1Beta3" + }, + "shortName": "ListJobs" + } + }, + "file": "dataflow_v1beta3_generated_jobs_v1_beta3_list_jobs_async.py", + "regionTag": "dataflow_v1beta3_generated_JobsV1Beta3_ListJobs_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "JobsV1Beta3" + }, + "shortName": "ListJobs" + } + }, + "file": "dataflow_v1beta3_generated_jobs_v1_beta3_list_jobs_sync.py", + "regionTag": "dataflow_v1beta3_generated_JobsV1Beta3_ListJobs_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "JobsV1Beta3" + }, + "shortName": "SnapshotJob" + } + }, + "file": "dataflow_v1beta3_generated_jobs_v1_beta3_snapshot_job_async.py", + "regionTag": "dataflow_v1beta3_generated_JobsV1Beta3_SnapshotJob_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "JobsV1Beta3" + }, + "shortName": "SnapshotJob" + } + }, + "file": "dataflow_v1beta3_generated_jobs_v1_beta3_snapshot_job_sync.py", + "regionTag": "dataflow_v1beta3_generated_JobsV1Beta3_SnapshotJob_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "JobsV1Beta3" + }, + "shortName": "UpdateJob" + } + }, + "file": "dataflow_v1beta3_generated_jobs_v1_beta3_update_job_async.py", + "regionTag": "dataflow_v1beta3_generated_JobsV1Beta3_UpdateJob_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "JobsV1Beta3" + }, + "shortName": "UpdateJob" + } + }, + "file": "dataflow_v1beta3_generated_jobs_v1_beta3_update_job_sync.py", + "regionTag": "dataflow_v1beta3_generated_JobsV1Beta3_UpdateJob_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "MessagesV1Beta3" + }, + "shortName": "ListJobMessages" + } + }, + "file": "dataflow_v1beta3_generated_messages_v1_beta3_list_job_messages_async.py", + "regionTag": "dataflow_v1beta3_generated_MessagesV1Beta3_ListJobMessages_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "MessagesV1Beta3" + }, + "shortName": "ListJobMessages" + } + }, + "file": "dataflow_v1beta3_generated_messages_v1_beta3_list_job_messages_sync.py", + "regionTag": "dataflow_v1beta3_generated_MessagesV1Beta3_ListJobMessages_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "MetricsV1Beta3" + }, + "shortName": "GetJobExecutionDetails" + } + }, + "file": "dataflow_v1beta3_generated_metrics_v1_beta3_get_job_execution_details_async.py", + "regionTag": "dataflow_v1beta3_generated_MetricsV1Beta3_GetJobExecutionDetails_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "MetricsV1Beta3" + }, + "shortName": "GetJobExecutionDetails" + } + }, + "file": "dataflow_v1beta3_generated_metrics_v1_beta3_get_job_execution_details_sync.py", + "regionTag": "dataflow_v1beta3_generated_MetricsV1Beta3_GetJobExecutionDetails_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "MetricsV1Beta3" + }, + "shortName": "GetJobMetrics" + } + }, + "file": "dataflow_v1beta3_generated_metrics_v1_beta3_get_job_metrics_async.py", + "regionTag": "dataflow_v1beta3_generated_MetricsV1Beta3_GetJobMetrics_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "MetricsV1Beta3" + }, + "shortName": "GetJobMetrics" + } + }, + "file": "dataflow_v1beta3_generated_metrics_v1_beta3_get_job_metrics_sync.py", + "regionTag": "dataflow_v1beta3_generated_MetricsV1Beta3_GetJobMetrics_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "MetricsV1Beta3" + }, + "shortName": "GetStageExecutionDetails" + } + }, + "file": "dataflow_v1beta3_generated_metrics_v1_beta3_get_stage_execution_details_async.py", + "regionTag": "dataflow_v1beta3_generated_MetricsV1Beta3_GetStageExecutionDetails_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "MetricsV1Beta3" + }, + "shortName": "GetStageExecutionDetails" + } + }, + "file": "dataflow_v1beta3_generated_metrics_v1_beta3_get_stage_execution_details_sync.py", + "regionTag": "dataflow_v1beta3_generated_MetricsV1Beta3_GetStageExecutionDetails_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "SnapshotsV1Beta3" + }, + "shortName": "DeleteSnapshot" + } + }, + "file": "dataflow_v1beta3_generated_snapshots_v1_beta3_delete_snapshot_async.py", + "regionTag": "dataflow_v1beta3_generated_SnapshotsV1Beta3_DeleteSnapshot_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "SnapshotsV1Beta3" + }, + "shortName": "DeleteSnapshot" + } + }, + "file": "dataflow_v1beta3_generated_snapshots_v1_beta3_delete_snapshot_sync.py", + "regionTag": "dataflow_v1beta3_generated_SnapshotsV1Beta3_DeleteSnapshot_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "SnapshotsV1Beta3" + }, + "shortName": "GetSnapshot" + } + }, + "file": "dataflow_v1beta3_generated_snapshots_v1_beta3_get_snapshot_async.py", + "regionTag": "dataflow_v1beta3_generated_SnapshotsV1Beta3_GetSnapshot_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "SnapshotsV1Beta3" + }, + "shortName": "GetSnapshot" + } + }, + "file": "dataflow_v1beta3_generated_snapshots_v1_beta3_get_snapshot_sync.py", + "regionTag": "dataflow_v1beta3_generated_SnapshotsV1Beta3_GetSnapshot_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "SnapshotsV1Beta3" + }, + "shortName": "ListSnapshots" + } + }, + "file": "dataflow_v1beta3_generated_snapshots_v1_beta3_list_snapshots_async.py", + "regionTag": "dataflow_v1beta3_generated_SnapshotsV1Beta3_ListSnapshots_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "SnapshotsV1Beta3" + }, + "shortName": "ListSnapshots" + } + }, + "file": "dataflow_v1beta3_generated_snapshots_v1_beta3_list_snapshots_sync.py", + "regionTag": "dataflow_v1beta3_generated_SnapshotsV1Beta3_ListSnapshots_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "TemplatesService" + }, + "shortName": "CreateJobFromTemplate" + } + }, + "file": "dataflow_v1beta3_generated_templates_service_create_job_from_template_async.py", + "regionTag": "dataflow_v1beta3_generated_TemplatesService_CreateJobFromTemplate_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": "TemplatesService" + }, + "shortName": "CreateJobFromTemplate" + } + }, + "file": "dataflow_v1beta3_generated_templates_service_create_job_from_template_sync.py", + "regionTag": "dataflow_v1beta3_generated_TemplatesService_CreateJobFromTemplate_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": "TemplatesService" + }, + "shortName": "GetTemplate" + } + }, + "file": "dataflow_v1beta3_generated_templates_service_get_template_async.py", + "regionTag": "dataflow_v1beta3_generated_TemplatesService_GetTemplate_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": "TemplatesService" + }, + "shortName": "GetTemplate" + } + }, + "file": "dataflow_v1beta3_generated_templates_service_get_template_sync.py", + "regionTag": "dataflow_v1beta3_generated_TemplatesService_GetTemplate_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": "TemplatesService" + }, + "shortName": "LaunchTemplate" + } + }, + "file": "dataflow_v1beta3_generated_templates_service_launch_template_async.py", + "regionTag": "dataflow_v1beta3_generated_TemplatesService_LaunchTemplate_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": "TemplatesService" + }, + "shortName": "LaunchTemplate" + } + }, + "file": "dataflow_v1beta3_generated_templates_service_launch_template_sync.py", + "regionTag": "dataflow_v1beta3_generated_TemplatesService_LaunchTemplate_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" + } + ] + } + ] +} diff --git a/scripts/fixup_dataflow_v1beta3_keywords.py b/scripts/fixup_dataflow_v1beta3_keywords.py index e833916..8afa679 100644 --- a/scripts/fixup_dataflow_v1beta3_keywords.py +++ b/scripts/fixup_dataflow_v1beta3_keywords.py @@ -1,6 +1,6 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. diff --git a/setup.py b/setup.py index 980b91a..0b48fda 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ name = "google-cloud-dataflow-client" description = "Cloud Dataflow API client library" -version = "0.3.1" +version = "0.4.0" release_status = "Development Status :: 4 - Beta" url = "https://github.com/googleapis/python-dataflow-client" dependencies = [ diff --git a/tests/__init__.py b/tests/__init__.py index 4de6597..e8e1c38 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py index 4de6597..e8e1c38 100644 --- a/tests/unit/__init__.py +++ b/tests/unit/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. diff --git a/tests/unit/gapic/__init__.py b/tests/unit/gapic/__init__.py index 4de6597..e8e1c38 100644 --- a/tests/unit/gapic/__init__.py +++ b/tests/unit/gapic/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. diff --git a/tests/unit/gapic/dataflow_v1beta3/__init__.py b/tests/unit/gapic/dataflow_v1beta3/__init__.py index 4de6597..e8e1c38 100644 --- a/tests/unit/gapic/dataflow_v1beta3/__init__.py +++ b/tests/unit/gapic/dataflow_v1beta3/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. diff --git a/tests/unit/gapic/dataflow_v1beta3/test_flex_templates_service.py b/tests/unit/gapic/dataflow_v1beta3/test_flex_templates_service.py index b9e54e5..9e476bc 100644 --- a/tests/unit/gapic/dataflow_v1beta3/test_flex_templates_service.py +++ b/tests/unit/gapic/dataflow_v1beta3/test_flex_templates_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -256,20 +256,20 @@ def test_flex_templates_service_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, @@ -338,7 +338,7 @@ def test_flex_templates_service_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 @@ -415,6 +415,87 @@ def test_flex_templates_service_client_mtls_env_auto( ) +@pytest.mark.parametrize( + "client_class", [FlexTemplatesServiceClient, FlexTemplatesServiceAsyncClient] +) +@mock.patch.object( + FlexTemplatesServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(FlexTemplatesServiceClient), +) +@mock.patch.object( + FlexTemplatesServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(FlexTemplatesServiceAsyncClient), +) +def test_flex_templates_service_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", [ @@ -437,7 +518,7 @@ def test_flex_templates_service_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, @@ -451,28 +532,31 @@ def test_flex_templates_service_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ ( FlexTemplatesServiceClient, transports.FlexTemplatesServiceGrpcTransport, "grpc", + grpc_helpers, ), ( FlexTemplatesServiceAsyncClient, transports.FlexTemplatesServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_flex_templates_service_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", @@ -505,9 +589,79 @@ def test_flex_templates_service_client_client_options_from_dict(): ) -def test_launch_flex_template( - transport: str = "grpc", request_type=templates.LaunchFlexTemplateRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + FlexTemplatesServiceClient, + transports.FlexTemplatesServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + FlexTemplatesServiceAsyncClient, + transports.FlexTemplatesServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_flex_templates_service_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( + "dataflow.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/compute", + "https://www.googleapis.com/auth/compute.readonly", + "https://www.googleapis.com/auth/userinfo.email", + ), + scopes=None, + default_host="dataflow.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("request_type", [templates.LaunchFlexTemplateRequest, dict,]) +def test_launch_flex_template(request_type, transport: str = "grpc"): client = FlexTemplatesServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -533,10 +687,6 @@ def test_launch_flex_template( assert isinstance(response, templates.LaunchFlexTemplateResponse) -def test_launch_flex_template_from_dict(): - test_launch_flex_template(request_type=dict) - - def test_launch_flex_template_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. @@ -610,6 +760,25 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.FlexTemplatesServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = FlexTemplatesServiceClient( + 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 = FlexTemplatesServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.FlexTemplatesServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -1102,7 +1271,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( @@ -1167,3 +1336,36 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (FlexTemplatesServiceClient, transports.FlexTemplatesServiceGrpcTransport), + ( + FlexTemplatesServiceAsyncClient, + transports.FlexTemplatesServiceGrpcAsyncIOTransport, + ), + ], +) +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/dataflow_v1beta3/test_jobs_v1_beta3.py b/tests/unit/gapic/dataflow_v1beta3/test_jobs_v1_beta3.py index 9fa038e..ec978a6 100644 --- a/tests/unit/gapic/dataflow_v1beta3/test_jobs_v1_beta3.py +++ b/tests/unit/gapic/dataflow_v1beta3/test_jobs_v1_beta3.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -243,20 +243,20 @@ def test_jobs_v1_beta3_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, @@ -313,7 +313,7 @@ def test_jobs_v1_beta3_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 @@ -390,6 +390,83 @@ def test_jobs_v1_beta3_client_mtls_env_auto( ) +@pytest.mark.parametrize("client_class", [JobsV1Beta3Client, JobsV1Beta3AsyncClient]) +@mock.patch.object( + JobsV1Beta3Client, "DEFAULT_ENDPOINT", modify_default_endpoint(JobsV1Beta3Client) +) +@mock.patch.object( + JobsV1Beta3AsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(JobsV1Beta3AsyncClient), +) +def test_jobs_v1_beta3_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", [ @@ -408,7 +485,7 @@ def test_jobs_v1_beta3_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, @@ -422,24 +499,26 @@ def test_jobs_v1_beta3_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (JobsV1Beta3Client, transports.JobsV1Beta3GrpcTransport, "grpc"), + (JobsV1Beta3Client, transports.JobsV1Beta3GrpcTransport, "grpc", grpc_helpers), ( JobsV1Beta3AsyncClient, transports.JobsV1Beta3GrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_jobs_v1_beta3_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", @@ -470,7 +549,74 @@ def test_jobs_v1_beta3_client_client_options_from_dict(): ) -def test_create_job(transport: str = "grpc", request_type=jobs.CreateJobRequest): +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + (JobsV1Beta3Client, transports.JobsV1Beta3GrpcTransport, "grpc", grpc_helpers), + ( + JobsV1Beta3AsyncClient, + transports.JobsV1Beta3GrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_jobs_v1_beta3_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( + "dataflow.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/compute", + "https://www.googleapis.com/auth/compute.readonly", + "https://www.googleapis.com/auth/userinfo.email", + ), + scopes=None, + default_host="dataflow.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("request_type", [jobs.CreateJobRequest, dict,]) +def test_create_job(request_type, transport: str = "grpc"): client = JobsV1Beta3Client( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -523,10 +669,6 @@ def test_create_job(transport: str = "grpc", request_type=jobs.CreateJobRequest) assert response.satisfies_pzs is True -def test_create_job_from_dict(): - test_create_job(request_type=dict) - - def test_create_job_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. @@ -605,7 +747,8 @@ async def test_create_job_async_from_dict(): await test_create_job_async(request_type=dict) -def test_get_job(transport: str = "grpc", request_type=jobs.GetJobRequest): +@pytest.mark.parametrize("request_type", [jobs.GetJobRequest, dict,]) +def test_get_job(request_type, transport: str = "grpc"): client = JobsV1Beta3Client( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -658,10 +801,6 @@ def test_get_job(transport: str = "grpc", request_type=jobs.GetJobRequest): assert response.satisfies_pzs is True -def test_get_job_from_dict(): - test_get_job(request_type=dict) - - def test_get_job_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. @@ -740,7 +879,8 @@ async def test_get_job_async_from_dict(): await test_get_job_async(request_type=dict) -def test_update_job(transport: str = "grpc", request_type=jobs.UpdateJobRequest): +@pytest.mark.parametrize("request_type", [jobs.UpdateJobRequest, dict,]) +def test_update_job(request_type, transport: str = "grpc"): client = JobsV1Beta3Client( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -793,10 +933,6 @@ def test_update_job(transport: str = "grpc", request_type=jobs.UpdateJobRequest) assert response.satisfies_pzs is True -def test_update_job_from_dict(): - test_update_job(request_type=dict) - - def test_update_job_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. @@ -875,7 +1011,8 @@ async def test_update_job_async_from_dict(): await test_update_job_async(request_type=dict) -def test_list_jobs(transport: str = "grpc", request_type=jobs.ListJobsRequest): +@pytest.mark.parametrize("request_type", [jobs.ListJobsRequest, dict,]) +def test_list_jobs(request_type, transport: str = "grpc"): client = JobsV1Beta3Client( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -902,10 +1039,6 @@ def test_list_jobs(transport: str = "grpc", request_type=jobs.ListJobsRequest): assert response.next_page_token == "next_page_token_value" -def test_list_jobs_from_dict(): - test_list_jobs(request_type=dict) - - def test_list_jobs_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. @@ -956,8 +1089,10 @@ async def test_list_jobs_async_from_dict(): await test_list_jobs_async(request_type=dict) -def test_list_jobs_pager(): - client = JobsV1Beta3Client(credentials=ga_credentials.AnonymousCredentials,) +def test_list_jobs_pager(transport_name: str = "grpc"): + client = JobsV1Beta3Client( + 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_jobs), "__call__") as call: @@ -982,8 +1117,10 @@ def test_list_jobs_pager(): assert all(isinstance(i, jobs.Job) for i in results) -def test_list_jobs_pages(): - client = JobsV1Beta3Client(credentials=ga_credentials.AnonymousCredentials,) +def test_list_jobs_pages(transport_name: str = "grpc"): + client = JobsV1Beta3Client( + 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_jobs), "__call__") as call: @@ -1055,9 +1192,8 @@ async def test_list_jobs_async_pages(): assert page_.raw_page.next_page_token == token -def test_aggregated_list_jobs( - transport: str = "grpc", request_type=jobs.ListJobsRequest -): +@pytest.mark.parametrize("request_type", [jobs.ListJobsRequest, dict,]) +def test_aggregated_list_jobs(request_type, transport: str = "grpc"): client = JobsV1Beta3Client( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1086,10 +1222,6 @@ def test_aggregated_list_jobs( assert response.next_page_token == "next_page_token_value" -def test_aggregated_list_jobs_from_dict(): - test_aggregated_list_jobs(request_type=dict) - - def test_aggregated_list_jobs_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. @@ -1144,8 +1276,10 @@ async def test_aggregated_list_jobs_async_from_dict(): await test_aggregated_list_jobs_async(request_type=dict) -def test_aggregated_list_jobs_pager(): - client = JobsV1Beta3Client(credentials=ga_credentials.AnonymousCredentials,) +def test_aggregated_list_jobs_pager(transport_name: str = "grpc"): + client = JobsV1Beta3Client( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1172,8 +1306,10 @@ def test_aggregated_list_jobs_pager(): assert all(isinstance(i, jobs.Job) for i in results) -def test_aggregated_list_jobs_pages(): - client = JobsV1Beta3Client(credentials=ga_credentials.AnonymousCredentials,) +def test_aggregated_list_jobs_pages(transport_name: str = "grpc"): + client = JobsV1Beta3Client( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1251,9 +1387,8 @@ async def test_aggregated_list_jobs_async_pages(): assert page_.raw_page.next_page_token == token -def test_check_active_jobs( - transport: str = "grpc", request_type=jobs.CheckActiveJobsRequest -): +@pytest.mark.parametrize("request_type", [jobs.CheckActiveJobsRequest, dict,]) +def test_check_active_jobs(request_type, transport: str = "grpc"): client = JobsV1Beta3Client( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1280,10 +1415,6 @@ def test_check_active_jobs( assert response.active_jobs_exist is True -def test_check_active_jobs_from_dict(): - test_check_active_jobs(request_type=dict) - - def test_check_active_jobs_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. @@ -1338,7 +1469,8 @@ async def test_check_active_jobs_async_from_dict(): await test_check_active_jobs_async(request_type=dict) -def test_snapshot_job(transport: str = "grpc", request_type=jobs.SnapshotJobRequest): +@pytest.mark.parametrize("request_type", [jobs.SnapshotJobRequest, dict,]) +def test_snapshot_job(request_type, transport: str = "grpc"): client = JobsV1Beta3Client( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1377,10 +1509,6 @@ def test_snapshot_job(transport: str = "grpc", request_type=jobs.SnapshotJobRequ assert response.region == "region_value" -def test_snapshot_job_from_dict(): - test_snapshot_job(request_type=dict) - - def test_snapshot_job_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. @@ -1465,6 +1593,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.JobsV1Beta3GrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = JobsV1Beta3Client(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 = JobsV1Beta3Client( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.JobsV1Beta3GrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -1944,7 +2089,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( @@ -2009,3 +2154,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (JobsV1Beta3Client, transports.JobsV1Beta3GrpcTransport), + (JobsV1Beta3AsyncClient, transports.JobsV1Beta3GrpcAsyncIOTransport), + ], +) +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/dataflow_v1beta3/test_messages_v1_beta3.py b/tests/unit/gapic/dataflow_v1beta3/test_messages_v1_beta3.py index 3ce3a9d..fbc90e0 100644 --- a/tests/unit/gapic/dataflow_v1beta3/test_messages_v1_beta3.py +++ b/tests/unit/gapic/dataflow_v1beta3/test_messages_v1_beta3.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -251,20 +251,20 @@ def test_messages_v1_beta3_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, @@ -333,7 +333,7 @@ def test_messages_v1_beta3_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 @@ -410,6 +410,87 @@ def test_messages_v1_beta3_client_mtls_env_auto( ) +@pytest.mark.parametrize( + "client_class", [MessagesV1Beta3Client, MessagesV1Beta3AsyncClient] +) +@mock.patch.object( + MessagesV1Beta3Client, + "DEFAULT_ENDPOINT", + modify_default_endpoint(MessagesV1Beta3Client), +) +@mock.patch.object( + MessagesV1Beta3AsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(MessagesV1Beta3AsyncClient), +) +def test_messages_v1_beta3_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", [ @@ -428,7 +509,7 @@ def test_messages_v1_beta3_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, @@ -442,24 +523,31 @@ def test_messages_v1_beta3_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (MessagesV1Beta3Client, transports.MessagesV1Beta3GrpcTransport, "grpc"), + ( + MessagesV1Beta3Client, + transports.MessagesV1Beta3GrpcTransport, + "grpc", + grpc_helpers, + ), ( MessagesV1Beta3AsyncClient, transports.MessagesV1Beta3GrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_messages_v1_beta3_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", @@ -492,9 +580,79 @@ def test_messages_v1_beta3_client_client_options_from_dict(): ) -def test_list_job_messages( - transport: str = "grpc", request_type=messages.ListJobMessagesRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + MessagesV1Beta3Client, + transports.MessagesV1Beta3GrpcTransport, + "grpc", + grpc_helpers, + ), + ( + MessagesV1Beta3AsyncClient, + transports.MessagesV1Beta3GrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_messages_v1_beta3_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( + "dataflow.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/compute", + "https://www.googleapis.com/auth/compute.readonly", + "https://www.googleapis.com/auth/userinfo.email", + ), + scopes=None, + default_host="dataflow.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("request_type", [messages.ListJobMessagesRequest, dict,]) +def test_list_job_messages(request_type, transport: str = "grpc"): client = MessagesV1Beta3Client( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -523,10 +681,6 @@ def test_list_job_messages( assert response.next_page_token == "next_page_token_value" -def test_list_job_messages_from_dict(): - test_list_job_messages(request_type=dict) - - def test_list_job_messages_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. @@ -581,8 +735,10 @@ async def test_list_job_messages_async_from_dict(): await test_list_job_messages_async(request_type=dict) -def test_list_job_messages_pager(): - client = MessagesV1Beta3Client(credentials=ga_credentials.AnonymousCredentials,) +def test_list_job_messages_pager(transport_name: str = "grpc"): + client = MessagesV1Beta3Client( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -618,8 +774,10 @@ def test_list_job_messages_pager(): assert all(isinstance(i, messages.JobMessage) for i in results) -def test_list_job_messages_pages(): - client = MessagesV1Beta3Client(credentials=ga_credentials.AnonymousCredentials,) +def test_list_job_messages_pages(transport_name: str = "grpc"): + client = MessagesV1Beta3Client( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -748,6 +906,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.MessagesV1Beta3GrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = MessagesV1Beta3Client(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 = MessagesV1Beta3Client( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.MessagesV1Beta3GrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -1236,7 +1411,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( @@ -1301,3 +1476,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (MessagesV1Beta3Client, transports.MessagesV1Beta3GrpcTransport), + (MessagesV1Beta3AsyncClient, transports.MessagesV1Beta3GrpcAsyncIOTransport), + ], +) +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/dataflow_v1beta3/test_metrics_v1_beta3.py b/tests/unit/gapic/dataflow_v1beta3/test_metrics_v1_beta3.py index e98ac56..e9b70c2 100644 --- a/tests/unit/gapic/dataflow_v1beta3/test_metrics_v1_beta3.py +++ b/tests/unit/gapic/dataflow_v1beta3/test_metrics_v1_beta3.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -249,20 +249,20 @@ def test_metrics_v1_beta3_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, @@ -321,7 +321,7 @@ def test_metrics_v1_beta3_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 @@ -398,6 +398,87 @@ def test_metrics_v1_beta3_client_mtls_env_auto( ) +@pytest.mark.parametrize( + "client_class", [MetricsV1Beta3Client, MetricsV1Beta3AsyncClient] +) +@mock.patch.object( + MetricsV1Beta3Client, + "DEFAULT_ENDPOINT", + modify_default_endpoint(MetricsV1Beta3Client), +) +@mock.patch.object( + MetricsV1Beta3AsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(MetricsV1Beta3AsyncClient), +) +def test_metrics_v1_beta3_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", [ @@ -416,7 +497,7 @@ def test_metrics_v1_beta3_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, @@ -430,24 +511,31 @@ def test_metrics_v1_beta3_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (MetricsV1Beta3Client, transports.MetricsV1Beta3GrpcTransport, "grpc"), + ( + MetricsV1Beta3Client, + transports.MetricsV1Beta3GrpcTransport, + "grpc", + grpc_helpers, + ), ( MetricsV1Beta3AsyncClient, transports.MetricsV1Beta3GrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_metrics_v1_beta3_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", @@ -480,9 +568,79 @@ def test_metrics_v1_beta3_client_client_options_from_dict(): ) -def test_get_job_metrics( - transport: str = "grpc", request_type=metrics.GetJobMetricsRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + MetricsV1Beta3Client, + transports.MetricsV1Beta3GrpcTransport, + "grpc", + grpc_helpers, + ), + ( + MetricsV1Beta3AsyncClient, + transports.MetricsV1Beta3GrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_metrics_v1_beta3_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( + "dataflow.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/compute", + "https://www.googleapis.com/auth/compute.readonly", + "https://www.googleapis.com/auth/userinfo.email", + ), + scopes=None, + default_host="dataflow.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("request_type", [metrics.GetJobMetricsRequest, dict,]) +def test_get_job_metrics(request_type, transport: str = "grpc"): client = MetricsV1Beta3Client( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -506,10 +664,6 @@ def test_get_job_metrics( assert isinstance(response, metrics.JobMetrics) -def test_get_job_metrics_from_dict(): - test_get_job_metrics(request_type=dict) - - def test_get_job_metrics_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. @@ -557,9 +711,8 @@ async def test_get_job_metrics_async_from_dict(): await test_get_job_metrics_async(request_type=dict) -def test_get_job_execution_details( - transport: str = "grpc", request_type=metrics.GetJobExecutionDetailsRequest -): +@pytest.mark.parametrize("request_type", [metrics.GetJobExecutionDetailsRequest, dict,]) +def test_get_job_execution_details(request_type, transport: str = "grpc"): client = MetricsV1Beta3Client( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -588,10 +741,6 @@ def test_get_job_execution_details( assert response.next_page_token == "next_page_token_value" -def test_get_job_execution_details_from_dict(): - test_get_job_execution_details(request_type=dict) - - def test_get_job_execution_details_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. @@ -646,8 +795,10 @@ async def test_get_job_execution_details_async_from_dict(): await test_get_job_execution_details_async(request_type=dict) -def test_get_job_execution_details_pager(): - client = MetricsV1Beta3Client(credentials=ga_credentials.AnonymousCredentials,) +def test_get_job_execution_details_pager(transport_name: str = "grpc"): + client = MetricsV1Beta3Client( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -683,8 +834,10 @@ def test_get_job_execution_details_pager(): assert all(isinstance(i, metrics.StageSummary) for i in results) -def test_get_job_execution_details_pages(): - client = MetricsV1Beta3Client(credentials=ga_credentials.AnonymousCredentials,) +def test_get_job_execution_details_pages(transport_name: str = "grpc"): + client = MetricsV1Beta3Client( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -789,9 +942,10 @@ async def test_get_job_execution_details_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_stage_execution_details( - transport: str = "grpc", request_type=metrics.GetStageExecutionDetailsRequest -): +@pytest.mark.parametrize( + "request_type", [metrics.GetStageExecutionDetailsRequest, dict,] +) +def test_get_stage_execution_details(request_type, transport: str = "grpc"): client = MetricsV1Beta3Client( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -820,10 +974,6 @@ def test_get_stage_execution_details( assert response.next_page_token == "next_page_token_value" -def test_get_stage_execution_details_from_dict(): - test_get_stage_execution_details(request_type=dict) - - def test_get_stage_execution_details_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. @@ -879,8 +1029,10 @@ async def test_get_stage_execution_details_async_from_dict(): await test_get_stage_execution_details_async(request_type=dict) -def test_get_stage_execution_details_pager(): - client = MetricsV1Beta3Client(credentials=ga_credentials.AnonymousCredentials,) +def test_get_stage_execution_details_pager(transport_name: str = "grpc"): + client = MetricsV1Beta3Client( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -916,8 +1068,10 @@ def test_get_stage_execution_details_pager(): assert all(isinstance(i, metrics.WorkerDetails) for i in results) -def test_get_stage_execution_details_pages(): - client = MetricsV1Beta3Client(credentials=ga_credentials.AnonymousCredentials,) +def test_get_stage_execution_details_pages(transport_name: str = "grpc"): + client = MetricsV1Beta3Client( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1042,6 +1196,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.MetricsV1Beta3GrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = MetricsV1Beta3Client(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 = MetricsV1Beta3Client( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.MetricsV1Beta3GrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -1534,7 +1705,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( @@ -1599,3 +1770,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (MetricsV1Beta3Client, transports.MetricsV1Beta3GrpcTransport), + (MetricsV1Beta3AsyncClient, transports.MetricsV1Beta3GrpcAsyncIOTransport), + ], +) +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/dataflow_v1beta3/test_snapshots_v1_beta3.py b/tests/unit/gapic/dataflow_v1beta3/test_snapshots_v1_beta3.py index 39d6a29..eee8da5 100644 --- a/tests/unit/gapic/dataflow_v1beta3/test_snapshots_v1_beta3.py +++ b/tests/unit/gapic/dataflow_v1beta3/test_snapshots_v1_beta3.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -252,20 +252,20 @@ def test_snapshots_v1_beta3_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, @@ -334,7 +334,7 @@ def test_snapshots_v1_beta3_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 @@ -411,6 +411,87 @@ def test_snapshots_v1_beta3_client_mtls_env_auto( ) +@pytest.mark.parametrize( + "client_class", [SnapshotsV1Beta3Client, SnapshotsV1Beta3AsyncClient] +) +@mock.patch.object( + SnapshotsV1Beta3Client, + "DEFAULT_ENDPOINT", + modify_default_endpoint(SnapshotsV1Beta3Client), +) +@mock.patch.object( + SnapshotsV1Beta3AsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(SnapshotsV1Beta3AsyncClient), +) +def test_snapshots_v1_beta3_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", [ @@ -429,7 +510,7 @@ def test_snapshots_v1_beta3_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, @@ -443,24 +524,31 @@ def test_snapshots_v1_beta3_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (SnapshotsV1Beta3Client, transports.SnapshotsV1Beta3GrpcTransport, "grpc"), + ( + SnapshotsV1Beta3Client, + transports.SnapshotsV1Beta3GrpcTransport, + "grpc", + grpc_helpers, + ), ( SnapshotsV1Beta3AsyncClient, transports.SnapshotsV1Beta3GrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_snapshots_v1_beta3_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", @@ -493,9 +581,79 @@ def test_snapshots_v1_beta3_client_client_options_from_dict(): ) -def test_get_snapshot( - transport: str = "grpc", request_type=snapshots.GetSnapshotRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + SnapshotsV1Beta3Client, + transports.SnapshotsV1Beta3GrpcTransport, + "grpc", + grpc_helpers, + ), + ( + SnapshotsV1Beta3AsyncClient, + transports.SnapshotsV1Beta3GrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_snapshots_v1_beta3_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( + "dataflow.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/compute", + "https://www.googleapis.com/auth/compute.readonly", + "https://www.googleapis.com/auth/userinfo.email", + ), + scopes=None, + default_host="dataflow.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize("request_type", [snapshots.GetSnapshotRequest, dict,]) +def test_get_snapshot(request_type, transport: str = "grpc"): client = SnapshotsV1Beta3Client( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -534,10 +692,6 @@ def test_get_snapshot( assert response.region == "region_value" -def test_get_snapshot_from_dict(): - test_get_snapshot(request_type=dict) - - def test_get_snapshot_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. @@ -602,9 +756,8 @@ async def test_get_snapshot_async_from_dict(): await test_get_snapshot_async(request_type=dict) -def test_delete_snapshot( - transport: str = "grpc", request_type=snapshots.DeleteSnapshotRequest -): +@pytest.mark.parametrize("request_type", [snapshots.DeleteSnapshotRequest, dict,]) +def test_delete_snapshot(request_type, transport: str = "grpc"): client = SnapshotsV1Beta3Client( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -628,10 +781,6 @@ def test_delete_snapshot( assert isinstance(response, snapshots.DeleteSnapshotResponse) -def test_delete_snapshot_from_dict(): - test_delete_snapshot(request_type=dict) - - def test_delete_snapshot_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. @@ -681,9 +830,8 @@ async def test_delete_snapshot_async_from_dict(): await test_delete_snapshot_async(request_type=dict) -def test_list_snapshots( - transport: str = "grpc", request_type=snapshots.ListSnapshotsRequest -): +@pytest.mark.parametrize("request_type", [snapshots.ListSnapshotsRequest, dict,]) +def test_list_snapshots(request_type, transport: str = "grpc"): client = SnapshotsV1Beta3Client( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -707,10 +855,6 @@ def test_list_snapshots( assert isinstance(response, snapshots.ListSnapshotsResponse) -def test_list_snapshots_from_dict(): - test_list_snapshots(request_type=dict) - - def test_list_snapshots_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. @@ -780,6 +924,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.SnapshotsV1Beta3GrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = SnapshotsV1Beta3Client(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 = SnapshotsV1Beta3Client( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.SnapshotsV1Beta3GrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -1272,7 +1433,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( @@ -1337,3 +1498,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (SnapshotsV1Beta3Client, transports.SnapshotsV1Beta3GrpcTransport), + (SnapshotsV1Beta3AsyncClient, transports.SnapshotsV1Beta3GrpcAsyncIOTransport), + ], +) +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/dataflow_v1beta3/test_templates_service.py b/tests/unit/gapic/dataflow_v1beta3/test_templates_service.py index ef66335..ada0bb8 100644 --- a/tests/unit/gapic/dataflow_v1beta3/test_templates_service.py +++ b/tests/unit/gapic/dataflow_v1beta3/test_templates_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# 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. @@ -254,20 +254,20 @@ def test_templates_service_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, @@ -336,7 +336,7 @@ def test_templates_service_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 @@ -413,6 +413,87 @@ def test_templates_service_client_mtls_env_auto( ) +@pytest.mark.parametrize( + "client_class", [TemplatesServiceClient, TemplatesServiceAsyncClient] +) +@mock.patch.object( + TemplatesServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(TemplatesServiceClient), +) +@mock.patch.object( + TemplatesServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(TemplatesServiceAsyncClient), +) +def test_templates_service_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", [ @@ -431,7 +512,7 @@ def test_templates_service_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, @@ -445,24 +526,31 @@ def test_templates_service_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (TemplatesServiceClient, transports.TemplatesServiceGrpcTransport, "grpc"), + ( + TemplatesServiceClient, + transports.TemplatesServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( TemplatesServiceAsyncClient, transports.TemplatesServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_templates_service_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", @@ -495,9 +583,81 @@ def test_templates_service_client_client_options_from_dict(): ) -def test_create_job_from_template( - transport: str = "grpc", request_type=templates.CreateJobFromTemplateRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + TemplatesServiceClient, + transports.TemplatesServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + TemplatesServiceAsyncClient, + transports.TemplatesServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_templates_service_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( + "dataflow.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/compute", + "https://www.googleapis.com/auth/compute.readonly", + "https://www.googleapis.com/auth/userinfo.email", + ), + scopes=None, + default_host="dataflow.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", [templates.CreateJobFromTemplateRequest, dict,] +) +def test_create_job_from_template(request_type, transport: str = "grpc"): client = TemplatesServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -552,10 +712,6 @@ def test_create_job_from_template( assert response.satisfies_pzs is True -def test_create_job_from_template_from_dict(): - test_create_job_from_template(request_type=dict) - - def test_create_job_from_template_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. @@ -638,9 +794,8 @@ async def test_create_job_from_template_async_from_dict(): await test_create_job_from_template_async(request_type=dict) -def test_launch_template( - transport: str = "grpc", request_type=templates.LaunchTemplateRequest -): +@pytest.mark.parametrize("request_type", [templates.LaunchTemplateRequest, dict,]) +def test_launch_template(request_type, transport: str = "grpc"): client = TemplatesServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -664,10 +819,6 @@ def test_launch_template( assert isinstance(response, templates.LaunchTemplateResponse) -def test_launch_template_from_dict(): - test_launch_template(request_type=dict) - - def test_launch_template_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. @@ -717,9 +868,8 @@ async def test_launch_template_async_from_dict(): await test_launch_template_async(request_type=dict) -def test_get_template( - transport: str = "grpc", request_type=templates.GetTemplateRequest -): +@pytest.mark.parametrize("request_type", [templates.GetTemplateRequest, dict,]) +def test_get_template(request_type, transport: str = "grpc"): client = TemplatesServiceClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -746,10 +896,6 @@ def test_get_template( assert response.template_type == templates.GetTemplateResponse.TemplateType.LEGACY -def test_get_template_from_dict(): - test_get_template(request_type=dict) - - def test_get_template_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. @@ -822,6 +968,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.TemplatesServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = TemplatesServiceClient(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 = TemplatesServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.TemplatesServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -1314,7 +1477,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( @@ -1379,3 +1542,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (TemplatesServiceClient, transports.TemplatesServiceGrpcTransport), + (TemplatesServiceAsyncClient, transports.TemplatesServiceGrpcAsyncIOTransport), + ], +) +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, + )