Skip to content

Commit 30b675e

Browse files
feat: [Many APIs] Add REST Interceptors which support reading metadata (#13503)
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: eyJwIjoicGFja2FnZXMvZ29vZ2xlLW1hcHMtbWFwc3BsYXRmb3JtZGF0YXNldHMvLk93bEJvdC55YW1sIiwiaCI6ImUyOTFjNGRkMWQ2NzBlZGExOTk5OGRlNzZmOTY3ZTE2MDNhNDg5OTMifQ== Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLW1hcHMtcm91dGVvcHRpbWl6YXRpb24vLk93bEJvdC55YW1sIiwiaCI6ImUyOTFjNGRkMWQ2NzBlZGExOTk5OGRlNzZmOTY3ZTE2MDNhNDg5OTMifQ== Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLW1hcHMtcm91dGluZy8uT3dsQm90LnlhbWwiLCJoIjoiZTI5MWM0ZGQxZDY3MGVkYTE5OTk4ZGU3NmY5NjdlMTYwM2E0ODk5MyJ9 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLW1hcHMtc29sYXIvLk93bEJvdC55YW1sIiwiaCI6ImUyOTFjNGRkMWQ2NzBlZGExOTk5OGRlNzZmOTY3ZTE2MDNhNDg5OTMifQ== Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLXNob3BwaW5nLWNzcy8uT3dsQm90LnlhbWwiLCJoIjoiZTI5MWM0ZGQxZDY3MGVkYTE5OTk4ZGU3NmY5NjdlMTYwM2E0ODk5MyJ9 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLXNob3BwaW5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4OTkzIn0= Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLXNob3BwaW5nLW1lcmNoYW50LXByb21vdGlvbnMvLk93bEJvdC55YW1sIiwiaCI6ImUyOTFjNGRkMWQ2NzBlZGExOTk5OGRlNzZmOTY3ZTE2MDNhNDg5OTMifQ== Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLXNob3BwaW5nLW1lcmNoYW50LXF1b3RhLy5Pd2xCb3QueWFtbCIsImgiOiJlMjkxYzRkZDFkNjcwZWRhMTk5OThkZTc2Zjk2N2UxNjAzYTQ4OTkzIn0= Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLXNob3BwaW5nLW1lcmNoYW50LXJlcG9ydHMvLk93bEJvdC55YW1sIiwiaCI6ImUyOTFjNGRkMWQ2NzBlZGExOTk5OGRlNzZmOTY3ZTE2MDNhNDg5OTMifQ== Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLXNob3BwaW5nLW1lcmNoYW50LXJldmlld3MvLk93bEJvdC55YW1sIiwiaCI6ImUyOTFjNGRkMWQ2NzBlZGExOTk5OGRlNzZmOTY3ZTE2MDNhNDg5OTMifQ== Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLXNob3BwaW5nLXR5cGUvLk93bEJvdC55YW1sIiwiaCI6ImUyOTFjNGRkMWQ2NzBlZGExOTk5OGRlNzZmOTY3ZTE2MDNhNDg5OTMifQ== Copy-Tag: eyJwIjoicGFja2FnZXMvZ3JhZmVhcy8uT3dsQm90LnlhbWwiLCJoIjoiZTI5MWM0ZGQxZDY3MGVkYTE5OTk4ZGU3NmY5NjdlMTYwM2E0ODk5MyJ9 --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent a31de41 commit 30b675e

File tree

208 files changed

+8746
-356
lines changed

Some content is hidden

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

208 files changed

+8746
-356
lines changed

packages/google-maps-mapsplatformdatasets/README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ In order to use this library, you first need to go through the following steps:
2626
1. `Select or create a Cloud Platform project.`_
2727
2. `Enable billing for your project.`_
2828
3. `Enable the Maps Platform Datasets API.`_
29-
4. `Setup Authentication.`_
29+
4. `Set up Authentication.`_
3030

3131
.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project
3232
.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project
3333
.. _Enable the Maps Platform Datasets API.: https://developers.google.com/maps
34-
.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html
34+
.. _Set up Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html
3535

3636
Installation
3737
~~~~~~~~~~~~

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

packages/google-maps-mapsplatformdatasets/google/maps/mapsplatformdatasets_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__ = "0.4.5" # {x-release-please-version}
16+
__version__ = "0.0.0" # {x-release-please-version}

packages/google-maps-mapsplatformdatasets/google/maps/mapsplatformdatasets_v1/services/maps_platform_datasets/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
@@ -486,6 +488,33 @@ def _validate_universe_domain(self):
486488
# NOTE (b/349488459): universe validation is disabled until further notice.
487489
return True
488490

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

packages/google-maps-mapsplatformdatasets/google/maps/mapsplatformdatasets_v1/services/maps_platform_datasets/transports/rest.py

Lines changed: 151 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,35 @@ def pre_create_dataset(
139139
def post_create_dataset(self, response: gmm_dataset.Dataset) -> gmm_dataset.Dataset:
140140
"""Post-rpc interceptor for create_dataset
141141
142-
Override in a subclass to manipulate the response
142+
DEPRECATED. Please use the `post_create_dataset_with_metadata`
143+
interceptor instead.
144+
145+
Override in a subclass to read or manipulate the response
143146
after it is returned by the MapsPlatformDatasets server but before
144-
it is returned to user code.
147+
it is returned to user code. This `post_create_dataset` interceptor runs
148+
before the `post_create_dataset_with_metadata` interceptor.
145149
"""
146150
return response
147151

152+
def post_create_dataset_with_metadata(
153+
self,
154+
response: gmm_dataset.Dataset,
155+
metadata: Sequence[Tuple[str, Union[str, bytes]]],
156+
) -> Tuple[gmm_dataset.Dataset, Sequence[Tuple[str, Union[str, bytes]]]]:
157+
"""Post-rpc interceptor for create_dataset
158+
159+
Override in a subclass to read or manipulate the response or metadata after it
160+
is returned by the MapsPlatformDatasets server but before it is returned to user code.
161+
162+
We recommend only using this `post_create_dataset_with_metadata`
163+
interceptor in new development instead of the `post_create_dataset` interceptor.
164+
When both interceptors are used, this `post_create_dataset_with_metadata` interceptor runs after the
165+
`post_create_dataset` interceptor. The (possibly modified) response returned by
166+
`post_create_dataset` will be passed to
167+
`post_create_dataset_with_metadata`.
168+
"""
169+
return response, metadata
170+
148171
def pre_delete_dataset(
149172
self,
150173
request: maps_platform_datasets.DeleteDatasetRequest,
@@ -180,12 +203,38 @@ def post_fetch_dataset_errors(
180203
) -> maps_platform_datasets.FetchDatasetErrorsResponse:
181204
"""Post-rpc interceptor for fetch_dataset_errors
182205
183-
Override in a subclass to manipulate the response
206+
DEPRECATED. Please use the `post_fetch_dataset_errors_with_metadata`
207+
interceptor instead.
208+
209+
Override in a subclass to read or manipulate the response
184210
after it is returned by the MapsPlatformDatasets server but before
185-
it is returned to user code.
211+
it is returned to user code. This `post_fetch_dataset_errors` interceptor runs
212+
before the `post_fetch_dataset_errors_with_metadata` interceptor.
186213
"""
187214
return response
188215

216+
def post_fetch_dataset_errors_with_metadata(
217+
self,
218+
response: maps_platform_datasets.FetchDatasetErrorsResponse,
219+
metadata: Sequence[Tuple[str, Union[str, bytes]]],
220+
) -> Tuple[
221+
maps_platform_datasets.FetchDatasetErrorsResponse,
222+
Sequence[Tuple[str, Union[str, bytes]]],
223+
]:
224+
"""Post-rpc interceptor for fetch_dataset_errors
225+
226+
Override in a subclass to read or manipulate the response or metadata after it
227+
is returned by the MapsPlatformDatasets server but before it is returned to user code.
228+
229+
We recommend only using this `post_fetch_dataset_errors_with_metadata`
230+
interceptor in new development instead of the `post_fetch_dataset_errors` interceptor.
231+
When both interceptors are used, this `post_fetch_dataset_errors_with_metadata` interceptor runs after the
232+
`post_fetch_dataset_errors` interceptor. The (possibly modified) response returned by
233+
`post_fetch_dataset_errors` will be passed to
234+
`post_fetch_dataset_errors_with_metadata`.
235+
"""
236+
return response, metadata
237+
189238
def pre_get_dataset(
190239
self,
191240
request: maps_platform_datasets.GetDatasetRequest,
@@ -204,12 +253,35 @@ def pre_get_dataset(
204253
def post_get_dataset(self, response: dataset.Dataset) -> dataset.Dataset:
205254
"""Post-rpc interceptor for get_dataset
206255
207-
Override in a subclass to manipulate the response
256+
DEPRECATED. Please use the `post_get_dataset_with_metadata`
257+
interceptor instead.
258+
259+
Override in a subclass to read or manipulate the response
208260
after it is returned by the MapsPlatformDatasets server but before
209-
it is returned to user code.
261+
it is returned to user code. This `post_get_dataset` interceptor runs
262+
before the `post_get_dataset_with_metadata` interceptor.
210263
"""
211264
return response
212265

266+
def post_get_dataset_with_metadata(
267+
self,
268+
response: dataset.Dataset,
269+
metadata: Sequence[Tuple[str, Union[str, bytes]]],
270+
) -> Tuple[dataset.Dataset, Sequence[Tuple[str, Union[str, bytes]]]]:
271+
"""Post-rpc interceptor for get_dataset
272+
273+
Override in a subclass to read or manipulate the response or metadata after it
274+
is returned by the MapsPlatformDatasets server but before it is returned to user code.
275+
276+
We recommend only using this `post_get_dataset_with_metadata`
277+
interceptor in new development instead of the `post_get_dataset` interceptor.
278+
When both interceptors are used, this `post_get_dataset_with_metadata` interceptor runs after the
279+
`post_get_dataset` interceptor. The (possibly modified) response returned by
280+
`post_get_dataset` will be passed to
281+
`post_get_dataset_with_metadata`.
282+
"""
283+
return response, metadata
284+
213285
def pre_list_datasets(
214286
self,
215287
request: maps_platform_datasets.ListDatasetsRequest,
@@ -230,12 +302,38 @@ def post_list_datasets(
230302
) -> maps_platform_datasets.ListDatasetsResponse:
231303
"""Post-rpc interceptor for list_datasets
232304
233-
Override in a subclass to manipulate the response
305+
DEPRECATED. Please use the `post_list_datasets_with_metadata`
306+
interceptor instead.
307+
308+
Override in a subclass to read or manipulate the response
234309
after it is returned by the MapsPlatformDatasets server but before
235-
it is returned to user code.
310+
it is returned to user code. This `post_list_datasets` interceptor runs
311+
before the `post_list_datasets_with_metadata` interceptor.
236312
"""
237313
return response
238314

315+
def post_list_datasets_with_metadata(
316+
self,
317+
response: maps_platform_datasets.ListDatasetsResponse,
318+
metadata: Sequence[Tuple[str, Union[str, bytes]]],
319+
) -> Tuple[
320+
maps_platform_datasets.ListDatasetsResponse,
321+
Sequence[Tuple[str, Union[str, bytes]]],
322+
]:
323+
"""Post-rpc interceptor for list_datasets
324+
325+
Override in a subclass to read or manipulate the response or metadata after it
326+
is returned by the MapsPlatformDatasets server but before it is returned to user code.
327+
328+
We recommend only using this `post_list_datasets_with_metadata`
329+
interceptor in new development instead of the `post_list_datasets` interceptor.
330+
When both interceptors are used, this `post_list_datasets_with_metadata` interceptor runs after the
331+
`post_list_datasets` interceptor. The (possibly modified) response returned by
332+
`post_list_datasets` will be passed to
333+
`post_list_datasets_with_metadata`.
334+
"""
335+
return response, metadata
336+
239337
def pre_update_dataset_metadata(
240338
self,
241339
request: maps_platform_datasets.UpdateDatasetMetadataRequest,
@@ -256,12 +354,35 @@ def post_update_dataset_metadata(
256354
) -> gmm_dataset.Dataset:
257355
"""Post-rpc interceptor for update_dataset_metadata
258356
259-
Override in a subclass to manipulate the response
357+
DEPRECATED. Please use the `post_update_dataset_metadata_with_metadata`
358+
interceptor instead.
359+
360+
Override in a subclass to read or manipulate the response
260361
after it is returned by the MapsPlatformDatasets server but before
261-
it is returned to user code.
362+
it is returned to user code. This `post_update_dataset_metadata` interceptor runs
363+
before the `post_update_dataset_metadata_with_metadata` interceptor.
262364
"""
263365
return response
264366

367+
def post_update_dataset_metadata_with_metadata(
368+
self,
369+
response: gmm_dataset.Dataset,
370+
metadata: Sequence[Tuple[str, Union[str, bytes]]],
371+
) -> Tuple[gmm_dataset.Dataset, Sequence[Tuple[str, Union[str, bytes]]]]:
372+
"""Post-rpc interceptor for update_dataset_metadata
373+
374+
Override in a subclass to read or manipulate the response or metadata after it
375+
is returned by the MapsPlatformDatasets server but before it is returned to user code.
376+
377+
We recommend only using this `post_update_dataset_metadata_with_metadata`
378+
interceptor in new development instead of the `post_update_dataset_metadata` interceptor.
379+
When both interceptors are used, this `post_update_dataset_metadata_with_metadata` interceptor runs after the
380+
`post_update_dataset_metadata` interceptor. The (possibly modified) response returned by
381+
`post_update_dataset_metadata` will be passed to
382+
`post_update_dataset_metadata_with_metadata`.
383+
"""
384+
return response, metadata
385+
265386

266387
@dataclasses.dataclass
267388
class MapsPlatformDatasetsRestStub:
@@ -475,6 +596,10 @@ def __call__(
475596
json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
476597

477598
resp = self._interceptor.post_create_dataset(resp)
599+
response_metadata = [(k, str(v)) for k, v in response.headers.items()]
600+
resp, _ = self._interceptor.post_create_dataset_with_metadata(
601+
resp, response_metadata
602+
)
478603
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
479604
logging.DEBUG
480605
): # pragma: NO COVER
@@ -730,6 +855,10 @@ def __call__(
730855
json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
731856

732857
resp = self._interceptor.post_fetch_dataset_errors(resp)
858+
response_metadata = [(k, str(v)) for k, v in response.headers.items()]
859+
resp, _ = self._interceptor.post_fetch_dataset_errors_with_metadata(
860+
resp, response_metadata
861+
)
733862
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
734863
logging.DEBUG
735864
): # pragma: NO COVER
@@ -877,6 +1006,10 @@ def __call__(
8771006
json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
8781007

8791008
resp = self._interceptor.post_get_dataset(resp)
1009+
response_metadata = [(k, str(v)) for k, v in response.headers.items()]
1010+
resp, _ = self._interceptor.post_get_dataset_with_metadata(
1011+
resp, response_metadata
1012+
)
8801013
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
8811014
logging.DEBUG
8821015
): # pragma: NO COVER
@@ -1019,6 +1152,10 @@ def __call__(
10191152
json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
10201153

10211154
resp = self._interceptor.post_list_datasets(resp)
1155+
response_metadata = [(k, str(v)) for k, v in response.headers.items()]
1156+
resp, _ = self._interceptor.post_list_datasets_with_metadata(
1157+
resp, response_metadata
1158+
)
10221159
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
10231160
logging.DEBUG
10241161
): # pragma: NO COVER
@@ -1175,6 +1312,10 @@ def __call__(
11751312
json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
11761313

11771314
resp = self._interceptor.post_update_dataset_metadata(resp)
1315+
response_metadata = [(k, str(v)) for k, v in response.headers.items()]
1316+
resp, _ = self._interceptor.post_update_dataset_metadata_with_metadata(
1317+
resp, response_metadata
1318+
)
11781319
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
11791320
logging.DEBUG
11801321
): # pragma: NO COVER

0 commit comments

Comments
 (0)