From 903b08e9436691a92f5557d3e8a0a49612d4d8db Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 1 Jul 2021 02:16:12 +0000 Subject: [PATCH] fix: disable always_use_jwt_access (#47) Committer: @busunkim96 PiperOrigin-RevId: 382142900 Source-Link: https://github.com/googleapis/googleapis/commit/513440fda515f3c799c22a30e3906dcda325004e Source-Link: https://github.com/googleapis/googleapis-gen/commit/7b1e2c31233f79a704ec21ca410bf661d6bc68d0 --- .../dataproc_metastore/transports/base.py | 2 +- .../dataproc_metastore/transports/grpc.py | 5 +++- .../transports/grpc_asyncio.py | 5 +++- .../dataproc_metastore/transports/base.py | 2 +- .../dataproc_metastore/transports/grpc.py | 5 +++- .../transports/grpc_asyncio.py | 5 +++- .../dataproc_metastore/transports/base.py | 2 +- .../dataproc_metastore/transports/grpc.py | 5 +++- .../transports/grpc_asyncio.py | 5 +++- .../metastore_v1/test_dataproc_metastore.py | 26 ++++++++++++++++--- .../test_dataproc_metastore.py | 26 ++++++++++++++++--- .../test_dataproc_metastore.py | 26 ++++++++++++++++--- 12 files changed, 93 insertions(+), 21 deletions(-) diff --git a/google/cloud/metastore_v1/services/dataproc_metastore/transports/base.py b/google/cloud/metastore_v1/services/dataproc_metastore/transports/base.py index 5e18e5d..c7ee6ca 100644 --- a/google/cloud/metastore_v1/services/dataproc_metastore/transports/base.py +++ b/google/cloud/metastore_v1/services/dataproc_metastore/transports/base.py @@ -98,7 +98,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. diff --git a/google/cloud/metastore_v1/services/dataproc_metastore/transports/grpc.py b/google/cloud/metastore_v1/services/dataproc_metastore/transports/grpc.py index cfe5358..08f2204 100644 --- a/google/cloud/metastore_v1/services/dataproc_metastore/transports/grpc.py +++ b/google/cloud/metastore_v1/services/dataproc_metastore/transports/grpc.py @@ -81,6 +81,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -121,6 +122,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -174,7 +177,7 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, - always_use_jwt_access=True, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: diff --git a/google/cloud/metastore_v1/services/dataproc_metastore/transports/grpc_asyncio.py b/google/cloud/metastore_v1/services/dataproc_metastore/transports/grpc_asyncio.py index 3b801ba..e87b398 100644 --- a/google/cloud/metastore_v1/services/dataproc_metastore/transports/grpc_asyncio.py +++ b/google/cloud/metastore_v1/services/dataproc_metastore/transports/grpc_asyncio.py @@ -127,6 +127,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -168,6 +169,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -220,7 +223,7 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, - always_use_jwt_access=True, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: diff --git a/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/base.py b/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/base.py index 903e4ca..ecf6a96 100644 --- a/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/base.py +++ b/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/base.py @@ -98,7 +98,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. diff --git a/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/grpc.py b/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/grpc.py index 7bee794..cd8a072 100644 --- a/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/grpc.py +++ b/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/grpc.py @@ -81,6 +81,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -121,6 +122,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -174,7 +177,7 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, - always_use_jwt_access=True, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: diff --git a/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/grpc_asyncio.py b/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/grpc_asyncio.py index 5b6b972..a418e1d 100644 --- a/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/grpc_asyncio.py +++ b/google/cloud/metastore_v1alpha/services/dataproc_metastore/transports/grpc_asyncio.py @@ -127,6 +127,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -168,6 +169,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -220,7 +223,7 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, - always_use_jwt_access=True, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: diff --git a/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/base.py b/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/base.py index c0ecacf..c81376a 100644 --- a/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/base.py +++ b/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/base.py @@ -100,7 +100,7 @@ def __init__( scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. diff --git a/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/grpc.py b/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/grpc.py index 8719b8b..eac7104 100644 --- a/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/grpc.py +++ b/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/grpc.py @@ -81,6 +81,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -121,6 +122,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -174,7 +177,7 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, - always_use_jwt_access=True, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: diff --git a/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/grpc_asyncio.py b/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/grpc_asyncio.py index abcd579..eb12574 100644 --- a/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/grpc_asyncio.py +++ b/google/cloud/metastore_v1beta/services/dataproc_metastore/transports/grpc_asyncio.py @@ -127,6 +127,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -168,6 +169,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -220,7 +223,7 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, - always_use_jwt_access=True, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: diff --git a/tests/unit/gapic/metastore_v1/test_dataproc_metastore.py b/tests/unit/gapic/metastore_v1/test_dataproc_metastore.py index f8edcd9..6a8cd1a 100644 --- a/tests/unit/gapic/metastore_v1/test_dataproc_metastore.py +++ b/tests/unit/gapic/metastore_v1/test_dataproc_metastore.py @@ -140,7 +140,25 @@ def test_dataproc_metastore_client_service_account_always_use_jwt(client_class): ) as use_jwt: creds = service_account.Credentials(None, None, None) client = client_class(credentials=creds) - use_jwt.assert_called_with(True) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.DataprocMetastoreGrpcTransport, "grpc"), + (transports.DataprocMetastoreGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_dataproc_metastore_client_service_account_always_use_jwt_true( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) @pytest.mark.parametrize( @@ -3319,7 +3337,7 @@ def test_dataproc_metastore_grpc_transport_client_cert_source_for_mtls(transport "squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_channel_creds, quota_project_id=None, options=[ @@ -3428,7 +3446,7 @@ def test_dataproc_metastore_transport_channel_mtls_with_client_cert_source( "mtls.squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -3475,7 +3493,7 @@ def test_dataproc_metastore_transport_channel_mtls_with_adc(transport_class): "mtls.squid.clam.whelk:443", credentials=mock_cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ diff --git a/tests/unit/gapic/metastore_v1alpha/test_dataproc_metastore.py b/tests/unit/gapic/metastore_v1alpha/test_dataproc_metastore.py index e0440eb..bc7a4a7 100644 --- a/tests/unit/gapic/metastore_v1alpha/test_dataproc_metastore.py +++ b/tests/unit/gapic/metastore_v1alpha/test_dataproc_metastore.py @@ -140,7 +140,25 @@ def test_dataproc_metastore_client_service_account_always_use_jwt(client_class): ) as use_jwt: creds = service_account.Credentials(None, None, None) client = client_class(credentials=creds) - use_jwt.assert_called_with(True) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.DataprocMetastoreGrpcTransport, "grpc"), + (transports.DataprocMetastoreGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_dataproc_metastore_client_service_account_always_use_jwt_true( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) @pytest.mark.parametrize( @@ -4495,7 +4513,7 @@ def test_dataproc_metastore_grpc_transport_client_cert_source_for_mtls(transport "squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_channel_creds, quota_project_id=None, options=[ @@ -4604,7 +4622,7 @@ def test_dataproc_metastore_transport_channel_mtls_with_client_cert_source( "mtls.squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -4651,7 +4669,7 @@ def test_dataproc_metastore_transport_channel_mtls_with_adc(transport_class): "mtls.squid.clam.whelk:443", credentials=mock_cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ diff --git a/tests/unit/gapic/metastore_v1beta/test_dataproc_metastore.py b/tests/unit/gapic/metastore_v1beta/test_dataproc_metastore.py index 0310c1d..be2b0bb 100644 --- a/tests/unit/gapic/metastore_v1beta/test_dataproc_metastore.py +++ b/tests/unit/gapic/metastore_v1beta/test_dataproc_metastore.py @@ -140,7 +140,25 @@ def test_dataproc_metastore_client_service_account_always_use_jwt(client_class): ) as use_jwt: creds = service_account.Credentials(None, None, None) client = client_class(credentials=creds) - use_jwt.assert_called_with(True) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.DataprocMetastoreGrpcTransport, "grpc"), + (transports.DataprocMetastoreGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_dataproc_metastore_client_service_account_always_use_jwt_true( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) @pytest.mark.parametrize( @@ -4495,7 +4513,7 @@ def test_dataproc_metastore_grpc_transport_client_cert_source_for_mtls(transport "squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_channel_creds, quota_project_id=None, options=[ @@ -4604,7 +4622,7 @@ def test_dataproc_metastore_transport_channel_mtls_with_client_cert_source( "mtls.squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -4651,7 +4669,7 @@ def test_dataproc_metastore_transport_channel_mtls_with_adc(transport_class): "mtls.squid.clam.whelk:443", credentials=mock_cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[