Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Commit e6bd01b

Browse files
feat: enable "rest" transport in Python for services supporting numeric enums (#549)
* feat: enable "rest" transport in Python for services supporting numeric enums PiperOrigin-RevId: 508143576 Source-Link: googleapis/googleapis@7a702a9 Source-Link: https://github.com/googleapis/googleapis-gen/commit/6ad1279c0e7aa787ac6b66c9fd4a210692edffcd Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNmFkMTI3OWMwZTdhYTc4N2FjNmI2NmM5ZmQ0YTIxMDY5MmVkZmZjZCJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * revert * Update samples and tests to use REST transport * revert * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * fix typo * add pytest import * lint * fix tests * fix: Add service_yaml_parameters to py_gapic_library BUILD.bazel targets PiperOrigin-RevId: 510187992 Source-Link: googleapis/googleapis@5edc235 Source-Link: https://github.com/googleapis/googleapis-gen/commit/b0bedb72e4765a3e0b674a28c50ea0f9a9b26a89 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYjBiZWRiNzJlNDc2NWEzZTBiNjc0YTI4YzUwZWEwZjlhOWIyNmE4OSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * revert * update tests to allow running both grpc and rest * remove transport for fixture * only test grpc for eventually_consistent_test * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * lint * fix tests * revert changes to test for rest transport * lint * fix test * testing * fix test --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent 5189a57 commit e6bd01b

File tree

69 files changed

+15546
-421
lines changed

Some content is hidden

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

69 files changed

+15546
-421
lines changed

google/cloud/asset_v1/gapic_metadata.json

+120
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,126 @@
246246
]
247247
}
248248
}
249+
},
250+
"rest": {
251+
"libraryClient": "AssetServiceClient",
252+
"rpcs": {
253+
"AnalyzeIamPolicy": {
254+
"methods": [
255+
"analyze_iam_policy"
256+
]
257+
},
258+
"AnalyzeIamPolicyLongrunning": {
259+
"methods": [
260+
"analyze_iam_policy_longrunning"
261+
]
262+
},
263+
"AnalyzeMove": {
264+
"methods": [
265+
"analyze_move"
266+
]
267+
},
268+
"AnalyzeOrgPolicies": {
269+
"methods": [
270+
"analyze_org_policies"
271+
]
272+
},
273+
"AnalyzeOrgPolicyGovernedAssets": {
274+
"methods": [
275+
"analyze_org_policy_governed_assets"
276+
]
277+
},
278+
"AnalyzeOrgPolicyGovernedContainers": {
279+
"methods": [
280+
"analyze_org_policy_governed_containers"
281+
]
282+
},
283+
"BatchGetAssetsHistory": {
284+
"methods": [
285+
"batch_get_assets_history"
286+
]
287+
},
288+
"BatchGetEffectiveIamPolicies": {
289+
"methods": [
290+
"batch_get_effective_iam_policies"
291+
]
292+
},
293+
"CreateFeed": {
294+
"methods": [
295+
"create_feed"
296+
]
297+
},
298+
"CreateSavedQuery": {
299+
"methods": [
300+
"create_saved_query"
301+
]
302+
},
303+
"DeleteFeed": {
304+
"methods": [
305+
"delete_feed"
306+
]
307+
},
308+
"DeleteSavedQuery": {
309+
"methods": [
310+
"delete_saved_query"
311+
]
312+
},
313+
"ExportAssets": {
314+
"methods": [
315+
"export_assets"
316+
]
317+
},
318+
"GetFeed": {
319+
"methods": [
320+
"get_feed"
321+
]
322+
},
323+
"GetSavedQuery": {
324+
"methods": [
325+
"get_saved_query"
326+
]
327+
},
328+
"ListAssets": {
329+
"methods": [
330+
"list_assets"
331+
]
332+
},
333+
"ListFeeds": {
334+
"methods": [
335+
"list_feeds"
336+
]
337+
},
338+
"ListSavedQueries": {
339+
"methods": [
340+
"list_saved_queries"
341+
]
342+
},
343+
"QueryAssets": {
344+
"methods": [
345+
"query_assets"
346+
]
347+
},
348+
"SearchAllIamPolicies": {
349+
"methods": [
350+
"search_all_iam_policies"
351+
]
352+
},
353+
"SearchAllResources": {
354+
"methods": [
355+
"search_all_resources"
356+
]
357+
},
358+
"UpdateFeed": {
359+
"methods": [
360+
"update_feed"
361+
]
362+
},
363+
"UpdateSavedQuery": {
364+
"methods": [
365+
"update_saved_query"
366+
]
367+
}
368+
}
249369
}
250370
}
251371
}

google/cloud/asset_v1/services/asset_service/async_client.py

+55
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
from google.cloud.asset_v1.services.asset_service import pagers
4848
from google.cloud.asset_v1.types import asset_service
4949
from google.cloud.asset_v1.types import assets
50+
from google.longrunning import operations_pb2
5051
from google.protobuf import field_mask_pb2 # type: ignore
5152
from google.protobuf import timestamp_pb2 # type: ignore
5253
from google.rpc import status_pb2 # type: ignore
@@ -3139,6 +3140,60 @@ async def sample_analyze_org_policy_governed_assets():
31393140
# Done; return the response.
31403141
return response
31413142

3143+
async def get_operation(
3144+
self,
3145+
request: Optional[operations_pb2.GetOperationRequest] = None,
3146+
*,
3147+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
3148+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3149+
metadata: Sequence[Tuple[str, str]] = (),
3150+
) -> operations_pb2.Operation:
3151+
r"""Gets the latest state of a long-running operation.
3152+
3153+
Args:
3154+
request (:class:`~.operations_pb2.GetOperationRequest`):
3155+
The request object. Request message for
3156+
`GetOperation` method.
3157+
retry (google.api_core.retry.Retry): Designation of what errors,
3158+
if any, should be retried.
3159+
timeout (float): The timeout for this request.
3160+
metadata (Sequence[Tuple[str, str]]): Strings which should be
3161+
sent along with the request as metadata.
3162+
Returns:
3163+
~.operations_pb2.Operation:
3164+
An ``Operation`` object.
3165+
"""
3166+
# Create or coerce a protobuf request object.
3167+
# The request isn't a proto-plus wrapped type,
3168+
# so it must be constructed via keyword expansion.
3169+
if isinstance(request, dict):
3170+
request = operations_pb2.GetOperationRequest(**request)
3171+
3172+
# Wrap the RPC method; this adds retry and timeout information,
3173+
# and friendly error handling.
3174+
rpc = gapic_v1.method.wrap_method(
3175+
self._client._transport.get_operation,
3176+
default_timeout=None,
3177+
client_info=DEFAULT_CLIENT_INFO,
3178+
)
3179+
3180+
# Certain fields should be provided within the metadata header;
3181+
# add these here.
3182+
metadata = tuple(metadata) + (
3183+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
3184+
)
3185+
3186+
# Send the request.
3187+
response = await rpc(
3188+
request,
3189+
retry=retry,
3190+
timeout=timeout,
3191+
metadata=metadata,
3192+
)
3193+
3194+
# Done; return the response.
3195+
return response
3196+
31423197
async def __aenter__(self):
31433198
return self
31443199

google/cloud/asset_v1/services/asset_service/client.py

+57
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@
5151
from google.cloud.asset_v1.services.asset_service import pagers
5252
from google.cloud.asset_v1.types import asset_service
5353
from google.cloud.asset_v1.types import assets
54+
from google.longrunning import operations_pb2
5455
from google.protobuf import field_mask_pb2 # type: ignore
5556
from google.protobuf import timestamp_pb2 # type: ignore
5657
from google.rpc import status_pb2 # type: ignore
5758
from google.type import expr_pb2 # type: ignore
5859
from .transports.base import AssetServiceTransport, DEFAULT_CLIENT_INFO
5960
from .transports.grpc import AssetServiceGrpcTransport
6061
from .transports.grpc_asyncio import AssetServiceGrpcAsyncIOTransport
62+
from .transports.rest import AssetServiceRestTransport
6163

6264

6365
class AssetServiceClientMeta(type):
@@ -71,6 +73,7 @@ class AssetServiceClientMeta(type):
7173
_transport_registry = OrderedDict() # type: Dict[str, Type[AssetServiceTransport]]
7274
_transport_registry["grpc"] = AssetServiceGrpcTransport
7375
_transport_registry["grpc_asyncio"] = AssetServiceGrpcAsyncIOTransport
76+
_transport_registry["rest"] = AssetServiceRestTransport
7477

7578
def get_transport_class(
7679
cls,
@@ -3355,6 +3358,60 @@ def __exit__(self, type, value, traceback):
33553358
"""
33563359
self.transport.close()
33573360

3361+
def get_operation(
3362+
self,
3363+
request: Optional[operations_pb2.GetOperationRequest] = None,
3364+
*,
3365+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
3366+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
3367+
metadata: Sequence[Tuple[str, str]] = (),
3368+
) -> operations_pb2.Operation:
3369+
r"""Gets the latest state of a long-running operation.
3370+
3371+
Args:
3372+
request (:class:`~.operations_pb2.GetOperationRequest`):
3373+
The request object. Request message for
3374+
`GetOperation` method.
3375+
retry (google.api_core.retry.Retry): Designation of what errors,
3376+
if any, should be retried.
3377+
timeout (float): The timeout for this request.
3378+
metadata (Sequence[Tuple[str, str]]): Strings which should be
3379+
sent along with the request as metadata.
3380+
Returns:
3381+
~.operations_pb2.Operation:
3382+
An ``Operation`` object.
3383+
"""
3384+
# Create or coerce a protobuf request object.
3385+
# The request isn't a proto-plus wrapped type,
3386+
# so it must be constructed via keyword expansion.
3387+
if isinstance(request, dict):
3388+
request = operations_pb2.GetOperationRequest(**request)
3389+
3390+
# Wrap the RPC method; this adds retry and timeout information,
3391+
# and friendly error handling.
3392+
rpc = gapic_v1.method.wrap_method(
3393+
self._transport.get_operation,
3394+
default_timeout=None,
3395+
client_info=DEFAULT_CLIENT_INFO,
3396+
)
3397+
3398+
# Certain fields should be provided within the metadata header;
3399+
# add these here.
3400+
metadata = tuple(metadata) + (
3401+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
3402+
)
3403+
3404+
# Send the request.
3405+
response = rpc(
3406+
request,
3407+
retry=retry,
3408+
timeout=timeout,
3409+
metadata=metadata,
3410+
)
3411+
3412+
# Done; return the response.
3413+
return response
3414+
33583415

33593416
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
33603417
gapic_version=package_version.__version__

google/cloud/asset_v1/services/asset_service/transports/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,20 @@
1919
from .base import AssetServiceTransport
2020
from .grpc import AssetServiceGrpcTransport
2121
from .grpc_asyncio import AssetServiceGrpcAsyncIOTransport
22+
from .rest import AssetServiceRestTransport
23+
from .rest import AssetServiceRestInterceptor
2224

2325

2426
# Compile a registry of transports.
2527
_transport_registry = OrderedDict() # type: Dict[str, Type[AssetServiceTransport]]
2628
_transport_registry["grpc"] = AssetServiceGrpcTransport
2729
_transport_registry["grpc_asyncio"] = AssetServiceGrpcAsyncIOTransport
30+
_transport_registry["rest"] = AssetServiceRestTransport
2831

2932
__all__ = (
3033
"AssetServiceTransport",
3134
"AssetServiceGrpcTransport",
3235
"AssetServiceGrpcAsyncIOTransport",
36+
"AssetServiceRestTransport",
37+
"AssetServiceRestInterceptor",
3338
)

google/cloud/asset_v1/services/asset_service/transports/base.py

+10
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from google.oauth2 import service_account # type: ignore
2929

3030
from google.cloud.asset_v1.types import asset_service
31+
from google.longrunning import operations_pb2
3132
from google.longrunning import operations_pb2 # type: ignore
3233
from google.protobuf import empty_pb2 # type: ignore
3334

@@ -627,6 +628,15 @@ def analyze_org_policy_governed_assets(
627628
]:
628629
raise NotImplementedError()
629630

631+
@property
632+
def get_operation(
633+
self,
634+
) -> Callable[
635+
[operations_pb2.GetOperationRequest],
636+
Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]],
637+
]:
638+
raise NotImplementedError()
639+
630640
@property
631641
def kind(self) -> str:
632642
raise NotImplementedError()

google/cloud/asset_v1/services/asset_service/transports/grpc.py

+18
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import grpc # type: ignore
2727

2828
from google.cloud.asset_v1.types import asset_service
29+
from google.longrunning import operations_pb2
2930
from google.longrunning import operations_pb2 # type: ignore
3031
from google.protobuf import empty_pb2 # type: ignore
3132
from .base import AssetServiceTransport, DEFAULT_CLIENT_INFO
@@ -970,6 +971,23 @@ def analyze_org_policy_governed_assets(
970971
def close(self):
971972
self.grpc_channel.close()
972973

974+
@property
975+
def get_operation(
976+
self,
977+
) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]:
978+
r"""Return a callable for the get_operation method over gRPC."""
979+
# Generate a "stub function" on-the-fly which will actually make
980+
# the request.
981+
# gRPC handles serialization and deserialization, so we just need
982+
# to pass in the functions for each.
983+
if "get_operation" not in self._stubs:
984+
self._stubs["get_operation"] = self.grpc_channel.unary_unary(
985+
"/google.longrunning.Operations/GetOperation",
986+
request_serializer=operations_pb2.GetOperationRequest.SerializeToString,
987+
response_deserializer=operations_pb2.Operation.FromString,
988+
)
989+
return self._stubs["get_operation"]
990+
973991
@property
974992
def kind(self) -> str:
975993
return "grpc"

google/cloud/asset_v1/services/asset_service/transports/grpc_asyncio.py

+18
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from grpc.experimental import aio # type: ignore
2727

2828
from google.cloud.asset_v1.types import asset_service
29+
from google.longrunning import operations_pb2
2930
from google.longrunning import operations_pb2 # type: ignore
3031
from google.protobuf import empty_pb2 # type: ignore
3132
from .base import AssetServiceTransport, DEFAULT_CLIENT_INFO
@@ -992,5 +993,22 @@ def analyze_org_policy_governed_assets(
992993
def close(self):
993994
return self.grpc_channel.close()
994995

996+
@property
997+
def get_operation(
998+
self,
999+
) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]:
1000+
r"""Return a callable for the get_operation method over gRPC."""
1001+
# Generate a "stub function" on-the-fly which will actually make
1002+
# the request.
1003+
# gRPC handles serialization and deserialization, so we just need
1004+
# to pass in the functions for each.
1005+
if "get_operation" not in self._stubs:
1006+
self._stubs["get_operation"] = self.grpc_channel.unary_unary(
1007+
"/google.longrunning.Operations/GetOperation",
1008+
request_serializer=operations_pb2.GetOperationRequest.SerializeToString,
1009+
response_deserializer=operations_pb2.Operation.FromString,
1010+
)
1011+
return self._stubs["get_operation"]
1012+
9951013

9961014
__all__ = ("AssetServiceGrpcAsyncIOTransport",)

0 commit comments

Comments
 (0)