diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index eecb84c..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:ae600f36b6bc972b368367b6f83a1d91ec2c82a4a116b383d67d547c56fe6de3 + digest: sha256:ed1f9983d5a935a89fe8085e8bb97d94e41015252c5b6c9771257cf8624367e6 + 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/CHANGELOG.md b/CHANGELOG.md index 5d08eeb..54b886c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## [1.4.0](https://github.com/googleapis/python-data-fusion/compare/v1.3.0...v1.4.0) (2022-02-26) + + +### Features + +* add api key support ([#63](https://github.com/googleapis/python-data-fusion/issues/63)) ([d57bee2](https://github.com/googleapis/python-data-fusion/commit/d57bee22c85867dfe7062dc391524cf5750b9474)) + + +### Bug Fixes + +* resolve DuplicateCredentialArgs error when using credentials_file ([65159ba](https://github.com/googleapis/python-data-fusion/commit/65159baba7657d473f753e793f8a0a5083432671)) + ## [1.3.0](https://github.com/googleapis/python-data-fusion/compare/v1.2.1...v1.3.0) (2022-01-14) diff --git a/google/cloud/data_fusion/__init__.py b/google/cloud/data_fusion/__init__.py index 472c822..7951c90 100644 --- a/google/cloud/data_fusion/__init__.py +++ b/google/cloud/data_fusion/__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/data_fusion_v1/__init__.py b/google/cloud/data_fusion_v1/__init__.py index 51d1054..00e27ef 100644 --- a/google/cloud/data_fusion_v1/__init__.py +++ b/google/cloud/data_fusion_v1/__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/data_fusion_v1/services/__init__.py b/google/cloud/data_fusion_v1/services/__init__.py index 4de6597..e8e1c38 100644 --- a/google/cloud/data_fusion_v1/services/__init__.py +++ b/google/cloud/data_fusion_v1/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/data_fusion_v1/services/data_fusion/__init__.py b/google/cloud/data_fusion_v1/services/data_fusion/__init__.py index 0e76e82..268bd96 100644 --- a/google/cloud/data_fusion_v1/services/data_fusion/__init__.py +++ b/google/cloud/data_fusion_v1/services/data_fusion/__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/data_fusion_v1/services/data_fusion/async_client.py b/google/cloud/data_fusion_v1/services/data_fusion/async_client.py index 10fc16a..669bfe3 100644 --- a/google/cloud/data_fusion_v1/services/data_fusion/async_client.py +++ b/google/cloud/data_fusion_v1/services/data_fusion/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,7 +16,7 @@ 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 @@ -110,6 +110,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 DataFusionClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> DataFusionTransport: """Returns the transport used by the client instance. @@ -182,6 +218,27 @@ async def list_available_versions( r"""Lists possible versions for Data Fusion instances in the specified project and location. + + .. code-block:: python + + from google.cloud import data_fusion_v1 + + def sample_list_available_versions(): + # Create a client + client = data_fusion_v1.DataFusionClient() + + # Initialize request argument(s) + request = data_fusion_v1.ListAvailableVersionsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_available_versions(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.data_fusion_v1.types.ListAvailableVersionsRequest, dict]): The request object. Request message for the list @@ -211,7 +268,7 @@ async def list_available_versions( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: @@ -264,6 +321,27 @@ async def list_instances( r"""Lists Data Fusion instances in the specified project and location. + + .. code-block:: python + + from google.cloud import data_fusion_v1 + + def sample_list_instances(): + # Create a client + client = data_fusion_v1.DataFusionClient() + + # Initialize request argument(s) + request = data_fusion_v1.ListInstancesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instances(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.data_fusion_v1.types.ListInstancesRequest, dict]): The request object. Request message for listing Data @@ -322,6 +400,25 @@ async def get_instance( ) -> datafusion.Instance: r"""Gets details of a single Data Fusion instance. + .. code-block:: python + + from google.cloud import data_fusion_v1 + + def sample_get_instance(): + # Create a client + client = data_fusion_v1.DataFusionClient() + + # Initialize request argument(s) + request = data_fusion_v1.GetInstanceRequest( + name="name_value", + ) + + # Make the request + response = client.get_instance(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.data_fusion_v1.types.GetInstanceRequest, dict]): The request object. Request message for getting details @@ -373,6 +470,31 @@ async def create_instance( r"""Creates a new Data Fusion instance in the specified project and location. + + .. code-block:: python + + from google.cloud import data_fusion_v1 + + def sample_create_instance(): + # Create a client + client = data_fusion_v1.DataFusionClient() + + # Initialize request argument(s) + request = data_fusion_v1.CreateInstanceRequest( + parent="parent_value", + instance_id="instance_id_value", + ) + + # Make the request + operation = client.create_instance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.data_fusion_v1.types.CreateInstanceRequest, dict]): The request object. Request message for creating a Data @@ -413,7 +535,7 @@ async def create_instance( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, instance, instance_id]) if request is not None and has_flattened_params: @@ -472,6 +594,29 @@ async def delete_instance( ) -> operation_async.AsyncOperation: r"""Deletes a single Date Fusion instance. + .. code-block:: python + + from google.cloud import data_fusion_v1 + + def sample_delete_instance(): + # Create a client + client = data_fusion_v1.DataFusionClient() + + # Initialize request argument(s) + request = data_fusion_v1.DeleteInstanceRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_instance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.data_fusion_v1.types.DeleteInstanceRequest, dict]): The request object. Request message for deleting a Data @@ -510,7 +655,7 @@ async def delete_instance( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -566,6 +711,32 @@ async def update_instance( ) -> operation_async.AsyncOperation: r"""Updates a single Data Fusion instance. + .. code-block:: python + + from google.cloud import data_fusion_v1 + + def sample_update_instance(): + # Create a client + client = data_fusion_v1.DataFusionClient() + + # Initialize request argument(s) + instance = data_fusion_v1.Instance() + instance.type_ = "DEVELOPER" + + request = data_fusion_v1.UpdateInstanceRequest( + instance=instance, + ) + + # Make the request + operation = client.update_instance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.data_fusion_v1.types.UpdateInstanceRequest, dict]): The request object. Request message for updating a Data @@ -611,7 +782,7 @@ async def update_instance( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([instance, update_mask]) if request is not None and has_flattened_params: @@ -670,6 +841,30 @@ async def restart_instance( r"""Restart a single Data Fusion instance. At the end of an operation instance is fully restarted. + + .. code-block:: python + + from google.cloud import data_fusion_v1 + + def sample_restart_instance(): + # Create a client + client = data_fusion_v1.DataFusionClient() + + # Initialize request argument(s) + request = data_fusion_v1.RestartInstanceRequest( + name="name_value", + ) + + # Make the request + operation = client.restart_instance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.data_fusion_v1.types.RestartInstanceRequest, dict]): The request object. Request message for restarting a diff --git a/google/cloud/data_fusion_v1/services/data_fusion/client.py b/google/cloud/data_fusion_v1/services/data_fusion/client.py index 1a1d81d..5705c9b 100644 --- a/google/cloud/data_fusion_v1/services/data_fusion/client.py +++ b/google/cloud/data_fusion_v1/services/data_fusion/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. @@ -261,6 +261,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, *, @@ -311,57 +378,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - if os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") not in ( - "true", - "false", - ): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" - ) - use_client_cert = ( - os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true" + 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, DataFusionTransport): # transport is a DataFusionTransport 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." @@ -373,6 +405,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, @@ -397,6 +438,27 @@ def list_available_versions( r"""Lists possible versions for Data Fusion instances in the specified project and location. + + .. code-block:: python + + from google.cloud import data_fusion_v1 + + def sample_list_available_versions(): + # Create a client + client = data_fusion_v1.DataFusionClient() + + # Initialize request argument(s) + request = data_fusion_v1.ListAvailableVersionsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_available_versions(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.data_fusion_v1.types.ListAvailableVersionsRequest, dict]): The request object. Request message for the list @@ -426,7 +488,7 @@ def list_available_versions( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: @@ -479,6 +541,27 @@ def list_instances( r"""Lists Data Fusion instances in the specified project and location. + + .. code-block:: python + + from google.cloud import data_fusion_v1 + + def sample_list_instances(): + # Create a client + client = data_fusion_v1.DataFusionClient() + + # Initialize request argument(s) + request = data_fusion_v1.ListInstancesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instances(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: request (Union[google.cloud.data_fusion_v1.types.ListInstancesRequest, dict]): The request object. Request message for listing Data @@ -538,6 +621,25 @@ def get_instance( ) -> datafusion.Instance: r"""Gets details of a single Data Fusion instance. + .. code-block:: python + + from google.cloud import data_fusion_v1 + + def sample_get_instance(): + # Create a client + client = data_fusion_v1.DataFusionClient() + + # Initialize request argument(s) + request = data_fusion_v1.GetInstanceRequest( + name="name_value", + ) + + # Make the request + response = client.get_instance(request=request) + + # Handle the response + print(response) + Args: request (Union[google.cloud.data_fusion_v1.types.GetInstanceRequest, dict]): The request object. Request message for getting details @@ -590,6 +692,31 @@ def create_instance( r"""Creates a new Data Fusion instance in the specified project and location. + + .. code-block:: python + + from google.cloud import data_fusion_v1 + + def sample_create_instance(): + # Create a client + client = data_fusion_v1.DataFusionClient() + + # Initialize request argument(s) + request = data_fusion_v1.CreateInstanceRequest( + parent="parent_value", + instance_id="instance_id_value", + ) + + # Make the request + operation = client.create_instance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.data_fusion_v1.types.CreateInstanceRequest, dict]): The request object. Request message for creating a Data @@ -630,7 +757,7 @@ def create_instance( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, instance, instance_id]) if request is not None and has_flattened_params: @@ -689,6 +816,29 @@ def delete_instance( ) -> operation.Operation: r"""Deletes a single Date Fusion instance. + .. code-block:: python + + from google.cloud import data_fusion_v1 + + def sample_delete_instance(): + # Create a client + client = data_fusion_v1.DataFusionClient() + + # Initialize request argument(s) + request = data_fusion_v1.DeleteInstanceRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_instance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.data_fusion_v1.types.DeleteInstanceRequest, dict]): The request object. Request message for deleting a Data @@ -727,7 +877,7 @@ def delete_instance( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -783,6 +933,32 @@ def update_instance( ) -> operation.Operation: r"""Updates a single Data Fusion instance. + .. code-block:: python + + from google.cloud import data_fusion_v1 + + def sample_update_instance(): + # Create a client + client = data_fusion_v1.DataFusionClient() + + # Initialize request argument(s) + instance = data_fusion_v1.Instance() + instance.type_ = "DEVELOPER" + + request = data_fusion_v1.UpdateInstanceRequest( + instance=instance, + ) + + # Make the request + operation = client.update_instance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.data_fusion_v1.types.UpdateInstanceRequest, dict]): The request object. Request message for updating a Data @@ -828,7 +1004,7 @@ def update_instance( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([instance, update_mask]) if request is not None and has_flattened_params: @@ -887,6 +1063,30 @@ def restart_instance( r"""Restart a single Data Fusion instance. At the end of an operation instance is fully restarted. + + .. code-block:: python + + from google.cloud import data_fusion_v1 + + def sample_restart_instance(): + # Create a client + client = data_fusion_v1.DataFusionClient() + + # Initialize request argument(s) + request = data_fusion_v1.RestartInstanceRequest( + name="name_value", + ) + + # Make the request + operation = client.restart_instance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: request (Union[google.cloud.data_fusion_v1.types.RestartInstanceRequest, dict]): The request object. Request message for restarting a diff --git a/google/cloud/data_fusion_v1/services/data_fusion/pagers.py b/google/cloud/data_fusion_v1/services/data_fusion/pagers.py index 279c2eb..55a7704 100644 --- a/google/cloud/data_fusion_v1/services/data_fusion/pagers.py +++ b/google/cloud/data_fusion_v1/services/data_fusion/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/data_fusion_v1/services/data_fusion/transports/__init__.py b/google/cloud/data_fusion_v1/services/data_fusion/transports/__init__.py index 9ed8169..0e1af2b 100644 --- a/google/cloud/data_fusion_v1/services/data_fusion/transports/__init__.py +++ b/google/cloud/data_fusion_v1/services/data_fusion/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/data_fusion_v1/services/data_fusion/transports/base.py b/google/cloud/data_fusion_v1/services/data_fusion/transports/base.py index bc3ff50..f9a5b4b 100644 --- a/google/cloud/data_fusion_v1/services/data_fusion/transports/base.py +++ b/google/cloud/data_fusion_v1/services/data_fusion/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. diff --git a/google/cloud/data_fusion_v1/services/data_fusion/transports/grpc.py b/google/cloud/data_fusion_v1/services/data_fusion/transports/grpc.py index 42304b2..46eedb5 100644 --- a/google/cloud/data_fusion_v1/services/data_fusion/transports/grpc.py +++ b/google/cloud/data_fusion_v1/services/data_fusion/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. @@ -163,8 +163,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -237,7 +240,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) diff --git a/google/cloud/data_fusion_v1/services/data_fusion/transports/grpc_asyncio.py b/google/cloud/data_fusion_v1/services/data_fusion/transports/grpc_asyncio.py index 81d776c..dc25802 100644 --- a/google/cloud/data_fusion_v1/services/data_fusion/transports/grpc_asyncio.py +++ b/google/cloud/data_fusion_v1/services/data_fusion/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. @@ -208,8 +208,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -239,7 +242,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel diff --git a/google/cloud/data_fusion_v1/types/__init__.py b/google/cloud/data_fusion_v1/types/__init__.py index 332610e..7b70267 100644 --- a/google/cloud/data_fusion_v1/types/__init__.py +++ b/google/cloud/data_fusion_v1/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/data_fusion_v1/types/datafusion.py b/google/cloud/data_fusion_v1/types/datafusion.py index 5dd9edb..39028b6 100644 --- a/google/cloud/data_fusion_v1/types/datafusion.py +++ b/google/cloud/data_fusion_v1/types/datafusion.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. @@ -58,8 +58,7 @@ class NetworkConfig(proto.Message): executing pipelines. In case of shared VPC where the network resides in another host project the network should specified in the form of - projects/{host-project- - id}/global/networks/{network} + projects/{host-project-id}/global/networks/{network} ip_allocation (str): The IP range in CIDR notation to use for the managed Data Fusion instance nodes. This range diff --git a/samples/generated_samples/datafusion_v1_generated_data_fusion_create_instance_async.py b/samples/generated_samples/datafusion_v1_generated_data_fusion_create_instance_async.py new file mode 100644 index 0000000..9af729c --- /dev/null +++ b/samples/generated_samples/datafusion_v1_generated_data_fusion_create_instance_async.py @@ -0,0 +1,50 @@ +# -*- 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 CreateInstance +# 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-data-fusion + + +# [START datafusion_v1_generated_DataFusion_CreateInstance_async] +from google.cloud import data_fusion_v1 + + +async def sample_create_instance(): + # Create a client + client = data_fusion_v1.DataFusionAsyncClient() + + # Initialize request argument(s) + request = data_fusion_v1.CreateInstanceRequest( + parent="parent_value", + instance_id="instance_id_value", + ) + + # Make the request + operation = client.create_instance(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END datafusion_v1_generated_DataFusion_CreateInstance_async] diff --git a/samples/generated_samples/datafusion_v1_generated_data_fusion_create_instance_sync.py b/samples/generated_samples/datafusion_v1_generated_data_fusion_create_instance_sync.py new file mode 100644 index 0000000..5ac59be --- /dev/null +++ b/samples/generated_samples/datafusion_v1_generated_data_fusion_create_instance_sync.py @@ -0,0 +1,50 @@ +# -*- 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 CreateInstance +# 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-data-fusion + + +# [START datafusion_v1_generated_DataFusion_CreateInstance_sync] +from google.cloud import data_fusion_v1 + + +def sample_create_instance(): + # Create a client + client = data_fusion_v1.DataFusionClient() + + # Initialize request argument(s) + request = data_fusion_v1.CreateInstanceRequest( + parent="parent_value", + instance_id="instance_id_value", + ) + + # Make the request + operation = client.create_instance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END datafusion_v1_generated_DataFusion_CreateInstance_sync] diff --git a/samples/generated_samples/datafusion_v1_generated_data_fusion_delete_instance_async.py b/samples/generated_samples/datafusion_v1_generated_data_fusion_delete_instance_async.py new file mode 100644 index 0000000..fc54fa5 --- /dev/null +++ b/samples/generated_samples/datafusion_v1_generated_data_fusion_delete_instance_async.py @@ -0,0 +1,49 @@ +# -*- 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 DeleteInstance +# 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-data-fusion + + +# [START datafusion_v1_generated_DataFusion_DeleteInstance_async] +from google.cloud import data_fusion_v1 + + +async def sample_delete_instance(): + # Create a client + client = data_fusion_v1.DataFusionAsyncClient() + + # Initialize request argument(s) + request = data_fusion_v1.DeleteInstanceRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_instance(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END datafusion_v1_generated_DataFusion_DeleteInstance_async] diff --git a/samples/generated_samples/datafusion_v1_generated_data_fusion_delete_instance_sync.py b/samples/generated_samples/datafusion_v1_generated_data_fusion_delete_instance_sync.py new file mode 100644 index 0000000..8461175 --- /dev/null +++ b/samples/generated_samples/datafusion_v1_generated_data_fusion_delete_instance_sync.py @@ -0,0 +1,49 @@ +# -*- 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 DeleteInstance +# 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-data-fusion + + +# [START datafusion_v1_generated_DataFusion_DeleteInstance_sync] +from google.cloud import data_fusion_v1 + + +def sample_delete_instance(): + # Create a client + client = data_fusion_v1.DataFusionClient() + + # Initialize request argument(s) + request = data_fusion_v1.DeleteInstanceRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_instance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END datafusion_v1_generated_DataFusion_DeleteInstance_sync] diff --git a/samples/generated_samples/datafusion_v1_generated_data_fusion_get_instance_async.py b/samples/generated_samples/datafusion_v1_generated_data_fusion_get_instance_async.py new file mode 100644 index 0000000..9aa8868 --- /dev/null +++ b/samples/generated_samples/datafusion_v1_generated_data_fusion_get_instance_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 GetInstance +# 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-data-fusion + + +# [START datafusion_v1_generated_DataFusion_GetInstance_async] +from google.cloud import data_fusion_v1 + + +async def sample_get_instance(): + # Create a client + client = data_fusion_v1.DataFusionAsyncClient() + + # Initialize request argument(s) + request = data_fusion_v1.GetInstanceRequest( + name="name_value", + ) + + # Make the request + response = await client.get_instance(request=request) + + # Handle the response + print(response) + +# [END datafusion_v1_generated_DataFusion_GetInstance_async] diff --git a/samples/generated_samples/datafusion_v1_generated_data_fusion_get_instance_sync.py b/samples/generated_samples/datafusion_v1_generated_data_fusion_get_instance_sync.py new file mode 100644 index 0000000..31bce3f --- /dev/null +++ b/samples/generated_samples/datafusion_v1_generated_data_fusion_get_instance_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 GetInstance +# 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-data-fusion + + +# [START datafusion_v1_generated_DataFusion_GetInstance_sync] +from google.cloud import data_fusion_v1 + + +def sample_get_instance(): + # Create a client + client = data_fusion_v1.DataFusionClient() + + # Initialize request argument(s) + request = data_fusion_v1.GetInstanceRequest( + name="name_value", + ) + + # Make the request + response = client.get_instance(request=request) + + # Handle the response + print(response) + +# [END datafusion_v1_generated_DataFusion_GetInstance_sync] diff --git a/samples/generated_samples/datafusion_v1_generated_data_fusion_list_available_versions_async.py b/samples/generated_samples/datafusion_v1_generated_data_fusion_list_available_versions_async.py new file mode 100644 index 0000000..46ae7b7 --- /dev/null +++ b/samples/generated_samples/datafusion_v1_generated_data_fusion_list_available_versions_async.py @@ -0,0 +1,46 @@ +# -*- 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 ListAvailableVersions +# 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-data-fusion + + +# [START datafusion_v1_generated_DataFusion_ListAvailableVersions_async] +from google.cloud import data_fusion_v1 + + +async def sample_list_available_versions(): + # Create a client + client = data_fusion_v1.DataFusionAsyncClient() + + # Initialize request argument(s) + request = data_fusion_v1.ListAvailableVersionsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_available_versions(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END datafusion_v1_generated_DataFusion_ListAvailableVersions_async] diff --git a/samples/generated_samples/datafusion_v1_generated_data_fusion_list_available_versions_sync.py b/samples/generated_samples/datafusion_v1_generated_data_fusion_list_available_versions_sync.py new file mode 100644 index 0000000..9ce3c42 --- /dev/null +++ b/samples/generated_samples/datafusion_v1_generated_data_fusion_list_available_versions_sync.py @@ -0,0 +1,46 @@ +# -*- 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 ListAvailableVersions +# 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-data-fusion + + +# [START datafusion_v1_generated_DataFusion_ListAvailableVersions_sync] +from google.cloud import data_fusion_v1 + + +def sample_list_available_versions(): + # Create a client + client = data_fusion_v1.DataFusionClient() + + # Initialize request argument(s) + request = data_fusion_v1.ListAvailableVersionsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_available_versions(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END datafusion_v1_generated_DataFusion_ListAvailableVersions_sync] diff --git a/samples/generated_samples/datafusion_v1_generated_data_fusion_list_instances_async.py b/samples/generated_samples/datafusion_v1_generated_data_fusion_list_instances_async.py new file mode 100644 index 0000000..7d33979 --- /dev/null +++ b/samples/generated_samples/datafusion_v1_generated_data_fusion_list_instances_async.py @@ -0,0 +1,46 @@ +# -*- 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 ListInstances +# 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-data-fusion + + +# [START datafusion_v1_generated_DataFusion_ListInstances_async] +from google.cloud import data_fusion_v1 + + +async def sample_list_instances(): + # Create a client + client = data_fusion_v1.DataFusionAsyncClient() + + # Initialize request argument(s) + request = data_fusion_v1.ListInstancesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instances(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END datafusion_v1_generated_DataFusion_ListInstances_async] diff --git a/samples/generated_samples/datafusion_v1_generated_data_fusion_list_instances_sync.py b/samples/generated_samples/datafusion_v1_generated_data_fusion_list_instances_sync.py new file mode 100644 index 0000000..b1bdf46 --- /dev/null +++ b/samples/generated_samples/datafusion_v1_generated_data_fusion_list_instances_sync.py @@ -0,0 +1,46 @@ +# -*- 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 ListInstances +# 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-data-fusion + + +# [START datafusion_v1_generated_DataFusion_ListInstances_sync] +from google.cloud import data_fusion_v1 + + +def sample_list_instances(): + # Create a client + client = data_fusion_v1.DataFusionClient() + + # Initialize request argument(s) + request = data_fusion_v1.ListInstancesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_instances(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END datafusion_v1_generated_DataFusion_ListInstances_sync] diff --git a/samples/generated_samples/datafusion_v1_generated_data_fusion_restart_instance_async.py b/samples/generated_samples/datafusion_v1_generated_data_fusion_restart_instance_async.py new file mode 100644 index 0000000..a31cd32 --- /dev/null +++ b/samples/generated_samples/datafusion_v1_generated_data_fusion_restart_instance_async.py @@ -0,0 +1,49 @@ +# -*- 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 RestartInstance +# 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-data-fusion + + +# [START datafusion_v1_generated_DataFusion_RestartInstance_async] +from google.cloud import data_fusion_v1 + + +async def sample_restart_instance(): + # Create a client + client = data_fusion_v1.DataFusionAsyncClient() + + # Initialize request argument(s) + request = data_fusion_v1.RestartInstanceRequest( + name="name_value", + ) + + # Make the request + operation = client.restart_instance(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END datafusion_v1_generated_DataFusion_RestartInstance_async] diff --git a/samples/generated_samples/datafusion_v1_generated_data_fusion_restart_instance_sync.py b/samples/generated_samples/datafusion_v1_generated_data_fusion_restart_instance_sync.py new file mode 100644 index 0000000..bba9bda --- /dev/null +++ b/samples/generated_samples/datafusion_v1_generated_data_fusion_restart_instance_sync.py @@ -0,0 +1,49 @@ +# -*- 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 RestartInstance +# 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-data-fusion + + +# [START datafusion_v1_generated_DataFusion_RestartInstance_sync] +from google.cloud import data_fusion_v1 + + +def sample_restart_instance(): + # Create a client + client = data_fusion_v1.DataFusionClient() + + # Initialize request argument(s) + request = data_fusion_v1.RestartInstanceRequest( + name="name_value", + ) + + # Make the request + operation = client.restart_instance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END datafusion_v1_generated_DataFusion_RestartInstance_sync] diff --git a/samples/generated_samples/datafusion_v1_generated_data_fusion_update_instance_async.py b/samples/generated_samples/datafusion_v1_generated_data_fusion_update_instance_async.py new file mode 100644 index 0000000..58fc1c0 --- /dev/null +++ b/samples/generated_samples/datafusion_v1_generated_data_fusion_update_instance_async.py @@ -0,0 +1,52 @@ +# -*- 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 UpdateInstance +# 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-data-fusion + + +# [START datafusion_v1_generated_DataFusion_UpdateInstance_async] +from google.cloud import data_fusion_v1 + + +async def sample_update_instance(): + # Create a client + client = data_fusion_v1.DataFusionAsyncClient() + + # Initialize request argument(s) + instance = data_fusion_v1.Instance() + instance.type_ = "DEVELOPER" + + request = data_fusion_v1.UpdateInstanceRequest( + instance=instance, + ) + + # Make the request + operation = client.update_instance(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END datafusion_v1_generated_DataFusion_UpdateInstance_async] diff --git a/samples/generated_samples/datafusion_v1_generated_data_fusion_update_instance_sync.py b/samples/generated_samples/datafusion_v1_generated_data_fusion_update_instance_sync.py new file mode 100644 index 0000000..f56b7d5 --- /dev/null +++ b/samples/generated_samples/datafusion_v1_generated_data_fusion_update_instance_sync.py @@ -0,0 +1,52 @@ +# -*- 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 UpdateInstance +# 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-data-fusion + + +# [START datafusion_v1_generated_DataFusion_UpdateInstance_sync] +from google.cloud import data_fusion_v1 + + +def sample_update_instance(): + # Create a client + client = data_fusion_v1.DataFusionClient() + + # Initialize request argument(s) + instance = data_fusion_v1.Instance() + instance.type_ = "DEVELOPER" + + request = data_fusion_v1.UpdateInstanceRequest( + instance=instance, + ) + + # Make the request + operation = client.update_instance(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END datafusion_v1_generated_DataFusion_UpdateInstance_sync] diff --git a/samples/generated_samples/snippet_metadata_data fusion_v1.json b/samples/generated_samples/snippet_metadata_data fusion_v1.json new file mode 100644 index 0000000..0f0a0b3 --- /dev/null +++ b/samples/generated_samples/snippet_metadata_data fusion_v1.json @@ -0,0 +1,627 @@ +{ + "snippets": [ + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "DataFusion" + }, + "shortName": "CreateInstance" + } + }, + "file": "datafusion_v1_generated_data_fusion_create_instance_async.py", + "regionTag": "datafusion_v1_generated_DataFusion_CreateInstance_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "DataFusion" + }, + "shortName": "CreateInstance" + } + }, + "file": "datafusion_v1_generated_data_fusion_create_instance_sync.py", + "regionTag": "datafusion_v1_generated_DataFusion_CreateInstance_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "DataFusion" + }, + "shortName": "DeleteInstance" + } + }, + "file": "datafusion_v1_generated_data_fusion_delete_instance_async.py", + "regionTag": "datafusion_v1_generated_DataFusion_DeleteInstance_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "DataFusion" + }, + "shortName": "DeleteInstance" + } + }, + "file": "datafusion_v1_generated_data_fusion_delete_instance_sync.py", + "regionTag": "datafusion_v1_generated_DataFusion_DeleteInstance_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "DataFusion" + }, + "shortName": "GetInstance" + } + }, + "file": "datafusion_v1_generated_data_fusion_get_instance_async.py", + "regionTag": "datafusion_v1_generated_DataFusion_GetInstance_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": "DataFusion" + }, + "shortName": "GetInstance" + } + }, + "file": "datafusion_v1_generated_data_fusion_get_instance_sync.py", + "regionTag": "datafusion_v1_generated_DataFusion_GetInstance_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": "DataFusion" + }, + "shortName": "ListAvailableVersions" + } + }, + "file": "datafusion_v1_generated_data_fusion_list_available_versions_async.py", + "regionTag": "datafusion_v1_generated_DataFusion_ListAvailableVersions_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "DataFusion" + }, + "shortName": "ListAvailableVersions" + } + }, + "file": "datafusion_v1_generated_data_fusion_list_available_versions_sync.py", + "regionTag": "datafusion_v1_generated_DataFusion_ListAvailableVersions_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "DataFusion" + }, + "shortName": "ListInstances" + } + }, + "file": "datafusion_v1_generated_data_fusion_list_instances_async.py", + "regionTag": "datafusion_v1_generated_DataFusion_ListInstances_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "DataFusion" + }, + "shortName": "ListInstances" + } + }, + "file": "datafusion_v1_generated_data_fusion_list_instances_sync.py", + "regionTag": "datafusion_v1_generated_DataFusion_ListInstances_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "DataFusion" + }, + "shortName": "RestartInstance" + } + }, + "file": "datafusion_v1_generated_data_fusion_restart_instance_async.py", + "regionTag": "datafusion_v1_generated_DataFusion_RestartInstance_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "DataFusion" + }, + "shortName": "RestartInstance" + } + }, + "file": "datafusion_v1_generated_data_fusion_restart_instance_sync.py", + "regionTag": "datafusion_v1_generated_DataFusion_RestartInstance_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "async": true, + "method": { + "service": { + "shortName": "DataFusion" + }, + "shortName": "UpdateInstance" + } + }, + "file": "datafusion_v1_generated_data_fusion_update_instance_async.py", + "regionTag": "datafusion_v1_generated_DataFusion_UpdateInstance_async", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ] + }, + { + "clientMethod": { + "method": { + "service": { + "shortName": "DataFusion" + }, + "shortName": "UpdateInstance" + } + }, + "file": "datafusion_v1_generated_data_fusion_update_instance_sync.py", + "regionTag": "datafusion_v1_generated_DataFusion_UpdateInstance_sync", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ] + } + ] +} diff --git a/scripts/fixup_data_fusion_v1_keywords.py b/scripts/fixup_data_fusion_v1_keywords.py index b8af153..b24f68e 100644 --- a/scripts/fixup_data_fusion_v1_keywords.py +++ b/scripts/fixup_data_fusion_v1_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 c896879..485064a 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ name = "google-cloud-data-fusion" description = "Cloud Data Fusion API client library" -version = "1.3.0" +version = "1.4.0" release_status = "Development Status :: 5 - Production/Stable" url = "https://github.com/googleapis/python-data-fusion" 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/data_fusion_v1/__init__.py b/tests/unit/gapic/data_fusion_v1/__init__.py index 4de6597..e8e1c38 100644 --- a/tests/unit/gapic/data_fusion_v1/__init__.py +++ b/tests/unit/gapic/data_fusion_v1/__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/data_fusion_v1/test_data_fusion.py b/tests/unit/gapic/data_fusion_v1/test_data_fusion.py index 14c9051..27ed703 100644 --- a/tests/unit/gapic/data_fusion_v1/test_data_fusion.py +++ b/tests/unit/gapic/data_fusion_v1/test_data_fusion.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. @@ -29,6 +29,7 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 from google.api_core import path_template @@ -390,6 +391,83 @@ def test_data_fusion_client_mtls_env_auto( ) +@pytest.mark.parametrize("client_class", [DataFusionClient, DataFusionAsyncClient]) +@mock.patch.object( + DataFusionClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DataFusionClient) +) +@mock.patch.object( + DataFusionAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(DataFusionAsyncClient), +) +def test_data_fusion_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", [ @@ -422,21 +500,23 @@ def test_data_fusion_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (DataFusionClient, transports.DataFusionGrpcTransport, "grpc"), + (DataFusionClient, transports.DataFusionGrpcTransport, "grpc", grpc_helpers), ( DataFusionAsyncClient, transports.DataFusionGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_data_fusion_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(client_options=options, transport=transport_name) @@ -470,6 +550,67 @@ def test_data_fusion_client_client_options_from_dict(): ) +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + (DataFusionClient, transports.DataFusionGrpcTransport, "grpc", grpc_helpers), + ( + DataFusionAsyncClient, + transports.DataFusionGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_data_fusion_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( + "datafusion.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="datafusion.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize( "request_type", [datafusion.ListAvailableVersionsRequest, dict,] ) @@ -2099,6 +2240,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.DataFusionGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = DataFusionClient(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 = DataFusionClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.DataFusionGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -2704,3 +2862,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (DataFusionClient, transports.DataFusionGrpcTransport), + (DataFusionAsyncClient, transports.DataFusionGrpcAsyncIOTransport), + ], +) +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, + )