Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.

Commit 9c1ad1a

Browse files
1 parent 2502c00 commit 9c1ad1a

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

google/cloud/networkconnectivity_v1alpha1/services/hub_service/transports/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def __init__(
101101
scopes_kwargs = self._get_scopes_kwargs(self._host, scopes)
102102

103103
# Save the scopes.
104-
self._scopes = scopes or self.AUTH_SCOPES
104+
self._scopes = scopes
105105

106106
# If no credentials are provided, then determine the appropriate
107107
# defaults.

google/cloud/networkconnectivity_v1alpha1/services/hub_service/transports/grpc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def __init__(
6363
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
6464
quota_project_id: Optional[str] = None,
6565
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
66+
always_use_jwt_access: Optional[bool] = False,
6667
) -> None:
6768
"""Instantiate the transport.
6869
@@ -103,6 +104,8 @@ def __init__(
103104
API requests. If ``None``, then default info will be used.
104105
Generally, you only need to set this if you're developing
105106
your own client library.
107+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
108+
be used for service account credentials.
106109
107110
Raises:
108111
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -156,7 +159,7 @@ def __init__(
156159
scopes=scopes,
157160
quota_project_id=quota_project_id,
158161
client_info=client_info,
159-
always_use_jwt_access=True,
162+
always_use_jwt_access=always_use_jwt_access,
160163
)
161164

162165
if not self._grpc_channel:

google/cloud/networkconnectivity_v1alpha1/services/hub_service/transports/grpc_asyncio.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def __init__(
109109
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
110110
quota_project_id=None,
111111
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
112+
always_use_jwt_access: Optional[bool] = False,
112113
) -> None:
113114
"""Instantiate the transport.
114115
@@ -150,6 +151,8 @@ def __init__(
150151
API requests. If ``None``, then default info will be used.
151152
Generally, you only need to set this if you're developing
152153
your own client library.
154+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
155+
be used for service account credentials.
153156
154157
Raises:
155158
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -202,7 +205,7 @@ def __init__(
202205
scopes=scopes,
203206
quota_project_id=quota_project_id,
204207
client_info=client_info,
205-
always_use_jwt_access=True,
208+
always_use_jwt_access=always_use_jwt_access,
206209
)
207210

208211
if not self._grpc_channel:

tests/unit/gapic/networkconnectivity_v1alpha1/test_hub_service.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,25 @@ def test_hub_service_client_service_account_always_use_jwt(client_class):
132132
) as use_jwt:
133133
creds = service_account.Credentials(None, None, None)
134134
client = client_class(credentials=creds)
135-
use_jwt.assert_called_with(True)
135+
use_jwt.assert_not_called()
136+
137+
138+
@pytest.mark.parametrize(
139+
"transport_class,transport_name",
140+
[
141+
(transports.HubServiceGrpcTransport, "grpc"),
142+
(transports.HubServiceGrpcAsyncIOTransport, "grpc_asyncio"),
143+
],
144+
)
145+
def test_hub_service_client_service_account_always_use_jwt_true(
146+
transport_class, transport_name
147+
):
148+
with mock.patch.object(
149+
service_account.Credentials, "with_always_use_jwt_access", create=True
150+
) as use_jwt:
151+
creds = service_account.Credentials(None, None, None)
152+
transport = transport_class(credentials=creds, always_use_jwt_access=True)
153+
use_jwt.assert_called_once_with(True)
136154

137155

138156
@pytest.mark.parametrize("client_class", [HubServiceClient, HubServiceAsyncClient,])
@@ -3001,7 +3019,7 @@ def test_hub_service_grpc_transport_client_cert_source_for_mtls(transport_class)
30013019
"squid.clam.whelk:443",
30023020
credentials=cred,
30033021
credentials_file=None,
3004-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
3022+
scopes=None,
30053023
ssl_credentials=mock_ssl_channel_creds,
30063024
quota_project_id=None,
30073025
options=[
@@ -3105,7 +3123,7 @@ def test_hub_service_transport_channel_mtls_with_client_cert_source(transport_cl
31053123
"mtls.squid.clam.whelk:443",
31063124
credentials=cred,
31073125
credentials_file=None,
3108-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
3126+
scopes=None,
31093127
ssl_credentials=mock_ssl_cred,
31103128
quota_project_id=None,
31113129
options=[
@@ -3149,7 +3167,7 @@ def test_hub_service_transport_channel_mtls_with_adc(transport_class):
31493167
"mtls.squid.clam.whelk:443",
31503168
credentials=mock_cred,
31513169
credentials_file=None,
3152-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
3170+
scopes=None,
31533171
ssl_credentials=mock_ssl_cred,
31543172
quota_project_id=None,
31553173
options=[

0 commit comments

Comments
 (0)