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

Commit 21c9d6e

Browse files
fix: disable always_use_jwt_access (#143)
Committer: @busunkim96 PiperOrigin-RevId: 382142900 Source-Link: googleapis/googleapis@513440f Source-Link: https://github.com/googleapis/googleapis-gen/commit/7b1e2c31233f79a704ec21ca410bf661d6bc68d0
1 parent ae89d26 commit 21c9d6e

File tree

8 files changed

+62
-32
lines changed

8 files changed

+62
-32
lines changed

google/cloud/language_v1/services/language_service/transports/base.py

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

101101
# Save the scopes.
102-
self._scopes = scopes or self.AUTH_SCOPES
102+
self._scopes = scopes
103103

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

google/cloud/language_v1/services/language_service/transports/grpc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def __init__(
5858
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
5959
quota_project_id: Optional[str] = None,
6060
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
61+
always_use_jwt_access: Optional[bool] = False,
6162
) -> None:
6263
"""Instantiate the transport.
6364
@@ -98,6 +99,8 @@ def __init__(
9899
API requests. If ``None``, then default info will be used.
99100
Generally, you only need to set this if you're developing
100101
your own client library.
102+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
103+
be used for service account credentials.
101104
102105
Raises:
103106
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -150,7 +153,7 @@ def __init__(
150153
scopes=scopes,
151154
quota_project_id=quota_project_id,
152155
client_info=client_info,
153-
always_use_jwt_access=True,
156+
always_use_jwt_access=always_use_jwt_access,
154157
)
155158

156159
if not self._grpc_channel:

google/cloud/language_v1/services/language_service/transports/grpc_asyncio.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def __init__(
104104
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
105105
quota_project_id=None,
106106
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
107+
always_use_jwt_access: Optional[bool] = False,
107108
) -> None:
108109
"""Instantiate the transport.
109110
@@ -145,6 +146,8 @@ def __init__(
145146
API requests. If ``None``, then default info will be used.
146147
Generally, you only need to set this if you're developing
147148
your own client library.
149+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
150+
be used for service account credentials.
148151
149152
Raises:
150153
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -196,7 +199,7 @@ def __init__(
196199
scopes=scopes,
197200
quota_project_id=quota_project_id,
198201
client_info=client_info,
199-
always_use_jwt_access=True,
202+
always_use_jwt_access=always_use_jwt_access,
200203
)
201204

202205
if not self._grpc_channel:

google/cloud/language_v1beta2/services/language_service/transports/base.py

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

101101
# Save the scopes.
102-
self._scopes = scopes or self.AUTH_SCOPES
102+
self._scopes = scopes
103103

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

google/cloud/language_v1beta2/services/language_service/transports/grpc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def __init__(
5858
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
5959
quota_project_id: Optional[str] = None,
6060
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
61+
always_use_jwt_access: Optional[bool] = False,
6162
) -> None:
6263
"""Instantiate the transport.
6364
@@ -98,6 +99,8 @@ def __init__(
9899
API requests. If ``None``, then default info will be used.
99100
Generally, you only need to set this if you're developing
100101
your own client library.
102+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
103+
be used for service account credentials.
101104
102105
Raises:
103106
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -150,7 +153,7 @@ def __init__(
150153
scopes=scopes,
151154
quota_project_id=quota_project_id,
152155
client_info=client_info,
153-
always_use_jwt_access=True,
156+
always_use_jwt_access=always_use_jwt_access,
154157
)
155158

156159
if not self._grpc_channel:

google/cloud/language_v1beta2/services/language_service/transports/grpc_asyncio.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def __init__(
104104
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
105105
quota_project_id=None,
106106
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
107+
always_use_jwt_access: Optional[bool] = False,
107108
) -> None:
108109
"""Instantiate the transport.
109110
@@ -145,6 +146,8 @@ def __init__(
145146
API requests. If ``None``, then default info will be used.
146147
Generally, you only need to set this if you're developing
147148
your own client library.
149+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
150+
be used for service account credentials.
148151
149152
Raises:
150153
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -196,7 +199,7 @@ def __init__(
196199
scopes=scopes,
197200
quota_project_id=quota_project_id,
198201
client_info=client_info,
199-
always_use_jwt_access=True,
202+
always_use_jwt_access=always_use_jwt_access,
200203
)
201204

202205
if not self._grpc_channel:

tests/unit/gapic/language_v1/test_language_service.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,25 @@ def test_language_service_client_service_account_always_use_jwt(client_class):
128128
) as use_jwt:
129129
creds = service_account.Credentials(None, None, None)
130130
client = client_class(credentials=creds)
131-
use_jwt.assert_called_with(True)
131+
use_jwt.assert_not_called()
132+
133+
134+
@pytest.mark.parametrize(
135+
"transport_class,transport_name",
136+
[
137+
(transports.LanguageServiceGrpcTransport, "grpc"),
138+
(transports.LanguageServiceGrpcAsyncIOTransport, "grpc_asyncio"),
139+
],
140+
)
141+
def test_language_service_client_service_account_always_use_jwt_true(
142+
transport_class, transport_name
143+
):
144+
with mock.patch.object(
145+
service_account.Credentials, "with_always_use_jwt_access", create=True
146+
) as use_jwt:
147+
creds = service_account.Credentials(None, None, None)
148+
transport = transport_class(credentials=creds, always_use_jwt_access=True)
149+
use_jwt.assert_called_once_with(True)
132150

133151

134152
@pytest.mark.parametrize(
@@ -1860,10 +1878,7 @@ def test_language_service_grpc_transport_client_cert_source_for_mtls(transport_c
18601878
"squid.clam.whelk:443",
18611879
credentials=cred,
18621880
credentials_file=None,
1863-
scopes=(
1864-
"https://www.googleapis.com/auth/cloud-language",
1865-
"https://www.googleapis.com/auth/cloud-platform",
1866-
),
1881+
scopes=None,
18671882
ssl_credentials=mock_ssl_channel_creds,
18681883
quota_project_id=None,
18691884
options=[
@@ -1972,10 +1987,7 @@ def test_language_service_transport_channel_mtls_with_client_cert_source(
19721987
"mtls.squid.clam.whelk:443",
19731988
credentials=cred,
19741989
credentials_file=None,
1975-
scopes=(
1976-
"https://www.googleapis.com/auth/cloud-language",
1977-
"https://www.googleapis.com/auth/cloud-platform",
1978-
),
1990+
scopes=None,
19791991
ssl_credentials=mock_ssl_cred,
19801992
quota_project_id=None,
19811993
options=[
@@ -2022,10 +2034,7 @@ def test_language_service_transport_channel_mtls_with_adc(transport_class):
20222034
"mtls.squid.clam.whelk:443",
20232035
credentials=mock_cred,
20242036
credentials_file=None,
2025-
scopes=(
2026-
"https://www.googleapis.com/auth/cloud-language",
2027-
"https://www.googleapis.com/auth/cloud-platform",
2028-
),
2037+
scopes=None,
20292038
ssl_credentials=mock_ssl_cred,
20302039
quota_project_id=None,
20312040
options=[

tests/unit/gapic/language_v1beta2/test_language_service.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,25 @@ def test_language_service_client_service_account_always_use_jwt(client_class):
130130
) as use_jwt:
131131
creds = service_account.Credentials(None, None, None)
132132
client = client_class(credentials=creds)
133-
use_jwt.assert_called_with(True)
133+
use_jwt.assert_not_called()
134+
135+
136+
@pytest.mark.parametrize(
137+
"transport_class,transport_name",
138+
[
139+
(transports.LanguageServiceGrpcTransport, "grpc"),
140+
(transports.LanguageServiceGrpcAsyncIOTransport, "grpc_asyncio"),
141+
],
142+
)
143+
def test_language_service_client_service_account_always_use_jwt_true(
144+
transport_class, transport_name
145+
):
146+
with mock.patch.object(
147+
service_account.Credentials, "with_always_use_jwt_access", create=True
148+
) as use_jwt:
149+
creds = service_account.Credentials(None, None, None)
150+
transport = transport_class(credentials=creds, always_use_jwt_access=True)
151+
use_jwt.assert_called_once_with(True)
134152

135153

136154
@pytest.mark.parametrize(
@@ -1862,10 +1880,7 @@ def test_language_service_grpc_transport_client_cert_source_for_mtls(transport_c
18621880
"squid.clam.whelk:443",
18631881
credentials=cred,
18641882
credentials_file=None,
1865-
scopes=(
1866-
"https://www.googleapis.com/auth/cloud-language",
1867-
"https://www.googleapis.com/auth/cloud-platform",
1868-
),
1883+
scopes=None,
18691884
ssl_credentials=mock_ssl_channel_creds,
18701885
quota_project_id=None,
18711886
options=[
@@ -1974,10 +1989,7 @@ def test_language_service_transport_channel_mtls_with_client_cert_source(
19741989
"mtls.squid.clam.whelk:443",
19751990
credentials=cred,
19761991
credentials_file=None,
1977-
scopes=(
1978-
"https://www.googleapis.com/auth/cloud-language",
1979-
"https://www.googleapis.com/auth/cloud-platform",
1980-
),
1992+
scopes=None,
19811993
ssl_credentials=mock_ssl_cred,
19821994
quota_project_id=None,
19831995
options=[
@@ -2024,10 +2036,7 @@ def test_language_service_transport_channel_mtls_with_adc(transport_class):
20242036
"mtls.squid.clam.whelk:443",
20252037
credentials=mock_cred,
20262038
credentials_file=None,
2027-
scopes=(
2028-
"https://www.googleapis.com/auth/cloud-language",
2029-
"https://www.googleapis.com/auth/cloud-platform",
2030-
),
2039+
scopes=None,
20312040
ssl_credentials=mock_ssl_cred,
20322041
quota_project_id=None,
20332042
options=[

0 commit comments

Comments
 (0)