Skip to content

Commit 8a3376a

Browse files
feat: [google-cloud-run] Add REST Interceptors which support reading metadata (#13489)
BEGIN_COMMIT_OVERRIDE feat: add BuildConfig to Services for configuring Run functions feat: add BuildInfo to Revision for displaying BuildConfig used for a specific revision deployment feat: add Base Image URI to Container feat: add creator field to Execution feat: add project_descriptor to BuildspackBuild docs: some typos were fixed and formatting changed feat: Add REST Interceptors which support reading metadata feat: Add support for reading selective GAPIC generation methods from service YAML chore: Update gapic-generator-python to v1.22.0 END_COMMIT_OVERRIDE - [ ] Regenerate this pull request now. feat: Add support for reading selective GAPIC generation methods from service YAML chore: Update gapic-generator-python to v1.22.0 PiperOrigin-RevId: 724026024 Source-Link: googleapis/googleapis@ad99638 Source-Link: googleapis/googleapis-gen@e291c4d Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXJ1bi8uT3dsQm90LnlhbWwiLCJoIjoiZTI5MWM0ZGQxZDY3MGVkYTE5OTk4ZGU3NmY5NjdlMTYwM2E0ODk5MyJ9 BEGIN_NESTED_COMMIT feat: [google-cloud-run] add BuildConfig to Services for configuring Run functions feat: add BuildInfo to Revision for displaying BuildConfig used for a specific revision deployment feat: add Base Image URI to Container feat: add creator field to Execution feat: add project_descriptor to BuildspackBuild docs: some typos were fixed and formatting changed PiperOrigin-RevId: 723249447 Source-Link: googleapis/googleapis@3d19492 Source-Link: googleapis/googleapis-gen@c7231d3 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXJ1bi8uT3dsQm90LnlhbWwiLCJoIjoiYzcyMzFkMzVhMmZiNWViZjRiN2M0ZDdlOWNmYTYyNDYwNzViMTlkYyJ9 END_NESTED_COMMIT --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: ohmayr <[email protected]>
1 parent 71b9301 commit 8a3376a

File tree

32 files changed

+2015
-290
lines changed

32 files changed

+2015
-290
lines changed

packages/google-cloud-run/google/cloud/run/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
UpdateJobRequest,
5858
)
5959
from google.cloud.run_v2.types.k8s_min import (
60+
BuildInfo,
6061
CloudSqlInstance,
6162
Container,
6263
ContainerPort,
@@ -110,6 +111,7 @@
110111
)
111112
from google.cloud.run_v2.types.vendor_settings import (
112113
BinaryAuthorization,
114+
BuildConfig,
113115
EncryptionKeyRevocationAction,
114116
ExecutionEnvironment,
115117
IngressTraffic,
@@ -153,6 +155,7 @@
153155
"ListJobsResponse",
154156
"RunJobRequest",
155157
"UpdateJobRequest",
158+
"BuildInfo",
156159
"CloudSqlInstance",
157160
"Container",
158161
"ContainerPort",
@@ -196,6 +199,7 @@
196199
"TrafficTargetStatus",
197200
"TrafficTargetAllocationType",
198201
"BinaryAuthorization",
202+
"BuildConfig",
199203
"NodeSelector",
200204
"RevisionScaling",
201205
"ServiceMesh",

packages/google-cloud-run/google/cloud/run/gapic_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "0.10.14" # {x-release-please-version}
16+
__version__ = "0.0.0" # {x-release-please-version}

packages/google-cloud-run/google/cloud/run_v2/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
UpdateJobRequest,
4848
)
4949
from .types.k8s_min import (
50+
BuildInfo,
5051
CloudSqlInstance,
5152
Container,
5253
ContainerPort,
@@ -100,6 +101,7 @@
100101
)
101102
from .types.vendor_settings import (
102103
BinaryAuthorization,
104+
BuildConfig,
103105
EncryptionKeyRevocationAction,
104106
ExecutionEnvironment,
105107
IngressTraffic,
@@ -118,6 +120,8 @@
118120
"ServicesAsyncClient",
119121
"TasksAsyncClient",
120122
"BinaryAuthorization",
123+
"BuildConfig",
124+
"BuildInfo",
121125
"BuildsClient",
122126
"CancelExecutionRequest",
123127
"CloudSqlInstance",

packages/google-cloud-run/google/cloud/run_v2/gapic_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "0.10.14" # {x-release-please-version}
16+
__version__ = "0.0.0" # {x-release-please-version}

packages/google-cloud-run/google/cloud/run_v2/services/builds/client.py

Lines changed: 68 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# limitations under the License.
1515
#
1616
from collections import OrderedDict
17+
from http import HTTPStatus
18+
import json
1719
import logging as std_logging
1820
import os
1921
import re
@@ -486,6 +488,33 @@ def _validate_universe_domain(self):
486488
# NOTE (b/349488459): universe validation is disabled until further notice.
487489
return True
488490

491+
def _add_cred_info_for_auth_errors(
492+
self, error: core_exceptions.GoogleAPICallError
493+
) -> None:
494+
"""Adds credential info string to error details for 401/403/404 errors.
495+
496+
Args:
497+
error (google.api_core.exceptions.GoogleAPICallError): The error to add the cred info.
498+
"""
499+
if error.code not in [
500+
HTTPStatus.UNAUTHORIZED,
501+
HTTPStatus.FORBIDDEN,
502+
HTTPStatus.NOT_FOUND,
503+
]:
504+
return
505+
506+
cred = self._transport._credentials
507+
508+
# get_cred_info is only available in google-auth>=2.35.0
509+
if not hasattr(cred, "get_cred_info"):
510+
return
511+
512+
# ignore the type check since pypy test fails when get_cred_info
513+
# is not available
514+
cred_info = cred.get_cred_info() # type: ignore
515+
if cred_info and hasattr(error._details, "append"):
516+
error._details.append(json.dumps(cred_info))
517+
489518
@property
490519
def api_endpoint(self):
491520
"""Return the API endpoint used by the client instance.
@@ -826,16 +855,20 @@ def list_operations(
826855
# Validate the universe domain.
827856
self._validate_universe_domain()
828857

829-
# Send the request.
830-
response = rpc(
831-
request,
832-
retry=retry,
833-
timeout=timeout,
834-
metadata=metadata,
835-
)
858+
try:
859+
# Send the request.
860+
response = rpc(
861+
request,
862+
retry=retry,
863+
timeout=timeout,
864+
metadata=metadata,
865+
)
836866

837-
# Done; return the response.
838-
return response
867+
# Done; return the response.
868+
return response
869+
except core_exceptions.GoogleAPICallError as e:
870+
self._add_cred_info_for_auth_errors(e)
871+
raise e
839872

840873
def get_operation(
841874
self,
@@ -881,16 +914,20 @@ def get_operation(
881914
# Validate the universe domain.
882915
self._validate_universe_domain()
883916

884-
# Send the request.
885-
response = rpc(
886-
request,
887-
retry=retry,
888-
timeout=timeout,
889-
metadata=metadata,
890-
)
917+
try:
918+
# Send the request.
919+
response = rpc(
920+
request,
921+
retry=retry,
922+
timeout=timeout,
923+
metadata=metadata,
924+
)
891925

892-
# Done; return the response.
893-
return response
926+
# Done; return the response.
927+
return response
928+
except core_exceptions.GoogleAPICallError as e:
929+
self._add_cred_info_for_auth_errors(e)
930+
raise e
894931

895932
def delete_operation(
896933
self,
@@ -998,16 +1035,20 @@ def wait_operation(
9981035
# Validate the universe domain.
9991036
self._validate_universe_domain()
10001037

1001-
# Send the request.
1002-
response = rpc(
1003-
request,
1004-
retry=retry,
1005-
timeout=timeout,
1006-
metadata=metadata,
1007-
)
1038+
try:
1039+
# Send the request.
1040+
response = rpc(
1041+
request,
1042+
retry=retry,
1043+
timeout=timeout,
1044+
metadata=metadata,
1045+
)
10081046

1009-
# Done; return the response.
1010-
return response
1047+
# Done; return the response.
1048+
return response
1049+
except core_exceptions.GoogleAPICallError as e:
1050+
self._add_cred_info_for_auth_errors(e)
1051+
raise e
10111052

10121053

10131054
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

packages/google-cloud-run/google/cloud/run_v2/services/builds/transports/rest.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,35 @@ def post_submit_build(
101101
) -> build.SubmitBuildResponse:
102102
"""Post-rpc interceptor for submit_build
103103
104-
Override in a subclass to manipulate the response
104+
DEPRECATED. Please use the `post_submit_build_with_metadata`
105+
interceptor instead.
106+
107+
Override in a subclass to read or manipulate the response
105108
after it is returned by the Builds server but before
106-
it is returned to user code.
109+
it is returned to user code. This `post_submit_build` interceptor runs
110+
before the `post_submit_build_with_metadata` interceptor.
107111
"""
108112
return response
109113

114+
def post_submit_build_with_metadata(
115+
self,
116+
response: build.SubmitBuildResponse,
117+
metadata: Sequence[Tuple[str, Union[str, bytes]]],
118+
) -> Tuple[build.SubmitBuildResponse, Sequence[Tuple[str, Union[str, bytes]]]]:
119+
"""Post-rpc interceptor for submit_build
120+
121+
Override in a subclass to read or manipulate the response or metadata after it
122+
is returned by the Builds server but before it is returned to user code.
123+
124+
We recommend only using this `post_submit_build_with_metadata`
125+
interceptor in new development instead of the `post_submit_build` interceptor.
126+
When both interceptors are used, this `post_submit_build_with_metadata` interceptor runs after the
127+
`post_submit_build` interceptor. The (possibly modified) response returned by
128+
`post_submit_build` will be passed to
129+
`post_submit_build_with_metadata`.
130+
"""
131+
return response, metadata
132+
110133
def pre_delete_operation(
111134
self,
112135
request: operations_pb2.DeleteOperationRequest,
@@ -418,6 +441,10 @@ def __call__(
418441
json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
419442

420443
resp = self._interceptor.post_submit_build(resp)
444+
response_metadata = [(k, str(v)) for k, v in response.headers.items()]
445+
resp, _ = self._interceptor.post_submit_build_with_metadata(
446+
resp, response_metadata
447+
)
421448
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
422449
logging.DEBUG
423450
): # pragma: NO COVER

packages/google-cloud-run/google/cloud/run_v2/services/executions/client.py

Lines changed: 68 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# limitations under the License.
1515
#
1616
from collections import OrderedDict
17+
from http import HTTPStatus
18+
import json
1719
import logging as std_logging
1820
import os
1921
import re
@@ -598,6 +600,33 @@ def _validate_universe_domain(self):
598600
# NOTE (b/349488459): universe validation is disabled until further notice.
599601
return True
600602

603+
def _add_cred_info_for_auth_errors(
604+
self, error: core_exceptions.GoogleAPICallError
605+
) -> None:
606+
"""Adds credential info string to error details for 401/403/404 errors.
607+
608+
Args:
609+
error (google.api_core.exceptions.GoogleAPICallError): The error to add the cred info.
610+
"""
611+
if error.code not in [
612+
HTTPStatus.UNAUTHORIZED,
613+
HTTPStatus.FORBIDDEN,
614+
HTTPStatus.NOT_FOUND,
615+
]:
616+
return
617+
618+
cred = self._transport._credentials
619+
620+
# get_cred_info is only available in google-auth>=2.35.0
621+
if not hasattr(cred, "get_cred_info"):
622+
return
623+
624+
# ignore the type check since pypy test fails when get_cred_info
625+
# is not available
626+
cred_info = cred.get_cred_info() # type: ignore
627+
if cred_info and hasattr(error._details, "append"):
628+
error._details.append(json.dumps(cred_info))
629+
601630
@property
602631
def api_endpoint(self):
603632
"""Return the API endpoint used by the client instance.
@@ -1323,16 +1352,20 @@ def list_operations(
13231352
# Validate the universe domain.
13241353
self._validate_universe_domain()
13251354

1326-
# Send the request.
1327-
response = rpc(
1328-
request,
1329-
retry=retry,
1330-
timeout=timeout,
1331-
metadata=metadata,
1332-
)
1355+
try:
1356+
# Send the request.
1357+
response = rpc(
1358+
request,
1359+
retry=retry,
1360+
timeout=timeout,
1361+
metadata=metadata,
1362+
)
13331363

1334-
# Done; return the response.
1335-
return response
1364+
# Done; return the response.
1365+
return response
1366+
except core_exceptions.GoogleAPICallError as e:
1367+
self._add_cred_info_for_auth_errors(e)
1368+
raise e
13361369

13371370
def get_operation(
13381371
self,
@@ -1378,16 +1411,20 @@ def get_operation(
13781411
# Validate the universe domain.
13791412
self._validate_universe_domain()
13801413

1381-
# Send the request.
1382-
response = rpc(
1383-
request,
1384-
retry=retry,
1385-
timeout=timeout,
1386-
metadata=metadata,
1387-
)
1414+
try:
1415+
# Send the request.
1416+
response = rpc(
1417+
request,
1418+
retry=retry,
1419+
timeout=timeout,
1420+
metadata=metadata,
1421+
)
13881422

1389-
# Done; return the response.
1390-
return response
1423+
# Done; return the response.
1424+
return response
1425+
except core_exceptions.GoogleAPICallError as e:
1426+
self._add_cred_info_for_auth_errors(e)
1427+
raise e
13911428

13921429
def delete_operation(
13931430
self,
@@ -1495,16 +1532,20 @@ def wait_operation(
14951532
# Validate the universe domain.
14961533
self._validate_universe_domain()
14971534

1498-
# Send the request.
1499-
response = rpc(
1500-
request,
1501-
retry=retry,
1502-
timeout=timeout,
1503-
metadata=metadata,
1504-
)
1535+
try:
1536+
# Send the request.
1537+
response = rpc(
1538+
request,
1539+
retry=retry,
1540+
timeout=timeout,
1541+
metadata=metadata,
1542+
)
15051543

1506-
# Done; return the response.
1507-
return response
1544+
# Done; return the response.
1545+
return response
1546+
except core_exceptions.GoogleAPICallError as e:
1547+
self._add_cred_info_for_auth_errors(e)
1548+
raise e
15081549

15091550

15101551
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

0 commit comments

Comments
 (0)