Skip to content

Commit b0e1f43

Browse files
feat: [google-cloud-documentai] Add REST Interceptors which support reading metadata (#13492)
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 docs: mark fields as unused 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: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLWRvY3VtZW50YWkvLk93bEJvdC55YW1sIiwiaCI6ImUyOTFjNGRkMWQ2NzBlZGExOTk5OGRlNzZmOTY3ZTE2MDNhNDg5OTMifQ== BEGIN_NESTED_COMMIT docs: [google-cloud-documentai] mark fields as unused PiperOrigin-RevId: 723639401 Source-Link: googleapis/googleapis@833292d Source-Link: googleapis/googleapis-gen@71f38d7 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLWRvY3VtZW50YWkvLk93bEJvdC55YW1sIiwiaCI6IjcxZjM4ZDc5OTk5ZTJmNjk1N2EzNGZlOGM3M2Q4ODM5NTYwNGYyOGMifQ== END_NESTED_COMMIT --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: ohmayr <[email protected]>
1 parent 0e9d669 commit b0e1f43

File tree

15 files changed

+2304
-217
lines changed

15 files changed

+2304
-217
lines changed

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

packages/google-cloud-documentai/google/cloud/documentai_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__ = "3.1.0" # {x-release-please-version}
16+
__version__ = "0.0.0" # {x-release-please-version}

packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/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
@@ -601,6 +603,33 @@ def _validate_universe_domain(self):
601603
# NOTE (b/349488459): universe validation is disabled until further notice.
602604
return True
603605

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

3552-
# Send the request.
3553-
response = rpc(
3554-
request,
3555-
retry=retry,
3556-
timeout=timeout,
3557-
metadata=metadata,
3558-
)
3581+
try:
3582+
# Send the request.
3583+
response = rpc(
3584+
request,
3585+
retry=retry,
3586+
timeout=timeout,
3587+
metadata=metadata,
3588+
)
35593589

3560-
# Done; return the response.
3561-
return response
3590+
# Done; return the response.
3591+
return response
3592+
except core_exceptions.GoogleAPICallError as e:
3593+
self._add_cred_info_for_auth_errors(e)
3594+
raise e
35623595

35633596
def get_operation(
35643597
self,
@@ -3604,16 +3637,20 @@ def get_operation(
36043637
# Validate the universe domain.
36053638
self._validate_universe_domain()
36063639

3607-
# Send the request.
3608-
response = rpc(
3609-
request,
3610-
retry=retry,
3611-
timeout=timeout,
3612-
metadata=metadata,
3613-
)
3640+
try:
3641+
# Send the request.
3642+
response = rpc(
3643+
request,
3644+
retry=retry,
3645+
timeout=timeout,
3646+
metadata=metadata,
3647+
)
36143648

3615-
# Done; return the response.
3616-
return response
3649+
# Done; return the response.
3650+
return response
3651+
except core_exceptions.GoogleAPICallError as e:
3652+
self._add_cred_info_for_auth_errors(e)
3653+
raise e
36173654

36183655
def cancel_operation(
36193656
self,
@@ -3714,16 +3751,20 @@ def get_location(
37143751
# Validate the universe domain.
37153752
self._validate_universe_domain()
37163753

3717-
# Send the request.
3718-
response = rpc(
3719-
request,
3720-
retry=retry,
3721-
timeout=timeout,
3722-
metadata=metadata,
3723-
)
3754+
try:
3755+
# Send the request.
3756+
response = rpc(
3757+
request,
3758+
retry=retry,
3759+
timeout=timeout,
3760+
metadata=metadata,
3761+
)
37243762

3725-
# Done; return the response.
3726-
return response
3763+
# Done; return the response.
3764+
return response
3765+
except core_exceptions.GoogleAPICallError as e:
3766+
self._add_cred_info_for_auth_errors(e)
3767+
raise e
37273768

37283769
def list_locations(
37293770
self,
@@ -3769,16 +3810,20 @@ def list_locations(
37693810
# Validate the universe domain.
37703811
self._validate_universe_domain()
37713812

3772-
# Send the request.
3773-
response = rpc(
3774-
request,
3775-
retry=retry,
3776-
timeout=timeout,
3777-
metadata=metadata,
3778-
)
3813+
try:
3814+
# Send the request.
3815+
response = rpc(
3816+
request,
3817+
retry=retry,
3818+
timeout=timeout,
3819+
metadata=metadata,
3820+
)
37793821

3780-
# Done; return the response.
3781-
return response
3822+
# Done; return the response.
3823+
return response
3824+
except core_exceptions.GoogleAPICallError as e:
3825+
self._add_cred_info_for_auth_errors(e)
3826+
raise e
37823827

37833828

37843829
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

0 commit comments

Comments
 (0)