Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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.24.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.24.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 @@ -461,6 +463,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 @@ -118,12 +118,37 @@ def post_aggregated_list(
) -> compute.AcceleratorTypeAggregatedList:
"""Post-rpc interceptor for aggregated_list

Override in a subclass to manipulate the response
DEPRECATED. Please use the `post_aggregated_list_with_metadata`
interceptor instead.

Override in a subclass to read or manipulate the response
after it is returned by the AcceleratorTypes server but before
it is returned to user code.
it is returned to user code. This `post_aggregated_list` interceptor runs
before the `post_aggregated_list_with_metadata` interceptor.
"""
return response

def post_aggregated_list_with_metadata(
self,
response: compute.AcceleratorTypeAggregatedList,
metadata: Sequence[Tuple[str, Union[str, bytes]]],
) -> Tuple[
compute.AcceleratorTypeAggregatedList, Sequence[Tuple[str, Union[str, bytes]]]
]:
"""Post-rpc interceptor for aggregated_list

Override in a subclass to read or manipulate the response or metadata after it
is returned by the AcceleratorTypes server but before it is returned to user code.

We recommend only using this `post_aggregated_list_with_metadata`
interceptor in new development instead of the `post_aggregated_list` interceptor.
When both interceptors are used, this `post_aggregated_list_with_metadata` interceptor runs after the
`post_aggregated_list` interceptor. The (possibly modified) response returned by
`post_aggregated_list` will be passed to
`post_aggregated_list_with_metadata`.
"""
return response, metadata

def pre_get(
self,
request: compute.GetAcceleratorTypeRequest,
Expand All @@ -141,12 +166,35 @@ def pre_get(
def post_get(self, response: compute.AcceleratorType) -> compute.AcceleratorType:
"""Post-rpc interceptor for get

Override in a subclass to manipulate the response
DEPRECATED. Please use the `post_get_with_metadata`
interceptor instead.

Override in a subclass to read or manipulate the response
after it is returned by the AcceleratorTypes server but before
it is returned to user code.
it is returned to user code. This `post_get` interceptor runs
before the `post_get_with_metadata` interceptor.
"""
return response

def post_get_with_metadata(
self,
response: compute.AcceleratorType,
metadata: Sequence[Tuple[str, Union[str, bytes]]],
) -> Tuple[compute.AcceleratorType, Sequence[Tuple[str, Union[str, bytes]]]]:
"""Post-rpc interceptor for get

Override in a subclass to read or manipulate the response or metadata after it
is returned by the AcceleratorTypes server but before it is returned to user code.

We recommend only using this `post_get_with_metadata`
interceptor in new development instead of the `post_get` interceptor.
When both interceptors are used, this `post_get_with_metadata` interceptor runs after the
`post_get` interceptor. The (possibly modified) response returned by
`post_get` will be passed to
`post_get_with_metadata`.
"""
return response, metadata

def pre_list(
self,
request: compute.ListAcceleratorTypesRequest,
Expand All @@ -166,12 +214,35 @@ def post_list(
) -> compute.AcceleratorTypeList:
"""Post-rpc interceptor for list

Override in a subclass to manipulate the response
DEPRECATED. Please use the `post_list_with_metadata`
interceptor instead.

Override in a subclass to read or manipulate the response
after it is returned by the AcceleratorTypes server but before
it is returned to user code.
it is returned to user code. This `post_list` interceptor runs
before the `post_list_with_metadata` interceptor.
"""
return response

def post_list_with_metadata(
self,
response: compute.AcceleratorTypeList,
metadata: Sequence[Tuple[str, Union[str, bytes]]],
) -> Tuple[compute.AcceleratorTypeList, Sequence[Tuple[str, Union[str, bytes]]]]:
"""Post-rpc interceptor for list

Override in a subclass to read or manipulate the response or metadata after it
is returned by the AcceleratorTypes server but before it is returned to user code.

We recommend only using this `post_list_with_metadata`
interceptor in new development instead of the `post_list` interceptor.
When both interceptors are used, this `post_list_with_metadata` interceptor runs after the
`post_list` interceptor. The (possibly modified) response returned by
`post_list` will be passed to
`post_list_with_metadata`.
"""
return response, metadata


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

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

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

resp = self._interceptor.post_list(resp)
response_metadata = [(k, str(v)) for k, v in response.headers.items()]
resp, _ = self._interceptor.post_list_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 @@ -15,6 +15,8 @@
#
from collections import OrderedDict
import functools
from http import HTTPStatus
import json
import logging as std_logging
import os
import re
Expand Down Expand Up @@ -459,6 +461,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
Loading
Loading