diff --git a/google/cloud/apigeeconnect_v1/services/connection_service/client.py b/google/cloud/apigeeconnect_v1/services/connection_service/client.py index 8d26524..0923c89 100644 --- a/google/cloud/apigeeconnect_v1/services/connection_service/client.py +++ b/google/cloud/apigeeconnect_v1/services/connection_service/client.py @@ -345,6 +345,10 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=( + Transport == type(self).get_transport_class("grpc") + or Transport == type(self).get_transport_class("grpc_asyncio") + ), ) def list_connections( diff --git a/google/cloud/apigeeconnect_v1/services/tether/client.py b/google/cloud/apigeeconnect_v1/services/tether/client.py index a562841..4aa5c86 100644 --- a/google/cloud/apigeeconnect_v1/services/tether/client.py +++ b/google/cloud/apigeeconnect_v1/services/tether/client.py @@ -340,6 +340,10 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=( + Transport == type(self).get_transport_class("grpc") + or Transport == type(self).get_transport_class("grpc_asyncio") + ), ) def egress( diff --git a/tests/unit/gapic/apigeeconnect_v1/test_connection_service.py b/tests/unit/gapic/apigeeconnect_v1/test_connection_service.py index b8a9e03..35d3ad0 100644 --- a/tests/unit/gapic/apigeeconnect_v1/test_connection_service.py +++ b/tests/unit/gapic/apigeeconnect_v1/test_connection_service.py @@ -123,18 +123,6 @@ def test_connection_service_client_from_service_account_info(client_class): assert client.transport._host == "apigeeconnect.googleapis.com:443" -@pytest.mark.parametrize( - "client_class", [ConnectionServiceClient, ConnectionServiceAsyncClient,] -) -def test_connection_service_client_service_account_always_use_jwt(client_class): - with mock.patch.object( - service_account.Credentials, "with_always_use_jwt_access", create=True - ) as use_jwt: - creds = service_account.Credentials(None, None, None) - client = client_class(credentials=creds) - use_jwt.assert_not_called() - - @pytest.mark.parametrize( "transport_class,transport_name", [ @@ -142,7 +130,7 @@ def test_connection_service_client_service_account_always_use_jwt(client_class): (transports.ConnectionServiceGrpcAsyncIOTransport, "grpc_asyncio"), ], ) -def test_connection_service_client_service_account_always_use_jwt_true( +def test_connection_service_client_service_account_always_use_jwt( transport_class, transport_name ): with mock.patch.object( @@ -152,6 +140,13 @@ def test_connection_service_client_service_account_always_use_jwt_true( transport = transport_class(credentials=creds, always_use_jwt_access=True) use_jwt.assert_called_once_with(True) + 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=False) + use_jwt.assert_not_called() + @pytest.mark.parametrize( "client_class", [ConnectionServiceClient, ConnectionServiceAsyncClient,] @@ -232,6 +227,7 @@ def test_connection_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -248,6 +244,7 @@ def test_connection_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -264,6 +261,7 @@ def test_connection_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has @@ -292,6 +290,7 @@ def test_connection_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -368,6 +367,7 @@ def test_connection_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -401,6 +401,7 @@ def test_connection_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -422,6 +423,7 @@ def test_connection_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -452,6 +454,7 @@ def test_connection_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -482,6 +485,7 @@ def test_connection_service_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -501,6 +505,7 @@ def test_connection_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) diff --git a/tests/unit/gapic/apigeeconnect_v1/test_tether.py b/tests/unit/gapic/apigeeconnect_v1/test_tether.py index 616f450..936d227 100644 --- a/tests/unit/gapic/apigeeconnect_v1/test_tether.py +++ b/tests/unit/gapic/apigeeconnect_v1/test_tether.py @@ -112,16 +112,6 @@ def test_tether_client_from_service_account_info(client_class): assert client.transport._host == "apigeeconnect.googleapis.com:443" -@pytest.mark.parametrize("client_class", [TetherClient, TetherAsyncClient,]) -def test_tether_client_service_account_always_use_jwt(client_class): - with mock.patch.object( - service_account.Credentials, "with_always_use_jwt_access", create=True - ) as use_jwt: - creds = service_account.Credentials(None, None, None) - client = client_class(credentials=creds) - use_jwt.assert_not_called() - - @pytest.mark.parametrize( "transport_class,transport_name", [ @@ -129,9 +119,7 @@ def test_tether_client_service_account_always_use_jwt(client_class): (transports.TetherGrpcAsyncIOTransport, "grpc_asyncio"), ], ) -def test_tether_client_service_account_always_use_jwt_true( - transport_class, transport_name -): +def test_tether_client_service_account_always_use_jwt(transport_class, transport_name): with mock.patch.object( service_account.Credentials, "with_always_use_jwt_access", create=True ) as use_jwt: @@ -139,6 +127,13 @@ def test_tether_client_service_account_always_use_jwt_true( transport = transport_class(credentials=creds, always_use_jwt_access=True) use_jwt.assert_called_once_with(True) + 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=False) + use_jwt.assert_not_called() + @pytest.mark.parametrize("client_class", [TetherClient, TetherAsyncClient,]) def test_tether_client_from_service_account_file(client_class): @@ -207,6 +202,7 @@ def test_tether_client_client_options(client_class, transport_class, transport_n client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -223,6 +219,7 @@ def test_tether_client_client_options(client_class, transport_class, transport_n client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -239,6 +236,7 @@ def test_tether_client_client_options(client_class, transport_class, transport_n client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has @@ -267,6 +265,7 @@ def test_tether_client_client_options(client_class, transport_class, transport_n client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -329,6 +328,7 @@ def test_tether_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -362,6 +362,7 @@ def test_tether_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -383,6 +384,7 @@ def test_tether_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -409,6 +411,7 @@ def test_tether_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -435,6 +438,7 @@ def test_tether_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -452,6 +456,7 @@ def test_tether_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, )