Skip to content

Commit 049bfb0

Browse files
fix!: uint64/int64 fields accept ints instead of strings (#92)
feat: add always_use_jwt_access fix: fix required query params handling (closes #12) fix!: uint64/int64 fields accept ints instead of strings Release-As: 0.5.0
1 parent 4b841ef commit 049bfb0

File tree

238 files changed

+7928
-7390
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

238 files changed

+7928
-7390
lines changed

packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/transports/base.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from google.api_core import gapic_v1 # type: ignore
2626
from google.api_core import retry as retries # type: ignore
2727
from google.auth import credentials as ga_credentials # type: ignore
28+
from google.oauth2 import service_account # type: ignore
2829

2930
from google.cloud.compute_v1.types import compute
3031

@@ -67,6 +68,7 @@ def __init__(
6768
scopes: Optional[Sequence[str]] = None,
6869
quota_project_id: Optional[str] = None,
6970
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
71+
always_use_jwt_access: Optional[bool] = False,
7072
**kwargs,
7173
) -> None:
7274
"""Instantiate the transport.
@@ -90,6 +92,8 @@ def __init__(
9092
API requests. If ``None``, then default info will be used.
9193
Generally, you only need to set this if you're developing
9294
your own client library.
95+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
96+
be used for service account credentials.
9397
"""
9498
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
9599
if ":" not in host:
@@ -99,7 +103,7 @@ def __init__(
99103
scopes_kwargs = self._get_scopes_kwargs(self._host, scopes)
100104

101105
# Save the scopes.
102-
self._scopes = scopes or self.AUTH_SCOPES
106+
self._scopes = scopes
103107

104108
# If no credentials are provided, then determine the appropriate
105109
# defaults.
@@ -118,6 +122,14 @@ def __init__(
118122
**scopes_kwargs, quota_project_id=quota_project_id
119123
)
120124

125+
# If the credentials is service account credentials, then always try to use self signed JWT.
126+
if (
127+
always_use_jwt_access
128+
and isinstance(credentials, service_account.Credentials)
129+
and hasattr(service_account.Credentials, "with_always_use_jwt_access")
130+
):
131+
credentials = credentials.with_always_use_jwt_access(True)
132+
121133
# Save the credentials.
122134
self._credentials = credentials
123135

packages/google-cloud-compute/google/cloud/compute_v1/services/accelerator_types/transports/rest.py

+8-22
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def __init__(
5353
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
5454
quota_project_id: Optional[str] = None,
5555
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
56+
always_use_jwt_access: Optional[bool] = False,
5657
) -> None:
5758
"""Instantiate the transport.
5859
@@ -86,7 +87,10 @@ def __init__(
8687
# TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the
8788
# credentials object
8889
super().__init__(
89-
host=host, credentials=credentials, client_info=client_info,
90+
host=host,
91+
credentials=credentials,
92+
client_info=client_info,
93+
always_use_jwt_access=always_use_jwt_access,
9094
)
9195
self._session = AuthorizedSession(
9296
self._credentials, default_host=self.DEFAULT_HOST
@@ -142,16 +146,10 @@ def aggregated_list(
142146
):
143147
query_params["returnPartialSuccess"] = request.return_partial_success
144148

145-
# TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here
146-
# discards default values
147-
# TODO(yon-mg): add test for proper url encoded strings
148-
query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()]
149-
url += "?{}".format("&".join(query_params)).replace(" ", "+")
150-
151149
# Send the request
152150
headers = dict(metadata)
153151
headers["Content-Type"] = "application/json"
154-
response = self._session.get(url, headers=headers,)
152+
response = self._session.get(url, headers=headers, params=query_params,)
155153

156154
# In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
157155
# subclass.
@@ -206,16 +204,10 @@ def get(
206204
# not required for GCE
207205
query_params = {}
208206

209-
# TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here
210-
# discards default values
211-
# TODO(yon-mg): add test for proper url encoded strings
212-
query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()]
213-
url += "?{}".format("&".join(query_params)).replace(" ", "+")
214-
215207
# Send the request
216208
headers = dict(metadata)
217209
headers["Content-Type"] = "application/json"
218-
response = self._session.get(url, headers=headers,)
210+
response = self._session.get(url, headers=headers, params=query_params,)
219211

220212
# In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
221213
# subclass.
@@ -269,16 +261,10 @@ def list(
269261
if compute.ListAcceleratorTypesRequest.return_partial_success in request:
270262
query_params["returnPartialSuccess"] = request.return_partial_success
271263

272-
# TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here
273-
# discards default values
274-
# TODO(yon-mg): add test for proper url encoded strings
275-
query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()]
276-
url += "?{}".format("&".join(query_params)).replace(" ", "+")
277-
278264
# Send the request
279265
headers = dict(metadata)
280266
headers["Content-Type"] = "application/json"
281-
response = self._session.get(url, headers=headers,)
267+
response = self._session.get(url, headers=headers, params=query_params,)
282268

283269
# In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
284270
# subclass.

packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/transports/base.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from google.api_core import gapic_v1 # type: ignore
2626
from google.api_core import retry as retries # type: ignore
2727
from google.auth import credentials as ga_credentials # type: ignore
28+
from google.oauth2 import service_account # type: ignore
2829

2930
from google.cloud.compute_v1.types import compute
3031

@@ -66,6 +67,7 @@ def __init__(
6667
scopes: Optional[Sequence[str]] = None,
6768
quota_project_id: Optional[str] = None,
6869
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
70+
always_use_jwt_access: Optional[bool] = False,
6971
**kwargs,
7072
) -> None:
7173
"""Instantiate the transport.
@@ -89,6 +91,8 @@ def __init__(
8991
API requests. If ``None``, then default info will be used.
9092
Generally, you only need to set this if you're developing
9193
your own client library.
94+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
95+
be used for service account credentials.
9296
"""
9397
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
9498
if ":" not in host:
@@ -98,7 +102,7 @@ def __init__(
98102
scopes_kwargs = self._get_scopes_kwargs(self._host, scopes)
99103

100104
# Save the scopes.
101-
self._scopes = scopes or self.AUTH_SCOPES
105+
self._scopes = scopes
102106

103107
# If no credentials are provided, then determine the appropriate
104108
# defaults.
@@ -117,6 +121,14 @@ def __init__(
117121
**scopes_kwargs, quota_project_id=quota_project_id
118122
)
119123

124+
# If the credentials is service account credentials, then always try to use self signed JWT.
125+
if (
126+
always_use_jwt_access
127+
and isinstance(credentials, service_account.Credentials)
128+
and hasattr(service_account.Credentials, "with_always_use_jwt_access")
129+
):
130+
credentials = credentials.with_always_use_jwt_access(True)
131+
120132
# Save the credentials.
121133
self._credentials = credentials
122134

packages/google-cloud-compute/google/cloud/compute_v1/services/addresses/transports/rest.py

+12-36
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def __init__(
5252
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
5353
quota_project_id: Optional[str] = None,
5454
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
55+
always_use_jwt_access: Optional[bool] = False,
5556
) -> None:
5657
"""Instantiate the transport.
5758
@@ -85,7 +86,10 @@ def __init__(
8586
# TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the
8687
# credentials object
8788
super().__init__(
88-
host=host, credentials=credentials, client_info=client_info,
89+
host=host,
90+
credentials=credentials,
91+
client_info=client_info,
92+
always_use_jwt_access=always_use_jwt_access,
8993
)
9094
self._session = AuthorizedSession(
9195
self._credentials, default_host=self.DEFAULT_HOST
@@ -138,16 +142,10 @@ def aggregated_list(
138142
if compute.AggregatedListAddressesRequest.return_partial_success in request:
139143
query_params["returnPartialSuccess"] = request.return_partial_success
140144

141-
# TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here
142-
# discards default values
143-
# TODO(yon-mg): add test for proper url encoded strings
144-
query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()]
145-
url += "?{}".format("&".join(query_params)).replace(" ", "+")
146-
147145
# Send the request
148146
headers = dict(metadata)
149147
headers["Content-Type"] = "application/json"
150-
response = self._session.get(url, headers=headers,)
148+
response = self._session.get(url, headers=headers, params=query_params,)
151149

152150
# In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
153151
# subclass.
@@ -224,16 +222,10 @@ def delete(
224222
if compute.DeleteAddressRequest.request_id in request:
225223
query_params["requestId"] = request.request_id
226224

227-
# TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here
228-
# discards default values
229-
# TODO(yon-mg): add test for proper url encoded strings
230-
query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()]
231-
url += "?{}".format("&".join(query_params)).replace(" ", "+")
232-
233225
# Send the request
234226
headers = dict(metadata)
235227
headers["Content-Type"] = "application/json"
236-
response = self._session.delete(url, headers=headers,)
228+
response = self._session.delete(url, headers=headers, params=query_params,)
237229

238230
# In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
239231
# subclass.
@@ -305,16 +297,10 @@ def get(
305297
# not required for GCE
306298
query_params = {}
307299

308-
# TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here
309-
# discards default values
310-
# TODO(yon-mg): add test for proper url encoded strings
311-
query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()]
312-
url += "?{}".format("&".join(query_params)).replace(" ", "+")
313-
314300
# Send the request
315301
headers = dict(metadata)
316302
headers["Content-Type"] = "application/json"
317-
response = self._session.get(url, headers=headers,)
303+
response = self._session.get(url, headers=headers, params=query_params,)
318304

319305
# In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
320306
# subclass.
@@ -393,16 +379,12 @@ def insert(
393379
if compute.InsertAddressRequest.request_id in request:
394380
query_params["requestId"] = request.request_id
395381

396-
# TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here
397-
# discards default values
398-
# TODO(yon-mg): add test for proper url encoded strings
399-
query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()]
400-
url += "?{}".format("&".join(query_params)).replace(" ", "+")
401-
402382
# Send the request
403383
headers = dict(metadata)
404384
headers["Content-Type"] = "application/json"
405-
response = self._session.post(url, headers=headers, data=body,)
385+
response = self._session.post(
386+
url, headers=headers, params=query_params, data=body,
387+
)
406388

407389
# In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
408390
# subclass.
@@ -453,16 +435,10 @@ def list(
453435
if compute.ListAddressesRequest.return_partial_success in request:
454436
query_params["returnPartialSuccess"] = request.return_partial_success
455437

456-
# TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here
457-
# discards default values
458-
# TODO(yon-mg): add test for proper url encoded strings
459-
query_params = ["{k}={v}".format(k=k, v=v) for k, v in query_params.items()]
460-
url += "?{}".format("&".join(query_params)).replace(" ", "+")
461-
462438
# Send the request
463439
headers = dict(metadata)
464440
headers["Content-Type"] = "application/json"
465-
response = self._session.get(url, headers=headers,)
441+
response = self._session.get(url, headers=headers, params=query_params,)
466442

467443
# In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
468444
# subclass.

packages/google-cloud-compute/google/cloud/compute_v1/services/autoscalers/transports/base.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from google.api_core import gapic_v1 # type: ignore
2626
from google.api_core import retry as retries # type: ignore
2727
from google.auth import credentials as ga_credentials # type: ignore
28+
from google.oauth2 import service_account # type: ignore
2829

2930
from google.cloud.compute_v1.types import compute
3031

@@ -66,6 +67,7 @@ def __init__(
6667
scopes: Optional[Sequence[str]] = None,
6768
quota_project_id: Optional[str] = None,
6869
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
70+
always_use_jwt_access: Optional[bool] = False,
6971
**kwargs,
7072
) -> None:
7173
"""Instantiate the transport.
@@ -89,6 +91,8 @@ def __init__(
8991
API requests. If ``None``, then default info will be used.
9092
Generally, you only need to set this if you're developing
9193
your own client library.
94+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
95+
be used for service account credentials.
9296
"""
9397
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
9498
if ":" not in host:
@@ -98,7 +102,7 @@ def __init__(
98102
scopes_kwargs = self._get_scopes_kwargs(self._host, scopes)
99103

100104
# Save the scopes.
101-
self._scopes = scopes or self.AUTH_SCOPES
105+
self._scopes = scopes
102106

103107
# If no credentials are provided, then determine the appropriate
104108
# defaults.
@@ -117,6 +121,14 @@ def __init__(
117121
**scopes_kwargs, quota_project_id=quota_project_id
118122
)
119123

124+
# If the credentials is service account credentials, then always try to use self signed JWT.
125+
if (
126+
always_use_jwt_access
127+
and isinstance(credentials, service_account.Credentials)
128+
and hasattr(service_account.Credentials, "with_always_use_jwt_access")
129+
):
130+
credentials = credentials.with_always_use_jwt_access(True)
131+
120132
# Save the credentials.
121133
self._credentials = credentials
122134

0 commit comments

Comments
 (0)