Skip to content

Commit 1bd2f44

Browse files
fix: disable always_use_jwt_access (#92)
Committer: @busunkim96 PiperOrigin-RevId: 382142900 Source-Link: googleapis/googleapis@513440f Source-Link: googleapis/googleapis-gen@7b1e2c3
1 parent 3460db1 commit 1bd2f44

File tree

4 files changed

+31
-16
lines changed

4 files changed

+31
-16
lines changed

packages/google-cloud-os-login/google/cloud/oslogin_v1/services/os_login_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.

packages/google-cloud-os-login/google/cloud/oslogin_v1/services/os_login_service/transports/grpc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def __init__(
6262
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
6363
quota_project_id: Optional[str] = None,
6464
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
65+
always_use_jwt_access: Optional[bool] = False,
6566
) -> None:
6667
"""Instantiate the transport.
6768
@@ -102,6 +103,8 @@ def __init__(
102103
API requests. If ``None``, then default info will be used.
103104
Generally, you only need to set this if you're developing
104105
your own client library.
106+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
107+
be used for service account credentials.
105108
106109
Raises:
107110
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -154,7 +157,7 @@ def __init__(
154157
scopes=scopes,
155158
quota_project_id=quota_project_id,
156159
client_info=client_info,
157-
always_use_jwt_access=True,
160+
always_use_jwt_access=always_use_jwt_access,
158161
)
159162

160163
if not self._grpc_channel:

packages/google-cloud-os-login/google/cloud/oslogin_v1/services/os_login_service/transports/grpc_asyncio.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def __init__(
108108
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
109109
quota_project_id=None,
110110
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
111+
always_use_jwt_access: Optional[bool] = False,
111112
) -> None:
112113
"""Instantiate the transport.
113114
@@ -149,6 +150,8 @@ def __init__(
149150
API requests. If ``None``, then default info will be used.
150151
Generally, you only need to set this if you're developing
151152
your own client library.
153+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
154+
be used for service account credentials.
152155
153156
Raises:
154157
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -200,7 +203,7 @@ def __init__(
200203
scopes=scopes,
201204
quota_project_id=quota_project_id,
202205
client_info=client_info,
203-
always_use_jwt_access=True,
206+
always_use_jwt_access=always_use_jwt_access,
204207
)
205208

206209
if not self._grpc_channel:

packages/google-cloud-os-login/tests/unit/gapic/oslogin_v1/test_os_login_service.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,25 @@ def test_os_login_service_client_service_account_always_use_jwt(client_class):
128128
) as use_jwt:
129129
creds = service_account.Credentials(None, None, None)
130130
client = client_class(credentials=creds)
131-
use_jwt.assert_called_with(True)
131+
use_jwt.assert_not_called()
132+
133+
134+
@pytest.mark.parametrize(
135+
"transport_class,transport_name",
136+
[
137+
(transports.OsLoginServiceGrpcTransport, "grpc"),
138+
(transports.OsLoginServiceGrpcAsyncIOTransport, "grpc_asyncio"),
139+
],
140+
)
141+
def test_os_login_service_client_service_account_always_use_jwt_true(
142+
transport_class, transport_name
143+
):
144+
with mock.patch.object(
145+
service_account.Credentials, "with_always_use_jwt_access", create=True
146+
) as use_jwt:
147+
creds = service_account.Credentials(None, None, None)
148+
transport = transport_class(credentials=creds, always_use_jwt_access=True)
149+
use_jwt.assert_called_once_with(True)
132150

133151

134152
@pytest.mark.parametrize(
@@ -2115,10 +2133,7 @@ def test_os_login_service_grpc_transport_client_cert_source_for_mtls(transport_c
21152133
"squid.clam.whelk:443",
21162134
credentials=cred,
21172135
credentials_file=None,
2118-
scopes=(
2119-
"https://www.googleapis.com/auth/cloud-platform",
2120-
"https://www.googleapis.com/auth/compute",
2121-
),
2136+
scopes=None,
21222137
ssl_credentials=mock_ssl_channel_creds,
21232138
quota_project_id=None,
21242139
options=[
@@ -2227,10 +2242,7 @@ def test_os_login_service_transport_channel_mtls_with_client_cert_source(
22272242
"mtls.squid.clam.whelk:443",
22282243
credentials=cred,
22292244
credentials_file=None,
2230-
scopes=(
2231-
"https://www.googleapis.com/auth/cloud-platform",
2232-
"https://www.googleapis.com/auth/compute",
2233-
),
2245+
scopes=None,
22342246
ssl_credentials=mock_ssl_cred,
22352247
quota_project_id=None,
22362248
options=[
@@ -2277,10 +2289,7 @@ def test_os_login_service_transport_channel_mtls_with_adc(transport_class):
22772289
"mtls.squid.clam.whelk:443",
22782290
credentials=mock_cred,
22792291
credentials_file=None,
2280-
scopes=(
2281-
"https://www.googleapis.com/auth/cloud-platform",
2282-
"https://www.googleapis.com/auth/compute",
2283-
),
2292+
scopes=None,
22842293
ssl_credentials=mock_ssl_cred,
22852294
quota_project_id=None,
22862295
options=[

0 commit comments

Comments
 (0)