
    .5                        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
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rSrSr " S S\R:                  5      r " S S\R:                  5      r " S S\5      r S r!S r"S r#S r$S r%S r&S  r'S! r(S,S" jr)S# r*S$ r+S% r,S& r-S,S' jr.S( r/S) r0S* r1S-S+ jr2g).z4Command line processing utilities for access levels.    )absolute_import)division)unicode_literals)encoding)util)waiter)base)concepts)common)policies)	arg_utils)concept_parsers)
exceptions)	resources)yamlN0accesscontextmanager.accessPolicies.accessLevelsa  
Invalid format: {}

The valid fields for the YAML objects in this file type are [{}].

For an access level condition file, an example of the YAML-formatted list of conditions will look like:

 - ipSubnetworks:
   - 162.222.181.197/24
   - 2001:db8::/48
 - members:
   - user:user@example.com

For access levels file, an example of the YAML-formatted list of access levels will look like:

 - name: accessPolicies/my_policy/accessLevels/my_level
   title: My Level
   description: Level for foo.
   basic:
     combiningFunction: AND
     conditions:
     - ipSubnetworks:
       - 192.168.100.14/24
       - 2001:db8::/48
     - members:
       - user1:user1@example.com
c                   (   ^  \ rS rSrU 4S jrSrU =r$ )ParseResponseErrorD   c                 J   > [         [        U ]  SR                  U5      5        g )NzIssue parsing response: {})superr   __init__format)selfreason	__class__s     =lib/googlecloudsdk/command_lib/accesscontextmanager/levels.pyr   ParseResponseError.__init__F   s"    	

5<<VDE     __name__
__module____qualname____firstlineno__r   __static_attributes____classcell__r   s   @r   r   r   D   s    F Fr   r   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )
ParseErrorK   c                 J   > [         [        U ]  SR                  X5      5        g )NzIssue parsing file [{}]: {})r   r*   r   r   )r   pathr   r   s      r   r   ParseError.__init__M   s!    	*
6==dKLr   r    r!   r(   s   @r   r*   r*   K   s    M Mr   r*   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )InvalidFormatErrorR   c           	         > UR                  5        Vs/ s H  oDR                  PM     nn[        [        U ]  U[
        R                  USR                  U5      5      5        g s  snf )N, )
all_fieldsnamer   r0   r   _INVALID_FORMAT_ERRORr   join)r   r-   r   message_classfvalid_fieldsr   s         r   r   InvalidFormatError.__init__T   s\    $1$<$<$>?$>qFF$>L?	

 5==dii- / 0 @s   A#r    r!   r(   s   @r   r0   r0   R   s    0 0r   r0   c                     [         R                  " U 5      $ ! [         R                   a   n[        U SR	                  U5      5      eS nAf[         R
                   a   n[        U SR	                  U5      5      eS nAff = f)NzProblem loading file: {}z Problem parsing data as YAML: {})r   	load_pathFileLoadErrorr*   r   YAMLParseError)r-   errs     r   	_LoadDatarA   [   sq    K>>$			 C
T5<<SA
BB			 K
T=DDSI
JJKs     A>AA>A99A>c                    [        5       nU H9  nUR                  5       (       d  M  UR                  UR                  5       5        M;     U(       a7  [        U SR	                  SR                  U5      5      [        US   5      5      eg NUnrecognized fields: [{}]r3   r   setall_unrecognized_fieldsupdater0   r   r7   type)r-   
conditionsunrecognized_fields	conditions       r   *_ValidateAllBasicConditionFieldsRecognizedrM   d   sx    i((**  !B!B!DE  
#**4995H+IJZ]  r   c           	          UR                  5       (       aB  [        U SR                  SR                  UR                  5       5      5      [	        U5      5      eg )NrD   r3   )rG   r0   r   r7   rI   )r-   exprs     r   "_ValidateAllCustomFieldsRecognizedrP   p   sR    	!!##
)00((*2, -.24j: : $r   c                    [        5       nU H9  nUR                  5       (       d  M  UR                  UR                  5       5        M;     U(       a7  [        U SR	                  SR                  U5      5      [        US   5      5      eg rC   rE   )r-   levelsrK   levels       r   !_ValidateAllLevelFieldsRecognizedrT   w   sw    e$$&&  !>!>!@A  
#**4995H+IJVAY  r   c                    ^  U 4S jnU$ )zFWrapper around ParseReplaceAccessLevelsResponse to accept api version.c                 <  > [         R                  " TS9n[        R                  R	                  U R
                  SS9n[        R                  " UR                  UR                  U5      n[        R                  " XCSR                  UR                  5       5      5      $ )aZ  Parse the Long Running Operation response of the ReplaceAccessLevels call.

Args:
  lro: Long Running Operation response of ReplaceAccessLevels.
  unused_args: not used.

Returns:
  The replacement Access Levels created by the ReplaceAccessLevels call.

Raises:
  ParseResponseError: if the response could not be parsed into the proper
  object.
versionzaccesscontextmanager.operations)
collectionz0Waiting for Replace Access Levels operation [{}])r   	GetClientr   REGISTRYParser5   r   BulkAPIOperationPolleraccessPolicies_accessLevels
operationsr   WaitForr   Name)lrounused_argsclientoperation_refpollerapi_versions        r   )VersionedParseReplaceAccessLevelsResponseSParseReplaceAccessLevelsResponse.<locals>.VersionedParseReplaceAccessLevelsResponse   s     ^^K0F&&,,> - @M**6+M+M+1+<+<mMF >>:AA 	"# #r   r    )rg   rh   s   ` r    ParseReplaceAccessLevelsResponserj      s    #2 
32r   c                    ^  U 4S jnU$ )6Wrapper around ParseCustomLevel to accept api version.c                 n  > [         R                  " U 5      nU(       d  [        U S5      e[        R                  " TS9nUR
                  n U Vs/ s H  n[        R                  " XC5      PM     nn[        X5        U$ s  snf ! [         a&  n[        U [        R                  " U5      U5      eSnAff = f)zParse a YAML representation of basic level conditions.

Args:
  path: str, path to file containing basic level conditions

Returns:
  list of Condition objects.

Raises:
  ParseError: if the file could not be read into the proper object
File is emptyrW   N)r   r=   r*   r   GetMessages	Conditionr   DictToMessage	Exceptionr0   six	text_typerM   )r-   datamessagesr8   crJ   r@   rg   s          r   "VersionedParseBasicLevelConditionsEParseBasicLevelConditions.<locals>.VersionedParseBasicLevelConditions   s     >>$Dt_--4H&&MHFJKdH**1<djK /t@ L HtS]]3%7GGH*   B  A?0B ?B 
B4!B//B4r    )rg   rx   s   ` r   ParseBasicLevelConditionsr{      s    8 
,+r   c                    ^  U 4S jnU$ )rl   c                 D  > [         R                  " U 5      nU(       d  [        U S5      e[        R                  " TS9nUR
                  n [        R                  " X5      n[        X5        U$ ! [         a&  n[        U [        R                  " U5      U5      eSnAff = f)zParse a YAML representation of custom level conditions.

Args:
  path: str, path to file containing custom level expression

Returns:
  string of CEL expression.

Raises:
  ParseError: if the file could not be read into the proper object
rn   rW   N)r   r=   r*   r   ro   Exprr   rq   rr   r0   rs   rt   rP   )r-   ru   rv   r8   rO   r@   rg   s         r   VersionedParseCustomLevel3ParseCustomLevel.<locals>.VersionedParseCustomLevel   s     >>$Dt_--4HMMMH##D8d 't2K	  HtS]]3%7GGHs   A/ /
B9!BBr    )rg   r   s   ` r   ParseCustomLevelr      s    6 
#"r   c                    ^  U 4S jnU$ )z7Wrapper around ParseAccessLevels to accept api version.c                 n  > [         R                  " U 5      nU(       d  [        U S5      e[        R                  " TS9nUR
                  n U Vs/ s H  n[        R                  " XC5      PM     nn[        X5        U$ s  snf ! [         a&  n[        U [        R                  " U5      U5      eSnAff = f)a  Parse a YAML representation of a list of Access Levels with basic/custom level conditions.

Args:
  path: str, path to file containing basic/custom access levels

Returns:
  list of Access Level objects.

Raises:
  ParseError: if the file could not be read into the proper object
rn   rW   N)r   r=   r*   r   ro   AccessLevelr   rq   rr   r0   rs   rt   rT   )r-   ru   rv   r8   rw   rR   r@   rg   s          r   VersionedParseAccessLevels5ParseAccessLevels.<locals>.VersionedParseAccessLevels   s     >>$Dt_--4H((MHBFG$Q&&q8$fG &d3M H HtS]]3%7GGHrz   r    )rg   r   s   ` r   ParseAccessLevelsr      s    6 
$#r   c                 t    A Uc  U$ UR                  S5      (       d  UR                  R                  S5        U$ )zFClear basic field (and default combine function) if spec not provided.basic_level_specbasic)IsSpecifiedaccessLevelreset)refargsreqs      r   (ClearCombiningFunctionUnlessBasicSpecSetr     s8    	[J			,	-	-OO'"	*r   c                  ,    [         R                  " SSS9$ )NrS   zThe ID of the access level.)r5   	help_text)r
    ResourceParameterAttributeConfigr    r   r   GetAttributeConfigr     s    		2	2;
= =r   c                  f    [         R                  " SS[        R                  " 5       [        5       S9$ )Nr   rS   )resource_nameaccessPoliciesIdaccessLevelsId)r
   ResourceSpecr   r   r    r   r   GetResourceSpecr     s-    			8224')	
+ +r   c                     [         R                  R                  S[        5       SR	                  U5      SS9R                  U 5        g)Add a resource argument for an access level.

NOTE: Must be used only if it's the only resource arg in the command.

Args:
  parser: the parser for the command.
  verb: str, the verb to describe the resource, such as 'to update'.
rS   The access level {}.TrequiredNr   ConceptParserForResourcer   r   AddToParserparserverbs     r   AddResourceArgr     sC     ++##D)	 ,  ![(r   c                     [         R                  R                  S[        5       SR	                  U5      SS9R                  U 5        g)r   z--levelr   Tr   Nr   r   s     r   AddResourceFlagArgr   /  sC     ++##D)	 ,  ![(r   c                     [         R                  " S[        R                  " U S9R                  R
                  SSS.SSS9$ )	Nz--combine-functionrW   andor)ANDORFz:For a basic level, determines how conditions are combined.)custom_mappingsr   help_str)r   ChoiceEnumMapperr   ro   
BasicLevel CombiningFunctionValueValuesEnumrg   s    r   GetCombineFunctionEnumMapperr   ?  sG    		#	#
)z*J*J K

 
r   c                     [         R                  " S5      [         R                  " S5      /nU H  nUR                  U 5        M     g)z1Add common args for level create/update commands.zaccess levelN)r   GetDescriptionArgGetTitleArgr   )r   r   args      r   AddLevelArgsr   M  s?     ~.(
$ cOOF r   c                     Sn[         R                  " SU[        U5      S9n[        US9R                  nUR                  U 5        UR                  U 5        g)z.Add args for basic spec (with no custom spec).as  Path to a file containing a list of basic access level conditions.

An access level condition file is a YAML-formatted list of conditions, which are YAML objects representing a Condition as described in the API reference. For example:

    ```
     - ipSubnetworks:
       - 162.222.181.197/24
       - 2001:db8::/48
     - members:
       - user:user@example.com
    ```--basic-level-spechelprI   r   N)r	   Argumentr{   r   
choice_argr   )r   rg   basic_level_help_textbasic_level_spec_argbasic_level_combine_args        r   AddBasicSpecArgsr   W  s`    
   $[13 9)z  ""6*%%f-r   c                    SnSn[         R                  " SU[        U5      S9n[        US9R                  n[         R
                  " SS9nUR                  U5        UR                  U5        [         R                  " SU[        U5      S9n[         R
                  " S	S9nUR                  U5        [         R
                  " S
SS9n	U	R                  U5        U	R                  U5        U	R                  U 5        g)z7Add args for basic and custom specs (grouped together).ar  Path to a file containing a list of basic access level conditions.

An access level condition file is a YAML-formatted list of conditions,which are YAML objects representing a Condition as described in the API reference. For example:

    ```
     - ipSubnetworks:
       - 162.222.181.197/24
       - 2001:db8::/48
     - members:
       - user:user@example.com
    ```zPath to a file representing an expression for an access level.

The expression is in the Common Expression Langague (CEL) format.For example:

    ```
     expression: "origin.region_code in ['US', 'CA']"
    ```r   r   r   zBasic level specification.)r   z--custom-level-speczCustom level specification.zLevel specification.T)r   mutexN)	r	   r   r{   r   r   ArgumentGroupAddArgumentr   r   )
r   rg   r   custom_level_help_textr   r   basic_level_spec_groupcustom_level_spec_argcustom_level_spec_grouplevel_spec_groups
             r   AddBasicAndCustomSpecArgsr   p  s    
    $[13 9)z   --3OP$$%9:$$%<=--!K(* !..(*%%&;<''-C4P5667v&r   c                 j    Uc  0 nUR                  SS5      (       a  [        X5        g[        X5        g)z/Add arguments for in-file level specifications.Ncustom_levelsF)getr   r   )r   rg   feature_masks      r   AddLevelSpecArgsr     s0    Lou--f2V)r   )N)NN)3__doc__
__future__r   r   r   apitools.base.pyr   +googlecloudsdk.api_lib.accesscontextmanagerr   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper	    googlecloudsdk.calliope.conceptsr
   /googlecloudsdk.command_lib.accesscontextmanagerr   r   $googlecloudsdk.command_lib.util.apisr   (googlecloudsdk.command_lib.util.conceptsr   googlecloudsdk.corer   r   r   rs   
COLLECTIONr6   Errorr   r*   r0   rA   rM   rP   rT   rj   r{   r   r   r   r   r   r   r   r   r   r   r   r   r    r   r   <module>r      s    ; &  ' % < . ( 5 B D : D * ) $ 
?
 :F)) FM!! M0 0K	:	3>,D#B$B	=
+) ) .21'h*r   