Skip to content

Commit 1a8b173

Browse files
1 parent e5ebf96 commit 1a8b173

File tree

96 files changed

+469
-23397
lines changed

Some content is hidden

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

96 files changed

+469
-23397
lines changed

‎google/cloud/errorreporting_v1beta1/services/error_group_service/client.py‎

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

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

‎google/cloud/errorreporting_v1beta1/services/error_group_service/transports/rest.py‎

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,35 @@ def pre_get_group(
114114
def post_get_group(self, response: common.ErrorGroup) -> common.ErrorGroup:
115115
"""Post-rpc interceptor for get_group
116116
117-
Override in a subclass to manipulate the response
117+
DEPRECATED. Please use the `post_get_group_with_metadata`
118+
interceptor instead.
119+
120+
Override in a subclass to read or manipulate the response
118121
after it is returned by the ErrorGroupService server but before
119-
it is returned to user code.
122+
it is returned to user code. This `post_get_group` interceptor runs
123+
before the `post_get_group_with_metadata` interceptor.
120124
"""
121125
return response
122126

127+
def post_get_group_with_metadata(
128+
self,
129+
response: common.ErrorGroup,
130+
metadata: Sequence[Tuple[str, Union[str, bytes]]],
131+
) -> Tuple[common.ErrorGroup, Sequence[Tuple[str, Union[str, bytes]]]]:
132+
"""Post-rpc interceptor for get_group
133+
134+
Override in a subclass to read or manipulate the response or metadata after it
135+
is returned by the ErrorGroupService server but before it is returned to user code.
136+
137+
We recommend only using this `post_get_group_with_metadata`
138+
interceptor in new development instead of the `post_get_group` interceptor.
139+
When both interceptors are used, this `post_get_group_with_metadata` interceptor runs after the
140+
`post_get_group` interceptor. The (possibly modified) response returned by
141+
`post_get_group` will be passed to
142+
`post_get_group_with_metadata`.
143+
"""
144+
return response, metadata
145+
123146
def pre_update_group(
124147
self,
125148
request: error_group_service.UpdateGroupRequest,
@@ -137,12 +160,35 @@ def pre_update_group(
137160
def post_update_group(self, response: common.ErrorGroup) -> common.ErrorGroup:
138161
"""Post-rpc interceptor for update_group
139162
140-
Override in a subclass to manipulate the response
163+
DEPRECATED. Please use the `post_update_group_with_metadata`
164+
interceptor instead.
165+
166+
Override in a subclass to read or manipulate the response
141167
after it is returned by the ErrorGroupService server but before
142-
it is returned to user code.
168+
it is returned to user code. This `post_update_group` interceptor runs
169+
before the `post_update_group_with_metadata` interceptor.
143170
"""
144171
return response
145172

173+
def post_update_group_with_metadata(
174+
self,
175+
response: common.ErrorGroup,
176+
metadata: Sequence[Tuple[str, Union[str, bytes]]],
177+
) -> Tuple[common.ErrorGroup, Sequence[Tuple[str, Union[str, bytes]]]]:
178+
"""Post-rpc interceptor for update_group
179+
180+
Override in a subclass to read or manipulate the response or metadata after it
181+
is returned by the ErrorGroupService server but before it is returned to user code.
182+
183+
We recommend only using this `post_update_group_with_metadata`
184+
interceptor in new development instead of the `post_update_group` interceptor.
185+
When both interceptors are used, this `post_update_group_with_metadata` interceptor runs after the
186+
`post_update_group` interceptor. The (possibly modified) response returned by
187+
`post_update_group` will be passed to
188+
`post_update_group_with_metadata`.
189+
"""
190+
return response, metadata
191+
146192

147193
@dataclasses.dataclass
148194
class ErrorGroupServiceRestStub:
@@ -350,6 +396,10 @@ def __call__(
350396
json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
351397

352398
resp = self._interceptor.post_get_group(resp)
399+
response_metadata = [(k, str(v)) for k, v in response.headers.items()]
400+
resp, _ = self._interceptor.post_get_group_with_metadata(
401+
resp, response_metadata
402+
)
353403
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
354404
logging.DEBUG
355405
): # pragma: NO COVER
@@ -499,6 +549,10 @@ def __call__(
499549
json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
500550

501551
resp = self._interceptor.post_update_group(resp)
552+
response_metadata = [(k, str(v)) for k, v in response.headers.items()]
553+
resp, _ = self._interceptor.post_update_group_with_metadata(
554+
resp, response_metadata
555+
)
502556
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
503557
logging.DEBUG
504558
): # pragma: NO COVER

‎google/cloud/errorreporting_v1beta1/services/error_stats_service/client.py‎

Lines changed: 29 additions & 0 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.

‎google/cloud/errorreporting_v1beta1/services/error_stats_service/transports/rest.py‎

Lines changed: 95 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,38 @@ def post_delete_events(
123123
) -> error_stats_service.DeleteEventsResponse:
124124
"""Post-rpc interceptor for delete_events
125125
126-
Override in a subclass to manipulate the response
126+
DEPRECATED. Please use the `post_delete_events_with_metadata`
127+
interceptor instead.
128+
129+
Override in a subclass to read or manipulate the response
127130
after it is returned by the ErrorStatsService server but before
128-
it is returned to user code.
131+
it is returned to user code. This `post_delete_events` interceptor runs
132+
before the `post_delete_events_with_metadata` interceptor.
129133
"""
130134
return response
131135

136+
def post_delete_events_with_metadata(
137+
self,
138+
response: error_stats_service.DeleteEventsResponse,
139+
metadata: Sequence[Tuple[str, Union[str, bytes]]],
140+
) -> Tuple[
141+
error_stats_service.DeleteEventsResponse,
142+
Sequence[Tuple[str, Union[str, bytes]]],
143+
]:
144+
"""Post-rpc interceptor for delete_events
145+
146+
Override in a subclass to read or manipulate the response or metadata after it
147+
is returned by the ErrorStatsService server but before it is returned to user code.
148+
149+
We recommend only using this `post_delete_events_with_metadata`
150+
interceptor in new development instead of the `post_delete_events` interceptor.
151+
When both interceptors are used, this `post_delete_events_with_metadata` interceptor runs after the
152+
`post_delete_events` interceptor. The (possibly modified) response returned by
153+
`post_delete_events` will be passed to
154+
`post_delete_events_with_metadata`.
155+
"""
156+
return response, metadata
157+
132158
def pre_list_events(
133159
self,
134160
request: error_stats_service.ListEventsRequest,
@@ -148,12 +174,37 @@ def post_list_events(
148174
) -> error_stats_service.ListEventsResponse:
149175
"""Post-rpc interceptor for list_events
150176
151-
Override in a subclass to manipulate the response
177+
DEPRECATED. Please use the `post_list_events_with_metadata`
178+
interceptor instead.
179+
180+
Override in a subclass to read or manipulate the response
152181
after it is returned by the ErrorStatsService server but before
153-
it is returned to user code.
182+
it is returned to user code. This `post_list_events` interceptor runs
183+
before the `post_list_events_with_metadata` interceptor.
154184
"""
155185
return response
156186

187+
def post_list_events_with_metadata(
188+
self,
189+
response: error_stats_service.ListEventsResponse,
190+
metadata: Sequence[Tuple[str, Union[str, bytes]]],
191+
) -> Tuple[
192+
error_stats_service.ListEventsResponse, Sequence[Tuple[str, Union[str, bytes]]]
193+
]:
194+
"""Post-rpc interceptor for list_events
195+
196+
Override in a subclass to read or manipulate the response or metadata after it
197+
is returned by the ErrorStatsService server but before it is returned to user code.
198+
199+
We recommend only using this `post_list_events_with_metadata`
200+
interceptor in new development instead of the `post_list_events` interceptor.
201+
When both interceptors are used, this `post_list_events_with_metadata` interceptor runs after the
202+
`post_list_events` interceptor. The (possibly modified) response returned by
203+
`post_list_events` will be passed to
204+
`post_list_events_with_metadata`.
205+
"""
206+
return response, metadata
207+
157208
def pre_list_group_stats(
158209
self,
159210
request: error_stats_service.ListGroupStatsRequest,
@@ -174,12 +225,38 @@ def post_list_group_stats(
174225
) -> error_stats_service.ListGroupStatsResponse:
175226
"""Post-rpc interceptor for list_group_stats
176227
177-
Override in a subclass to manipulate the response
228+
DEPRECATED. Please use the `post_list_group_stats_with_metadata`
229+
interceptor instead.
230+
231+
Override in a subclass to read or manipulate the response
178232
after it is returned by the ErrorStatsService server but before
179-
it is returned to user code.
233+
it is returned to user code. This `post_list_group_stats` interceptor runs
234+
before the `post_list_group_stats_with_metadata` interceptor.
180235
"""
181236
return response
182237

238+
def post_list_group_stats_with_metadata(
239+
self,
240+
response: error_stats_service.ListGroupStatsResponse,
241+
metadata: Sequence[Tuple[str, Union[str, bytes]]],
242+
) -> Tuple[
243+
error_stats_service.ListGroupStatsResponse,
244+
Sequence[Tuple[str, Union[str, bytes]]],
245+
]:
246+
"""Post-rpc interceptor for list_group_stats
247+
248+
Override in a subclass to read or manipulate the response or metadata after it
249+
is returned by the ErrorStatsService server but before it is returned to user code.
250+
251+
We recommend only using this `post_list_group_stats_with_metadata`
252+
interceptor in new development instead of the `post_list_group_stats` interceptor.
253+
When both interceptors are used, this `post_list_group_stats_with_metadata` interceptor runs after the
254+
`post_list_group_stats` interceptor. The (possibly modified) response returned by
255+
`post_list_group_stats` will be passed to
256+
`post_list_group_stats_with_metadata`.
257+
"""
258+
return response, metadata
259+
183260

184261
@dataclasses.dataclass
185262
class ErrorStatsServiceRestStub:
@@ -387,6 +464,10 @@ def __call__(
387464
json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
388465

389466
resp = self._interceptor.post_delete_events(resp)
467+
response_metadata = [(k, str(v)) for k, v in response.headers.items()]
468+
resp, _ = self._interceptor.post_delete_events_with_metadata(
469+
resp, response_metadata
470+
)
390471
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
391472
logging.DEBUG
392473
): # pragma: NO COVER
@@ -532,6 +613,10 @@ def __call__(
532613
json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
533614

534615
resp = self._interceptor.post_list_events(resp)
616+
response_metadata = [(k, str(v)) for k, v in response.headers.items()]
617+
resp, _ = self._interceptor.post_list_events_with_metadata(
618+
resp, response_metadata
619+
)
535620
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
536621
logging.DEBUG
537622
): # pragma: NO COVER
@@ -679,6 +764,10 @@ def __call__(
679764
json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
680765

681766
resp = self._interceptor.post_list_group_stats(resp)
767+
response_metadata = [(k, str(v)) for k, v in response.headers.items()]
768+
resp, _ = self._interceptor.post_list_group_stats_with_metadata(
769+
resp, response_metadata
770+
)
682771
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
683772
logging.DEBUG
684773
): # pragma: NO COVER

‎google/cloud/errorreporting_v1beta1/services/report_errors_service/client.py‎

Lines changed: 29 additions & 0 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
@@ -460,6 +462,33 @@ def _validate_universe_domain(self):
460462
# NOTE (b/349488459): universe validation is disabled until further notice.
461463
return True
462464

465+
def _add_cred_info_for_auth_errors(
466+
self, error: core_exceptions.GoogleAPICallError
467+
) -> None:
468+
"""Adds credential info string to error details for 401/403/404 errors.
469+
470+
Args:
471+
error (google.api_core.exceptions.GoogleAPICallError): The error to add the cred info.
472+
"""
473+
if error.code not in [
474+
HTTPStatus.UNAUTHORIZED,
475+
HTTPStatus.FORBIDDEN,
476+
HTTPStatus.NOT_FOUND,
477+
]:
478+
return
479+
480+
cred = self._transport._credentials
481+
482+
# get_cred_info is only available in google-auth>=2.35.0
483+
if not hasattr(cred, "get_cred_info"):
484+
return
485+
486+
# ignore the type check since pypy test fails when get_cred_info
487+
# is not available
488+
cred_info = cred.get_cred_info() # type: ignore
489+
if cred_info and hasattr(error._details, "append"):
490+
error._details.append(json.dumps(cred_info))
491+
463492
@property
464493
def api_endpoint(self):
465494
"""Return the API endpoint used by the client instance.

0 commit comments

Comments
 (0)