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

Commit c3dda3f

Browse files
1 parent e0a0c31 commit c3dda3f

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

google/cloud/managedidentities_v1/services/managed_identities_service/transports/base.py

+1-1
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/managedidentities_v1/services/managed_identities_service/transports/grpc.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def __init__(
9494
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
9595
quota_project_id: Optional[str] = None,
9696
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
97+
always_use_jwt_access: Optional[bool] = False,
9798
) -> None:
9899
"""Instantiate the transport.
99100
@@ -134,6 +135,8 @@ def __init__(
134135
API requests. If ``None``, then default info will be used.
135136
Generally, you only need to set this if you're developing
136137
your own client library.
138+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
139+
be used for service account credentials.
137140
138141
Raises:
139142
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -187,7 +190,7 @@ def __init__(
187190
scopes=scopes,
188191
quota_project_id=quota_project_id,
189192
client_info=client_info,
190-
always_use_jwt_access=True,
193+
always_use_jwt_access=always_use_jwt_access,
191194
)
192195

193196
if not self._grpc_channel:

google/cloud/managedidentities_v1/services/managed_identities_service/transports/grpc_asyncio.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def __init__(
140140
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
141141
quota_project_id=None,
142142
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
143+
always_use_jwt_access: Optional[bool] = False,
143144
) -> None:
144145
"""Instantiate the transport.
145146
@@ -181,6 +182,8 @@ def __init__(
181182
API requests. If ``None``, then default info will be used.
182183
Generally, you only need to set this if you're developing
183184
your own client library.
185+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
186+
be used for service account credentials.
184187
185188
Raises:
186189
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -233,7 +236,7 @@ def __init__(
233236
scopes=scopes,
234237
quota_project_id=quota_project_id,
235238
client_info=client_info,
236-
always_use_jwt_access=True,
239+
always_use_jwt_access=always_use_jwt_access,
237240
)
238241

239242
if not self._grpc_channel:

tests/unit/gapic/managedidentities_v1/test_managed_identities_service.py

+22-4
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,25 @@ def test_managed_identities_service_client_service_account_always_use_jwt(client
143143
) as use_jwt:
144144
creds = service_account.Credentials(None, None, None)
145145
client = client_class(credentials=creds)
146-
use_jwt.assert_called_with(True)
146+
use_jwt.assert_not_called()
147+
148+
149+
@pytest.mark.parametrize(
150+
"transport_class,transport_name",
151+
[
152+
(transports.ManagedIdentitiesServiceGrpcTransport, "grpc"),
153+
(transports.ManagedIdentitiesServiceGrpcAsyncIOTransport, "grpc_asyncio"),
154+
],
155+
)
156+
def test_managed_identities_service_client_service_account_always_use_jwt_true(
157+
transport_class, transport_name
158+
):
159+
with mock.patch.object(
160+
service_account.Credentials, "with_always_use_jwt_access", create=True
161+
) as use_jwt:
162+
creds = service_account.Credentials(None, None, None)
163+
transport = transport_class(credentials=creds, always_use_jwt_access=True)
164+
use_jwt.assert_called_once_with(True)
147165

148166

149167
@pytest.mark.parametrize(
@@ -3210,7 +3228,7 @@ def test_managed_identities_service_grpc_transport_client_cert_source_for_mtls(
32103228
"squid.clam.whelk:443",
32113229
credentials=cred,
32123230
credentials_file=None,
3213-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
3231+
scopes=None,
32143232
ssl_credentials=mock_ssl_channel_creds,
32153233
quota_project_id=None,
32163234
options=[
@@ -3319,7 +3337,7 @@ def test_managed_identities_service_transport_channel_mtls_with_client_cert_sour
33193337
"mtls.squid.clam.whelk:443",
33203338
credentials=cred,
33213339
credentials_file=None,
3322-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
3340+
scopes=None,
33233341
ssl_credentials=mock_ssl_cred,
33243342
quota_project_id=None,
33253343
options=[
@@ -3366,7 +3384,7 @@ def test_managed_identities_service_transport_channel_mtls_with_adc(transport_cl
33663384
"mtls.squid.clam.whelk:443",
33673385
credentials=mock_cred,
33683386
credentials_file=None,
3369-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
3387+
scopes=None,
33703388
ssl_credentials=mock_ssl_cred,
33713389
quota_project_id=None,
33723390
options=[

0 commit comments

Comments
 (0)