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

Commit 5d8a4bb

Browse files
fix: disable always_use_jwt_access (#92)
Committer: @busunkim96 PiperOrigin-RevId: 382142900 Source-Link: googleapis/googleapis@513440f Source-Link: https://github.com/googleapis/googleapis-gen/commit/7b1e2c31233f79a704ec21ca410bf661d6bc68d0
1 parent 3b71ec4 commit 5d8a4bb

8 files changed

Lines changed: 62 additions & 14 deletions

File tree

‎google/cloud/osconfig_v1/services/os_config_service/transports/base.py‎

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

100100
# Save the scopes.
101-
self._scopes = scopes or self.AUTH_SCOPES
101+
self._scopes = scopes
102102

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

‎google/cloud/osconfig_v1/services/os_config_service/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/osconfig_v1/services/os_config_service/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:

‎google/cloud/osconfig_v1alpha/services/os_config_zonal_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.

‎google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/grpc.py‎

Lines changed: 4 additions & 1 deletion
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
@@ -158,7 +161,7 @@ def __init__(
158161
scopes=scopes,
159162
quota_project_id=quota_project_id,
160163
client_info=client_info,
161-
always_use_jwt_access=True,
164+
always_use_jwt_access=always_use_jwt_access,
162165
)
163166

164167
if not self._grpc_channel:

‎google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/grpc_asyncio.py‎

Lines changed: 4 additions & 1 deletion
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
@@ -204,7 +207,7 @@ def __init__(
204207
scopes=scopes,
205208
quota_project_id=quota_project_id,
206209
client_info=client_info,
207-
always_use_jwt_access=True,
210+
always_use_jwt_access=always_use_jwt_access,
208211
)
209212

210213
if not self._grpc_channel:

‎tests/unit/gapic/osconfig_v1/test_os_config_service.py‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,25 @@ def test_os_config_service_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.OsConfigServiceGrpcTransport, "grpc"),
146+
(transports.OsConfigServiceGrpcAsyncIOTransport, "grpc_asyncio"),
147+
],
148+
)
149+
def test_os_config_service_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(
@@ -3168,7 +3186,7 @@ def test_os_config_service_grpc_transport_client_cert_source_for_mtls(transport_
31683186
"squid.clam.whelk:443",
31693187
credentials=cred,
31703188
credentials_file=None,
3171-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
3189+
scopes=None,
31723190
ssl_credentials=mock_ssl_channel_creds,
31733191
quota_project_id=None,
31743192
options=[
@@ -3277,7 +3295,7 @@ def test_os_config_service_transport_channel_mtls_with_client_cert_source(
32773295
"mtls.squid.clam.whelk:443",
32783296
credentials=cred,
32793297
credentials_file=None,
3280-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
3298+
scopes=None,
32813299
ssl_credentials=mock_ssl_cred,
32823300
quota_project_id=None,
32833301
options=[
@@ -3324,7 +3342,7 @@ def test_os_config_service_transport_channel_mtls_with_adc(transport_class):
33243342
"mtls.squid.clam.whelk:443",
33253343
credentials=mock_cred,
33263344
credentials_file=None,
3327-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
3345+
scopes=None,
33283346
ssl_credentials=mock_ssl_cred,
33293347
quota_project_id=None,
33303348
options=[

‎tests/unit/gapic/osconfig_v1alpha/test_os_config_zonal_service.py‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,25 @@ def test_os_config_zonal_service_client_service_account_always_use_jwt(client_cl
145145
) as use_jwt:
146146
creds = service_account.Credentials(None, None, None)
147147
client = client_class(credentials=creds)
148-
use_jwt.assert_called_with(True)
148+
use_jwt.assert_not_called()
149+
150+
151+
@pytest.mark.parametrize(
152+
"transport_class,transport_name",
153+
[
154+
(transports.OsConfigZonalServiceGrpcTransport, "grpc"),
155+
(transports.OsConfigZonalServiceGrpcAsyncIOTransport, "grpc_asyncio"),
156+
],
157+
)
158+
def test_os_config_zonal_service_client_service_account_always_use_jwt_true(
159+
transport_class, transport_name
160+
):
161+
with mock.patch.object(
162+
service_account.Credentials, "with_always_use_jwt_access", create=True
163+
) as use_jwt:
164+
creds = service_account.Credentials(None, None, None)
165+
transport = transport_class(credentials=creds, always_use_jwt_access=True)
166+
use_jwt.assert_called_once_with(True)
149167

150168

151169
@pytest.mark.parametrize(
@@ -4530,7 +4548,7 @@ def test_os_config_zonal_service_grpc_transport_client_cert_source_for_mtls(
45304548
"squid.clam.whelk:443",
45314549
credentials=cred,
45324550
credentials_file=None,
4533-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
4551+
scopes=None,
45344552
ssl_credentials=mock_ssl_channel_creds,
45354553
quota_project_id=None,
45364554
options=[
@@ -4639,7 +4657,7 @@ def test_os_config_zonal_service_transport_channel_mtls_with_client_cert_source(
46394657
"mtls.squid.clam.whelk:443",
46404658
credentials=cred,
46414659
credentials_file=None,
4642-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
4660+
scopes=None,
46434661
ssl_credentials=mock_ssl_cred,
46444662
quota_project_id=None,
46454663
options=[
@@ -4686,7 +4704,7 @@ def test_os_config_zonal_service_transport_channel_mtls_with_adc(transport_class
46864704
"mtls.squid.clam.whelk:443",
46874705
credentials=mock_cred,
46884706
credentials_file=None,
4689-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
4707+
scopes=None,
46904708
ssl_credentials=mock_ssl_cred,
46914709
quota_project_id=None,
46924710
options=[

0 commit comments

Comments
 (0)