Skip to content

Commit 7d58f2e

Browse files
fix: disable always_use_jwt_access (#126)
Committer: @busunkim96 PiperOrigin-RevId: 382142900 Source-Link: googleapis/googleapis@513440f Source-Link: googleapis/googleapis-gen@7b1e2c3
1 parent 9099ac1 commit 7d58f2e

File tree

12 files changed

+93
-21
lines changed

12 files changed

+93
-21
lines changed

packages/google-cloud-tasks/google/cloud/tasks_v2/services/cloud_tasks/transports/base.py

+1-1
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.

packages/google-cloud-tasks/google/cloud/tasks_v2/services/cloud_tasks/transports/grpc.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def __init__(
6565
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
6666
quota_project_id: Optional[str] = None,
6767
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
68+
always_use_jwt_access: Optional[bool] = False,
6869
) -> None:
6970
"""Instantiate the transport.
7071
@@ -105,6 +106,8 @@ def __init__(
105106
API requests. If ``None``, then default info will be used.
106107
Generally, you only need to set this if you're developing
107108
your own client library.
109+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
110+
be used for service account credentials.
108111
109112
Raises:
110113
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -157,7 +160,7 @@ def __init__(
157160
scopes=scopes,
158161
quota_project_id=quota_project_id,
159162
client_info=client_info,
160-
always_use_jwt_access=True,
163+
always_use_jwt_access=always_use_jwt_access,
161164
)
162165

163166
if not self._grpc_channel:

packages/google-cloud-tasks/google/cloud/tasks_v2/services/cloud_tasks/transports/grpc_asyncio.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def __init__(
111111
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
112112
quota_project_id=None,
113113
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
114+
always_use_jwt_access: Optional[bool] = False,
114115
) -> None:
115116
"""Instantiate the transport.
116117
@@ -152,6 +153,8 @@ def __init__(
152153
API requests. If ``None``, then default info will be used.
153154
Generally, you only need to set this if you're developing
154155
your own client library.
156+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
157+
be used for service account credentials.
155158
156159
Raises:
157160
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -203,7 +206,7 @@ def __init__(
203206
scopes=scopes,
204207
quota_project_id=quota_project_id,
205208
client_info=client_info,
206-
always_use_jwt_access=True,
209+
always_use_jwt_access=always_use_jwt_access,
207210
)
208211

209212
if not self._grpc_channel:

packages/google-cloud-tasks/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/base.py

+1-1
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.

packages/google-cloud-tasks/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/grpc.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def __init__(
6565
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
6666
quota_project_id: Optional[str] = None,
6767
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
68+
always_use_jwt_access: Optional[bool] = False,
6869
) -> None:
6970
"""Instantiate the transport.
7071
@@ -105,6 +106,8 @@ def __init__(
105106
API requests. If ``None``, then default info will be used.
106107
Generally, you only need to set this if you're developing
107108
your own client library.
109+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
110+
be used for service account credentials.
108111
109112
Raises:
110113
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -157,7 +160,7 @@ def __init__(
157160
scopes=scopes,
158161
quota_project_id=quota_project_id,
159162
client_info=client_info,
160-
always_use_jwt_access=True,
163+
always_use_jwt_access=always_use_jwt_access,
161164
)
162165

163166
if not self._grpc_channel:

packages/google-cloud-tasks/google/cloud/tasks_v2beta2/services/cloud_tasks/transports/grpc_asyncio.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def __init__(
111111
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
112112
quota_project_id=None,
113113
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
114+
always_use_jwt_access: Optional[bool] = False,
114115
) -> None:
115116
"""Instantiate the transport.
116117
@@ -152,6 +153,8 @@ def __init__(
152153
API requests. If ``None``, then default info will be used.
153154
Generally, you only need to set this if you're developing
154155
your own client library.
156+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
157+
be used for service account credentials.
155158
156159
Raises:
157160
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -203,7 +206,7 @@ def __init__(
203206
scopes=scopes,
204207
quota_project_id=quota_project_id,
205208
client_info=client_info,
206-
always_use_jwt_access=True,
209+
always_use_jwt_access=always_use_jwt_access,
207210
)
208211

209212
if not self._grpc_channel:

packages/google-cloud-tasks/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/base.py

+1-1
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.

packages/google-cloud-tasks/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/grpc.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def __init__(
6565
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
6666
quota_project_id: Optional[str] = None,
6767
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
68+
always_use_jwt_access: Optional[bool] = False,
6869
) -> None:
6970
"""Instantiate the transport.
7071
@@ -105,6 +106,8 @@ def __init__(
105106
API requests. If ``None``, then default info will be used.
106107
Generally, you only need to set this if you're developing
107108
your own client library.
109+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
110+
be used for service account credentials.
108111
109112
Raises:
110113
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -157,7 +160,7 @@ def __init__(
157160
scopes=scopes,
158161
quota_project_id=quota_project_id,
159162
client_info=client_info,
160-
always_use_jwt_access=True,
163+
always_use_jwt_access=always_use_jwt_access,
161164
)
162165

163166
if not self._grpc_channel:

packages/google-cloud-tasks/google/cloud/tasks_v2beta3/services/cloud_tasks/transports/grpc_asyncio.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def __init__(
111111
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
112112
quota_project_id=None,
113113
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
114+
always_use_jwt_access: Optional[bool] = False,
114115
) -> None:
115116
"""Instantiate the transport.
116117
@@ -152,6 +153,8 @@ def __init__(
152153
API requests. If ``None``, then default info will be used.
153154
Generally, you only need to set this if you're developing
154155
your own client library.
156+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
157+
be used for service account credentials.
155158
156159
Raises:
157160
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -203,7 +206,7 @@ def __init__(
203206
scopes=scopes,
204207
quota_project_id=quota_project_id,
205208
client_info=client_info,
206-
always_use_jwt_access=True,
209+
always_use_jwt_access=always_use_jwt_access,
207210
)
208211

209212
if not self._grpc_channel:

packages/google-cloud-tasks/tests/unit/gapic/tasks_v2/test_cloud_tasks.py

+22-4
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,25 @@ def test_cloud_tasks_client_service_account_always_use_jwt(client_class):
134134
) as use_jwt:
135135
creds = service_account.Credentials(None, None, None)
136136
client = client_class(credentials=creds)
137-
use_jwt.assert_called_with(True)
137+
use_jwt.assert_not_called()
138+
139+
140+
@pytest.mark.parametrize(
141+
"transport_class,transport_name",
142+
[
143+
(transports.CloudTasksGrpcTransport, "grpc"),
144+
(transports.CloudTasksGrpcAsyncIOTransport, "grpc_asyncio"),
145+
],
146+
)
147+
def test_cloud_tasks_client_service_account_always_use_jwt_true(
148+
transport_class, transport_name
149+
):
150+
with mock.patch.object(
151+
service_account.Credentials, "with_always_use_jwt_access", create=True
152+
) as use_jwt:
153+
creds = service_account.Credentials(None, None, None)
154+
transport = transport_class(credentials=creds, always_use_jwt_access=True)
155+
use_jwt.assert_called_once_with(True)
138156

139157

140158
@pytest.mark.parametrize("client_class", [CloudTasksClient, CloudTasksAsyncClient,])
@@ -4233,7 +4251,7 @@ def test_cloud_tasks_grpc_transport_client_cert_source_for_mtls(transport_class)
42334251
"squid.clam.whelk:443",
42344252
credentials=cred,
42354253
credentials_file=None,
4236-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
4254+
scopes=None,
42374255
ssl_credentials=mock_ssl_channel_creds,
42384256
quota_project_id=None,
42394257
options=[
@@ -4337,7 +4355,7 @@ def test_cloud_tasks_transport_channel_mtls_with_client_cert_source(transport_cl
43374355
"mtls.squid.clam.whelk:443",
43384356
credentials=cred,
43394357
credentials_file=None,
4340-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
4358+
scopes=None,
43414359
ssl_credentials=mock_ssl_cred,
43424360
quota_project_id=None,
43434361
options=[
@@ -4381,7 +4399,7 @@ def test_cloud_tasks_transport_channel_mtls_with_adc(transport_class):
43814399
"mtls.squid.clam.whelk:443",
43824400
credentials=mock_cred,
43834401
credentials_file=None,
4384-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
4402+
scopes=None,
43854403
ssl_credentials=mock_ssl_cred,
43864404
quota_project_id=None,
43874405
options=[

packages/google-cloud-tasks/tests/unit/gapic/tasks_v2beta2/test_cloud_tasks.py

+22-4
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,25 @@ def test_cloud_tasks_client_service_account_always_use_jwt(client_class):
134134
) as use_jwt:
135135
creds = service_account.Credentials(None, None, None)
136136
client = client_class(credentials=creds)
137-
use_jwt.assert_called_with(True)
137+
use_jwt.assert_not_called()
138+
139+
140+
@pytest.mark.parametrize(
141+
"transport_class,transport_name",
142+
[
143+
(transports.CloudTasksGrpcTransport, "grpc"),
144+
(transports.CloudTasksGrpcAsyncIOTransport, "grpc_asyncio"),
145+
],
146+
)
147+
def test_cloud_tasks_client_service_account_always_use_jwt_true(
148+
transport_class, transport_name
149+
):
150+
with mock.patch.object(
151+
service_account.Credentials, "with_always_use_jwt_access", create=True
152+
) as use_jwt:
153+
creds = service_account.Credentials(None, None, None)
154+
transport = transport_class(credentials=creds, always_use_jwt_access=True)
155+
use_jwt.assert_called_once_with(True)
138156

139157

140158
@pytest.mark.parametrize("client_class", [CloudTasksClient, CloudTasksAsyncClient,])
@@ -5090,7 +5108,7 @@ def test_cloud_tasks_grpc_transport_client_cert_source_for_mtls(transport_class)
50905108
"squid.clam.whelk:443",
50915109
credentials=cred,
50925110
credentials_file=None,
5093-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
5111+
scopes=None,
50945112
ssl_credentials=mock_ssl_channel_creds,
50955113
quota_project_id=None,
50965114
options=[
@@ -5194,7 +5212,7 @@ def test_cloud_tasks_transport_channel_mtls_with_client_cert_source(transport_cl
51945212
"mtls.squid.clam.whelk:443",
51955213
credentials=cred,
51965214
credentials_file=None,
5197-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
5215+
scopes=None,
51985216
ssl_credentials=mock_ssl_cred,
51995217
quota_project_id=None,
52005218
options=[
@@ -5238,7 +5256,7 @@ def test_cloud_tasks_transport_channel_mtls_with_adc(transport_class):
52385256
"mtls.squid.clam.whelk:443",
52395257
credentials=mock_cred,
52405258
credentials_file=None,
5241-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
5259+
scopes=None,
52425260
ssl_credentials=mock_ssl_cred,
52435261
quota_project_id=None,
52445262
options=[

packages/google-cloud-tasks/tests/unit/gapic/tasks_v2beta3/test_cloud_tasks.py

+22-4
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,25 @@ def test_cloud_tasks_client_service_account_always_use_jwt(client_class):
134134
) as use_jwt:
135135
creds = service_account.Credentials(None, None, None)
136136
client = client_class(credentials=creds)
137-
use_jwt.assert_called_with(True)
137+
use_jwt.assert_not_called()
138+
139+
140+
@pytest.mark.parametrize(
141+
"transport_class,transport_name",
142+
[
143+
(transports.CloudTasksGrpcTransport, "grpc"),
144+
(transports.CloudTasksGrpcAsyncIOTransport, "grpc_asyncio"),
145+
],
146+
)
147+
def test_cloud_tasks_client_service_account_always_use_jwt_true(
148+
transport_class, transport_name
149+
):
150+
with mock.patch.object(
151+
service_account.Credentials, "with_always_use_jwt_access", create=True
152+
) as use_jwt:
153+
creds = service_account.Credentials(None, None, None)
154+
transport = transport_class(credentials=creds, always_use_jwt_access=True)
155+
use_jwt.assert_called_once_with(True)
138156

139157

140158
@pytest.mark.parametrize("client_class", [CloudTasksClient, CloudTasksAsyncClient,])
@@ -4311,7 +4329,7 @@ def test_cloud_tasks_grpc_transport_client_cert_source_for_mtls(transport_class)
43114329
"squid.clam.whelk:443",
43124330
credentials=cred,
43134331
credentials_file=None,
4314-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
4332+
scopes=None,
43154333
ssl_credentials=mock_ssl_channel_creds,
43164334
quota_project_id=None,
43174335
options=[
@@ -4415,7 +4433,7 @@ def test_cloud_tasks_transport_channel_mtls_with_client_cert_source(transport_cl
44154433
"mtls.squid.clam.whelk:443",
44164434
credentials=cred,
44174435
credentials_file=None,
4418-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
4436+
scopes=None,
44194437
ssl_credentials=mock_ssl_cred,
44204438
quota_project_id=None,
44214439
options=[
@@ -4459,7 +4477,7 @@ def test_cloud_tasks_transport_channel_mtls_with_adc(transport_class):
44594477
"mtls.squid.clam.whelk:443",
44604478
credentials=mock_cred,
44614479
credentials_file=None,
4462-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
4480+
scopes=None,
44634481
ssl_credentials=mock_ssl_cred,
44644482
quota_project_id=None,
44654483
options=[

0 commit comments

Comments
 (0)