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 fba0d7c..dd209b8 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 @@ -247,7 +247,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: @@ -449,7 +449,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: @@ -546,7 +546,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: @@ -647,7 +647,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: 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 810a9ac..53faaa1 100644 --- a/google/cloud/data_fusion_v1/services/data_fusion/client.py +++ b/google/cloud/data_fusion_v1/services/data_fusion/client.py @@ -467,7 +467,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: @@ -671,7 +671,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: @@ -768,7 +768,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: @@ -869,7 +869,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: 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..f69292d 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 @@ -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..92d3630 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 @@ -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/datafusion.py b/google/cloud/data_fusion_v1/types/datafusion.py index 5dd9edb..69d73dc 100644 --- a/google/cloud/data_fusion_v1/types/datafusion.py +++ b/google/cloud/data_fusion_v1/types/datafusion.py @@ -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/tests/unit/gapic/data_fusion_v1/test_data_fusion.py b/tests/unit/gapic/data_fusion_v1/test_data_fusion.py index 560141b..b381220 100644 --- a/tests/unit/gapic/data_fusion_v1/test_data_fusion.py +++ b/tests/unit/gapic/data_fusion_v1/test_data_fusion.py @@ -29,6 +29,7 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 from google.api_core import path_template @@ -499,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) @@ -547,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,] )