Skip to content
This repository was archived by the owner on Mar 15, 2025. It is now read-only.

Commit b6bf93c

Browse files
fix: disable always_use_jwt_access (#62)
Committer: @busunkim96 PiperOrigin-RevId: 382142900 Source-Link: googleapis/googleapis@513440f Source-Link: googleapis/googleapis-gen@7b1e2c3
1 parent 53ec0a8 commit b6bf93c

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

google/cloud/orgpolicy_v2/services/org_policy/transports/base.py

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

101101
# Save the scopes.
102-
self._scopes = scopes or self.AUTH_SCOPES
102+
self._scopes = scopes
103103

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

google/cloud/orgpolicy_v2/services/org_policy/transports/grpc.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def __init__(
7979
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
8080
quota_project_id: Optional[str] = None,
8181
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
82+
always_use_jwt_access: Optional[bool] = False,
8283
) -> None:
8384
"""Instantiate the transport.
8485
@@ -119,6 +120,8 @@ def __init__(
119120
API requests. If ``None``, then default info will be used.
120121
Generally, you only need to set this if you're developing
121122
your own client library.
123+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
124+
be used for service account credentials.
122125
123126
Raises:
124127
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -171,7 +174,7 @@ def __init__(
171174
scopes=scopes,
172175
quota_project_id=quota_project_id,
173176
client_info=client_info,
174-
always_use_jwt_access=True,
177+
always_use_jwt_access=always_use_jwt_access,
175178
)
176179

177180
if not self._grpc_channel:

google/cloud/orgpolicy_v2/services/org_policy/transports/grpc_asyncio.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def __init__(
125125
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
126126
quota_project_id=None,
127127
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
128+
always_use_jwt_access: Optional[bool] = False,
128129
) -> None:
129130
"""Instantiate the transport.
130131
@@ -166,6 +167,8 @@ def __init__(
166167
API requests. If ``None``, then default info will be used.
167168
Generally, you only need to set this if you're developing
168169
your own client library.
170+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
171+
be used for service account credentials.
169172
170173
Raises:
171174
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -217,7 +220,7 @@ def __init__(
217220
scopes=scopes,
218221
quota_project_id=quota_project_id,
219222
client_info=client_info,
220-
always_use_jwt_access=True,
223+
always_use_jwt_access=always_use_jwt_access,
221224
)
222225

223226
if not self._grpc_channel:

tests/unit/gapic/orgpolicy_v2/test_org_policy.py

+22-4
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,25 @@ def test_org_policy_client_service_account_always_use_jwt(client_class):
121121
) as use_jwt:
122122
creds = service_account.Credentials(None, None, None)
123123
client = client_class(credentials=creds)
124-
use_jwt.assert_called_with(True)
124+
use_jwt.assert_not_called()
125+
126+
127+
@pytest.mark.parametrize(
128+
"transport_class,transport_name",
129+
[
130+
(transports.OrgPolicyGrpcTransport, "grpc"),
131+
(transports.OrgPolicyGrpcAsyncIOTransport, "grpc_asyncio"),
132+
],
133+
)
134+
def test_org_policy_client_service_account_always_use_jwt_true(
135+
transport_class, transport_name
136+
):
137+
with mock.patch.object(
138+
service_account.Credentials, "with_always_use_jwt_access", create=True
139+
) as use_jwt:
140+
creds = service_account.Credentials(None, None, None)
141+
transport = transport_class(credentials=creds, always_use_jwt_access=True)
142+
use_jwt.assert_called_once_with(True)
125143

126144

127145
@pytest.mark.parametrize("client_class", [OrgPolicyClient, OrgPolicyAsyncClient,])
@@ -2366,7 +2384,7 @@ def test_org_policy_grpc_transport_client_cert_source_for_mtls(transport_class):
23662384
"squid.clam.whelk:443",
23672385
credentials=cred,
23682386
credentials_file=None,
2369-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
2387+
scopes=None,
23702388
ssl_credentials=mock_ssl_channel_creds,
23712389
quota_project_id=None,
23722390
options=[
@@ -2470,7 +2488,7 @@ def test_org_policy_transport_channel_mtls_with_client_cert_source(transport_cla
24702488
"mtls.squid.clam.whelk:443",
24712489
credentials=cred,
24722490
credentials_file=None,
2473-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
2491+
scopes=None,
24742492
ssl_credentials=mock_ssl_cred,
24752493
quota_project_id=None,
24762494
options=[
@@ -2514,7 +2532,7 @@ def test_org_policy_transport_channel_mtls_with_adc(transport_class):
25142532
"mtls.squid.clam.whelk:443",
25152533
credentials=mock_cred,
25162534
credentials_file=None,
2517-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
2535+
scopes=None,
25182536
ssl_credentials=mock_ssl_cred,
25192537
quota_project_id=None,
25202538
options=[

0 commit comments

Comments
 (0)