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

Commit e9ffec8

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

File tree

8 files changed

+62
-32
lines changed

8 files changed

+62
-32
lines changed

google/cloud/billing/budgets_v1/services/budget_service/transports/base.py

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

105105
# Save the scopes.
106-
self._scopes = scopes or self.AUTH_SCOPES
106+
self._scopes = scopes
107107

108108
# If no credentials are provided, then determine the appropriate
109109
# defaults.

google/cloud/billing/budgets_v1/services/budget_service/transports/grpc.py

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

159162
if not self._grpc_channel:

google/cloud/billing/budgets_v1/services/budget_service/transports/grpc_asyncio.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def __init__(
107107
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
108108
quota_project_id=None,
109109
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
110+
always_use_jwt_access: Optional[bool] = False,
110111
) -> None:
111112
"""Instantiate the transport.
112113
@@ -148,6 +149,8 @@ def __init__(
148149
API requests. If ``None``, then default info will be used.
149150
Generally, you only need to set this if you're developing
150151
your own client library.
152+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
153+
be used for service account credentials.
151154
152155
Raises:
153156
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -199,7 +202,7 @@ def __init__(
199202
scopes=scopes,
200203
quota_project_id=quota_project_id,
201204
client_info=client_info,
202-
always_use_jwt_access=True,
205+
always_use_jwt_access=always_use_jwt_access,
203206
)
204207

205208
if not self._grpc_channel:

google/cloud/billing/budgets_v1beta1/services/budget_service/transports/base.py

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

105105
# Save the scopes.
106-
self._scopes = scopes or self.AUTH_SCOPES
106+
self._scopes = scopes
107107

108108
# If no credentials are provided, then determine the appropriate
109109
# defaults.

google/cloud/billing/budgets_v1beta1/services/budget_service/transports/grpc.py

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

159162
if not self._grpc_channel:

google/cloud/billing/budgets_v1beta1/services/budget_service/transports/grpc_asyncio.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def __init__(
107107
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
108108
quota_project_id=None,
109109
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
110+
always_use_jwt_access: Optional[bool] = False,
110111
) -> None:
111112
"""Instantiate the transport.
112113
@@ -148,6 +149,8 @@ def __init__(
148149
API requests. If ``None``, then default info will be used.
149150
Generally, you only need to set this if you're developing
150151
your own client library.
152+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
153+
be used for service account credentials.
151154
152155
Raises:
153156
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -199,7 +202,7 @@ def __init__(
199202
scopes=scopes,
200203
quota_project_id=quota_project_id,
201204
client_info=client_info,
202-
always_use_jwt_access=True,
205+
always_use_jwt_access=always_use_jwt_access,
203206
)
204207

205208
if not self._grpc_channel:

tests/unit/gapic/budgets_v1/test_budget_service.py

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

139157

140158
@pytest.mark.parametrize(
@@ -1958,10 +1976,7 @@ def test_budget_service_grpc_transport_client_cert_source_for_mtls(transport_cla
19581976
"squid.clam.whelk:443",
19591977
credentials=cred,
19601978
credentials_file=None,
1961-
scopes=(
1962-
"https://www.googleapis.com/auth/cloud-billing",
1963-
"https://www.googleapis.com/auth/cloud-platform",
1964-
),
1979+
scopes=None,
19651980
ssl_credentials=mock_ssl_channel_creds,
19661981
quota_project_id=None,
19671982
options=[
@@ -2068,10 +2083,7 @@ def test_budget_service_transport_channel_mtls_with_client_cert_source(transport
20682083
"mtls.squid.clam.whelk:443",
20692084
credentials=cred,
20702085
credentials_file=None,
2071-
scopes=(
2072-
"https://www.googleapis.com/auth/cloud-billing",
2073-
"https://www.googleapis.com/auth/cloud-platform",
2074-
),
2086+
scopes=None,
20752087
ssl_credentials=mock_ssl_cred,
20762088
quota_project_id=None,
20772089
options=[
@@ -2118,10 +2130,7 @@ def test_budget_service_transport_channel_mtls_with_adc(transport_class):
21182130
"mtls.squid.clam.whelk:443",
21192131
credentials=mock_cred,
21202132
credentials_file=None,
2121-
scopes=(
2122-
"https://www.googleapis.com/auth/cloud-billing",
2123-
"https://www.googleapis.com/auth/cloud-platform",
2124-
),
2133+
scopes=None,
21252134
ssl_credentials=mock_ssl_cred,
21262135
quota_project_id=None,
21272136
options=[

tests/unit/gapic/budgets_v1beta1/test_budget_service.py

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

141159

142160
@pytest.mark.parametrize(
@@ -1606,10 +1624,7 @@ def test_budget_service_grpc_transport_client_cert_source_for_mtls(transport_cla
16061624
"squid.clam.whelk:443",
16071625
credentials=cred,
16081626
credentials_file=None,
1609-
scopes=(
1610-
"https://www.googleapis.com/auth/cloud-billing",
1611-
"https://www.googleapis.com/auth/cloud-platform",
1612-
),
1627+
scopes=None,
16131628
ssl_credentials=mock_ssl_channel_creds,
16141629
quota_project_id=None,
16151630
options=[
@@ -1716,10 +1731,7 @@ def test_budget_service_transport_channel_mtls_with_client_cert_source(transport
17161731
"mtls.squid.clam.whelk:443",
17171732
credentials=cred,
17181733
credentials_file=None,
1719-
scopes=(
1720-
"https://www.googleapis.com/auth/cloud-billing",
1721-
"https://www.googleapis.com/auth/cloud-platform",
1722-
),
1734+
scopes=None,
17231735
ssl_credentials=mock_ssl_cred,
17241736
quota_project_id=None,
17251737
options=[
@@ -1766,10 +1778,7 @@ def test_budget_service_transport_channel_mtls_with_adc(transport_class):
17661778
"mtls.squid.clam.whelk:443",
17671779
credentials=mock_cred,
17681780
credentials_file=None,
1769-
scopes=(
1770-
"https://www.googleapis.com/auth/cloud-billing",
1771-
"https://www.googleapis.com/auth/cloud-platform",
1772-
),
1781+
scopes=None,
17731782
ssl_credentials=mock_ssl_cred,
17741783
quota_project_id=None,
17751784
options=[

0 commit comments

Comments
 (0)