Skip to content
This repository was archived by the owner on Oct 31, 2023. It is now read-only.

Commit bdb8baf

Browse files
feat: Adding support for encryption_key_revocation_action and encryption_key_shutdown_duration for RevisionTemplate and ExecutionTemplate (#80)
* docs: Add documentation for enums fix: Add context manager return types chore: Update gapic-generator-python to v1.8.1 PiperOrigin-RevId: 503210727 Source-Link: googleapis/googleapis@a391fd1 Source-Link: https://github.com/googleapis/googleapis-gen/commit/0080f830dec37c3384157082bce279e37079ea58 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMDA4MGY4MzBkZWMzN2MzMzg0MTU3MDgyYmNlMjc5ZTM3MDc5ZWE1OCJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * feat: Adding support for encryption_key_revocation_action and encryption_key_shutdown_duration for RevisionTemplate and ExecutionTemplate docs: Documentation improvements, including clarification that v1 labels/annotations are rejected in v2 API PiperOrigin-RevId: 503293343 Source-Link: googleapis/googleapis@e3d3d63 Source-Link: https://github.com/googleapis/googleapis-gen/commit/f401f99dd0e2bfe7fbe6b190d3381ba648f21227 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZjQwMWY5OWRkMGUyYmZlN2ZiZTZiMTkwZDMzODFiYTY0OGYyMTIyNyJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * set cov_level to 99 Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <[email protected]>
1 parent b05d380 commit bdb8baf

Some content is hidden

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

53 files changed

+2744
-117
lines changed

.github/workflows/unittest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ jobs:
5454
- name: Report coverage results
5555
run: |
5656
coverage combine .coverage-results/.coverage*
57-
coverage report --show-missing --fail-under=100
57+
coverage report --show-missing --fail-under=99

google/cloud/run/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
)
9999
from google.cloud.run_v2.types.vendor_settings import (
100100
BinaryAuthorization,
101+
EncryptionKeyRevocationAction,
101102
ExecutionEnvironment,
102103
IngressTraffic,
103104
RevisionScaling,
@@ -172,6 +173,7 @@
172173
"BinaryAuthorization",
173174
"RevisionScaling",
174175
"VpcAccess",
176+
"EncryptionKeyRevocationAction",
175177
"ExecutionEnvironment",
176178
"IngressTraffic",
177179
)

google/cloud/run_v2/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
)
9494
from .types.vendor_settings import (
9595
BinaryAuthorization,
96+
EncryptionKeyRevocationAction,
9697
ExecutionEnvironment,
9798
IngressTraffic,
9899
RevisionScaling,
@@ -116,6 +117,7 @@
116117
"DeleteJobRequest",
117118
"DeleteRevisionRequest",
118119
"DeleteServiceRequest",
120+
"EncryptionKeyRevocationAction",
119121
"EnvVar",
120122
"EnvVarSource",
121123
"Execution",

google/cloud/run_v2/services/executions/async_client.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,66 @@ async def delete_operation(
736736
metadata=metadata,
737737
)
738738

739+
async def wait_operation(
740+
self,
741+
request: Optional[operations_pb2.WaitOperationRequest] = None,
742+
*,
743+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
744+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
745+
metadata: Sequence[Tuple[str, str]] = (),
746+
) -> operations_pb2.Operation:
747+
r"""Waits until the specified long-running operation is done or reaches at most
748+
a specified timeout, returning the latest state.
749+
750+
If the operation is already done, the latest state is immediately returned.
751+
If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC
752+
timeout is used. If the server does not support this method, it returns
753+
`google.rpc.Code.UNIMPLEMENTED`.
754+
755+
Args:
756+
request (:class:`~.operations_pb2.WaitOperationRequest`):
757+
The request object. Request message for
758+
`WaitOperation` method.
759+
retry (google.api_core.retry.Retry): Designation of what errors,
760+
if any, should be retried.
761+
timeout (float): The timeout for this request.
762+
metadata (Sequence[Tuple[str, str]]): Strings which should be
763+
sent along with the request as metadata.
764+
Returns:
765+
~.operations_pb2.Operation:
766+
An ``Operation`` object.
767+
"""
768+
# Create or coerce a protobuf request object.
769+
# The request isn't a proto-plus wrapped type,
770+
# so it must be constructed via keyword expansion.
771+
if isinstance(request, dict):
772+
request = operations_pb2.WaitOperationRequest(**request)
773+
774+
# Wrap the RPC method; this adds retry and timeout information,
775+
# and friendly error handling.
776+
rpc = gapic_v1.method.wrap_method(
777+
self._client._transport.wait_operation,
778+
default_timeout=None,
779+
client_info=DEFAULT_CLIENT_INFO,
780+
)
781+
782+
# Certain fields should be provided within the metadata header;
783+
# add these here.
784+
metadata = tuple(metadata) + (
785+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
786+
)
787+
788+
# Send the request.
789+
response = await rpc(
790+
request,
791+
retry=retry,
792+
timeout=timeout,
793+
metadata=metadata,
794+
)
795+
796+
# Done; return the response.
797+
return response
798+
739799
async def __aenter__(self):
740800
return self
741801

google/cloud/run_v2/services/executions/client.py

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ def sample_delete_execution():
905905
# Done; return the response.
906906
return response
907907

908-
def __enter__(self):
908+
def __enter__(self) -> "ExecutionsClient":
909909
return self
910910

911911
def __exit__(self, type, value, traceback):
@@ -1081,6 +1081,66 @@ def delete_operation(
10811081
metadata=metadata,
10821082
)
10831083

1084+
def wait_operation(
1085+
self,
1086+
request: Optional[operations_pb2.WaitOperationRequest] = None,
1087+
*,
1088+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
1089+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1090+
metadata: Sequence[Tuple[str, str]] = (),
1091+
) -> operations_pb2.Operation:
1092+
r"""Waits until the specified long-running operation is done or reaches at most
1093+
a specified timeout, returning the latest state.
1094+
1095+
If the operation is already done, the latest state is immediately returned.
1096+
If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC
1097+
timeout is used. If the server does not support this method, it returns
1098+
`google.rpc.Code.UNIMPLEMENTED`.
1099+
1100+
Args:
1101+
request (:class:`~.operations_pb2.WaitOperationRequest`):
1102+
The request object. Request message for
1103+
`WaitOperation` method.
1104+
retry (google.api_core.retry.Retry): Designation of what errors,
1105+
if any, should be retried.
1106+
timeout (float): The timeout for this request.
1107+
metadata (Sequence[Tuple[str, str]]): Strings which should be
1108+
sent along with the request as metadata.
1109+
Returns:
1110+
~.operations_pb2.Operation:
1111+
An ``Operation`` object.
1112+
"""
1113+
# Create or coerce a protobuf request object.
1114+
# The request isn't a proto-plus wrapped type,
1115+
# so it must be constructed via keyword expansion.
1116+
if isinstance(request, dict):
1117+
request = operations_pb2.WaitOperationRequest(**request)
1118+
1119+
# Wrap the RPC method; this adds retry and timeout information,
1120+
# and friendly error handling.
1121+
rpc = gapic_v1.method.wrap_method(
1122+
self._transport.wait_operation,
1123+
default_timeout=None,
1124+
client_info=DEFAULT_CLIENT_INFO,
1125+
)
1126+
1127+
# Certain fields should be provided within the metadata header;
1128+
# add these here.
1129+
metadata = tuple(metadata) + (
1130+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1131+
)
1132+
1133+
# Send the request.
1134+
response = rpc(
1135+
request,
1136+
retry=retry,
1137+
timeout=timeout,
1138+
metadata=metadata,
1139+
)
1140+
1141+
# Done; return the response.
1142+
return response
1143+
10841144

10851145
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
10861146
gapic_version=package_version.__version__

google/cloud/run_v2/services/executions/transports/base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,15 @@ def delete_operation(
212212
) -> Callable[[operations_pb2.DeleteOperationRequest], None,]:
213213
raise NotImplementedError()
214214

215+
@property
216+
def wait_operation(
217+
self,
218+
) -> Callable[
219+
[operations_pb2.WaitOperationRequest],
220+
Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]],
221+
]:
222+
raise NotImplementedError()
223+
215224
@property
216225
def kind(self) -> str:
217226
raise NotImplementedError()

google/cloud/run_v2/services/executions/transports/grpc.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,23 @@ def delete_operation(
343343
)
344344
return self._stubs["delete_operation"]
345345

346+
@property
347+
def wait_operation(
348+
self,
349+
) -> Callable[[operations_pb2.WaitOperationRequest], None]:
350+
r"""Return a callable for the wait_operation method over gRPC."""
351+
# Generate a "stub function" on-the-fly which will actually make
352+
# the request.
353+
# gRPC handles serialization and deserialization, so we just need
354+
# to pass in the functions for each.
355+
if "delete_operation" not in self._stubs:
356+
self._stubs["wait_operation"] = self.grpc_channel.unary_unary(
357+
"/google.longrunning.Operations/WaitOperation",
358+
request_serializer=operations_pb2.WaitOperationRequest.SerializeToString,
359+
response_deserializer=None,
360+
)
361+
return self._stubs["wait_operation"]
362+
346363
@property
347364
def get_operation(
348365
self,

google/cloud/run_v2/services/executions/transports/grpc_asyncio.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,23 @@ def delete_operation(
352352
)
353353
return self._stubs["delete_operation"]
354354

355+
@property
356+
def wait_operation(
357+
self,
358+
) -> Callable[[operations_pb2.WaitOperationRequest], None]:
359+
r"""Return a callable for the wait_operation method over gRPC."""
360+
# Generate a "stub function" on-the-fly which will actually make
361+
# the request.
362+
# gRPC handles serialization and deserialization, so we just need
363+
# to pass in the functions for each.
364+
if "delete_operation" not in self._stubs:
365+
self._stubs["wait_operation"] = self.grpc_channel.unary_unary(
366+
"/google.longrunning.Operations/WaitOperation",
367+
request_serializer=operations_pb2.WaitOperationRequest.SerializeToString,
368+
response_deserializer=None,
369+
)
370+
return self._stubs["wait_operation"]
371+
355372
@property
356373
def get_operation(
357374
self,

google/cloud/run_v2/services/executions/transports/rest.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,29 @@ def post_list_operations(
239239
"""
240240
return response
241241

242+
def pre_wait_operation(
243+
self,
244+
request: operations_pb2.WaitOperationRequest,
245+
metadata: Sequence[Tuple[str, str]],
246+
) -> operations_pb2.Operation:
247+
"""Pre-rpc interceptor for wait_operation
248+
249+
Override in a subclass to manipulate the request or metadata
250+
before they are sent to the Executions server.
251+
"""
252+
return request, metadata
253+
254+
def post_wait_operation(
255+
self, response: operations_pb2.WaitOperationRequest
256+
) -> operations_pb2.Operation:
257+
"""Post-rpc interceptor for wait_operation
258+
259+
Override in a subclass to manipulate the response
260+
after it is returned by the Executions server but before
261+
it is returned to user code.
262+
"""
263+
return response
264+
242265

243266
@dataclasses.dataclass
244267
class ExecutionsRestStub:
@@ -365,6 +388,13 @@ def operations_client(self) -> operations_v1.AbstractOperationsClient:
365388
"uri": "/v2/{name=projects/*/locations/*}/operations",
366389
},
367390
],
391+
"google.longrunning.Operations.WaitOperation": [
392+
{
393+
"method": "post",
394+
"uri": "/v2/{name=projects/*/locations/*/operations/*}:wait",
395+
"body": "*",
396+
},
397+
],
368398
}
369399

370400
rest_transport = operations_v1.OperationsRestTransport(
@@ -878,6 +908,76 @@ def __call__(
878908
resp = self._interceptor.post_list_operations(resp)
879909
return resp
880910

911+
@property
912+
def wait_operation(self):
913+
return self._WaitOperation(self._session, self._host, self._interceptor) # type: ignore
914+
915+
class _WaitOperation(ExecutionsRestStub):
916+
def __call__(
917+
self,
918+
request: operations_pb2.WaitOperationRequest,
919+
*,
920+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
921+
timeout: Optional[float] = None,
922+
metadata: Sequence[Tuple[str, str]] = (),
923+
) -> operations_pb2.Operation:
924+
925+
r"""Call the wait operation method over HTTP.
926+
927+
Args:
928+
request (operations_pb2.WaitOperationRequest):
929+
The request object for WaitOperation method.
930+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
931+
should be retried.
932+
timeout (float): The timeout for this request.
933+
metadata (Sequence[Tuple[str, str]]): Strings which should be
934+
sent along with the request as metadata.
935+
936+
Returns:
937+
operations_pb2.Operation: Response from WaitOperation method.
938+
"""
939+
940+
http_options: List[Dict[str, str]] = [
941+
{
942+
"method": "post",
943+
"uri": "/v2/{name=projects/*/locations/*/operations/*}:wait",
944+
"body": "*",
945+
},
946+
]
947+
948+
request, metadata = self._interceptor.pre_wait_operation(request, metadata)
949+
request_kwargs = json_format.MessageToDict(request)
950+
transcoded_request = path_template.transcode(http_options, **request_kwargs)
951+
952+
body = json.loads(json.dumps(transcoded_request["body"]))
953+
uri = transcoded_request["uri"]
954+
method = transcoded_request["method"]
955+
956+
# Jsonify the query params
957+
query_params = json.loads(json.dumps(transcoded_request["query_params"]))
958+
959+
# Send the request
960+
headers = dict(metadata)
961+
headers["Content-Type"] = "application/json"
962+
963+
response = getattr(self._session, method)(
964+
"{host}{uri}".format(host=self._host, uri=uri),
965+
timeout=timeout,
966+
headers=headers,
967+
params=rest_helpers.flatten_query_params(query_params),
968+
data=body,
969+
)
970+
971+
# In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
972+
# subclass.
973+
if response.status_code >= 400:
974+
raise core_exceptions.from_http_response(response)
975+
976+
resp = operations_pb2.Operation()
977+
resp = json_format.Parse(response.content.decode("utf-8"), resp)
978+
resp = self._interceptor.post_wait_operation(resp)
979+
return resp
980+
881981
@property
882982
def kind(self) -> str:
883983
return "rest"

0 commit comments

Comments
 (0)