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

Commit 0880d9a

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

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

google/cloud/iam_credentials_v1/services/iam_credentials/transports/base.py

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

9898
# Save the scopes.
99-
self._scopes = scopes or self.AUTH_SCOPES
99+
self._scopes = scopes
100100

101101
# If no credentials are provided, then determine the appropriate
102102
# defaults.

google/cloud/iam_credentials_v1/services/iam_credentials/transports/grpc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def __init__(
6666
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
6767
quota_project_id: Optional[str] = None,
6868
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
69+
always_use_jwt_access: Optional[bool] = False,
6970
) -> None:
7071
"""Instantiate the transport.
7172
@@ -106,6 +107,8 @@ def __init__(
106107
API requests. If ``None``, then default info will be used.
107108
Generally, you only need to set this if you're developing
108109
your own client library.
110+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
111+
be used for service account credentials.
109112
110113
Raises:
111114
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -158,7 +161,7 @@ def __init__(
158161
scopes=scopes,
159162
quota_project_id=quota_project_id,
160163
client_info=client_info,
161-
always_use_jwt_access=True,
164+
always_use_jwt_access=always_use_jwt_access,
162165
)
163166

164167
if not self._grpc_channel:

google/cloud/iam_credentials_v1/services/iam_credentials/transports/grpc_asyncio.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def __init__(
112112
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
113113
quota_project_id=None,
114114
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
115+
always_use_jwt_access: Optional[bool] = False,
115116
) -> None:
116117
"""Instantiate the transport.
117118
@@ -153,6 +154,8 @@ def __init__(
153154
API requests. If ``None``, then default info will be used.
154155
Generally, you only need to set this if you're developing
155156
your own client library.
157+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
158+
be used for service account credentials.
156159
157160
Raises:
158161
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -204,7 +207,7 @@ def __init__(
204207
scopes=scopes,
205208
quota_project_id=quota_project_id,
206209
client_info=client_info,
207-
always_use_jwt_access=True,
210+
always_use_jwt_access=always_use_jwt_access,
208211
)
209212

210213
if not self._grpc_channel:

tests/unit/gapic/credentials_v1/test_iam_credentials.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,25 @@ def test_iam_credentials_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.IAMCredentialsGrpcTransport, "grpc"),
142+
(transports.IAMCredentialsGrpcAsyncIOTransport, "grpc_asyncio"),
143+
],
144+
)
145+
def test_iam_credentials_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(
@@ -1684,7 +1702,7 @@ def test_iam_credentials_grpc_transport_client_cert_source_for_mtls(transport_cl
16841702
"squid.clam.whelk:443",
16851703
credentials=cred,
16861704
credentials_file=None,
1687-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
1705+
scopes=None,
16881706
ssl_credentials=mock_ssl_channel_creds,
16891707
quota_project_id=None,
16901708
options=[
@@ -1793,7 +1811,7 @@ def test_iam_credentials_transport_channel_mtls_with_client_cert_source(
17931811
"mtls.squid.clam.whelk:443",
17941812
credentials=cred,
17951813
credentials_file=None,
1796-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
1814+
scopes=None,
17971815
ssl_credentials=mock_ssl_cred,
17981816
quota_project_id=None,
17991817
options=[
@@ -1840,7 +1858,7 @@ def test_iam_credentials_transport_channel_mtls_with_adc(transport_class):
18401858
"mtls.squid.clam.whelk:443",
18411859
credentials=mock_cred,
18421860
credentials_file=None,
1843-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
1861+
scopes=None,
18441862
ssl_credentials=mock_ssl_cred,
18451863
quota_project_id=None,
18461864
options=[

0 commit comments

Comments
 (0)