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

Commit cff1d3e

Browse files
fix: disable always_use_jwt_access (#93)
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 3a6999d commit cff1d3e

8 files changed

Lines changed: 62 additions & 14 deletions

File tree

‎google/cloud/billing_v1/services/cloud_billing/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/billing_v1/services/cloud_billing/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:

‎google/cloud/billing_v1/services/cloud_billing/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:

‎google/cloud/billing_v1/services/cloud_catalog/transports/base.py‎

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

9898
# Save the scopes.
99-
self._scopes = scopes or self.AUTH_SCOPES
99+
self._scopes = scopes
100100

101101
# If no credentials are provided, then determine the appropriate
102102
# defaults.

‎google/cloud/billing_v1/services/cloud_catalog/transports/grpc.py‎

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

157160
if not self._grpc_channel:

‎google/cloud/billing_v1/services/cloud_catalog/transports/grpc_asyncio.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def __init__(
105105
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
106106
quota_project_id=None,
107107
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
108+
always_use_jwt_access: Optional[bool] = False,
108109
) -> None:
109110
"""Instantiate the transport.
110111
@@ -146,6 +147,8 @@ def __init__(
146147
API requests. If ``None``, then default info will be used.
147148
Generally, you only need to set this if you're developing
148149
your own client library.
150+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
151+
be used for service account credentials.
149152
150153
Raises:
151154
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -197,7 +200,7 @@ def __init__(
197200
scopes=scopes,
198201
quota_project_id=quota_project_id,
199202
client_info=client_info,
200-
always_use_jwt_access=True,
203+
always_use_jwt_access=always_use_jwt_access,
201204
)
202205

203206
if not self._grpc_channel:

‎tests/unit/gapic/billing_v1/test_cloud_billing.py‎

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

130148

131149
@pytest.mark.parametrize("client_class", [CloudBillingClient, CloudBillingAsyncClient,])
@@ -3165,7 +3183,7 @@ def test_cloud_billing_grpc_transport_client_cert_source_for_mtls(transport_clas
31653183
"squid.clam.whelk:443",
31663184
credentials=cred,
31673185
credentials_file=None,
3168-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
3186+
scopes=None,
31693187
ssl_credentials=mock_ssl_channel_creds,
31703188
quota_project_id=None,
31713189
options=[
@@ -3269,7 +3287,7 @@ def test_cloud_billing_transport_channel_mtls_with_client_cert_source(transport_
32693287
"mtls.squid.clam.whelk:443",
32703288
credentials=cred,
32713289
credentials_file=None,
3272-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
3290+
scopes=None,
32733291
ssl_credentials=mock_ssl_cred,
32743292
quota_project_id=None,
32753293
options=[
@@ -3313,7 +3331,7 @@ def test_cloud_billing_transport_channel_mtls_with_adc(transport_class):
33133331
"mtls.squid.clam.whelk:443",
33143332
credentials=mock_cred,
33153333
credentials_file=None,
3316-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
3334+
scopes=None,
33173335
ssl_credentials=mock_ssl_cred,
33183336
quota_project_id=None,
33193337
options=[

‎tests/unit/gapic/billing_v1/test_cloud_catalog.py‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,25 @@ def test_cloud_catalog_client_service_account_always_use_jwt(client_class):
121121
) as use_jwt:
122122
creds = service_account.Credentials(None, None, None)
123123
client = client_class(credentials=creds)
124-
use_jwt.assert_called_with(True)
124+
use_jwt.assert_not_called()
125+
126+
127+
@pytest.mark.parametrize(
128+
"transport_class,transport_name",
129+
[
130+
(transports.CloudCatalogGrpcTransport, "grpc"),
131+
(transports.CloudCatalogGrpcAsyncIOTransport, "grpc_asyncio"),
132+
],
133+
)
134+
def test_cloud_catalog_client_service_account_always_use_jwt_true(
135+
transport_class, transport_name
136+
):
137+
with mock.patch.object(
138+
service_account.Credentials, "with_always_use_jwt_access", create=True
139+
) as use_jwt:
140+
creds = service_account.Credentials(None, None, None)
141+
transport = transport_class(credentials=creds, always_use_jwt_access=True)
142+
use_jwt.assert_called_once_with(True)
125143

126144

127145
@pytest.mark.parametrize("client_class", [CloudCatalogClient, CloudCatalogAsyncClient,])
@@ -1270,7 +1288,7 @@ def test_cloud_catalog_grpc_transport_client_cert_source_for_mtls(transport_clas
12701288
"squid.clam.whelk:443",
12711289
credentials=cred,
12721290
credentials_file=None,
1273-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
1291+
scopes=None,
12741292
ssl_credentials=mock_ssl_channel_creds,
12751293
quota_project_id=None,
12761294
options=[
@@ -1374,7 +1392,7 @@ def test_cloud_catalog_transport_channel_mtls_with_client_cert_source(transport_
13741392
"mtls.squid.clam.whelk:443",
13751393
credentials=cred,
13761394
credentials_file=None,
1377-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
1395+
scopes=None,
13781396
ssl_credentials=mock_ssl_cred,
13791397
quota_project_id=None,
13801398
options=[
@@ -1418,7 +1436,7 @@ def test_cloud_catalog_transport_channel_mtls_with_adc(transport_class):
14181436
"mtls.squid.clam.whelk:443",
14191437
credentials=mock_cred,
14201438
credentials_file=None,
1421-
scopes=("https://www.googleapis.com/auth/cloud-platform",),
1439+
scopes=None,
14221440
ssl_credentials=mock_ssl_cred,
14231441
quota_project_id=None,
14241442
options=[

0 commit comments

Comments
 (0)