Skip to content

Commit e8a83ec

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

File tree

4 files changed

+31
-22
lines changed

4 files changed

+31
-22
lines changed

packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/transports/base.py

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

107107
# Save the scopes.
108-
self._scopes = scopes or self.AUTH_SCOPES
108+
self._scopes = scopes
109109

110110
# If no credentials are provided, then determine the appropriate
111111
# defaults.

packages/google-cloud-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/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-monitoring-dashboards/google/cloud/monitoring_dashboard_v1/services/dashboards_service/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-monitoring-dashboards/tests/unit/gapic/dashboard_v1/test_dashboards_service.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,25 @@ def test_dashboards_service_client_service_account_always_use_jwt(client_class):
141141
) as use_jwt:
142142
creds = service_account.Credentials(None, None, None)
143143
client = client_class(credentials=creds)
144-
use_jwt.assert_called_with(True)
144+
use_jwt.assert_not_called()
145+
146+
147+
@pytest.mark.parametrize(
148+
"transport_class,transport_name",
149+
[
150+
(transports.DashboardsServiceGrpcTransport, "grpc"),
151+
(transports.DashboardsServiceGrpcAsyncIOTransport, "grpc_asyncio"),
152+
],
153+
)
154+
def test_dashboards_service_client_service_account_always_use_jwt_true(
155+
transport_class, transport_name
156+
):
157+
with mock.patch.object(
158+
service_account.Credentials, "with_always_use_jwt_access", create=True
159+
) as use_jwt:
160+
creds = service_account.Credentials(None, None, None)
161+
transport = transport_class(credentials=creds, always_use_jwt_access=True)
162+
use_jwt.assert_called_once_with(True)
145163

146164

147165
@pytest.mark.parametrize(
@@ -1666,12 +1684,7 @@ def test_dashboards_service_grpc_transport_client_cert_source_for_mtls(transport
16661684
"squid.clam.whelk:443",
16671685
credentials=cred,
16681686
credentials_file=None,
1669-
scopes=(
1670-
"https://www.googleapis.com/auth/cloud-platform",
1671-
"https://www.googleapis.com/auth/monitoring",
1672-
"https://www.googleapis.com/auth/monitoring.read",
1673-
"https://www.googleapis.com/auth/monitoring.write",
1674-
),
1687+
scopes=None,
16751688
ssl_credentials=mock_ssl_channel_creds,
16761689
quota_project_id=None,
16771690
options=[
@@ -1780,12 +1793,7 @@ def test_dashboards_service_transport_channel_mtls_with_client_cert_source(
17801793
"mtls.squid.clam.whelk:443",
17811794
credentials=cred,
17821795
credentials_file=None,
1783-
scopes=(
1784-
"https://www.googleapis.com/auth/cloud-platform",
1785-
"https://www.googleapis.com/auth/monitoring",
1786-
"https://www.googleapis.com/auth/monitoring.read",
1787-
"https://www.googleapis.com/auth/monitoring.write",
1788-
),
1796+
scopes=None,
17891797
ssl_credentials=mock_ssl_cred,
17901798
quota_project_id=None,
17911799
options=[
@@ -1832,12 +1840,7 @@ def test_dashboards_service_transport_channel_mtls_with_adc(transport_class):
18321840
"mtls.squid.clam.whelk:443",
18331841
credentials=mock_cred,
18341842
credentials_file=None,
1835-
scopes=(
1836-
"https://www.googleapis.com/auth/cloud-platform",
1837-
"https://www.googleapis.com/auth/monitoring",
1838-
"https://www.googleapis.com/auth/monitoring.read",
1839-
"https://www.googleapis.com/auth/monitoring.write",
1840-
),
1843+
scopes=None,
18411844
ssl_credentials=mock_ssl_cred,
18421845
quota_project_id=None,
18431846
options=[

0 commit comments

Comments
 (0)