
                             S r SSKrSSKJr  SSKJr  SSKJ	r	  S r
S rS r SS	 jr SS
 jrS rS r SS jr SS jr SS jrg)zThe utils for asset surface.    N)
exceptions)util)
propertiesc                 &    [        U5      Ul        U$ )ao  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                     U R                   (       a!  [        U R                   5        U R                   $ SR                  [        R                  R
                  R                  R                  5       5      $ )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                 j    [         R                  " SU 5      (       d  [        R                  " SS5      eg)a1  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   5   s6     
%u	-	-

4
4 /0 0 
.r   c                 B   U c,  Uc)  Uc&  [         R                  " SSR                  U5      5      eU (       a  U(       a  [         R                  " SS5      eU (       a  U(       a  [         R                  " SS5      eU(       a  U(       a  [         R                  " SS5      egg)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%   K   s    
 go&.

5
51	vi " " g

9
9	# #f

9
9" "

9
9)X
NN Wr   c                     [        XX#5        U (       a  SR                  U 5      $ U(       a  SR                  U5      $ SR                  U5      $ )DGets the parent name from organization Id, project Id, or folder Id.organizations/{0}folders/{0}r   )r%   r   r#   s       r   GetParentNameForExportr*   _   sG    
 vA%%l33''			w	''r   c                     U (       a  SR                  U 5      $ U(       a  SR                  U5      $ SR                  [        R                  " U5      5      $ zKGet the parent name from organization Number, project Id, or folder Number.r(   r)   r   r   project_utilGetProjectNumberr   r   r   s      r   GetFeedParentr1   l   F    %%l33''			|<<WE	FFr   c                     U (       a  SR                  U 5      $ U(       a  SR                  U5      $ SR                  [        R                  " U5      5      $ r,   r-   r0   s      r   GetSavedQueriesParentr4   u   r2   r   c                     U c)  Uc&  [         R                  " SSR                  U5      5      eU (       a  U(       a  [         R                  " SS5      egg)r   Nz--organization or --projectz4Should specify the organization, or project for {0}.r   r   r    r   r   r$   s      r   VerifyParentForGetHistoryr7   ~   s[     go

5
5%>EE	  g

9
9	# # \r   c                 l    [        XU5        U (       a  SR                  U 5      $ SR                  U5      $ )z6Gets the parent name from organization Id, project Id.r(   r   )r7   r   r6   s      r   GetParentNameForGetHistoryr9      s3     L9=%%l33			w	''r   c                     [        XX#5      $ )r'   )r*   r#   s       r    GetParentNameForAnalyzeIamPolicyr;      s     
 v	IIr   )zroot cloud asset)zpolicy analysis scope)__doc__r   googlecloudsdk.callioper   r   #googlecloudsdk.command_lib.projectsr   r.   googlecloudsdk.corer   r   r   r   r%   r*   r1   r4   r7   r9   r;    r   r   <module>rA      si    # 
 C D *&M02 %7O. &8
(GG );#  *<( 0GJr   