コード例 #1
0
    def __init__(self,
                 method: Callable[...,
                                  asset_service.SearchAllIamPoliciesResponse],
                 request: asset_service.SearchAllIamPoliciesRequest,
                 response: asset_service.SearchAllIamPoliciesResponse,
                 *,
                 metadata: Sequence[Tuple[str, str]] = ()):
        """Instantiate the pager.

        Args:
            method (Callable): The method that was originally called, and
                which instantiated this pager.
            request (:class:`~.asset_service.SearchAllIamPoliciesRequest`):
                The initial request object.
            response (:class:`~.asset_service.SearchAllIamPoliciesResponse`):
                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.SearchAllIamPoliciesRequest(request)
        self._response = response
        self._metadata = metadata
コード例 #2
0
    async def search_all_iam_policies(
        self,
        request: Union[asset_service.SearchAllIamPoliciesRequest, dict] = None,
        *,
        scope: str = None,
        query: str = None,
        retry: OptionalRetry = gapic_v1.method.DEFAULT,
        timeout: float = None,
        metadata: Sequence[Tuple[str, str]] = (),
    ) -> pagers.SearchAllIamPoliciesAsyncPager:
        r"""Searches all the IAM policies under a given
        accessible CRM scope (project/folder/organization). This
        RPC gives callers especially admins the ability to
        search all the IAM policies under a scope, even if they
        don't have .getIamPolicy permission of all the IAM
        policies. Callers should have
        cloud.assets.SearchAllIamPolicies permission on the
        requested scope, otherwise it will be rejected.

        .. code-block:: python

            from google.cloud import asset_v1p1beta1

            async def sample_search_all_iam_policies():
                # Create a client
                client = asset_v1p1beta1.AssetServiceAsyncClient()

                # Initialize request argument(s)
                request = asset_v1p1beta1.SearchAllIamPoliciesRequest(
                    scope="scope_value",
                )

                # Make the request
                page_result = client.search_all_iam_policies(request=request)

                # Handle the response
                async for response in page_result:
                    print(response)

        Args:
            request (Union[google.cloud.asset_v1p1beta1.types.SearchAllIamPoliciesRequest, dict]):
                The request object. Search all IAM policies request.
            scope (:class:`str`):
                Required. The relative name of an asset. The search is
                limited to the resources within the ``scope``. The
                allowed value must be:

                -  Organization number (such as "organizations/123")
                -  Folder number(such as "folders/1234")
                -  Project number (such as "projects/12345")
                -  Project id (such as "projects/abc")

                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. Examples:

                -  "policy:[email protected]"
                -  "policy:([email protected] viewer)"

                This corresponds to the ``query`` 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:
            google.cloud.asset_v1p1beta1.services.asset_service.pagers.SearchAllIamPoliciesAsyncPager:
                Search all IAM policies response.
                Iterating over this object will yield
                results and resolve additional pages
                automatically.

        """
        # Create or coerce a protobuf request object.
        # Quick 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])
        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.")

        request = asset_service.SearchAllIamPoliciesRequest(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

        # 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_iam_policies,
            default_retry=retries.Retry(
                initial=0.1,
                maximum=60.0,
                multiplier=1.3,
                predicate=retries.if_exception_type(
                    core_exceptions.DeadlineExceeded,
                    core_exceptions.ServiceUnavailable,
                ),
                deadline=15.0,
            ),
            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.SearchAllIamPoliciesAsyncPager(
            method=rpc,
            request=request,
            response=response,
            metadata=metadata,
        )

        # Done; return the response.
        return response
コード例 #3
0
ファイル: client.py プロジェクト: kybru91/python-asset
    def search_all_iam_policies(
        self,
        request: asset_service.SearchAllIamPoliciesRequest = None,
        *,
        scope: str = None,
        query: str = None,
        retry: retries.Retry = gapic_v1.method.DEFAULT,
        timeout: float = None,
        metadata: Sequence[Tuple[str, str]] = (),
    ) -> pagers.SearchAllIamPoliciesPager:
        r"""Searches all the IAM policies under a given
        accessible CRM scope (project/folder/organization). This
        RPC gives callers especially admins the ability to
        search all the IAM policies under a scope, even if they
        don't have .getIamPolicy permission of all the IAM
        policies. Callers should have
        cloud.assets.SearchAllIamPolicies permission on the
        requested scope, otherwise it will be rejected.

        Args:
            request (google.cloud.asset_v1p1beta1.types.SearchAllIamPoliciesRequest):
                The request object. Search all IAM policies request.
            scope (str):
                Required. The relative name of an asset. The search is
                limited to the resources within the ``scope``. The
                allowed value must be:

                -  Organization number (such as "organizations/123")
                -  Folder number(such as "folders/1234")
                -  Project number (such as "projects/12345")
                -  Project id (such as "projects/abc")

                This corresponds to the ``scope`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.
            query (str):
                Optional. The query statement. Examples:

                -  "policy:[email protected]"
                -  "policy:([email protected] viewer)"

                This corresponds to the ``query`` 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:
            google.cloud.asset_v1p1beta1.services.asset_service.pagers.SearchAllIamPoliciesPager:
                Search all IAM policies 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])
        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.SearchAllIamPoliciesRequest.
        # There's no risk of modifying the input as we've already verified
        # there are no flattened fields.
        if not isinstance(request, asset_service.SearchAllIamPoliciesRequest):
            request = asset_service.SearchAllIamPoliciesRequest(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

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

        # 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.SearchAllIamPoliciesPager(
            method=rpc, request=request, response=response, metadata=metadata,
        )

        # Done; return the response.
        return response