Skip to content

Commit 4aa45a5

Browse files
fix: disable always_use_jwt_access (#100)
Committer: @busunkim96 PiperOrigin-RevId: 382142900 Source-Link: googleapis/googleapis@513440f Source-Link: googleapis/googleapis-gen@7b1e2c3
1 parent 7bdc8b2 commit 4aa45a5

File tree

8 files changed

+62
-35
lines changed

8 files changed

+62
-35
lines changed

packages/google-cloud-trace/google/cloud/trace_v1/services/trace_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-trace/google/cloud/trace_v1/services/trace_service/transports/grpc.py

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

161164
if not self._grpc_channel:

packages/google-cloud-trace/google/cloud/trace_v1/services/trace_service/transports/grpc_asyncio.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def __init__(
109109
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
110110
quota_project_id=None,
111111
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
112+
always_use_jwt_access: Optional[bool] = False,
112113
) -> None:
113114
"""Instantiate the transport.
114115
@@ -150,6 +151,8 @@ def __init__(
150151
API requests. If ``None``, then default info will be used.
151152
Generally, you only need to set this if you're developing
152153
your own client library.
154+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
155+
be used for service account credentials.
153156
154157
Raises:
155158
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -201,7 +204,7 @@ def __init__(
201204
scopes=scopes,
202205
quota_project_id=quota_project_id,
203206
client_info=client_info,
204-
always_use_jwt_access=True,
207+
always_use_jwt_access=always_use_jwt_access,
205208
)
206209

207210
if not self._grpc_channel:

packages/google-cloud-trace/google/cloud/trace_v2/services/trace_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-trace/google/cloud/trace_v2/services/trace_service/transports/grpc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __init__(
6464
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
6565
quota_project_id: Optional[str] = None,
6666
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
67+
always_use_jwt_access: Optional[bool] = False,
6768
) -> None:
6869
"""Instantiate the transport.
6970
@@ -104,6 +105,8 @@ def __init__(
104105
API requests. If ``None``, then default info will be used.
105106
Generally, you only need to set this if you're developing
106107
your own client library.
108+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
109+
be used for service account credentials.
107110
108111
Raises:
109112
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -156,7 +159,7 @@ def __init__(
156159
scopes=scopes,
157160
quota_project_id=quota_project_id,
158161
client_info=client_info,
159-
always_use_jwt_access=True,
162+
always_use_jwt_access=always_use_jwt_access,
160163
)
161164

162165
if not self._grpc_channel:

packages/google-cloud-trace/google/cloud/trace_v2/services/trace_service/transports/grpc_asyncio.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def __init__(
110110
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
111111
quota_project_id=None,
112112
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
113+
always_use_jwt_access: Optional[bool] = False,
113114
) -> None:
114115
"""Instantiate the transport.
115116
@@ -151,6 +152,8 @@ def __init__(
151152
API requests. If ``None``, then default info will be used.
152153
Generally, you only need to set this if you're developing
153154
your own client library.
155+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
156+
be used for service account credentials.
154157
155158
Raises:
156159
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -202,7 +205,7 @@ def __init__(
202205
scopes=scopes,
203206
quota_project_id=quota_project_id,
204207
client_info=client_info,
205-
always_use_jwt_access=True,
208+
always_use_jwt_access=always_use_jwt_access,
206209
)
207210

208211
if not self._grpc_channel:

packages/google-cloud-trace/tests/unit/gapic/trace_v1/test_trace_service.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,25 @@ def test_trace_service_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.TraceServiceGrpcTransport, "grpc"),
131+
(transports.TraceServiceGrpcAsyncIOTransport, "grpc_asyncio"),
132+
],
133+
)
134+
def test_trace_service_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", [TraceServiceClient, TraceServiceAsyncClient,])
@@ -1319,11 +1337,7 @@ def test_trace_service_grpc_transport_client_cert_source_for_mtls(transport_clas
13191337
"squid.clam.whelk:443",
13201338
credentials=cred,
13211339
credentials_file=None,
1322-
scopes=(
1323-
"https://www.googleapis.com/auth/cloud-platform",
1324-
"https://www.googleapis.com/auth/trace.append",
1325-
"https://www.googleapis.com/auth/trace.readonly",
1326-
),
1340+
scopes=None,
13271341
ssl_credentials=mock_ssl_channel_creds,
13281342
quota_project_id=None,
13291343
options=[
@@ -1427,11 +1441,7 @@ def test_trace_service_transport_channel_mtls_with_client_cert_source(transport_
14271441
"mtls.squid.clam.whelk:443",
14281442
credentials=cred,
14291443
credentials_file=None,
1430-
scopes=(
1431-
"https://www.googleapis.com/auth/cloud-platform",
1432-
"https://www.googleapis.com/auth/trace.append",
1433-
"https://www.googleapis.com/auth/trace.readonly",
1434-
),
1444+
scopes=None,
14351445
ssl_credentials=mock_ssl_cred,
14361446
quota_project_id=None,
14371447
options=[
@@ -1475,11 +1485,7 @@ def test_trace_service_transport_channel_mtls_with_adc(transport_class):
14751485
"mtls.squid.clam.whelk:443",
14761486
credentials=mock_cred,
14771487
credentials_file=None,
1478-
scopes=(
1479-
"https://www.googleapis.com/auth/cloud-platform",
1480-
"https://www.googleapis.com/auth/trace.append",
1481-
"https://www.googleapis.com/auth/trace.readonly",
1482-
),
1488+
scopes=None,
14831489
ssl_credentials=mock_ssl_cred,
14841490
quota_project_id=None,
14851491
options=[

packages/google-cloud-trace/tests/unit/gapic/trace_v2/test_trace_service.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,25 @@ def test_trace_service_client_service_account_always_use_jwt(client_class):
124124
) as use_jwt:
125125
creds = service_account.Credentials(None, None, None)
126126
client = client_class(credentials=creds)
127-
use_jwt.assert_called_with(True)
127+
use_jwt.assert_not_called()
128+
129+
130+
@pytest.mark.parametrize(
131+
"transport_class,transport_name",
132+
[
133+
(transports.TraceServiceGrpcTransport, "grpc"),
134+
(transports.TraceServiceGrpcAsyncIOTransport, "grpc_asyncio"),
135+
],
136+
)
137+
def test_trace_service_client_service_account_always_use_jwt_true(
138+
transport_class, transport_name
139+
):
140+
with mock.patch.object(
141+
service_account.Credentials, "with_always_use_jwt_access", create=True
142+
) as use_jwt:
143+
creds = service_account.Credentials(None, None, None)
144+
transport = transport_class(credentials=creds, always_use_jwt_access=True)
145+
use_jwt.assert_called_once_with(True)
128146

129147

130148
@pytest.mark.parametrize("client_class", [TraceServiceClient, TraceServiceAsyncClient,])
@@ -1114,10 +1132,7 @@ def test_trace_service_grpc_transport_client_cert_source_for_mtls(transport_clas
11141132
"squid.clam.whelk:443",
11151133
credentials=cred,
11161134
credentials_file=None,
1117-
scopes=(
1118-
"https://www.googleapis.com/auth/cloud-platform",
1119-
"https://www.googleapis.com/auth/trace.append",
1120-
),
1135+
scopes=None,
11211136
ssl_credentials=mock_ssl_channel_creds,
11221137
quota_project_id=None,
11231138
options=[
@@ -1221,10 +1236,7 @@ def test_trace_service_transport_channel_mtls_with_client_cert_source(transport_
12211236
"mtls.squid.clam.whelk:443",
12221237
credentials=cred,
12231238
credentials_file=None,
1224-
scopes=(
1225-
"https://www.googleapis.com/auth/cloud-platform",
1226-
"https://www.googleapis.com/auth/trace.append",
1227-
),
1239+
scopes=None,
12281240
ssl_credentials=mock_ssl_cred,
12291241
quota_project_id=None,
12301242
options=[
@@ -1268,10 +1280,7 @@ def test_trace_service_transport_channel_mtls_with_adc(transport_class):
12681280
"mtls.squid.clam.whelk:443",
12691281
credentials=mock_cred,
12701282
credentials_file=None,
1271-
scopes=(
1272-
"https://www.googleapis.com/auth/cloud-platform",
1273-
"https://www.googleapis.com/auth/trace.append",
1274-
),
1283+
scopes=None,
12751284
ssl_credentials=mock_ssl_cred,
12761285
quota_project_id=None,
12771286
options=[

0 commit comments

Comments
 (0)