From f4cff83baf1865477139bd14b02a12e47505150d 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:02:08 +0000 Subject: [PATCH] fix: disable always_use_jwt_access (#15) fix: disable always_use_jwt_access Committer: @busunkim96 PiperOrigin-RevId: 382142900 Source-Link: https://github.com/googleapis/googleapis/commit/513440fda515f3c799c22a30e3906dcda325004e Source-Link: https://github.com/googleapis/googleapis-gen/commit/7b1e2c31233f79a704ec21ca410bf661d6bc68d0 --- .../connection_service/transports/base.py | 2 +- .../connection_service/transports/grpc.py | 5 +++- .../transports/grpc_asyncio.py | 5 +++- .../services/tether/transports/base.py | 2 +- .../services/tether/transports/grpc.py | 5 +++- .../tether/transports/grpc_asyncio.py | 5 +++- .../test_connection_service.py | 26 ++++++++++++++++--- .../gapic/apigeeconnect_v1/test_tether.py | 26 ++++++++++++++++--- 8 files changed, 62 insertions(+), 14 deletions(-) diff --git a/google/cloud/apigeeconnect_v1/services/connection_service/transports/base.py b/google/cloud/apigeeconnect_v1/services/connection_service/transports/base.py index 9d59e39..3a93550 100644 --- a/google/cloud/apigeeconnect_v1/services/connection_service/transports/base.py +++ b/google/cloud/apigeeconnect_v1/services/connection_service/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/apigeeconnect_v1/services/connection_service/transports/grpc.py b/google/cloud/apigeeconnect_v1/services/connection_service/transports/grpc.py index 742188f..c9d4913 100644 --- a/google/cloud/apigeeconnect_v1/services/connection_service/transports/grpc.py +++ b/google/cloud/apigeeconnect_v1/services/connection_service/transports/grpc.py @@ -58,6 +58,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. @@ -98,6 +99,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 @@ -150,7 +153,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/apigeeconnect_v1/services/connection_service/transports/grpc_asyncio.py b/google/cloud/apigeeconnect_v1/services/connection_service/transports/grpc_asyncio.py index cb2cf0a..93ff5d8 100644 --- a/google/cloud/apigeeconnect_v1/services/connection_service/transports/grpc_asyncio.py +++ b/google/cloud/apigeeconnect_v1/services/connection_service/transports/grpc_asyncio.py @@ -104,6 +104,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. @@ -145,6 +146,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 @@ -196,7 +199,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/apigeeconnect_v1/services/tether/transports/base.py b/google/cloud/apigeeconnect_v1/services/tether/transports/base.py index 82a0be4..b7ae91b 100644 --- a/google/cloud/apigeeconnect_v1/services/tether/transports/base.py +++ b/google/cloud/apigeeconnect_v1/services/tether/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/apigeeconnect_v1/services/tether/transports/grpc.py b/google/cloud/apigeeconnect_v1/services/tether/transports/grpc.py index fccaa0a..b3780a3 100644 --- a/google/cloud/apigeeconnect_v1/services/tether/transports/grpc.py +++ b/google/cloud/apigeeconnect_v1/services/tether/transports/grpc.py @@ -60,6 +60,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. @@ -100,6 +101,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 @@ -152,7 +155,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/apigeeconnect_v1/services/tether/transports/grpc_asyncio.py b/google/cloud/apigeeconnect_v1/services/tether/transports/grpc_asyncio.py index ff861a9..89b6509 100644 --- a/google/cloud/apigeeconnect_v1/services/tether/transports/grpc_asyncio.py +++ b/google/cloud/apigeeconnect_v1/services/tether/transports/grpc_asyncio.py @@ -106,6 +106,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. @@ -147,6 +148,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 @@ -198,7 +201,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/apigeeconnect_v1/test_connection_service.py b/tests/unit/gapic/apigeeconnect_v1/test_connection_service.py index 26dd6e7..b8a9e03 100644 --- a/tests/unit/gapic/apigeeconnect_v1/test_connection_service.py +++ b/tests/unit/gapic/apigeeconnect_v1/test_connection_service.py @@ -132,7 +132,25 @@ def test_connection_service_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.ConnectionServiceGrpcTransport, "grpc"), + (transports.ConnectionServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_connection_service_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( @@ -1109,7 +1127,7 @@ def test_connection_service_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=[ @@ -1218,7 +1236,7 @@ def test_connection_service_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=[ @@ -1265,7 +1283,7 @@ def test_connection_service_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/apigeeconnect_v1/test_tether.py b/tests/unit/gapic/apigeeconnect_v1/test_tether.py index 3added8..616f450 100644 --- a/tests/unit/gapic/apigeeconnect_v1/test_tether.py +++ b/tests/unit/gapic/apigeeconnect_v1/test_tether.py @@ -119,7 +119,25 @@ def test_tether_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.TetherGrpcTransport, "grpc"), + (transports.TetherGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_tether_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("client_class", [TetherClient, TetherAsyncClient,]) @@ -767,7 +785,7 @@ def test_tether_grpc_transport_client_cert_source_for_mtls(transport_class): "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=[ @@ -871,7 +889,7 @@ def test_tether_transport_channel_mtls_with_client_cert_source(transport_class): "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=[ @@ -915,7 +933,7 @@ def test_tether_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=[