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

Commit 5431e8b

Browse files
fix: disable always_use_jwt_access (#174)
Committer: @busunkim96 PiperOrigin-RevId: 382142900 Source-Link: googleapis/googleapis@513440f Source-Link: https://github.com/googleapis/googleapis-gen/commit/7b1e2c31233f79a704ec21ca410bf661d6bc68d0
1 parent 350e81e commit 5431e8b

File tree

12 files changed

+93
-21
lines changed

12 files changed

+93
-21
lines changed

google/cloud/securitycenter_v1/services/security_center/transports/base.py

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

118118
# Save the scopes.
119-
self._scopes = scopes or self.AUTH_SCOPES
119+
self._scopes = scopes
120120

121121
# If no credentials are provided, then determine the appropriate
122122
# defaults.

google/cloud/securitycenter_v1/services/security_center/transports/grpc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def __init__(
7575
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
7676
quota_project_id: Optional[str] = None,
7777
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
78+
always_use_jwt_access: Optional[bool] = False,
7879
) -> None:
7980
"""Instantiate the transport.
8081
@@ -115,6 +116,8 @@ def __init__(
115116
API requests. If ``None``, then default info will be used.
116117
Generally, you only need to set this if you're developing
117118
your own client library.
119+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
120+
be used for service account credentials.
118121
119122
Raises:
120123
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -168,7 +171,7 @@ def __init__(
168171
scopes=scopes,
169172
quota_project_id=quota_project_id,
170173
client_info=client_info,
171-
always_use_jwt_access=True,
174+
always_use_jwt_access=always_use_jwt_access,
172175
)
173176

174177
if not self._grpc_channel:

google/cloud/securitycenter_v1/services/security_center/transports/grpc_asyncio.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ def __init__(
121121
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
122122
quota_project_id=None,
123123
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
124+
always_use_jwt_access: Optional[bool] = False,
124125
) -> None:
125126
"""Instantiate the transport.
126127
@@ -162,6 +163,8 @@ def __init__(
162163
API requests. If ``None``, then default info will be used.
163164
Generally, you only need to set this if you're developing
164165
your own client library.
166+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
167+
be used for service account credentials.
165168
166169
Raises:
167170
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -214,7 +217,7 @@ def __init__(
214217
scopes=scopes,
215218
quota_project_id=quota_project_id,
216219
client_info=client_info,
217-
always_use_jwt_access=True,
220+
always_use_jwt_access=always_use_jwt_access,
218221
)
219222

220223
if not self._grpc_channel:

google/cloud/securitycenter_v1beta1/services/security_center/transports/base.py

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

115115
# Save the scopes.
116-
self._scopes = scopes or self.AUTH_SCOPES
116+
self._scopes = scopes
117117

118118
# If no credentials are provided, then determine the appropriate
119119
# defaults.

google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def __init__(
7272
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
7373
quota_project_id: Optional[str] = None,
7474
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
75+
always_use_jwt_access: Optional[bool] = False,
7576
) -> None:
7677
"""Instantiate the transport.
7778
@@ -112,6 +113,8 @@ def __init__(
112113
API requests. If ``None``, then default info will be used.
113114
Generally, you only need to set this if you're developing
114115
your own client library.
116+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
117+
be used for service account credentials.
115118
116119
Raises:
117120
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -165,7 +168,7 @@ def __init__(
165168
scopes=scopes,
166169
quota_project_id=quota_project_id,
167170
client_info=client_info,
168-
always_use_jwt_access=True,
171+
always_use_jwt_access=always_use_jwt_access,
169172
)
170173

171174
if not self._grpc_channel:

google/cloud/securitycenter_v1beta1/services/security_center/transports/grpc_asyncio.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def __init__(
118118
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
119119
quota_project_id=None,
120120
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
121+
always_use_jwt_access: Optional[bool] = False,
121122
) -> None:
122123
"""Instantiate the transport.
123124
@@ -159,6 +160,8 @@ def __init__(
159160
API requests. If ``None``, then default info will be used.
160161
Generally, you only need to set this if you're developing
161162
your own client library.
163+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
164+
be used for service account credentials.
162165
163166
Raises:
164167
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -211,7 +214,7 @@ def __init__(
211214
scopes=scopes,
212215
quota_project_id=quota_project_id,
213216
client_info=client_info,
214-
always_use_jwt_access=True,
217+
always_use_jwt_access=always_use_jwt_access,
215218
)
216219

217220
if not self._grpc_channel:

google/cloud/securitycenter_v1p1beta1/services/security_center/transports/base.py

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

120120
# Save the scopes.
121-
self._scopes = scopes or self.AUTH_SCOPES
121+
self._scopes = scopes
122122

123123
# If no credentials are provided, then determine the appropriate
124124
# defaults.

google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def __init__(
7777
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
7878
quota_project_id: Optional[str] = None,
7979
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
80+
always_use_jwt_access: Optional[bool] = False,
8081
) -> None:
8182
"""Instantiate the transport.
8283
@@ -117,6 +118,8 @@ def __init__(
117118
API requests. If ``None``, then default info will be used.
118119
Generally, you only need to set this if you're developing
119120
your own client library.
121+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
122+
be used for service account credentials.
120123
121124
Raises:
122125
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -170,7 +173,7 @@ def __init__(
170173
scopes=scopes,
171174
quota_project_id=quota_project_id,
172175
client_info=client_info,
173-
always_use_jwt_access=True,
176+
always_use_jwt_access=always_use_jwt_access,
174177
)
175178

176179
if not self._grpc_channel:

google/cloud/securitycenter_v1p1beta1/services/security_center/transports/grpc_asyncio.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def __init__(
123123
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
124124
quota_project_id=None,
125125
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
126+
always_use_jwt_access: Optional[bool] = False,
126127
) -> None:
127128
"""Instantiate the transport.
128129
@@ -164,6 +165,8 @@ def __init__(
164165
API requests. If ``None``, then default info will be used.
165166
Generally, you only need to set this if you're developing
166167
your own client library.
168+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
169+
be used for service account credentials.
167170
168171
Raises:
169172
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -216,7 +219,7 @@ def __init__(
216219
scopes=scopes,
217220
quota_project_id=quota_project_id,
218221
client_info=client_info,
219-
always_use_jwt_access=True,
222+
always_use_jwt_access=always_use_jwt_access,
220223
)
221224

222225
if not self._grpc_channel:

tests/unit/gapic/securitycenter_v1/test_security_center.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,25 @@ def test_security_center_client_service_account_always_use_jwt(client_class):
156156
) as use_jwt:
157157
creds = service_account.Credentials(None, None, None)
158158
client = client_class(credentials=creds)
159-
use_jwt.assert_called_with(True)
159+
use_jwt.assert_not_called()
160+
161+
162+
@pytest.mark.parametrize(
163+
"transport_class,transport_name",
164+
[
165+
(transports.SecurityCenterGrpcTransport, "grpc"),
166+
(transports.SecurityCenterGrpcAsyncIOTransport, "grpc_asyncio"),
167+
],
168+
)
169+
def test_security_center_client_service_account_always_use_jwt_true(
170+
transport_class, transport_name
171+
):
172+
with mock.patch.object(
173+
service_account.Credentials, "with_always_use_jwt_access", create=True
174+
) as use_jwt:
175+
creds = service_account.Credentials(None, None, None)
176+
transport = transport_class(credentials=creds, always_use_jwt_access=True)
177+
use_jwt.assert_called_once_with(True)
160178

161179

162180
@pytest.mark.parametrize(
@@ -6876,7 +6894,7 @@ def test_security_center_grpc_transport_client_cert_source_for_mtls(transport_cl
68766894
"squid.clam.whelk:443",
68776895
credentials=cred,
68786896
credentials_file=None,
6879-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
6897+
scopes=None,
68806898
ssl_credentials=mock_ssl_channel_creds,
68816899
quota_project_id=None,
68826900
options=[
@@ -6985,7 +7003,7 @@ def test_security_center_transport_channel_mtls_with_client_cert_source(
69857003
"mtls.squid.clam.whelk:443",
69867004
credentials=cred,
69877005
credentials_file=None,
6988-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
7006+
scopes=None,
69897007
ssl_credentials=mock_ssl_cred,
69907008
quota_project_id=None,
69917009
options=[
@@ -7032,7 +7050,7 @@ def test_security_center_transport_channel_mtls_with_adc(transport_class):
70327050
"mtls.squid.clam.whelk:443",
70337051
credentials=mock_cred,
70347052
credentials_file=None,
7035-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
7053+
scopes=None,
70367054
ssl_credentials=mock_ssl_cred,
70377055
quota_project_id=None,
70387056
options=[

0 commit comments

Comments
 (0)