Skip to content
This repository was archived by the owner on Feb 26, 2026. It is now read-only.

Commit 9be4b65

Browse files
1 parent b3c5d42 commit 9be4b65

File tree

163 files changed

+321
-61329
lines changed

Some content is hidden

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

163 files changed

+321
-61329
lines changed

google/cloud/logging_v2/services/config_service_v2/client.py

Lines changed: 55 additions & 18 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
@@ -599,6 +601,33 @@ def _validate_universe_domain(self):
599601
# NOTE (b/349488459): universe validation is disabled until further notice.
600602
return True
601603

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

4464-
# Send the request.
4465-
response = rpc(
4466-
request,
4467-
retry=retry,
4468-
timeout=timeout,
4469-
metadata=metadata,
4470-
)
4493+
try:
4494+
# Send the request.
4495+
response = rpc(
4496+
request,
4497+
retry=retry,
4498+
timeout=timeout,
4499+
metadata=metadata,
4500+
)
44714501

4472-
# Done; return the response.
4473-
return response
4502+
# Done; return the response.
4503+
return response
4504+
except core_exceptions.GoogleAPICallError as e:
4505+
self._add_cred_info_for_auth_errors(e)
4506+
raise e
44744507

44754508
def get_operation(
44764509
self,
@@ -4516,16 +4549,20 @@ def get_operation(
45164549
# Validate the universe domain.
45174550
self._validate_universe_domain()
45184551

4519-
# Send the request.
4520-
response = rpc(
4521-
request,
4522-
retry=retry,
4523-
timeout=timeout,
4524-
metadata=metadata,
4525-
)
4552+
try:
4553+
# Send the request.
4554+
response = rpc(
4555+
request,
4556+
retry=retry,
4557+
timeout=timeout,
4558+
metadata=metadata,
4559+
)
45264560

4527-
# Done; return the response.
4528-
return response
4561+
# Done; return the response.
4562+
return response
4563+
except core_exceptions.GoogleAPICallError as e:
4564+
self._add_cred_info_for_auth_errors(e)
4565+
raise e
45294566

45304567
def cancel_operation(
45314568
self,

google/cloud/logging_v2/services/logging_service_v2/client.py

Lines changed: 55 additions & 18 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
@@ -481,6 +483,33 @@ def _validate_universe_domain(self):
481483
# NOTE (b/349488459): universe validation is disabled until further notice.
482484
return True
483485

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

1506-
# Send the request.
1507-
response = rpc(
1508-
request,
1509-
retry=retry,
1510-
timeout=timeout,
1511-
metadata=metadata,
1512-
)
1535+
try:
1536+
# Send the request.
1537+
response = rpc(
1538+
request,
1539+
retry=retry,
1540+
timeout=timeout,
1541+
metadata=metadata,
1542+
)
15131543

1514-
# Done; return the response.
1515-
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
15161549

15171550
def get_operation(
15181551
self,
@@ -1558,16 +1591,20 @@ def get_operation(
15581591
# Validate the universe domain.
15591592
self._validate_universe_domain()
15601593

1561-
# Send the request.
1562-
response = rpc(
1563-
request,
1564-
retry=retry,
1565-
timeout=timeout,
1566-
metadata=metadata,
1567-
)
1594+
try:
1595+
# Send the request.
1596+
response = rpc(
1597+
request,
1598+
retry=retry,
1599+
timeout=timeout,
1600+
metadata=metadata,
1601+
)
15681602

1569-
# Done; return the response.
1570-
return response
1603+
# Done; return the response.
1604+
return response
1605+
except core_exceptions.GoogleAPICallError as e:
1606+
self._add_cred_info_for_auth_errors(e)
1607+
raise e
15711608

15721609
def cancel_operation(
15731610
self,

google/cloud/logging_v2/services/metrics_service_v2/client.py

Lines changed: 55 additions & 18 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
@@ -480,6 +482,33 @@ def _validate_universe_domain(self):
480482
# NOTE (b/349488459): universe validation is disabled until further notice.
481483
return True
482484

485+
def _add_cred_info_for_auth_errors(
486+
self, error: core_exceptions.GoogleAPICallError
487+
) -> None:
488+
"""Adds credential info string to error details for 401/403/404 errors.
489+
490+
Args:
491+
error (google.api_core.exceptions.GoogleAPICallError): The error to add the cred info.
492+
"""
493+
if error.code not in [
494+
HTTPStatus.UNAUTHORIZED,
495+
HTTPStatus.FORBIDDEN,
496+
HTTPStatus.NOT_FOUND,
497+
]:
498+
return
499+
500+
cred = self._transport._credentials
501+
502+
# get_cred_info is only available in google-auth>=2.35.0
503+
if not hasattr(cred, "get_cred_info"):
504+
return
505+
506+
# ignore the type check since pypy test fails when get_cred_info
507+
# is not available
508+
cred_info = cred.get_cred_info() # type: ignore
509+
if cred_info and hasattr(error._details, "append"):
510+
error._details.append(json.dumps(cred_info))
511+
483512
@property
484513
def api_endpoint(self):
485514
"""Return the API endpoint used by the client instance.
@@ -1348,16 +1377,20 @@ def list_operations(
13481377
# Validate the universe domain.
13491378
self._validate_universe_domain()
13501379

1351-
# Send the request.
1352-
response = rpc(
1353-
request,
1354-
retry=retry,
1355-
timeout=timeout,
1356-
metadata=metadata,
1357-
)
1380+
try:
1381+
# Send the request.
1382+
response = rpc(
1383+
request,
1384+
retry=retry,
1385+
timeout=timeout,
1386+
metadata=metadata,
1387+
)
13581388

1359-
# Done; return the response.
1360-
return response
1389+
# Done; return the response.
1390+
return response
1391+
except core_exceptions.GoogleAPICallError as e:
1392+
self._add_cred_info_for_auth_errors(e)
1393+
raise e
13611394

13621395
def get_operation(
13631396
self,
@@ -1403,16 +1436,20 @@ def get_operation(
14031436
# Validate the universe domain.
14041437
self._validate_universe_domain()
14051438

1406-
# Send the request.
1407-
response = rpc(
1408-
request,
1409-
retry=retry,
1410-
timeout=timeout,
1411-
metadata=metadata,
1412-
)
1439+
try:
1440+
# Send the request.
1441+
response = rpc(
1442+
request,
1443+
retry=retry,
1444+
timeout=timeout,
1445+
metadata=metadata,
1446+
)
14131447

1414-
# Done; return the response.
1415-
return response
1448+
# Done; return the response.
1449+
return response
1450+
except core_exceptions.GoogleAPICallError as e:
1451+
self._add_cred_info_for_auth_errors(e)
1452+
raise e
14161453

14171454
def cancel_operation(
14181455
self,

owl-bot-staging/v2/.coveragerc

Lines changed: 0 additions & 13 deletions
This file was deleted.

owl-bot-staging/v2/.flake8

Lines changed: 0 additions & 33 deletions
This file was deleted.

owl-bot-staging/v2/MANIFEST.in

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)