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 f0b30d2..e49aec6 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 @@ -19,13 +19,15 @@ from typing import Dict, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core.client_options import ClientOptions # type: ignore from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.data_fusion_v1.services.data_fusion import pagers @@ -165,10 +167,10 @@ def __init__( async def list_available_versions( self, - request: datafusion.ListAvailableVersionsRequest = None, + request: Union[datafusion.ListAvailableVersionsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListAvailableVersionsAsyncPager: @@ -176,7 +178,7 @@ async def list_available_versions( the specified project and location. Args: - request (:class:`google.cloud.data_fusion_v1.types.ListAvailableVersionsRequest`): + request (Union[google.cloud.data_fusion_v1.types.ListAvailableVersionsRequest, dict]): The request object. Request message for the list available versions request. parent (:class:`str`): @@ -248,9 +250,9 @@ async def list_available_versions( async def list_instances( self, - request: datafusion.ListInstancesRequest = None, + request: Union[datafusion.ListInstancesRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListInstancesAsyncPager: @@ -258,7 +260,7 @@ async def list_instances( and location. Args: - request (:class:`google.cloud.data_fusion_v1.types.ListInstancesRequest`): + request (Union[google.cloud.data_fusion_v1.types.ListInstancesRequest, dict]): The request object. Request message for listing Data Fusion instances. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -307,16 +309,16 @@ async def list_instances( async def get_instance( self, - request: datafusion.GetInstanceRequest = None, + request: Union[datafusion.GetInstanceRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> datafusion.Instance: r"""Gets details of a single Data Fusion instance. Args: - request (:class:`google.cloud.data_fusion_v1.types.GetInstanceRequest`): + request (Union[google.cloud.data_fusion_v1.types.GetInstanceRequest, dict]): The request object. Request message for getting details about a Data Fusion instance. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -354,12 +356,12 @@ async def get_instance( async def create_instance( self, - request: datafusion.CreateInstanceRequest = None, + request: Union[datafusion.CreateInstanceRequest, dict] = None, *, parent: str = None, instance: datafusion.Instance = None, instance_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -367,7 +369,7 @@ async def create_instance( project and location. Args: - request (:class:`google.cloud.data_fusion_v1.types.CreateInstanceRequest`): + request (Union[google.cloud.data_fusion_v1.types.CreateInstanceRequest, dict]): The request object. Request message for creating a Data Fusion instance. parent (:class:`str`): @@ -454,17 +456,17 @@ async def create_instance( async def delete_instance( self, - request: datafusion.DeleteInstanceRequest = None, + request: Union[datafusion.DeleteInstanceRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a single Date Fusion instance. Args: - request (:class:`google.cloud.data_fusion_v1.types.DeleteInstanceRequest`): + request (Union[google.cloud.data_fusion_v1.types.DeleteInstanceRequest, dict]): The request object. Request message for deleting a Data Fusion instance. name (:class:`str`): @@ -547,18 +549,18 @@ async def delete_instance( async def update_instance( self, - request: datafusion.UpdateInstanceRequest = None, + request: Union[datafusion.UpdateInstanceRequest, dict] = None, *, instance: datafusion.Instance = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Updates a single Data Fusion instance. Args: - request (:class:`google.cloud.data_fusion_v1.types.UpdateInstanceRequest`): + request (Union[google.cloud.data_fusion_v1.types.UpdateInstanceRequest, dict]): The request object. instance (:class:`google.cloud.data_fusion_v1.types.Instance`): The instance resource that replaces @@ -649,9 +651,9 @@ async def update_instance( async def restart_instance( self, - request: datafusion.RestartInstanceRequest = None, + request: Union[datafusion.RestartInstanceRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -659,7 +661,7 @@ async def restart_instance( At the end of an operation instance is fully restarted. Args: - request (:class:`google.cloud.data_fusion_v1.types.RestartInstanceRequest`): + request (Union[google.cloud.data_fusion_v1.types.RestartInstanceRequest, dict]): The request object. Request message for restarting a Data Fusion instance. retry (google.api_core.retry.Retry): Designation of what errors, if any, 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 0374d93..fbfd514 100644 --- a/google/cloud/data_fusion_v1/services/data_fusion/client.py +++ b/google/cloud/data_fusion_v1/services/data_fusion/client.py @@ -30,6 +30,8 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.data_fusion_v1.services.data_fusion import pagers @@ -358,7 +360,7 @@ def list_available_versions( request: Union[datafusion.ListAvailableVersionsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListAvailableVersionsPager: @@ -440,7 +442,7 @@ def list_instances( self, request: Union[datafusion.ListInstancesRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListInstancesPager: @@ -500,7 +502,7 @@ def get_instance( self, request: Union[datafusion.GetInstanceRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> datafusion.Instance: @@ -551,7 +553,7 @@ def create_instance( parent: str = None, instance: datafusion.Instance = None, instance_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -649,7 +651,7 @@ def delete_instance( request: Union[datafusion.DeleteInstanceRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -743,7 +745,7 @@ def update_instance( *, instance: datafusion.Instance = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -843,7 +845,7 @@ def restart_instance( self, request: Union[datafusion.RestartInstanceRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: 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 7db10f1..05abf0a 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 @@ -15,7 +15,6 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore @@ -39,15 +38,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - class DataFusionTransport(abc.ABC): """Abstract transport class for DataFusion.""" @@ -97,7 +87,7 @@ def __init__( host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. self._scopes = scopes @@ -130,29 +120,6 @@ def __init__( # Save the credentials. self._credentials = credentials - # TODO(busunkim): This method is in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-auth is increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -191,7 +158,7 @@ def close(self): raise NotImplementedError() @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() 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 11723eb..43311c6 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 @@ -114,7 +114,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) 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 e531369..6ec2391 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 @@ -21,7 +21,6 @@ from google.api_core import operations_v1 # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -161,7 +160,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/setup.py b/setup.py index 2db34ca..0545baf 100644 --- a/setup.py +++ b/setup.py @@ -29,9 +29,8 @@ # NOTE: Maintainers, please do not require google-api-core>=2.x.x # Until this issue is closed # https://github.com/googleapis/google-cloud-python/issues/10566 - "google-api-core[grpc] >= 1.26.0, <3.0.0dev", + "google-api-core[grpc] >= 1.28.0, <3.0.0dev", "proto-plus >= 1.15.0", - "packaging >= 14.3", ] package_root = os.path.abspath(os.path.dirname(__file__)) diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index fe11de2..1e3ec8b 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -4,7 +4,5 @@ # Pin the version to the lower bound. # e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev", # Then this file should have google-cloud-foo==1.14.0 -google-api-core==1.26.0 +google-api-core==1.28.0 proto-plus==1.15.0 -packaging==14.3 -google-auth==1.24.0 # TODO: remove when google-auth>=1.25.0 si transitively required through google-api-core \ No newline at end of file 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 d2691b0..e4b9d77 100644 --- a/tests/unit/gapic/data_fusion_v1/test_data_fusion.py +++ b/tests/unit/gapic/data_fusion_v1/test_data_fusion.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -39,9 +38,6 @@ from google.cloud.data_fusion_v1.services.data_fusion import DataFusionClient from google.cloud.data_fusion_v1.services.data_fusion import pagers from google.cloud.data_fusion_v1.services.data_fusion import transports -from google.cloud.data_fusion_v1.services.data_fusion.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.data_fusion_v1.types import datafusion from google.longrunning import operations_pb2 from google.oauth2 import service_account @@ -50,20 +46,6 @@ import google.auth -# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively -# through google-api-core: -# - Delete the auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -211,7 +193,7 @@ def test_data_fusion_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -228,7 +210,7 @@ def test_data_fusion_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -245,7 +227,7 @@ def test_data_fusion_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -274,7 +256,7 @@ def test_data_fusion_client_client_options( options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -331,7 +313,7 @@ def test_data_fusion_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) if use_client_cert_env == "false": expected_client_cert_source = None @@ -373,7 +355,7 @@ def test_data_fusion_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -395,7 +377,7 @@ def test_data_fusion_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -426,7 +408,7 @@ def test_data_fusion_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -457,7 +439,7 @@ def test_data_fusion_client_client_options_credentials_file( 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) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -2201,7 +2183,6 @@ def test_data_fusion_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_data_fusion_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2222,26 +2203,6 @@ def test_data_fusion_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_data_fusion_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.data_fusion_v1.services.data_fusion.transports.DataFusionTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.DataFusionTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_data_fusion_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -2253,7 +2214,6 @@ def test_data_fusion_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_data_fusion_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2266,23 +2226,10 @@ def test_data_fusion_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_data_fusion_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - DataFusionClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [transports.DataFusionGrpcTransport, transports.DataFusionGrpcAsyncIOTransport,], ) -@requires_google_auth_gte_1_25_0 def test_data_fusion_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2296,23 +2243,6 @@ def test_data_fusion_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [transports.DataFusionGrpcTransport, transports.DataFusionGrpcAsyncIOTransport,], -) -@requires_google_auth_lt_1_25_0 -def test_data_fusion_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [