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

Commit 1f0b236

Browse files
1 parent 3bb64ca commit 1f0b236

File tree

8 files changed

+62
-14
lines changed

8 files changed

+62
-14
lines changed

google/cloud/redis_v1/services/cloud_redis/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/redis_v1/services/cloud_redis/transports/grpc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def __init__(
7979
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
8080
quota_project_id: Optional[str] = None,
8181
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
82+
always_use_jwt_access: Optional[bool] = False,
8283
) -> None:
8384
"""Instantiate the transport.
8485
@@ -119,6 +120,8 @@ def __init__(
119120
API requests. If ``None``, then default info will be used.
120121
Generally, you only need to set this if you're developing
121122
your own client library.
123+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
124+
be used for service account credentials.
122125
123126
Raises:
124127
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -172,7 +175,7 @@ def __init__(
172175
scopes=scopes,
173176
quota_project_id=quota_project_id,
174177
client_info=client_info,
175-
always_use_jwt_access=True,
178+
always_use_jwt_access=always_use_jwt_access,
176179
)
177180

178181
if not self._grpc_channel:

google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def __init__(
125125
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
126126
quota_project_id=None,
127127
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
128+
always_use_jwt_access: Optional[bool] = False,
128129
) -> None:
129130
"""Instantiate the transport.
130131
@@ -166,6 +167,8 @@ def __init__(
166167
API requests. If ``None``, then default info will be used.
167168
Generally, you only need to set this if you're developing
168169
your own client library.
170+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
171+
be used for service account credentials.
169172
170173
Raises:
171174
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -218,7 +221,7 @@ def __init__(
218221
scopes=scopes,
219222
quota_project_id=quota_project_id,
220223
client_info=client_info,
221-
always_use_jwt_access=True,
224+
always_use_jwt_access=always_use_jwt_access,
222225
)
223226

224227
if not self._grpc_channel:

google/cloud/redis_v1beta1/services/cloud_redis/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/redis_v1beta1/services/cloud_redis/transports/grpc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def __init__(
7979
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
8080
quota_project_id: Optional[str] = None,
8181
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
82+
always_use_jwt_access: Optional[bool] = False,
8283
) -> None:
8384
"""Instantiate the transport.
8485
@@ -119,6 +120,8 @@ def __init__(
119120
API requests. If ``None``, then default info will be used.
120121
Generally, you only need to set this if you're developing
121122
your own client library.
123+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
124+
be used for service account credentials.
122125
123126
Raises:
124127
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -172,7 +175,7 @@ def __init__(
172175
scopes=scopes,
173176
quota_project_id=quota_project_id,
174177
client_info=client_info,
175-
always_use_jwt_access=True,
178+
always_use_jwt_access=always_use_jwt_access,
176179
)
177180

178181
if not self._grpc_channel:

google/cloud/redis_v1beta1/services/cloud_redis/transports/grpc_asyncio.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def __init__(
125125
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
126126
quota_project_id=None,
127127
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
128+
always_use_jwt_access: Optional[bool] = False,
128129
) -> None:
129130
"""Instantiate the transport.
130131
@@ -166,6 +167,8 @@ def __init__(
166167
API requests. If ``None``, then default info will be used.
167168
Generally, you only need to set this if you're developing
168169
your own client library.
170+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
171+
be used for service account credentials.
169172
170173
Raises:
171174
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -218,7 +221,7 @@ def __init__(
218221
scopes=scopes,
219222
quota_project_id=quota_project_id,
220223
client_info=client_info,
221-
always_use_jwt_access=True,
224+
always_use_jwt_access=always_use_jwt_access,
222225
)
223226

224227
if not self._grpc_channel:

tests/unit/gapic/redis_v1/test_cloud_redis.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,25 @@ def test_cloud_redis_client_service_account_always_use_jwt(client_class):
126126
) as use_jwt:
127127
creds = service_account.Credentials(None, None, None)
128128
client = client_class(credentials=creds)
129-
use_jwt.assert_called_with(True)
129+
use_jwt.assert_not_called()
130+
131+
132+
@pytest.mark.parametrize(
133+
"transport_class,transport_name",
134+
[
135+
(transports.CloudRedisGrpcTransport, "grpc"),
136+
(transports.CloudRedisGrpcAsyncIOTransport, "grpc_asyncio"),
137+
],
138+
)
139+
def test_cloud_redis_client_service_account_always_use_jwt_true(
140+
transport_class, transport_name
141+
):
142+
with mock.patch.object(
143+
service_account.Credentials, "with_always_use_jwt_access", create=True
144+
) as use_jwt:
145+
creds = service_account.Credentials(None, None, None)
146+
transport = transport_class(credentials=creds, always_use_jwt_access=True)
147+
use_jwt.assert_called_once_with(True)
130148

131149

132150
@pytest.mark.parametrize("client_class", [CloudRedisClient, CloudRedisAsyncClient,])
@@ -2825,7 +2843,7 @@ def test_cloud_redis_grpc_transport_client_cert_source_for_mtls(transport_class)
28252843
"squid.clam.whelk:443",
28262844
credentials=cred,
28272845
credentials_file=None,
2828-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
2846+
scopes=None,
28292847
ssl_credentials=mock_ssl_channel_creds,
28302848
quota_project_id=None,
28312849
options=[
@@ -2929,7 +2947,7 @@ def test_cloud_redis_transport_channel_mtls_with_client_cert_source(transport_cl
29292947
"mtls.squid.clam.whelk:443",
29302948
credentials=cred,
29312949
credentials_file=None,
2932-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
2950+
scopes=None,
29332951
ssl_credentials=mock_ssl_cred,
29342952
quota_project_id=None,
29352953
options=[
@@ -2973,7 +2991,7 @@ def test_cloud_redis_transport_channel_mtls_with_adc(transport_class):
29732991
"mtls.squid.clam.whelk:443",
29742992
credentials=mock_cred,
29752993
credentials_file=None,
2976-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
2994+
scopes=None,
29772995
ssl_credentials=mock_ssl_cred,
29782996
quota_project_id=None,
29792997
options=[

tests/unit/gapic/redis_v1beta1/test_cloud_redis.py

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

132150

133151
@pytest.mark.parametrize("client_class", [CloudRedisClient, CloudRedisAsyncClient,])
@@ -2826,7 +2844,7 @@ def test_cloud_redis_grpc_transport_client_cert_source_for_mtls(transport_class)
28262844
"squid.clam.whelk:443",
28272845
credentials=cred,
28282846
credentials_file=None,
2829-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
2847+
scopes=None,
28302848
ssl_credentials=mock_ssl_channel_creds,
28312849
quota_project_id=None,
28322850
options=[
@@ -2930,7 +2948,7 @@ def test_cloud_redis_transport_channel_mtls_with_client_cert_source(transport_cl
29302948
"mtls.squid.clam.whelk:443",
29312949
credentials=cred,
29322950
credentials_file=None,
2933-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
2951+
scopes=None,
29342952
ssl_credentials=mock_ssl_cred,
29352953
quota_project_id=None,
29362954
options=[
@@ -2974,7 +2992,7 @@ def test_cloud_redis_transport_channel_mtls_with_adc(transport_class):
29742992
"mtls.squid.clam.whelk:443",
29752993
credentials=mock_cred,
29762994
credentials_file=None,
2977-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
2995+
scopes=None,
29782996
ssl_credentials=mock_ssl_cred,
29792997
quota_project_id=None,
29802998
options=[

0 commit comments

Comments
 (0)