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

Commit 911eb25

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

File tree

4 files changed

+31
-16
lines changed

4 files changed

+31
-16
lines changed

google/cloud/iot_v1/services/device_manager/transports/base.py

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

105105
# Save the scopes.
106-
self._scopes = scopes or self.AUTH_SCOPES
106+
self._scopes = scopes
107107

108108
# If no credentials are provided, then determine the appropriate
109109
# defaults.

google/cloud/iot_v1/services/device_manager/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:

google/cloud/iot_v1/services/device_manager/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:

tests/unit/gapic/iot_v1/test_device_manager.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,25 @@ def test_device_manager_client_service_account_always_use_jwt(client_class):
136136
) as use_jwt:
137137
creds = service_account.Credentials(None, None, None)
138138
client = client_class(credentials=creds)
139-
use_jwt.assert_called_with(True)
139+
use_jwt.assert_not_called()
140+
141+
142+
@pytest.mark.parametrize(
143+
"transport_class,transport_name",
144+
[
145+
(transports.DeviceManagerGrpcTransport, "grpc"),
146+
(transports.DeviceManagerGrpcAsyncIOTransport, "grpc_asyncio"),
147+
],
148+
)
149+
def test_device_manager_client_service_account_always_use_jwt_true(
150+
transport_class, transport_name
151+
):
152+
with mock.patch.object(
153+
service_account.Credentials, "with_always_use_jwt_access", create=True
154+
) as use_jwt:
155+
creds = service_account.Credentials(None, None, None)
156+
transport = transport_class(credentials=creds, always_use_jwt_access=True)
157+
use_jwt.assert_called_once_with(True)
140158

141159

142160
@pytest.mark.parametrize(
@@ -5333,10 +5351,7 @@ def test_device_manager_grpc_transport_client_cert_source_for_mtls(transport_cla
53335351
"squid.clam.whelk:443",
53345352
credentials=cred,
53355353
credentials_file=None,
5336-
scopes=(
5337-
"https://www.googleapis.com/auth/cloud-platform",
5338-
"https://www.googleapis.com/auth/cloudiot",
5339-
),
5354+
scopes=None,
53405355
ssl_credentials=mock_ssl_channel_creds,
53415356
quota_project_id=None,
53425357
options=[
@@ -5443,10 +5458,7 @@ def test_device_manager_transport_channel_mtls_with_client_cert_source(transport
54435458
"mtls.squid.clam.whelk:443",
54445459
credentials=cred,
54455460
credentials_file=None,
5446-
scopes=(
5447-
"https://www.googleapis.com/auth/cloud-platform",
5448-
"https://www.googleapis.com/auth/cloudiot",
5449-
),
5461+
scopes=None,
54505462
ssl_credentials=mock_ssl_cred,
54515463
quota_project_id=None,
54525464
options=[
@@ -5493,10 +5505,7 @@ def test_device_manager_transport_channel_mtls_with_adc(transport_class):
54935505
"mtls.squid.clam.whelk:443",
54945506
credentials=mock_cred,
54955507
credentials_file=None,
5496-
scopes=(
5497-
"https://www.googleapis.com/auth/cloud-platform",
5498-
"https://www.googleapis.com/auth/cloudiot",
5499-
),
5508+
scopes=None,
55005509
ssl_credentials=mock_ssl_cred,
55015510
quota_project_id=None,
55025511
options=[

0 commit comments

Comments
 (0)