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

Commit b03acdf

Browse files
fix: disable always_use_jwt_access (#15)
fix: disable always_use_jwt_access Committer: @busunkim96 PiperOrigin-RevId: 382142900 Source-Link: googleapis/googleapis@513440f Source-Link: https://github.com/googleapis/googleapis-gen/commit/7b1e2c31233f79a704ec21ca410bf661d6bc68d0
1 parent 9b62029 commit b03acdf

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

google/cloud/tpu_v1/services/tpu/transports/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def __init__(
9898
scopes_kwargs = self._get_scopes_kwargs(self._host, scopes)
9999

100100
# Save the scopes.
101-
self._scopes = scopes or self.AUTH_SCOPES
101+
self._scopes = scopes
102102

103103
# If no credentials are provided, then determine the appropriate
104104
# defaults.

google/cloud/tpu_v1/services/tpu/transports/grpc.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def __init__(
6060
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
6161
quota_project_id: Optional[str] = None,
6262
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
63+
always_use_jwt_access: Optional[bool] = False,
6364
) -> None:
6465
"""Instantiate the transport.
6566
@@ -100,6 +101,8 @@ def __init__(
100101
API requests. If ``None``, then default info will be used.
101102
Generally, you only need to set this if you're developing
102103
your own client library.
104+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
105+
be used for service account credentials.
103106
104107
Raises:
105108
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -153,7 +156,7 @@ def __init__(
153156
scopes=scopes,
154157
quota_project_id=quota_project_id,
155158
client_info=client_info,
156-
always_use_jwt_access=True,
159+
always_use_jwt_access=always_use_jwt_access,
157160
)
158161

159162
if not self._grpc_channel:

google/cloud/tpu_v1/services/tpu/transports/grpc_asyncio.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def __init__(
106106
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
107107
quota_project_id=None,
108108
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
109+
always_use_jwt_access: Optional[bool] = False,
109110
) -> None:
110111
"""Instantiate the transport.
111112
@@ -147,6 +148,8 @@ def __init__(
147148
API requests. If ``None``, then default info will be used.
148149
Generally, you only need to set this if you're developing
149150
your own client library.
151+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
152+
be used for service account credentials.
150153
151154
Raises:
152155
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -199,7 +202,7 @@ def __init__(
199202
scopes=scopes,
200203
quota_project_id=quota_project_id,
201204
client_info=client_info,
202-
always_use_jwt_access=True,
205+
always_use_jwt_access=always_use_jwt_access,
203206
)
204207

205208
if not self._grpc_channel:

tests/unit/gapic/tpu_v1/test_tpu.py

+22-4
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,25 @@ def test_tpu_client_service_account_always_use_jwt(client_class):
117117
) as use_jwt:
118118
creds = service_account.Credentials(None, None, None)
119119
client = client_class(credentials=creds)
120-
use_jwt.assert_called_with(True)
120+
use_jwt.assert_not_called()
121+
122+
123+
@pytest.mark.parametrize(
124+
"transport_class,transport_name",
125+
[
126+
(transports.TpuGrpcTransport, "grpc"),
127+
(transports.TpuGrpcAsyncIOTransport, "grpc_asyncio"),
128+
],
129+
)
130+
def test_tpu_client_service_account_always_use_jwt_true(
131+
transport_class, transport_name
132+
):
133+
with mock.patch.object(
134+
service_account.Credentials, "with_always_use_jwt_access", create=True
135+
) as use_jwt:
136+
creds = service_account.Credentials(None, None, None)
137+
transport = transport_class(credentials=creds, always_use_jwt_access=True)
138+
use_jwt.assert_called_once_with(True)
121139

122140

123141
@pytest.mark.parametrize("client_class", [TpuClient, TpuAsyncClient,])
@@ -3248,7 +3266,7 @@ def test_tpu_grpc_transport_client_cert_source_for_mtls(transport_class):
32483266
"squid.clam.whelk:443",
32493267
credentials=cred,
32503268
credentials_file=None,
3251-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
3269+
scopes=None,
32523270
ssl_credentials=mock_ssl_channel_creds,
32533271
quota_project_id=None,
32543272
options=[
@@ -3347,7 +3365,7 @@ def test_tpu_transport_channel_mtls_with_client_cert_source(transport_class):
33473365
"mtls.squid.clam.whelk:443",
33483366
credentials=cred,
33493367
credentials_file=None,
3350-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
3368+
scopes=None,
33513369
ssl_credentials=mock_ssl_cred,
33523370
quota_project_id=None,
33533371
options=[
@@ -3390,7 +3408,7 @@ def test_tpu_transport_channel_mtls_with_adc(transport_class):
33903408
"mtls.squid.clam.whelk:443",
33913409
credentials=mock_cred,
33923410
credentials_file=None,
3393-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
3411+
scopes=None,
33943412
ssl_credentials=mock_ssl_cred,
33953413
quota_project_id=None,
33963414
options=[

0 commit comments

Comments
 (0)