Skip to content

Commit dfa9237

Browse files
fix: disable always_use_jwt_access (#41)
Committer: @busunkim96 PiperOrigin-RevId: 382142900 Source-Link: googleapis/googleapis@513440f Source-Link: googleapis/googleapis-gen@7b1e2c3
1 parent e657ef1 commit dfa9237

File tree

8 files changed

+62
-32
lines changed

8 files changed

+62
-32
lines changed

packages/google-cloud-service-control/google/cloud/servicecontrol_v1/services/quota_controller/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.

packages/google-cloud-service-control/google/cloud/servicecontrol_v1/services/quota_controller/transports/grpc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def __init__(
6060
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
6161
quota_project_id: Optional[str] = None,
6262
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
63+
always_use_jwt_access: Optional[bool] = False,
6364
) -> None:
6465
"""Instantiate the transport.
6566
@@ -100,6 +101,8 @@ def __init__(
100101
API requests. If ``None``, then default info will be used.
101102
Generally, you only need to set this if you're developing
102103
your own client library.
104+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
105+
be used for service account credentials.
103106
104107
Raises:
105108
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -152,7 +155,7 @@ def __init__(
152155
scopes=scopes,
153156
quota_project_id=quota_project_id,
154157
client_info=client_info,
155-
always_use_jwt_access=True,
158+
always_use_jwt_access=always_use_jwt_access,
156159
)
157160

158161
if not self._grpc_channel:

packages/google-cloud-service-control/google/cloud/servicecontrol_v1/services/quota_controller/transports/grpc_asyncio.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def __init__(
106106
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
107107
quota_project_id=None,
108108
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
109+
always_use_jwt_access: Optional[bool] = False,
109110
) -> None:
110111
"""Instantiate the transport.
111112
@@ -147,6 +148,8 @@ def __init__(
147148
API requests. If ``None``, then default info will be used.
148149
Generally, you only need to set this if you're developing
149150
your own client library.
151+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
152+
be used for service account credentials.
150153
151154
Raises:
152155
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -198,7 +201,7 @@ def __init__(
198201
scopes=scopes,
199202
quota_project_id=quota_project_id,
200203
client_info=client_info,
201-
always_use_jwt_access=True,
204+
always_use_jwt_access=always_use_jwt_access,
202205
)
203206

204207
if not self._grpc_channel:

packages/google-cloud-service-control/google/cloud/servicecontrol_v1/services/service_controller/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.

packages/google-cloud-service-control/google/cloud/servicecontrol_v1/services/service_controller/transports/grpc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def __init__(
6060
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
6161
quota_project_id: Optional[str] = None,
6262
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
63+
always_use_jwt_access: Optional[bool] = False,
6364
) -> None:
6465
"""Instantiate the transport.
6566
@@ -100,6 +101,8 @@ def __init__(
100101
API requests. If ``None``, then default info will be used.
101102
Generally, you only need to set this if you're developing
102103
your own client library.
104+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
105+
be used for service account credentials.
103106
104107
Raises:
105108
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -152,7 +155,7 @@ def __init__(
152155
scopes=scopes,
153156
quota_project_id=quota_project_id,
154157
client_info=client_info,
155-
always_use_jwt_access=True,
158+
always_use_jwt_access=always_use_jwt_access,
156159
)
157160

158161
if not self._grpc_channel:

packages/google-cloud-service-control/google/cloud/servicecontrol_v1/services/service_controller/transports/grpc_asyncio.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def __init__(
106106
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
107107
quota_project_id=None,
108108
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
109+
always_use_jwt_access: Optional[bool] = False,
109110
) -> None:
110111
"""Instantiate the transport.
111112
@@ -147,6 +148,8 @@ def __init__(
147148
API requests. If ``None``, then default info will be used.
148149
Generally, you only need to set this if you're developing
149150
your own client library.
151+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
152+
be used for service account credentials.
150153
151154
Raises:
152155
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -198,7 +201,7 @@ def __init__(
198201
scopes=scopes,
199202
quota_project_id=quota_project_id,
200203
client_info=client_info,
201-
always_use_jwt_access=True,
204+
always_use_jwt_access=always_use_jwt_access,
202205
)
203206

204207
if not self._grpc_channel:

packages/google-cloud-service-control/tests/unit/gapic/servicecontrol_v1/test_quota_controller.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,25 @@ def test_quota_controller_client_service_account_always_use_jwt(client_class):
135135
) as use_jwt:
136136
creds = service_account.Credentials(None, None, None)
137137
client = client_class(credentials=creds)
138-
use_jwt.assert_called_with(True)
138+
use_jwt.assert_not_called()
139+
140+
141+
@pytest.mark.parametrize(
142+
"transport_class,transport_name",
143+
[
144+
(transports.QuotaControllerGrpcTransport, "grpc"),
145+
(transports.QuotaControllerGrpcAsyncIOTransport, "grpc_asyncio"),
146+
],
147+
)
148+
def test_quota_controller_client_service_account_always_use_jwt_true(
149+
transport_class, transport_name
150+
):
151+
with mock.patch.object(
152+
service_account.Credentials, "with_always_use_jwt_access", create=True
153+
) as use_jwt:
154+
creds = service_account.Credentials(None, None, None)
155+
transport = transport_class(credentials=creds, always_use_jwt_access=True)
156+
use_jwt.assert_called_once_with(True)
139157

140158

141159
@pytest.mark.parametrize(
@@ -876,10 +894,7 @@ def test_quota_controller_grpc_transport_client_cert_source_for_mtls(transport_c
876894
"squid.clam.whelk:443",
877895
credentials=cred,
878896
credentials_file=None,
879-
scopes=(
880-
"https://www.googleapis.com/auth/cloud-platform",
881-
"https://www.googleapis.com/auth/servicecontrol",
882-
),
897+
scopes=None,
883898
ssl_credentials=mock_ssl_channel_creds,
884899
quota_project_id=None,
885900
options=[
@@ -988,10 +1003,7 @@ def test_quota_controller_transport_channel_mtls_with_client_cert_source(
9881003
"mtls.squid.clam.whelk:443",
9891004
credentials=cred,
9901005
credentials_file=None,
991-
scopes=(
992-
"https://www.googleapis.com/auth/cloud-platform",
993-
"https://www.googleapis.com/auth/servicecontrol",
994-
),
1006+
scopes=None,
9951007
ssl_credentials=mock_ssl_cred,
9961008
quota_project_id=None,
9971009
options=[
@@ -1038,10 +1050,7 @@ def test_quota_controller_transport_channel_mtls_with_adc(transport_class):
10381050
"mtls.squid.clam.whelk:443",
10391051
credentials=mock_cred,
10401052
credentials_file=None,
1041-
scopes=(
1042-
"https://www.googleapis.com/auth/cloud-platform",
1043-
"https://www.googleapis.com/auth/servicecontrol",
1044-
),
1053+
scopes=None,
10451054
ssl_credentials=mock_ssl_cred,
10461055
quota_project_id=None,
10471056
options=[

packages/google-cloud-service-control/tests/unit/gapic/servicecontrol_v1/test_service_controller.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,25 @@ def test_service_controller_client_service_account_always_use_jwt(client_class):
143143
) as use_jwt:
144144
creds = service_account.Credentials(None, None, None)
145145
client = client_class(credentials=creds)
146-
use_jwt.assert_called_with(True)
146+
use_jwt.assert_not_called()
147+
148+
149+
@pytest.mark.parametrize(
150+
"transport_class,transport_name",
151+
[
152+
(transports.ServiceControllerGrpcTransport, "grpc"),
153+
(transports.ServiceControllerGrpcAsyncIOTransport, "grpc_asyncio"),
154+
],
155+
)
156+
def test_service_controller_client_service_account_always_use_jwt_true(
157+
transport_class, transport_name
158+
):
159+
with mock.patch.object(
160+
service_account.Credentials, "with_always_use_jwt_access", create=True
161+
) as use_jwt:
162+
creds = service_account.Credentials(None, None, None)
163+
transport = transport_class(credentials=creds, always_use_jwt_access=True)
164+
use_jwt.assert_called_once_with(True)
147165

148166

149167
@pytest.mark.parametrize(
@@ -976,10 +994,7 @@ def test_service_controller_grpc_transport_client_cert_source_for_mtls(transport
976994
"squid.clam.whelk:443",
977995
credentials=cred,
978996
credentials_file=None,
979-
scopes=(
980-
"https://www.googleapis.com/auth/cloud-platform",
981-
"https://www.googleapis.com/auth/servicecontrol",
982-
),
997+
scopes=None,
983998
ssl_credentials=mock_ssl_channel_creds,
984999
quota_project_id=None,
9851000
options=[
@@ -1088,10 +1103,7 @@ def test_service_controller_transport_channel_mtls_with_client_cert_source(
10881103
"mtls.squid.clam.whelk:443",
10891104
credentials=cred,
10901105
credentials_file=None,
1091-
scopes=(
1092-
"https://www.googleapis.com/auth/cloud-platform",
1093-
"https://www.googleapis.com/auth/servicecontrol",
1094-
),
1106+
scopes=None,
10951107
ssl_credentials=mock_ssl_cred,
10961108
quota_project_id=None,
10971109
options=[
@@ -1138,10 +1150,7 @@ def test_service_controller_transport_channel_mtls_with_adc(transport_class):
11381150
"mtls.squid.clam.whelk:443",
11391151
credentials=mock_cred,
11401152
credentials_file=None,
1141-
scopes=(
1142-
"https://www.googleapis.com/auth/cloud-platform",
1143-
"https://www.googleapis.com/auth/servicecontrol",
1144-
),
1153+
scopes=None,
11451154
ssl_credentials=mock_ssl_cred,
11461155
quota_project_id=None,
11471156
options=[

0 commit comments

Comments
 (0)