示例#1
0
    def __init__(self,
                 method: Callable[...,
                                  asset_service.SearchAllResourcesResponse],
                 request: asset_service.SearchAllResourcesRequest,
                 response: asset_service.SearchAllResourcesResponse,
                 *,
                 metadata: Sequence[Tuple[str, str]] = ()):
        """Instantiate the pager.

        Args:
            method (Callable): The method that was originally called, and
                which instantiated this pager.
            request (google.cloud.asset_v1.types.SearchAllResourcesRequest):
                The initial request object.
            response (google.cloud.asset_v1.types.SearchAllResourcesResponse):
                The initial response object.
            metadata (Sequence[Tuple[str, str]]): Strings which should be
                sent along with the request as metadata.
        """
        self._method = method
        self._request = asset_service.SearchAllResourcesRequest(request)
        self._response = response
        self._metadata = metadata
示例#2
0
    async def search_all_resources(
        self,
        request: asset_service.SearchAllResourcesRequest = None,
        *,
        scope: str = None,
        query: str = None,
        asset_types: Sequence[str] = None,
        retry: retries.Retry = gapic_v1.method.DEFAULT,
        timeout: float = None,
        metadata: Sequence[Tuple[str, str]] = (),
    ) -> pagers.SearchAllResourcesAsyncPager:
        r"""Searches all Cloud resources within the specified scope, such as
        a project, folder, or organization. The caller must be granted
        the ``cloudasset.assets.searchAllResources`` permission on the
        desired scope, otherwise the request will be rejected.

        Args:
            request (:class:`~.asset_service.SearchAllResourcesRequest`):
                The request object. Search all resources request.
            scope (:class:`str`):
                Required. A scope can be a project, a folder, or an
                organization. The search is limited to the resources
                within the ``scope``. The caller must be granted the
                ```cloudasset.assets.searchAllResources`` <http://cloud.google.com/asset-inventory/docs/access-control#required_permissions>`__
                permission on the desired scope.

                The allowed values are:

                -  projects/{PROJECT_ID} (e.g., "projects/foo-bar")
                -  projects/{PROJECT_NUMBER} (e.g., "projects/12345678")
                -  folders/{FOLDER_NUMBER} (e.g., "folders/1234567")
                -  organizations/{ORGANIZATION_NUMBER} (e.g.,
                   "organizations/123456")
                This corresponds to the ``scope`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.
            query (:class:`str`):
                Optional. The query statement. See `how to construct a
                query <http://cloud.google.com/asset-inventory/docs/searching-resources#how_to_construct_a_query>`__
                for more information. If not specified or empty, it will
                search all the resources within the specified ``scope``.
                Note that the query string is compared against each
                Cloud IAM policy binding, including its members, roles,
                and Cloud IAM conditions. The returned Cloud IAM
                policies will only contain the bindings that match your
                query. To learn more about the IAM policy structure, see
                `IAM policy
                doc <https://cloud.google.com/iam/docs/policies#structure>`__.

                Examples:

                -  ``name:Important`` to find Cloud resources whose name
                   contains "Important" as a word.
                -  ``displayName:Impor*`` to find Cloud resources whose
                   display name contains "Impor" as a prefix.
                -  ``description:*por*`` to find Cloud resources whose
                   description contains "por" as a substring.
                -  ``location:us-west*`` to find Cloud resources whose
                   location is prefixed with "us-west".
                -  ``labels:prod`` to find Cloud resources whose labels
                   contain "prod" as a key or value.
                -  ``labels.env:prod`` to find Cloud resources that have
                   a label "env" and its value is "prod".
                -  ``labels.env:*`` to find Cloud resources that have a
                   label "env".
                -  ``Important`` to find Cloud resources that contain
                   "Important" as a word in any of the searchable
                   fields.
                -  ``Impor*`` to find Cloud resources that contain
                   "Impor" as a prefix in any of the searchable fields.
                -  ``*por*`` to find Cloud resources that contain "por"
                   as a substring in any of the searchable fields.
                -  ``Important location:(us-west1 OR global)`` to find
                   Cloud resources that contain "Important" as a word in
                   any of the searchable fields and are also located in
                   the "us-west1" region or the "global" location.
                This corresponds to the ``query`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.
            asset_types (:class:`Sequence[str]`):
                Optional. A list of asset types that this request
                searches for. If empty, it will search all the
                `searchable asset
                types <https://cloud.google.com/asset-inventory/docs/supported-asset-types#searchable_asset_types>`__.
                This corresponds to the ``asset_types`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.

            retry (google.api_core.retry.Retry): Designation of what errors, if any,
                should be retried.
            timeout (float): The timeout for this request.
            metadata (Sequence[Tuple[str, str]]): Strings which should be
                sent along with the request as metadata.

        Returns:
            ~.pagers.SearchAllResourcesAsyncPager:
                Search all resources response.
                Iterating over this object will yield
                results and resolve additional pages
                automatically.

        """
        # Create or coerce a protobuf request object.
        # Sanity check: If we got a request object, we should *not* have
        # gotten any keyword arguments that map to the request.
        if request is not None and any([scope, query, asset_types]):
            raise ValueError("If the `request` argument is set, then none of "
                             "the individual field arguments should be set.")

        request = asset_service.SearchAllResourcesRequest(request)

        # If we have keyword arguments corresponding to fields on the
        # request, apply these.

        if scope is not None:
            request.scope = scope
        if query is not None:
            request.query = query
        if asset_types is not None:
            request.asset_types = asset_types

        # Wrap the RPC method; this adds retry and timeout information,
        # and friendly error handling.
        rpc = gapic_v1.method_async.wrap_method(
            self._client._transport.search_all_resources,
            default_retry=retries.Retry(
                initial=0.1,
                maximum=60.0,
                multiplier=1.3,
                predicate=retries.if_exception_type(
                    exceptions.ServiceUnavailable,
                    exceptions.DeadlineExceeded,
                ),
            ),
            default_timeout=15.0,
            client_info=DEFAULT_CLIENT_INFO,
        )

        # Certain fields should be provided within the metadata header;
        # add these here.
        metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata(
            (("scope", request.scope), )), )

        # Send the request.
        response = await rpc(
            request,
            retry=retry,
            timeout=timeout,
            metadata=metadata,
        )

        # This method is paged; wrap the response in a pager, which provides
        # an `__aiter__` convenience method.
        response = pagers.SearchAllResourcesAsyncPager(
            method=rpc,
            request=request,
            response=response,
            metadata=metadata,
        )

        # Done; return the response.
        return response
示例#3
0
    def search_all_resources(
        self,
        request: asset_service.SearchAllResourcesRequest = None,
        *,
        scope: str = None,
        query: str = None,
        asset_types: Sequence[str] = None,
        retry: retries.Retry = gapic_v1.method.DEFAULT,
        timeout: float = None,
        metadata: Sequence[Tuple[str, str]] = (),
    ) -> pagers.SearchAllResourcesPager:
        r"""Searches all the resources within the given
        accessible scope (e.g., a project, a folder or an
        organization). Callers should have
        cloud.assets.SearchAllResources permission upon the
        requested scope, otherwise the request will be rejected.

        Args:
            request (:class:`~.asset_service.SearchAllResourcesRequest`):
                The request object. Search all resources request.
            scope (:class:`str`):
                Required. A scope can be a project, a folder or an
                organization. The search is limited to the resources
                within the ``scope``.

                The allowed values are:

                -  projects/{PROJECT_ID}
                -  projects/{PROJECT_NUMBER}
                -  folders/{FOLDER_NUMBER}
                -  organizations/{ORGANIZATION_NUMBER}
                This corresponds to the ``scope`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.
            query (:class:`str`):
                Optional. The query statement. An empty query can be
                specified to search all the resources of certain
                ``asset_types`` within the given ``scope``.

                Examples:

                -  ``name : "Important"`` to find Cloud resources whose
                   name contains "Important" as a word.
                -  ``displayName : "Impor*"`` to find Cloud resources
                   whose display name contains "Impor" as a word prefix.
                -  ``description : "*por*"`` to find Cloud resources
                   whose description contains "por" as a substring.
                -  ``location : "us-west*"`` to find Cloud resources
                   whose location is prefixed with "us-west".
                -  ``labels : "prod"`` to find Cloud resources whose
                   labels contain "prod" as a key or value.
                -  ``labels.env : "prod"`` to find Cloud resources which
                   have a label "env" and its value is "prod".
                -  ``labels.env : *`` to find Cloud resources which have
                   a label "env".
                -  ``"Important"`` to find Cloud resources which contain
                   "Important" as a word in any of the searchable
                   fields.
                -  ``"Impor*"`` to find Cloud resources which contain
                   "Impor" as a word prefix in any of the searchable
                   fields.
                -  ``"*por*"`` to find Cloud resources which contain
                   "por" as a substring in any of the searchable fields.
                -  ``("Important" AND location : ("us-west1" OR "global"))``
                   to find Cloud resources which contain "Important" as
                   a word in any of the searchable fields and are also
                   located in the "us-west1" region or the "global"
                   location.

                See `how to construct a
                query <https://cloud.google.com/asset-inventory/docs/searching-resources#how_to_construct_a_query>`__
                for more details.
                This corresponds to the ``query`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.
            asset_types (:class:`Sequence[str]`):
                Optional. A list of asset types that this request
                searches for. If empty, it will search all the
                `searchable asset
                types <https://cloud.google.com/asset-inventory/docs/supported-asset-types#searchable_asset_types>`__.
                This corresponds to the ``asset_types`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.

            retry (google.api_core.retry.Retry): Designation of what errors, if any,
                should be retried.
            timeout (float): The timeout for this request.
            metadata (Sequence[Tuple[str, str]]): Strings which should be
                sent along with the request as metadata.

        Returns:
            ~.pagers.SearchAllResourcesPager:
                Search all resources response.
                Iterating over this object will yield
                results and resolve additional pages
                automatically.

        """
        # Create or coerce a protobuf request object.
        # Sanity check: If we got a request object, we should *not* have
        # gotten any keyword arguments that map to the request.
        has_flattened_params = any([scope, query, asset_types])
        if request is not None and has_flattened_params:
            raise ValueError("If the `request` argument is set, then none of "
                             "the individual field arguments should be set.")

        # Minor optimization to avoid making a copy if the user passes
        # in a asset_service.SearchAllResourcesRequest.
        # There's no risk of modifying the input as we've already verified
        # there are no flattened fields.
        if not isinstance(request, asset_service.SearchAllResourcesRequest):
            request = asset_service.SearchAllResourcesRequest(request)

            # If we have keyword arguments corresponding to fields on the
            # request, apply these.

            if scope is not None:
                request.scope = scope
            if query is not None:
                request.query = query
            if asset_types is not None:
                request.asset_types = asset_types

        # Wrap the RPC method; this adds retry and timeout information,
        # and friendly error handling.
        rpc = self._transport._wrapped_methods[
            self._transport.search_all_resources]

        # Certain fields should be provided within the metadata header;
        # add these here.
        metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata(
            (("scope", request.scope), )), )

        # Send the request.
        response = rpc(
            request,
            retry=retry,
            timeout=timeout,
            metadata=metadata,
        )

        # This method is paged; wrap the response in a pager, which provides
        # an `__iter__` convenience method.
        response = pagers.SearchAllResourcesPager(
            method=rpc,
            request=request,
            response=response,
            metadata=metadata,
        )

        # Done; return the response.
        return response