From 9a14561ac984b783f79c89f7d34624859390e2d1 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 08:46:24 -0600 Subject: [PATCH] fix: disable always_use_jwt_access (#5) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: use gapic-generator-python 0.50.3 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 * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/master/packages/owl-bot/README.md Co-authored-by: Owl Bot --- .../network_security/transports/base.py | 2 +- .../network_security/transports/grpc.py | 5 +++- .../transports/grpc_asyncio.py | 5 +++- .../test_network_security.py | 26 ++++++++++++++++--- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/google/cloud/network_security_v1beta1/services/network_security/transports/base.py b/google/cloud/network_security_v1beta1/services/network_security/transports/base.py index 4864719..c1d0300 100644 --- a/google/cloud/network_security_v1beta1/services/network_security/transports/base.py +++ b/google/cloud/network_security_v1beta1/services/network_security/transports/base.py @@ -111,7 +111,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/network_security_v1beta1/services/network_security/transports/grpc.py b/google/cloud/network_security_v1beta1/services/network_security/transports/grpc.py index aa5c38f..f8fd775 100644 --- a/google/cloud/network_security_v1beta1/services/network_security/transports/grpc.py +++ b/google/cloud/network_security_v1beta1/services/network_security/transports/grpc.py @@ -68,6 +68,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. @@ -108,6 +109,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 @@ -161,7 +164,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/network_security_v1beta1/services/network_security/transports/grpc_asyncio.py b/google/cloud/network_security_v1beta1/services/network_security/transports/grpc_asyncio.py index 57b247c..7632628 100644 --- a/google/cloud/network_security_v1beta1/services/network_security/transports/grpc_asyncio.py +++ b/google/cloud/network_security_v1beta1/services/network_security/transports/grpc_asyncio.py @@ -114,6 +114,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. @@ -155,6 +156,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 @@ -207,7 +210,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/network_security_v1beta1/test_network_security.py b/tests/unit/gapic/network_security_v1beta1/test_network_security.py index 562b134..f061f28 100644 --- a/tests/unit/gapic/network_security_v1beta1/test_network_security.py +++ b/tests/unit/gapic/network_security_v1beta1/test_network_security.py @@ -150,7 +150,25 @@ def test_network_security_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.NetworkSecurityGrpcTransport, "grpc"), + (transports.NetworkSecurityGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_network_security_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( @@ -4772,7 +4790,7 @@ def test_network_security_grpc_transport_client_cert_source_for_mtls(transport_c "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=[ @@ -4881,7 +4899,7 @@ def test_network_security_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=[ @@ -4928,7 +4946,7 @@ def test_network_security_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=[