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

Commit 5cda9ac

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

File tree

8 files changed

+62
-14
lines changed

8 files changed

+62
-14
lines changed

google/cloud/security/privateca_v1/services/certificate_authority_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/security/privateca_v1/services/certificate_authority_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
@@ -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:

google/cloud/security/privateca_v1/services/certificate_authority_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
@@ -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:

google/cloud/security/privateca_v1beta1/services/certificate_authority_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/security/privateca_v1beta1/services/certificate_authority_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
@@ -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:

google/cloud/security/privateca_v1beta1/services/certificate_authority_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
@@ -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:

tests/unit/gapic/privateca_v1/test_certificate_authority_service.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,25 @@ def test_certificate_authority_service_client_service_account_always_use_jwt(
151151
) as use_jwt:
152152
creds = service_account.Credentials(None, None, None)
153153
client = client_class(credentials=creds)
154-
use_jwt.assert_called_with(True)
154+
use_jwt.assert_not_called()
155+
156+
157+
@pytest.mark.parametrize(
158+
"transport_class,transport_name",
159+
[
160+
(transports.CertificateAuthorityServiceGrpcTransport, "grpc"),
161+
(transports.CertificateAuthorityServiceGrpcAsyncIOTransport, "grpc_asyncio"),
162+
],
163+
)
164+
def test_certificate_authority_service_client_service_account_always_use_jwt_true(
165+
transport_class, transport_name
166+
):
167+
with mock.patch.object(
168+
service_account.Credentials, "with_always_use_jwt_access", create=True
169+
) as use_jwt:
170+
creds = service_account.Credentials(None, None, None)
171+
transport = transport_class(credentials=creds, always_use_jwt_access=True)
172+
use_jwt.assert_called_once_with(True)
155173

156174

157175
@pytest.mark.parametrize(
@@ -8378,7 +8396,7 @@ def test_certificate_authority_service_grpc_transport_client_cert_source_for_mtl
83788396
"squid.clam.whelk:443",
83798397
credentials=cred,
83808398
credentials_file=None,
8381-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
8399+
scopes=None,
83828400
ssl_credentials=mock_ssl_channel_creds,
83838401
quota_project_id=None,
83848402
options=[
@@ -8487,7 +8505,7 @@ def test_certificate_authority_service_transport_channel_mtls_with_client_cert_s
84878505
"mtls.squid.clam.whelk:443",
84888506
credentials=cred,
84898507
credentials_file=None,
8490-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
8508+
scopes=None,
84918509
ssl_credentials=mock_ssl_cred,
84928510
quota_project_id=None,
84938511
options=[
@@ -8534,7 +8552,7 @@ def test_certificate_authority_service_transport_channel_mtls_with_adc(transport
85348552
"mtls.squid.clam.whelk:443",
85358553
credentials=mock_cred,
85368554
credentials_file=None,
8537-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
8555+
scopes=None,
85388556
ssl_credentials=mock_ssl_cred,
85398557
quota_project_id=None,
85408558
options=[

tests/unit/gapic/privateca_v1beta1/test_certificate_authority_service.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,25 @@ def test_certificate_authority_service_client_service_account_always_use_jwt(
151151
) as use_jwt:
152152
creds = service_account.Credentials(None, None, None)
153153
client = client_class(credentials=creds)
154-
use_jwt.assert_called_with(True)
154+
use_jwt.assert_not_called()
155+
156+
157+
@pytest.mark.parametrize(
158+
"transport_class,transport_name",
159+
[
160+
(transports.CertificateAuthorityServiceGrpcTransport, "grpc"),
161+
(transports.CertificateAuthorityServiceGrpcAsyncIOTransport, "grpc_asyncio"),
162+
],
163+
)
164+
def test_certificate_authority_service_client_service_account_always_use_jwt_true(
165+
transport_class, transport_name
166+
):
167+
with mock.patch.object(
168+
service_account.Credentials, "with_always_use_jwt_access", create=True
169+
) as use_jwt:
170+
creds = service_account.Credentials(None, None, None)
171+
transport = transport_class(credentials=creds, always_use_jwt_access=True)
172+
use_jwt.assert_called_once_with(True)
155173

156174

157175
@pytest.mark.parametrize(
@@ -6199,7 +6217,7 @@ def test_certificate_authority_service_grpc_transport_client_cert_source_for_mtl
61996217
"squid.clam.whelk:443",
62006218
credentials=cred,
62016219
credentials_file=None,
6202-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
6220+
scopes=None,
62036221
ssl_credentials=mock_ssl_channel_creds,
62046222
quota_project_id=None,
62056223
options=[
@@ -6308,7 +6326,7 @@ def test_certificate_authority_service_transport_channel_mtls_with_client_cert_s
63086326
"mtls.squid.clam.whelk:443",
63096327
credentials=cred,
63106328
credentials_file=None,
6311-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
6329+
scopes=None,
63126330
ssl_credentials=mock_ssl_cred,
63136331
quota_project_id=None,
63146332
options=[
@@ -6355,7 +6373,7 @@ def test_certificate_authority_service_transport_channel_mtls_with_adc(transport
63556373
"mtls.squid.clam.whelk:443",
63566374
credentials=mock_cred,
63576375
credentials_file=None,
6358-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
6376+
scopes=None,
63596377
ssl_credentials=mock_ssl_cred,
63606378
quota_project_id=None,
63616379
options=[

0 commit comments

Comments
 (0)