|
38 | 38 | from google.cloud.asset_v1.types import assets |
39 | 39 | from google.protobuf import field_mask_pb2 # type: ignore |
40 | 40 | from google.protobuf import timestamp_pb2 # type: ignore |
| 41 | +from google.rpc import status_pb2 # type: ignore |
41 | 42 | from google.type import expr_pb2 # type: ignore |
42 | 43 | from .transports.base import AssetServiceTransport, DEFAULT_CLIENT_INFO |
43 | 44 | from .transports.grpc_asyncio import AssetServiceGrpcAsyncIOTransport |
@@ -1748,6 +1749,101 @@ async def sample_analyze_move(): |
1748 | 1749 | # Done; return the response. |
1749 | 1750 | return response |
1750 | 1751 |
|
| 1752 | + async def query_assets( |
| 1753 | + self, |
| 1754 | + request: Union[asset_service.QueryAssetsRequest, dict] = None, |
| 1755 | + *, |
| 1756 | + retry: OptionalRetry = gapic_v1.method.DEFAULT, |
| 1757 | + timeout: float = None, |
| 1758 | + metadata: Sequence[Tuple[str, str]] = (), |
| 1759 | + ) -> asset_service.QueryAssetsResponse: |
| 1760 | + r"""Issue a job that queries assets using a SQL statement compatible |
| 1761 | + with `BigQuery Standard |
| 1762 | + SQL <http://cloud/bigquery/docs/reference/standard-sql/enabling-standard-sql>`__. |
| 1763 | +
|
| 1764 | + If the query execution finishes within timeout and there's no |
| 1765 | + pagination, the full query results will be returned in the |
| 1766 | + ``QueryAssetsResponse``. |
| 1767 | +
|
| 1768 | + Otherwise, full query results can be obtained by issuing extra |
| 1769 | + requests with the ``job_reference`` from the a previous |
| 1770 | + ``QueryAssets`` call. |
| 1771 | +
|
| 1772 | + Note, the query result has approximately 10 GB limitation |
| 1773 | + enforced by BigQuery |
| 1774 | + https://cloud.google.com/bigquery/docs/best-practices-performance-output, |
| 1775 | + queries return larger results will result in errors. |
| 1776 | +
|
| 1777 | + .. code-block:: python |
| 1778 | +
|
| 1779 | + from google.cloud import asset_v1 |
| 1780 | +
|
| 1781 | + async def sample_query_assets(): |
| 1782 | + # Create a client |
| 1783 | + client = asset_v1.AssetServiceAsyncClient() |
| 1784 | +
|
| 1785 | + # Initialize request argument(s) |
| 1786 | + request = asset_v1.QueryAssetsRequest( |
| 1787 | + statement="statement_value", |
| 1788 | + parent="parent_value", |
| 1789 | + ) |
| 1790 | +
|
| 1791 | + # Make the request |
| 1792 | + response = await client.query_assets(request=request) |
| 1793 | +
|
| 1794 | + # Handle the response |
| 1795 | + print(response) |
| 1796 | +
|
| 1797 | + Args: |
| 1798 | + request (Union[google.cloud.asset_v1.types.QueryAssetsRequest, dict]): |
| 1799 | + The request object. QueryAssets request. |
| 1800 | + retry (google.api_core.retry.Retry): Designation of what errors, if any, |
| 1801 | + should be retried. |
| 1802 | + timeout (float): The timeout for this request. |
| 1803 | + metadata (Sequence[Tuple[str, str]]): Strings which should be |
| 1804 | + sent along with the request as metadata. |
| 1805 | +
|
| 1806 | + Returns: |
| 1807 | + google.cloud.asset_v1.types.QueryAssetsResponse: |
| 1808 | + QueryAssets response. |
| 1809 | + """ |
| 1810 | + # Create or coerce a protobuf request object. |
| 1811 | + request = asset_service.QueryAssetsRequest(request) |
| 1812 | + |
| 1813 | + # Wrap the RPC method; this adds retry and timeout information, |
| 1814 | + # and friendly error handling. |
| 1815 | + rpc = gapic_v1.method_async.wrap_method( |
| 1816 | + self._client._transport.query_assets, |
| 1817 | + default_retry=retries.Retry( |
| 1818 | + initial=0.1, |
| 1819 | + maximum=60.0, |
| 1820 | + multiplier=1.3, |
| 1821 | + predicate=retries.if_exception_type( |
| 1822 | + core_exceptions.ServiceUnavailable, |
| 1823 | + ), |
| 1824 | + deadline=200.0, |
| 1825 | + ), |
| 1826 | + default_timeout=200.0, |
| 1827 | + client_info=DEFAULT_CLIENT_INFO, |
| 1828 | + ) |
| 1829 | + |
| 1830 | + # Certain fields should be provided within the metadata header; |
| 1831 | + # add these here. |
| 1832 | + metadata = tuple(metadata) + ( |
| 1833 | + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), |
| 1834 | + ) |
| 1835 | + |
| 1836 | + # Send the request. |
| 1837 | + response = await rpc( |
| 1838 | + request, |
| 1839 | + retry=retry, |
| 1840 | + timeout=timeout, |
| 1841 | + metadata=metadata, |
| 1842 | + ) |
| 1843 | + |
| 1844 | + # Done; return the response. |
| 1845 | + return response |
| 1846 | + |
1751 | 1847 | async def create_saved_query( |
1752 | 1848 | self, |
1753 | 1849 | request: Union[asset_service.CreateSavedQueryRequest, dict] = None, |
@@ -2337,16 +2433,7 @@ async def sample_batch_get_effective_iam_policies(): |
2337 | 2433 | # and friendly error handling. |
2338 | 2434 | rpc = gapic_v1.method_async.wrap_method( |
2339 | 2435 | self._client._transport.batch_get_effective_iam_policies, |
2340 | | - default_retry=retries.Retry( |
2341 | | - initial=0.1, |
2342 | | - maximum=60.0, |
2343 | | - multiplier=1.3, |
2344 | | - predicate=retries.if_exception_type( |
2345 | | - core_exceptions.ServiceUnavailable, |
2346 | | - ), |
2347 | | - deadline=300.0, |
2348 | | - ), |
2349 | | - default_timeout=300.0, |
| 2436 | + default_timeout=None, |
2350 | 2437 | client_info=DEFAULT_CLIENT_INFO, |
2351 | 2438 | ) |
2352 | 2439 |
|
|
0 commit comments