
    Z              
          S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SSK	Jr  SS	KJr   " S
 S\
R                  5      r " S S\5      r " S S\5      rSrSSSSSSSSSS.	rSr " S S\R(                  5      rS S jrg)!z!The Cloud Resource Search lister.    )absolute_import)division)unicode_literals)
list_pager)apis)
exceptions)log)resource_expr_rewritec                       \ rS rSrSrSrg)Error   zBase exception for this module. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       2lib/googlecloudsdk/api_lib/util/resource_search.pyr   r      s    'r   r   c                       \ rS rSrSrSrg)CollectionNotIndexed"   zThe collection is not indexed.r   Nr   r   r   r   r   r   "   s    &r   r   c                       \ rS rSrSrSrg)QueryOperatorNotSupported&   z(An operator in a query is not supported.r   Nr   r   r   r   r   r   &   s    0r   r   i  ProjectDiskHealthCheckHttpHealthCheckHttpsHealthCheckImageInstanceTemplateInstance
Subnetwork)	zcloudresourcemanager.projectszcompute.diskszcompute.healthCheckszcompute.httpHealthCheckszcompute.httpsHealthCheckszcompute.imageszcompute.instanceGroupszcompute.instanceszcompute.subnetworks	resourcesc                   $    \ rS rSrSrS rS rSrg)QueryRewriterB   z$Resource filter expression rewriter.c                     UR                   $ )aY  Rewrites global restriction in call.

Args:
  call: A list of resource_lex._TransformCall objects. In this case the list
    has one element that is a global restriction with a global_restriction
    property that is the restriction substring to match.

Returns:
  The global restriction rewrite which is simply the global_restriction
  string.
)global_restriction)selfcalls     r   RewriteGlobalQueryRewriter.RewriteGlobalE   s     """r   c           
         AUS;   a  [        SR                  U5      5      e[        U[        5      (       a  UOU/nUS:X  a$  SnU Vs/ s H  nSR                  U5      PM     nnOoUS:X  ai  Un/ nU H_  nUR	                  [
        S-   5      (       a&  UR                  U[        [
        5      S-   S	 5        MF   UR                  [        U   5        Ma     U Vs/ s H"  nSR                  XU R                  U5      S9PM$     n	nSR                  U	5      n
[        U	5      S:  a  SU
-   S-   n
U
$ s  snf ! [         a    [        S
R                  U5      5      ef = fs  snf )zRewrites <key op operand>.)~zDThe [{}] operator is not supported in cloud resource search queries.projectselfLinkz/projects/{}/z@type.   Nz'Collection [{}] not indexed for search.z{key}{op}{value})keyopvaluez OR z( z ))r   format
isinstancelist
startswith CLOUD_RESOURCE_SEARCH_COLLECTIONappendlenRESOURCE_TYPESKeyErrorr   Quotejoin)r-   r7   r8   operandkey_typevaluesr9   collections
collectionpartsexprs              r   RewriteTermQueryRewriter.RewriteTermS   s{    		V|%VBZ! ! #7D11WyF
i
 c;AB6%&&u-6fBf	 kf#*  !AC!GHH
--
3'G#H1#L#MN
ONMM.45 $ !"   &&3TZZ=N&O  
 ";;uD
5zA~D[4dK- C  N&9@@LN NN"s   D.9D3)E3%Er   N)r   r   r   r   r   r/   rL   r   r   r   r   r)   r)   B   s    ,#*r   r)   Nc           
   #      #    [        5       R                  U5      u  pV[        R                  " SX&5        Uc  [        nU(       aA  SR                  U Vs/ s H#  nUR                  S5      (       a  USS S-   OUPM%     sn5      nOSn[        R                  " SS5      n	[        R                  " U	R                  U	5      S	U	R                  R                  UUS
9SU USS9 H$  n
U(       a  U
R                  OU
R                  v   M&     gs  snf 7f)a  Yields the list of Cloud Resources for collection.

Not all collections are indexed for search.

Args:
  limit: The max number of resources to return. None for unlimited.
  page_size: The max number of resources per response page. The defsult is
    PAGE_SIE.
  query: A resource filter expression. Use @type:collection to filter
    resources by collection. Use the resources._RESOURCE_TYPE_ collection to
    specify CloudResourceSearch resource types. By default all indexed
    resources are in play.
  sort_by: A list of field names to sort by. Prefix a name with ~ to reverse
    the sort for that name.
  uri: Return the resource URI if true.

Raises:
  CollectionNotIndexed: If the collection is not indexed for search.
  QueryOperatorNotSupported: If the query contains an unsupported operator.
  HttpError: request/response errors.

Yields:
  The list of Cloud Resources for collection.
z,Resource search query="%s" remote_query="%s"N,r2   r6   z desccloudresourcesearchv1Search)orderByqueryresultspageSize)servicemethodrequestfieldlimit
batch_sizebatch_size_attribute)r)   Rewriter	   info	PAGE_SIZErD   r=   r   GetClientInstancer   YieldFromListResourcesServiceMESSAGES_MODULE)CloudresourcesearchResourcesSearchRequestresourceUrlresource)r[   	page_sizerT   sort_byuri_remote_querynameorder_byclientresults              r   Listrq      s    2 "O++E2/!((95OIxx%,.%,T 04s/C/CabG+M%,. /H H!!"7>&((%%f-$$NN O  %
'f !$&

8
'.s   AD*D	>BD)NNNNF)r   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.utilr   googlecloudsdk.corer   r	   googlecloudsdk.core.resourcer
   r   r   r   r`   rA   r>   Backendr)   rq   r   r   r   <module>rx      s     ( &  ' ' , * # >(J ('5 '1 1 	 &/) 1!30#'
 $/  ;)11 ;|09r   