Skip to content

Commit 8d49d85

Browse files
1 parent ea4ad05 commit 8d49d85

File tree

154 files changed

+1277
-76480
lines changed

Some content is hidden

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

154 files changed

+1277
-76480
lines changed

‎google/pubsub_v1/services/publisher/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 functools
1921
import os
@@ -534,6 +536,33 @@ def _validate_universe_domain(self):
534536
# NOTE (b/349488459): universe validation is disabled until further notice.
535537
return True
536538

539+
def _add_cred_info_for_auth_errors(
540+
self, error: core_exceptions.GoogleAPICallError
541+
) -> None:
542+
"""Adds credential info string to error details for 401/403/404 errors.
543+
544+
Args:
545+
error (google.api_core.exceptions.GoogleAPICallError): The error to add the cred info.
546+
"""
547+
if error.code not in [
548+
HTTPStatus.UNAUTHORIZED,
549+
HTTPStatus.FORBIDDEN,
550+
HTTPStatus.NOT_FOUND,
551+
]:
552+
return
553+
554+
cred = self._transport._credentials
555+
556+
# get_cred_info is only available in google-auth>=2.35.0
557+
if not hasattr(cred, "get_cred_info"):
558+
return
559+
560+
# ignore the type check since pypy test fails when get_cred_info
561+
# is not available
562+
cred_info = cred.get_cred_info() # type: ignore
563+
if cred_info and hasattr(error._details, "append"):
564+
error._details.append(json.dumps(cred_info))
565+
537566
@property
538567
def api_endpoint(self):
539568
"""Return the API endpoint used by the client instance.
@@ -1868,16 +1897,20 @@ def set_iam_policy(
18681897
# Validate the universe domain.
18691898
self._validate_universe_domain()
18701899

1871-
# Send the request.
1872-
response = rpc(
1873-
request,
1874-
retry=retry,
1875-
timeout=timeout,
1876-
metadata=metadata,
1877-
)
1900+
try:
1901+
# Send the request.
1902+
response = rpc(
1903+
request,
1904+
retry=retry,
1905+
timeout=timeout,
1906+
metadata=metadata,
1907+
)
18781908

1879-
# Done; return the response.
1880-
return response
1909+
# Done; return the response.
1910+
return response
1911+
except core_exceptions.GoogleAPICallError as e:
1912+
self._add_cred_info_for_auth_errors(e)
1913+
raise e
18811914

18821915
def get_iam_policy(
18831916
self,
@@ -1995,16 +2028,20 @@ def get_iam_policy(
19952028
# Validate the universe domain.
19962029
self._validate_universe_domain()
19972030

1998-
# Send the request.
1999-
response = rpc(
2000-
request,
2001-
retry=retry,
2002-
timeout=timeout,
2003-
metadata=metadata,
2004-
)
2031+
try:
2032+
# Send the request.
2033+
response = rpc(
2034+
request,
2035+
retry=retry,
2036+
timeout=timeout,
2037+
metadata=metadata,
2038+
)
20052039

2006-
# Done; return the response.
2007-
return response
2040+
# Done; return the response.
2041+
return response
2042+
except core_exceptions.GoogleAPICallError as e:
2043+
self._add_cred_info_for_auth_errors(e)
2044+
raise e
20082045

20092046
def test_iam_permissions(
20102047
self,
@@ -2060,16 +2097,20 @@ def test_iam_permissions(
20602097
# Validate the universe domain.
20612098
self._validate_universe_domain()
20622099

2063-
# Send the request.
2064-
response = rpc(
2065-
request,
2066-
retry=retry,
2067-
timeout=timeout,
2068-
metadata=metadata,
2069-
)
2100+
try:
2101+
# Send the request.
2102+
response = rpc(
2103+
request,
2104+
retry=retry,
2105+
timeout=timeout,
2106+
metadata=metadata,
2107+
)
20702108

2071-
# Done; return the response.
2072-
return response
2109+
# Done; return the response.
2110+
return response
2111+
except core_exceptions.GoogleAPICallError as e:
2112+
self._add_cred_info_for_auth_errors(e)
2113+
raise e
20732114

20742115

20752116
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

0 commit comments

Comments
 (0)