Skip to content

Commit

Permalink
feat: [Many APIs] Add REST Interceptors which support reading metadata (
Browse files Browse the repository at this point in the history
#13498)

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
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:
eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLWVzc2VudGlhbC1jb250YWN0cy8uT3dsQm90LnlhbWwiLCJoIjoiZTI5MWM0ZGQxZDY3MGVkYTE5OTk4ZGU3NmY5NjdlMTYwM2E0ODk5MyJ9
Copy-Tag:
eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLWV2ZW50YXJjLXB1Ymxpc2hpbmcvLk93bEJvdC55YW1sIiwiaCI6ImUyOTFjNGRkMWQ2NzBlZGExOTk5OGRlNzZmOTY3ZTE2MDNhNDg5OTMifQ==
Copy-Tag:
eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLWV2ZW50YXJjLy5Pd2xCb3QueWFtbCIsImgiOiJlMjkxYzRkZDFkNjcwZWRhMTk5OThkZTc2Zjk2N2UxNjAzYTQ4OTkzIn0=
Copy-Tag:
eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLWZpbGVzdG9yZS8uT3dsQm90LnlhbWwiLCJoIjoiZTI5MWM0ZGQxZDY3MGVkYTE5OTk4ZGU3NmY5NjdlMTYwM2E0ODk5MyJ9
Copy-Tag:
eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLWZ1bmN0aW9ucy8uT3dsQm90LnlhbWwiLCJoIjoiZTI5MWM0ZGQxZDY3MGVkYTE5OTk4ZGU3NmY5NjdlMTYwM2E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29vZ2xlLWNsb3VkLW1hbmFnZWQtaWRlbnRpdGllcy8uT3dsQm90LnlhbWwiLCJoIjoiZTI5MWM0ZGQxZDY3MGVkYTE5OTk4ZGU3NmY5NjdlMTYwM2E0ODk5MyJ9

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: ohmayr <omairnaveed@ymail.com>
  • Loading branch information
3 people authored Feb 11, 2025
1 parent e92d527 commit 908d742
Show file tree
Hide file tree
Showing 176 changed files with 14,788 additions and 1,357 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
__version__ = "1.9.0" # {x-release-please-version}
__version__ = "0.0.0" # {x-release-please-version}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
__version__ = "1.9.0" # {x-release-please-version}
__version__ = "0.0.0" # {x-release-please-version}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# limitations under the License.
#
from collections import OrderedDict
from http import HTTPStatus
import json
import logging as std_logging
import os
import re
Expand Down Expand Up @@ -486,6 +488,33 @@ def _validate_universe_domain(self):
# NOTE (b/349488459): universe validation is disabled until further notice.
return True

def _add_cred_info_for_auth_errors(
self, error: core_exceptions.GoogleAPICallError
) -> None:
"""Adds credential info string to error details for 401/403/404 errors.
Args:
error (google.api_core.exceptions.GoogleAPICallError): The error to add the cred info.
"""
if error.code not in [
HTTPStatus.UNAUTHORIZED,
HTTPStatus.FORBIDDEN,
HTTPStatus.NOT_FOUND,
]:
return

cred = self._transport._credentials

# get_cred_info is only available in google-auth>=2.35.0
if not hasattr(cred, "get_cred_info"):
return

# ignore the type check since pypy test fails when get_cred_info
# is not available
cred_info = cred.get_cred_info() # type: ignore
if cred_info and hasattr(error._details, "append"):
error._details.append(json.dumps(cred_info))

@property
def api_endpoint(self):
"""Return the API endpoint used by the client instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,37 @@ def post_compute_contacts(
) -> service.ComputeContactsResponse:
"""Post-rpc interceptor for compute_contacts
Override in a subclass to manipulate the response
DEPRECATED. Please use the `post_compute_contacts_with_metadata`
interceptor instead.
Override in a subclass to read or manipulate the response
after it is returned by the EssentialContactsService server but before
it is returned to user code.
it is returned to user code. This `post_compute_contacts` interceptor runs
before the `post_compute_contacts_with_metadata` interceptor.
"""
return response

def post_compute_contacts_with_metadata(
self,
response: service.ComputeContactsResponse,
metadata: Sequence[Tuple[str, Union[str, bytes]]],
) -> Tuple[
service.ComputeContactsResponse, Sequence[Tuple[str, Union[str, bytes]]]
]:
"""Post-rpc interceptor for compute_contacts
Override in a subclass to read or manipulate the response or metadata after it
is returned by the EssentialContactsService server but before it is returned to user code.
We recommend only using this `post_compute_contacts_with_metadata`
interceptor in new development instead of the `post_compute_contacts` interceptor.
When both interceptors are used, this `post_compute_contacts_with_metadata` interceptor runs after the
`post_compute_contacts` interceptor. The (possibly modified) response returned by
`post_compute_contacts` will be passed to
`post_compute_contacts_with_metadata`.
"""
return response, metadata

def pre_create_contact(
self,
request: service.CreateContactRequest,
Expand All @@ -161,12 +186,35 @@ def pre_create_contact(
def post_create_contact(self, response: service.Contact) -> service.Contact:
"""Post-rpc interceptor for create_contact
Override in a subclass to manipulate the response
DEPRECATED. Please use the `post_create_contact_with_metadata`
interceptor instead.
Override in a subclass to read or manipulate the response
after it is returned by the EssentialContactsService server but before
it is returned to user code.
it is returned to user code. This `post_create_contact` interceptor runs
before the `post_create_contact_with_metadata` interceptor.
"""
return response

def post_create_contact_with_metadata(
self,
response: service.Contact,
metadata: Sequence[Tuple[str, Union[str, bytes]]],
) -> Tuple[service.Contact, Sequence[Tuple[str, Union[str, bytes]]]]:
"""Post-rpc interceptor for create_contact
Override in a subclass to read or manipulate the response or metadata after it
is returned by the EssentialContactsService server but before it is returned to user code.
We recommend only using this `post_create_contact_with_metadata`
interceptor in new development instead of the `post_create_contact` interceptor.
When both interceptors are used, this `post_create_contact_with_metadata` interceptor runs after the
`post_create_contact` interceptor. The (possibly modified) response returned by
`post_create_contact` will be passed to
`post_create_contact_with_metadata`.
"""
return response, metadata

def pre_delete_contact(
self,
request: service.DeleteContactRequest,
Expand Down Expand Up @@ -194,12 +242,35 @@ def pre_get_contact(
def post_get_contact(self, response: service.Contact) -> service.Contact:
"""Post-rpc interceptor for get_contact
Override in a subclass to manipulate the response
DEPRECATED. Please use the `post_get_contact_with_metadata`
interceptor instead.
Override in a subclass to read or manipulate the response
after it is returned by the EssentialContactsService server but before
it is returned to user code.
it is returned to user code. This `post_get_contact` interceptor runs
before the `post_get_contact_with_metadata` interceptor.
"""
return response

def post_get_contact_with_metadata(
self,
response: service.Contact,
metadata: Sequence[Tuple[str, Union[str, bytes]]],
) -> Tuple[service.Contact, Sequence[Tuple[str, Union[str, bytes]]]]:
"""Post-rpc interceptor for get_contact
Override in a subclass to read or manipulate the response or metadata after it
is returned by the EssentialContactsService server but before it is returned to user code.
We recommend only using this `post_get_contact_with_metadata`
interceptor in new development instead of the `post_get_contact` interceptor.
When both interceptors are used, this `post_get_contact_with_metadata` interceptor runs after the
`post_get_contact` interceptor. The (possibly modified) response returned by
`post_get_contact` will be passed to
`post_get_contact_with_metadata`.
"""
return response, metadata

def pre_list_contacts(
self,
request: service.ListContactsRequest,
Expand All @@ -217,12 +288,35 @@ def post_list_contacts(
) -> service.ListContactsResponse:
"""Post-rpc interceptor for list_contacts
Override in a subclass to manipulate the response
DEPRECATED. Please use the `post_list_contacts_with_metadata`
interceptor instead.
Override in a subclass to read or manipulate the response
after it is returned by the EssentialContactsService server but before
it is returned to user code.
it is returned to user code. This `post_list_contacts` interceptor runs
before the `post_list_contacts_with_metadata` interceptor.
"""
return response

def post_list_contacts_with_metadata(
self,
response: service.ListContactsResponse,
metadata: Sequence[Tuple[str, Union[str, bytes]]],
) -> Tuple[service.ListContactsResponse, Sequence[Tuple[str, Union[str, bytes]]]]:
"""Post-rpc interceptor for list_contacts
Override in a subclass to read or manipulate the response or metadata after it
is returned by the EssentialContactsService server but before it is returned to user code.
We recommend only using this `post_list_contacts_with_metadata`
interceptor in new development instead of the `post_list_contacts` interceptor.
When both interceptors are used, this `post_list_contacts_with_metadata` interceptor runs after the
`post_list_contacts` interceptor. The (possibly modified) response returned by
`post_list_contacts` will be passed to
`post_list_contacts_with_metadata`.
"""
return response, metadata

def pre_send_test_message(
self,
request: service.SendTestMessageRequest,
Expand Down Expand Up @@ -250,12 +344,35 @@ def pre_update_contact(
def post_update_contact(self, response: service.Contact) -> service.Contact:
"""Post-rpc interceptor for update_contact
Override in a subclass to manipulate the response
DEPRECATED. Please use the `post_update_contact_with_metadata`
interceptor instead.
Override in a subclass to read or manipulate the response
after it is returned by the EssentialContactsService server but before
it is returned to user code.
it is returned to user code. This `post_update_contact` interceptor runs
before the `post_update_contact_with_metadata` interceptor.
"""
return response

def post_update_contact_with_metadata(
self,
response: service.Contact,
metadata: Sequence[Tuple[str, Union[str, bytes]]],
) -> Tuple[service.Contact, Sequence[Tuple[str, Union[str, bytes]]]]:
"""Post-rpc interceptor for update_contact
Override in a subclass to read or manipulate the response or metadata after it
is returned by the EssentialContactsService server but before it is returned to user code.
We recommend only using this `post_update_contact_with_metadata`
interceptor in new development instead of the `post_update_contact` interceptor.
When both interceptors are used, this `post_update_contact_with_metadata` interceptor runs after the
`post_update_contact` interceptor. The (possibly modified) response returned by
`post_update_contact` will be passed to
`post_update_contact_with_metadata`.
"""
return response, metadata


@dataclasses.dataclass
class EssentialContactsServiceRestStub:
Expand Down Expand Up @@ -468,6 +585,10 @@ def __call__(
json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)

resp = self._interceptor.post_compute_contacts(resp)
response_metadata = [(k, str(v)) for k, v in response.headers.items()]
resp, _ = self._interceptor.post_compute_contacts_with_metadata(
resp, response_metadata
)
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
logging.DEBUG
): # pragma: NO COVER
Expand Down Expand Up @@ -620,6 +741,10 @@ def __call__(
json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)

resp = self._interceptor.post_create_contact(resp)
response_metadata = [(k, str(v)) for k, v in response.headers.items()]
resp, _ = self._interceptor.post_create_contact_with_metadata(
resp, response_metadata
)
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
logging.DEBUG
): # pragma: NO COVER
Expand Down Expand Up @@ -874,6 +999,10 @@ def __call__(
json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)

resp = self._interceptor.post_get_contact(resp)
response_metadata = [(k, str(v)) for k, v in response.headers.items()]
resp, _ = self._interceptor.post_get_contact_with_metadata(
resp, response_metadata
)
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
logging.DEBUG
): # pragma: NO COVER
Expand Down Expand Up @@ -1020,6 +1149,10 @@ def __call__(
json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)

resp = self._interceptor.post_list_contacts(resp)
response_metadata = [(k, str(v)) for k, v in response.headers.items()]
resp, _ = self._interceptor.post_list_contacts_with_metadata(
resp, response_metadata
)
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
logging.DEBUG
): # pragma: NO COVER
Expand Down Expand Up @@ -1290,6 +1423,10 @@ def __call__(
json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)

resp = self._interceptor.post_update_contact(resp)
response_metadata = [(k, str(v)) for k, v in response.headers.items()]
resp, _ = self._interceptor.post_update_contact_with_metadata(
resp, response_metadata
)
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
logging.DEBUG
): # pragma: NO COVER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"language": "PYTHON",
"name": "google-cloud-essential-contacts",
"version": "1.9.0"
"version": "0.1.0"
},
"snippets": [
{
Expand Down
Loading

0 comments on commit 908d742

Please sign in to comment.