Skip to content

Commit 7a2f3e6

Browse files
feat: [google-cloud-service-management] Add REST Interceptors which support reading metadata (#13483)
BEGIN_COMMIT_OVERRIDE 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 feat: add support for field generate_omitted_as_internal in selective gapic generation 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: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXNlcnZpY2UtbWFuYWdlbWVudC8uT3dsQm90LnlhbWwiLCJoIjoiZTI5MWM0ZGQxZDY3MGVkYTE5OTk4ZGU3NmY5NjdlMTYwM2E0ODk5MyJ9 BEGIN_NESTED_COMMIT feat: [google-cloud-service-management] add support for field generate_omitted_as_internal in selective gapic generation PiperOrigin-RevId: 721375937 Source-Link: googleapis/googleapis@78733bf Source-Link: googleapis/googleapis-gen@a1335fa Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXNlcnZpY2UtbWFuYWdlbWVudC8uT3dsQm90LnlhbWwiLCJoIjoiYTEzMzVmYTk0NjM5OTc5YTM4MzFlMDYwMzVhYWM0NGEyNGZkYWNjNCJ9 END_NESTED_COMMIT --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: ohmayr <[email protected]>
1 parent 6142165 commit 7a2f3e6

File tree

6 files changed

+609
-66
lines changed

6 files changed

+609
-66
lines changed

packages/google-cloud-service-management/google/cloud/servicemanagement/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__ = "1.12.0" # {x-release-please-version}
16+
__version__ = "0.0.0" # {x-release-please-version}

packages/google-cloud-service-management/google/cloud/servicemanagement_v1/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__ = "1.12.0" # {x-release-please-version}
16+
__version__ = "0.0.0" # {x-release-please-version}

packages/google-cloud-service-management/google/cloud/servicemanagement_v1/services/service_manager/client.py

Lines changed: 81 additions & 36 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
@@ -495,6 +497,33 @@ def _validate_universe_domain(self):
495497
# NOTE (b/349488459): universe validation is disabled until further notice.
496498
return True
497499

500+
def _add_cred_info_for_auth_errors(
501+
self, error: core_exceptions.GoogleAPICallError
502+
) -> None:
503+
"""Adds credential info string to error details for 401/403/404 errors.
504+
505+
Args:
506+
error (google.api_core.exceptions.GoogleAPICallError): The error to add the cred info.
507+
"""
508+
if error.code not in [
509+
HTTPStatus.UNAUTHORIZED,
510+
HTTPStatus.FORBIDDEN,
511+
HTTPStatus.NOT_FOUND,
512+
]:
513+
return
514+
515+
cred = self._transport._credentials
516+
517+
# get_cred_info is only available in google-auth>=2.35.0
518+
if not hasattr(cred, "get_cred_info"):
519+
return
520+
521+
# ignore the type check since pypy test fails when get_cred_info
522+
# is not available
523+
cred_info = cred.get_cred_info() # type: ignore
524+
if cred_info and hasattr(error._details, "append"):
525+
error._details.append(json.dumps(cred_info))
526+
498527
@property
499528
def api_endpoint(self):
500529
"""Return the API endpoint used by the client instance.
@@ -2537,16 +2566,20 @@ def list_operations(
25372566
# Validate the universe domain.
25382567
self._validate_universe_domain()
25392568

2540-
# Send the request.
2541-
response = rpc(
2542-
request,
2543-
retry=retry,
2544-
timeout=timeout,
2545-
metadata=metadata,
2546-
)
2569+
try:
2570+
# Send the request.
2571+
response = rpc(
2572+
request,
2573+
retry=retry,
2574+
timeout=timeout,
2575+
metadata=metadata,
2576+
)
25472577

2548-
# Done; return the response.
2549-
return response
2578+
# Done; return the response.
2579+
return response
2580+
except core_exceptions.GoogleAPICallError as e:
2581+
self._add_cred_info_for_auth_errors(e)
2582+
raise e
25502583

25512584
def set_iam_policy(
25522585
self,
@@ -2658,16 +2691,20 @@ def set_iam_policy(
26582691
# Validate the universe domain.
26592692
self._validate_universe_domain()
26602693

2661-
# Send the request.
2662-
response = rpc(
2663-
request,
2664-
retry=retry,
2665-
timeout=timeout,
2666-
metadata=metadata,
2667-
)
2694+
try:
2695+
# Send the request.
2696+
response = rpc(
2697+
request,
2698+
retry=retry,
2699+
timeout=timeout,
2700+
metadata=metadata,
2701+
)
26682702

2669-
# Done; return the response.
2670-
return response
2703+
# Done; return the response.
2704+
return response
2705+
except core_exceptions.GoogleAPICallError as e:
2706+
self._add_cred_info_for_auth_errors(e)
2707+
raise e
26712708

26722709
def get_iam_policy(
26732710
self,
@@ -2780,16 +2817,20 @@ def get_iam_policy(
27802817
# Validate the universe domain.
27812818
self._validate_universe_domain()
27822819

2783-
# Send the request.
2784-
response = rpc(
2785-
request,
2786-
retry=retry,
2787-
timeout=timeout,
2788-
metadata=metadata,
2789-
)
2820+
try:
2821+
# Send the request.
2822+
response = rpc(
2823+
request,
2824+
retry=retry,
2825+
timeout=timeout,
2826+
metadata=metadata,
2827+
)
27902828

2791-
# Done; return the response.
2792-
return response
2829+
# Done; return the response.
2830+
return response
2831+
except core_exceptions.GoogleAPICallError as e:
2832+
self._add_cred_info_for_auth_errors(e)
2833+
raise e
27932834

27942835
def test_iam_permissions(
27952836
self,
@@ -2840,16 +2881,20 @@ def test_iam_permissions(
28402881
# Validate the universe domain.
28412882
self._validate_universe_domain()
28422883

2843-
# Send the request.
2844-
response = rpc(
2845-
request,
2846-
retry=retry,
2847-
timeout=timeout,
2848-
metadata=metadata,
2849-
)
2884+
try:
2885+
# Send the request.
2886+
response = rpc(
2887+
request,
2888+
retry=retry,
2889+
timeout=timeout,
2890+
metadata=metadata,
2891+
)
28502892

2851-
# Done; return the response.
2852-
return response
2893+
# Done; return the response.
2894+
return response
2895+
except core_exceptions.GoogleAPICallError as e:
2896+
self._add_cred_info_for_auth_errors(e)
2897+
raise e
28532898

28542899

28552900
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

0 commit comments

Comments
 (0)