
    s                         d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddl	m
Z ddlmZ d	 Zd
 Zd Z	 ddZ	 ddZd Zd Z	 ddZ	 ddZ	 ddZy)zThe utils for asset surface.    )absolute_import)division)unicode_literalsN)
exceptions)util)
propertiesc                 &    t        |      |_        |S )a  Update the request scope to fall back to core project if not specified.

  Used by Asset Search gcloud `modify_request_hooks`. When --scope flag is not
  specified, it will modify the request.scope to fallback to the core properties
  project.

  Args:
    unused_ref: unused.
    args: The argument namespace.
    request: The request to modify.

  Returns:
    The modified request.
  )GetDefaultScopeIfEmptyscope)
unused_refargsrequests      -lib/googlecloudsdk/command_lib/asset/utils.pySetDefaultScopeIfEmptyr      s     ).'-	.    c                     | j                   r!t        | j                          | j                   S dj                  t        j                  j
                  j                  j                               S )zHReturn the request scope and fall back to core project if not specified.projects/{0})r   VerifyScopeForSearchformatr   VALUEScoreproject	GetOrFail)r   s    r   r
   r
   /   sK    	ZZ$::  !2!2!7!7!?!?!I!I!KLLr   c                 \    t        j                  d|       st        j                  dd      y)aG  Perform permissive validation of the search scope.

  This validation is required although the API server contains similar request
  validation.
  The reason is that a malformed scope will be translated into an
  invalid URL, resulting in 404. For example, scope "projects/123/abc/" is
  translated to
  "https://cloudasset.googleapis.com/v1p1beta1/projects/123/abc/resources:searchAll".(404)
  However our OnePlatform API only accepts URL in format:
  "https://cloudasset.googleapis.com/v1p1beta1/*/*/resources:searchAll"

  Args:
    scope: the scope string of a search request.
  z^[^/#?]+/[^/#?]+$z--scopezA valid scope should be: projects/{PROJECT_ID}, projects/{PROJECT_NUMBER}, folders/{FOLDER_NUMBER} or organizations/{ORGANIZATION_NUMBER}.N)rematchgcloud_exceptionsInvalidArgumentException)r   s    r   r   r   8   s3     
%u	-

4
4 /0 0 
.r   c                     | )|'|%t        j                  ddj                  |            | r|rt        j                  dd      | r|rt        j                  dd      |r|rt        j                  dd      yy)Verify the parent name.Nz'--organization or --project or --folderzCShould specify the organization, or project, or the folder for {0}.organizationr   folderr   RequiredArgumentExceptionr   ConflictingArgumentsExceptionr!   r   r"   	attributes       r   VerifyParentForExportr(   N   s    
 go&.

5
51	vi " " g

9
9	# #f

9
9" "

9
9)X
NN Wr   c                     t        | |||       | rdj                  |       S |rdj                  |      S dj                  |      S )DGets the parent name from organization Id, project Id, or folder Id.organizations/{0}folders/{0}r   )r(   r   r&   s       r   GetParentNameForExportr-   b   sK    
 gvyA%%l33''			w	''r   c                     | rdj                  |       S |rdj                  |      S dj                  t        j                  |            S zKGet the parent name from organization Number, project Id, or folder Number.r+   r,   r   r   project_utilGetProjectNumberr!   r   r"   s      r   GetFeedParentr4   o   F    %%l33''			|<<WE	FFr   c                     | rdj                  |       S |rdj                  |      S dj                  t        j                  |            S r/   r0   r3   s      r   GetSavedQueriesParentr7   x   r5   r   c                     | '|%t        j                  ddj                  |            | r|rt        j                  dd      yy)r    Nz--organization or --projectz4Should specify the organization, or project for {0}.r!   r   r#   r!   r   r'   s      r   VerifyParentForGetHistoryr:      s[     go

5
5%>EE	  g

9
9	# # \r   c                 d    t        | ||       | rdj                  |       S dj                  |      S )z6Gets the parent name from organization Id, project Id.r+   r   )r:   r   r9   s      r   GetParentNameForGetHistoryr<      s5     L'9=%%l33			w	''r   c                     t        | |||      S )r*   )r-   r&   s       r    GetParentNameForAnalyzeIamPolicyr>      s     
 gvy	IIr   )zroot cloud asset)zpolicy analysis scope)__doc__
__future__r   r   r   r   googlecloudsdk.callioper   r   #googlecloudsdk.command_lib.projectsr   r1   googlecloudsdk.corer   r   r
   r   r(   r-   r4   r7   r:   r<   r>    r   r   <module>rE      sp    # &  ' 	 C D *&M02 %7O. &8
(GG );#  *<( 0GJr   