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

Commit 17b7a5b

Browse files
feat: added helper methods for long running operations, IAM, and locations (#260)
* feat: added helper methods for long running operations, IAM, and locations docs: clarified that vpcConnector shortname is only returned if the connector is in the same project as the function docs: applied general style guide updates to descriptions PiperOrigin-RevId: 530688922 Source-Link: googleapis/googleapis@a540c8a Source-Link: https://github.com/googleapis/googleapis-gen/commit/dca7c4dd03c0db64c5626c84c7309ce4eee4b967 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZGNhN2M0ZGQwM2MwZGI2NGM1NjI2Yzg0YzczMDljZTRlZWU0Yjk2NyJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent fc6da6a commit 17b7a5b

File tree

10 files changed

+1470
-120
lines changed

10 files changed

+1470
-120
lines changed

google/cloud/functions_v1/services/cloud_functions_service/async_client.py

Lines changed: 175 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@
4444

4545
from google.api_core import operation # type: ignore
4646
from google.api_core import operation_async # type: ignore
47+
from google.cloud.location import locations_pb2 # type: ignore
4748
from google.iam.v1 import iam_policy_pb2 # type: ignore
4849
from google.iam.v1 import policy_pb2 # type: ignore
50+
from google.longrunning import operations_pb2
4951
from google.protobuf import duration_pb2 # type: ignore
5052
from google.protobuf import empty_pb2 # type: ignore
5153
from google.protobuf import timestamp_pb2 # type: ignore
@@ -396,7 +398,7 @@ async def sample_get_function():
396398
google.cloud.functions_v1.types.CloudFunction:
397399
Describes a Cloud Function that
398400
contains user computation executed in
399-
response to an event. It encapsulate
401+
response to an event. It encapsulates
400402
function and triggers configurations.
401403
402404
"""
@@ -464,7 +466,7 @@ async def create_function(
464466
) -> operation_async.AsyncOperation:
465467
r"""Creates a new function. If a function with the given name
466468
already exists in the specified project, the long running
467-
operation will return ``ALREADY_EXISTS`` error.
469+
operation returns an ``ALREADY_EXISTS`` error.
468470
469471
.. code-block:: python
470472
@@ -527,7 +529,7 @@ async def sample_create_function():
527529
An object representing a long-running operation.
528530
529531
The result type for the operation will be :class:`google.cloud.functions_v1.types.CloudFunction` Describes a Cloud Function that contains user computation executed in
530-
response to an event. It encapsulate function and
532+
response to an event. It encapsulates function and
531533
triggers configurations.
532534
533535
"""
@@ -648,7 +650,7 @@ async def sample_update_function():
648650
An object representing a long-running operation.
649651
650652
The result type for the operation will be :class:`google.cloud.functions_v1.types.CloudFunction` Describes a Cloud Function that contains user computation executed in
651-
response to an event. It encapsulate function and
653+
response to an event. It encapsulates function and
652654
triggers configurations.
653655
654656
"""
@@ -725,8 +727,7 @@ async def delete_function(
725727
) -> operation_async.AsyncOperation:
726728
r"""Deletes a function with the given name from the
727729
specified project. If the given function is used by some
728-
trigger, the trigger will be updated to remove this
729-
function.
730+
trigger, the trigger is updated to remove this function.
730731
731732
.. code-block:: python
732733
@@ -990,13 +991,13 @@ async def generate_upload_url(
990991
credentials would be used, but that identity does not have
991992
permissions to upload files to the URL.
992993
993-
When making a HTTP PUT request, these two headers need to be
994+
When making an HTTP PUT request, these two headers must be
994995
specified:
995996
996997
- ``content-type: application/zip``
997998
- ``x-goog-content-length-range: 0,104857600``
998999
999-
And this header SHOULD NOT be specified:
1000+
And this header must NOT be specified:
10001001
10011002
- ``Authorization: Bearer YOUR_TOKEN``
10021003
@@ -1076,9 +1077,9 @@ async def generate_download_url(
10761077
) -> functions.GenerateDownloadUrlResponse:
10771078
r"""Returns a signed URL for downloading deployed
10781079
function source code. The URL is only valid for a
1079-
limited period and should be used within minutes after
1080+
limited period and must be used within minutes after
10801081
generation.
1081-
For more information about the signed URL usage see:
1082+
For more information about the signed URL usage, see:
10821083
https://cloud.google.com/storage/docs/access-control/signed-urls
10831084
10841085
.. code-block:: python
@@ -1443,8 +1444,8 @@ async def test_iam_permissions(
14431444
metadata: Sequence[Tuple[str, str]] = (),
14441445
) -> iam_policy_pb2.TestIamPermissionsResponse:
14451446
r"""Tests the specified permissions against the IAM access control
1446-
policy for a function. If the function does not exist, this will
1447-
return an empty set of permissions, not a NOT_FOUND error.
1447+
policy for a function. If the function does not exist, this
1448+
returns an empty set of permissions, not a NOT_FOUND error.
14481449
14491450
.. code-block:: python
14501451
@@ -1518,6 +1519,168 @@ async def sample_test_iam_permissions():
15181519
# Done; return the response.
15191520
return response
15201521

1522+
async def list_operations(
1523+
self,
1524+
request: Optional[operations_pb2.ListOperationsRequest] = None,
1525+
*,
1526+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
1527+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1528+
metadata: Sequence[Tuple[str, str]] = (),
1529+
) -> operations_pb2.ListOperationsResponse:
1530+
r"""Lists operations that match the specified filter in the request.
1531+
1532+
Args:
1533+
request (:class:`~.operations_pb2.ListOperationsRequest`):
1534+
The request object. Request message for
1535+
`ListOperations` method.
1536+
retry (google.api_core.retry.Retry): Designation of what errors,
1537+
if any, should be retried.
1538+
timeout (float): The timeout for this request.
1539+
metadata (Sequence[Tuple[str, str]]): Strings which should be
1540+
sent along with the request as metadata.
1541+
Returns:
1542+
~.operations_pb2.ListOperationsResponse:
1543+
Response message for ``ListOperations`` method.
1544+
"""
1545+
# Create or coerce a protobuf request object.
1546+
# The request isn't a proto-plus wrapped type,
1547+
# so it must be constructed via keyword expansion.
1548+
if isinstance(request, dict):
1549+
request = operations_pb2.ListOperationsRequest(**request)
1550+
1551+
# Wrap the RPC method; this adds retry and timeout information,
1552+
# and friendly error handling.
1553+
rpc = gapic_v1.method.wrap_method(
1554+
self._client._transport.list_operations,
1555+
default_timeout=None,
1556+
client_info=DEFAULT_CLIENT_INFO,
1557+
)
1558+
1559+
# Certain fields should be provided within the metadata header;
1560+
# add these here.
1561+
metadata = tuple(metadata) + (
1562+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1563+
)
1564+
1565+
# Send the request.
1566+
response = await rpc(
1567+
request,
1568+
retry=retry,
1569+
timeout=timeout,
1570+
metadata=metadata,
1571+
)
1572+
1573+
# Done; return the response.
1574+
return response
1575+
1576+
async def get_operation(
1577+
self,
1578+
request: Optional[operations_pb2.GetOperationRequest] = None,
1579+
*,
1580+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
1581+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1582+
metadata: Sequence[Tuple[str, str]] = (),
1583+
) -> operations_pb2.Operation:
1584+
r"""Gets the latest state of a long-running operation.
1585+
1586+
Args:
1587+
request (:class:`~.operations_pb2.GetOperationRequest`):
1588+
The request object. Request message for
1589+
`GetOperation` method.
1590+
retry (google.api_core.retry.Retry): Designation of what errors,
1591+
if any, should be retried.
1592+
timeout (float): The timeout for this request.
1593+
metadata (Sequence[Tuple[str, str]]): Strings which should be
1594+
sent along with the request as metadata.
1595+
Returns:
1596+
~.operations_pb2.Operation:
1597+
An ``Operation`` object.
1598+
"""
1599+
# Create or coerce a protobuf request object.
1600+
# The request isn't a proto-plus wrapped type,
1601+
# so it must be constructed via keyword expansion.
1602+
if isinstance(request, dict):
1603+
request = operations_pb2.GetOperationRequest(**request)
1604+
1605+
# Wrap the RPC method; this adds retry and timeout information,
1606+
# and friendly error handling.
1607+
rpc = gapic_v1.method.wrap_method(
1608+
self._client._transport.get_operation,
1609+
default_timeout=None,
1610+
client_info=DEFAULT_CLIENT_INFO,
1611+
)
1612+
1613+
# Certain fields should be provided within the metadata header;
1614+
# add these here.
1615+
metadata = tuple(metadata) + (
1616+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1617+
)
1618+
1619+
# Send the request.
1620+
response = await rpc(
1621+
request,
1622+
retry=retry,
1623+
timeout=timeout,
1624+
metadata=metadata,
1625+
)
1626+
1627+
# Done; return the response.
1628+
return response
1629+
1630+
async def list_locations(
1631+
self,
1632+
request: Optional[locations_pb2.ListLocationsRequest] = None,
1633+
*,
1634+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
1635+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1636+
metadata: Sequence[Tuple[str, str]] = (),
1637+
) -> locations_pb2.ListLocationsResponse:
1638+
r"""Lists information about the supported locations for this service.
1639+
1640+
Args:
1641+
request (:class:`~.location_pb2.ListLocationsRequest`):
1642+
The request object. Request message for
1643+
`ListLocations` method.
1644+
retry (google.api_core.retry.Retry): Designation of what errors,
1645+
if any, should be retried.
1646+
timeout (float): The timeout for this request.
1647+
metadata (Sequence[Tuple[str, str]]): Strings which should be
1648+
sent along with the request as metadata.
1649+
Returns:
1650+
~.location_pb2.ListLocationsResponse:
1651+
Response message for ``ListLocations`` method.
1652+
"""
1653+
# Create or coerce a protobuf request object.
1654+
# The request isn't a proto-plus wrapped type,
1655+
# so it must be constructed via keyword expansion.
1656+
if isinstance(request, dict):
1657+
request = locations_pb2.ListLocationsRequest(**request)
1658+
1659+
# Wrap the RPC method; this adds retry and timeout information,
1660+
# and friendly error handling.
1661+
rpc = gapic_v1.method.wrap_method(
1662+
self._client._transport.list_locations,
1663+
default_timeout=None,
1664+
client_info=DEFAULT_CLIENT_INFO,
1665+
)
1666+
1667+
# Certain fields should be provided within the metadata header;
1668+
# add these here.
1669+
metadata = tuple(metadata) + (
1670+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1671+
)
1672+
1673+
# Send the request.
1674+
response = await rpc(
1675+
request,
1676+
retry=retry,
1677+
timeout=timeout,
1678+
metadata=metadata,
1679+
)
1680+
1681+
# Done; return the response.
1682+
return response
1683+
15211684
async def __aenter__(self):
15221685
return self
15231686

0 commit comments

Comments
 (0)