
    c                     f   S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSK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J!r!  SSK"J#r#  SSK$J%r%  SSK&J'r'  SSK(r( " S S\RR                  5      r* " S S\RV                  5      r, " S S\-5      r. " S S\R^                  5      r0S  r1S! r2 " S" S#\(Rf                  " \Rh                  \-5      5      r5 " S$ S%\55      r6 " S& S'\55      r7 " S( S)\55      r8 " S* S+\55      r9 " S, S-\55      r: " S. S/\55      r; " S0 S1\55      r< " S2 S3\55      r= " S4 S5\55      r> " S6 S7\55      r? " S8 S9\?5      r@ " S: S;\?5      rA " S< S=\55      rB " S> S?\55      rC " S@ SA\55      rDg)BaA  A yaml to calliope command translator.

Calliope allows you to register a hook that converts a yaml command spec into
a calliope command class. The Translator class in this module implements that
interface and provides generators for a yaml command spec. The schema for the
spec can be found in yaml_command_schema.yaml.
    )absolute_import)division)unicode_literalsN)messages)encoding)
exceptions)HttpBadRequestError)waiter)base)command_loading)
completers)	arg_utils)registry)yaml_command_schema)yaml_command_schema_util)labels_util)log)	resources)
console_io)resource_transform)filesc                       \ rS rSrSrS rSrg)
Translator9   z8Class that implements the calliope translator interface.c                 h    [         R                  " US   U5      n[        5       R                  X15      $ )N)r   CommandDataCommandBuilderGenerate)selfpathcommand_dataspecs       Clib/googlecloudsdk/command_lib/util/apis/yaml_command_translator.py	TranslateTranslator.Translate<   s,    **48\BD$$T00     N)__name__
__module____qualname____firstlineno____doc__r%   __static_attributes__r(   r'   r$   r   r   9   s
    @1r'   r   c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )DeclarativeIamRolesCompleterA   zAn IAM role completer for a resource argument.

The Complete() method override bypasses the completion cache.

Attributes:
  _get_resource_ref: DeclarativeArgumentGenerator.GetPrimaryResource method
    to parse the resource ref.
c                 :   > [         [        U ]
  " S0 UD6  Xl        g )Nr(   )superr0   __init___get_resource_ref)r    get_resource_refkwargs	__class__s      r$   r4   %DeclarativeIamRolesCompleter.__init__K   s    	
&6@@-r'   c                 h    U R                  UR                  5      nUR                  5       nSSSSSU/$ )Niamzlist-grantable-rolesz--quietz--flatten=namez--format=disable)r5   parsed_argsSelfLink)r    parameter_inforesource_refresource_uris       r$   GetListCommand+DeclarativeIamRolesCompleter.GetListCommandO   s@    )).*D*DEL((*L%y2BL r'   c                     U R                  U5      nU R                  X25      nU=(       d    /  Vs/ s H"  nUc  M  UR                  U5      (       d  M   UPM$     sn$ s  snf )z;Bypasses the cache and returns completions matching prefix.)rA   GetAllItems
startswith)r    prefixr>   commanditemsitems         r$   Complete%DeclarativeIamRolesCompleter.CompleteW   s`    !!.1GW5E"$ 	 $ 7 	  s   AAA)r5   )
r)   r*   r+   r,   r-   r4   rA   rJ   r.   __classcell__)r8   s   @r$   r0   r0   A   s    . r'   r0   c                   0    \ rS rSrSrS rS rS rS rSr	g)	r   a   z3Generates calliope commands based on the yaml spec.c                 ^   0 U l         U R                  [        5        U R                  [        5        U R                  [        5        U R                  [
        5        U R                  [        5        U R                  [        5        U R                  [        5        U R                  [        5        U R                  [        5        U R                  [        5        U R                  [        5        U R                  [        5        U R                  [        5        U R                  [        5        g N)command_generatorsRegisterCommandGeneratorDescribeCommandGeneratorListCommandGeneratorDeleteCommandGeneratorCreateCommandGeneratorWaitCommandGeneratorUpdateCommandGeneratorGenericCommandGeneratorGetIamPolicyCommandGeneratorSetIamPolicyCommandGenerator#AddIamPolicyBindingCommandGenerator&RemoveIamPolicyBindingCommandGeneratorImportCommandGeneratorExportCommandGeneratorConfigExportCommandGeneratorr    s    r$   r4   CommandBuilder.__init__d   s     D!!":;!!"67!!"89!!"89!!"67!!"89!!"9:!!">?!!">?!!"EF!!"HI!!"89!!"89!!">?r'   c                     UR                   U R                  ;   a$  [        SR                  UR                   5      5      eXR                  UR                   '   g )Nz.Command type [{}] has already been registered.)command_typerQ   
ValueErrorformat)r    command_generators     r$   rR   'CommandBuilder.RegisterCommandGeneratorw   sO    %%)@)@@GNN

(
(* + +>O-::;r'   c                     UR                   U R                  ;  a4  [        SR                  SR	                  U5      UR                   5      5      eU R                  UR                      " U5      $ )a`  Returns the command generator for a spec and path.

Args:
  spec: yaml_command_schema.CommandData, the spec for the command being
    generated.
  path: Path for the command.

Raises:
  ValueError: If we don't know how to generate the given command type (this
    is not actually possible right now due to the enum).

Returns:
  The command generator.
z'Command [{}] unknown command type [{}]. )rd   rQ   re   rf   join)r    r#   r!   s      r$   GetCommandGenerator"CommandBuilder.GetCommandGenerator}   sb      7 77@GG
((4.$++- . .""4#4#45d;;r'   c                 D    U R                  X5      nUR                  5       $ )zGenerates a calliope command from the yaml spec.

Args:
  spec: yaml_command_schema.CommandData, the spec for the command being
    generated.
  path: Path for the command.

Returns:
  calliope.base.Command, The command that implements the spec.
)rl   r   )r    r#   r!   	generators       r$   r   CommandBuilder.Generate   s#     ((4Ir'   )rQ   N)
r)   r*   r+   r,   r-   r4   rR   rl   r   r.   r(   r'   r$   r   r   a   s    ;@&P<( r'   r   c                   P    \ rS rSrSrS r\S 5       r\S 5       rS r	S r
S rS	rg
)AsyncOperationPoller   z(An implementation of a operation poller.c                     Xl         X0l        U R                   R                  R                  (       d  SU l        OX l        X@l        U=(       a    UR                  R                  U l        g)a  Creates the poller.

Args:
  spec: yaml_command_schema.CommandData, the spec for the command being
    generated.
  resource_ref: resources.Resource, The resource reference for the resource
    being operated on (not the operation itself). If None, the operation
    will just be returned when it is done instead of getting the resulting
    resource.
  args: Namespace, The args namespace.
  operation_collection: str, collection name of operation
  method: registry.APIMethod, method used to make original api request
N)	r#   argsasync_extract_resource_resultr?   _operation_collection
collection	full_name_resource_collection)r    r#   r?   ru   operation_collectionmethods         r$   r4   AsyncOperationPoller.__init__   sN     II9933d&!5 & F6+<+<+F+FDr'   c                    U R                   R                  R                  =(       d     U R                   R                  R                  n[        R
                  " U R                  U R                   R                  R                  US9$ )Napi_version)r#   rv   r   requestr   	GetMethodrx   r}   )r    r   s     r$   operation_method%AsyncOperationPoller.operation_method   s^    ))""..O$))2C2C2O2OK""		! !r'   c                 ~    [         R                  " U R                  SU R                  R                  R
                  S9$ )Ngetr   )r   r   r{   r#   r   r   ra   s    r$   resource_get_method(AsyncOperationPoller.resource_get_method   s4    !!II%%113 3r'   c                    [        XR                  R                  R                  R                  5      n[        U[        R                  5      (       a  UR                  nX R                  R                  R                  R                  ;   d-  X R                  R                  R                  R                  ;   a  [        XR                  R                  R                  R                  5      nU(       d/  X R                  R                  R                  R                  ;   a  SnU(       a  [        R                  " [        U5      5      egg)z
Overrides.zThe operation failed.TF)getattrr#   rv   statefield
isinstanceapitools_messagesEnumnamesuccess_valueserror_valueserrorr
   OperationErrorSerializeError)r    	operationresultr   s       r$   IsDoneAsyncOperationPoller.IsDone   s    Y		 0 0 6 6 < <=F&+0011{{f))""((777))""((555i!1!1!7!7!=!=>ev!1!1!7!7!D!DD'	##N5$9::r'   c                    U R                   R                  5       nUR                  5       n0 nUR                  5        H^  n[	        UU R
                  R                  R                  R                  UR                  UR                  5      U5      XER                  '   M`     U" S0 UD6nU R
                  R                  R                   H  nU" XR                  U5      nM     U R                   R                  U5      $ )zrOverrides.

Args:
  operation_ref: googlecloudsdk.core.resources.Resource.

Returns:
  fetched operation message.
r(   )r   GetRequestTypeRelativeName
all_fieldsr   r#   rv   operation_get_method_paramsr   r   modify_request_hooksru   Call)r    operation_refrequest_typerelative_namefieldsfr   hooks           r$   PollAsyncOperationPoller.Poll   s     ((779L!..0MF$$&

))


6
6
:
:166166
J
fVVn '
 $V$G		  55]IIw7g 6  %%g..r'   c                    UnU R                   (       aR  U R                  nUR                  5       " 5       n[        R                  " U R                   X4SS9  UR                  U5      n[        X R                  R                  R                  5      $ )znOverrides.

Args:
  operation: api_name_messages.Operation.

Returns:
  result of result_service.Get request.
T)is_primary_resource)
r?   r   r   r   ParseResourceIntoMessager   _GetAttributer#   rv   result_attribute)r    r   r   
get_methodr   s        r$   	GetResultAsyncOperationPoller.GetResult   ss     F++j))+-g((


ZdLw'f!1!1!B!BCCr'   )rx   r{   ru   r?   r#   N)r)   r*   r+   r,   r-   r4   propertyr   r   r   r   r   r.   r(   r'   r$   rr   rr      sC    0G2 ! ! 3 3$/,Dr'   rr   c                     [        U [        R                  5      (       a  U $  [        R                  " [
        R                  " U 5      SSSS9$ ! [         a    U s $ f = f)z/Serializes the error message for better format.   T),z: )indent	sort_keys
separators)r   sixstring_typesjsondumpsr   MessageToDict	Exception)r   s    r$   r   r     s]    s''((L::u%	   
 
 Ls   *A AAc           
          U(       a)  UR                  S5       H  n U c    g[        X5      n M     U $ ! [         a%    [        SR                  U[	        U 5      5      5      ef = f)aH  Gets attributes and sub-attributes out of an object.

Args:
  obj: The object to extract the attributes from.
  attr_path: str, The dotted path of attributes to extract.

Raises:
  AttributeError: If the attribute doesn't exist on the object.

Returns:
  The desired attribute or None if any of the parent attributes were None.
.Nz*Attribute path [{}] not found on type [{}])splitr   AttributeErrorrf   type)obj	attr_pathattrs      r$   r   r     ss     $L;c 	 % 
*	  L8??	@DS	KL 	LLs   33/A"c                       \ 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S jrS rS rSS jrS r SS jrSS jrS rS rS r\R0                  S 5       rS rSrg)BaseCommandGeneratori/  z"Base class for command generation.c                     Xl         [        R                  R                  UR                  5      U l        U R                  5         g rP   )r#   r   CommandTypeHasRequestMethodrd   has_request_methodInitializeGeneratorForCommand)r    r#   s     r$   r4   BaseCommandGenerator.__init__2  s5    I1==NND&&(r'   c                     SSK Jn  U R                  (       a  U R                  5       U l        O/ U l        UR                  U R                  R                  R                  5      U l	        g)z*Initializes the arg_generator for command.r   arg_marshallingN)
$googlecloudsdk.command_lib.util.apisr   r   _GetMethodsmethodsDeclarativeArgumentGeneratorr#   	argumentsparamsarg_generator)r    r   s     r$   r   2BaseCommandGenerator.InitializeGeneratorForCommand8  sP     E %%'dldl(EE		""$Dr'   Nc           
      j   / nU R                   R                  R                   H  nUR                  [        R
                  " UU=(       d     U R                   R                  R                  U R                   R                  R                  U R                   R                  R                  S95        M     U$ )N)disable_pagination)	r#   r   collectionsappendr   r   r}   r   r   )r    r}   r   ry   s       r$   r    BaseCommandGenerator._GetMethodsF  s    Gii''33
nnX''


,DII%%,,
))


'
'!YY..AA	C D 4 Nr'   c                    U R                   R                  U R                  5      nU R                  U5      nU H  nUR	                  U5        M     U R
                  R                  R                  (       a<  U R
                  R                  R                  5        H  nUR	                  U5        M     U R
                  R                  R                  (       a9  UR                  R                  U R
                  R                  R                  5        U R
                  R                  R                  (       a:  UR                  R                  U R
                  R                  R                  5        gg)zPerforms argument actions common to all commands.

Adds all generated arguments to the parser
Sets the command output format if specified

Args:
  parser: The argparse parser.
N)r   GenerateArgsr   _ExcludeAddToParserr#   r   additional_arguments_hookoutputrf   display_info	AddFormatflatten
AddFlatten)r    parserru   args       r$   _CommonArgs BaseCommandGenerator._CommonArgsP  s     **4<<8D]]6"F	oof yy44$$>>@# Ayy##DII$4$4$;$;<yy$$TYY%5%5%=%=>  r'   c                 v   ^ ^ UU 4S jn[        TSS5      SL a   TR                  5       R                  U5        gg)zGenerates and registers a function to create a URI from a resource.

Args:
  args: The argparse namespace.

Returns:
  f(resource) -> str, A function that converts the given resource payload
  into a URI.
c                   > [        U TR                  R                  R                  5      nTR                  R                  TR                  T5      R                  nTR                  R                  UTU5      nUR                  5       $ rP   )
r   r#   responseid_fieldr   GetPrimaryResourcer   r}   GetResponseResourceRefr=   )resourceid_valuer}   refru   r    s       r$   URIFunc6BaseCommandGenerator._RegisterURIFunc.<locals>.URIFunco  sj    
DII&&//1h!!44T\\4HOOf55hfMc\\^r'   uriNT)r   GetDisplayInfo
AddUriFunc)r    ru   r   s   `` r$   _RegisterURIFunc%BaseCommandGenerator._RegisterURIFunce  s7     tUD!T)
&&w/ *r'   c                     U R                   R                  R                   H6  n[        R                  " SR                  U5      SS9R                  U5        M8     U$ )zuExcludes specified arguments from the parser.

Args:
  parser: The argparse parser.

Returns:
  The argparse parser.
z--{} help)r#   r   excluder   Argumentrf   RemoveFromParser)r    r   r   s      r$   r   BaseCommandGenerator._Exclude{  sE     yy""**
mmFMM#&R0AA&I +Mr'   c                 >   U R                   R                  R                  (       d  U R                  $ U R                  R                  U R                  U5      nUR                  U5      nU R                   R                  R                  X15      nU R                  U5      $ rP   )r#   r   modify_method_hookr   r   r   Parser   )r    ru   	specifiedr   new_method_names        r$   _GetRuntimeMethods'BaseCommandGenerator._GetRuntimeMethods  st    99//\\""55dllDII
//$
Cii''::3EOO,,r'   c                    U R                  U5      U l        U R                  R                  U R                  U5      nUR                  nUR                  U5      nU R                  R                  R                  (       a  [        R                  " U R                  U R                  R                  R                  UU R                  U5      U R                  Xa5      5      U R                  R                  R                  SSS9  U R                  R                  R                   (       a&  X`R                  R                  R!                  Xa5      4$ U R                  R                  R"                  (       a&  U R                  R                  R#                  Xa5      nO0 nU(       a  UR%                  U5        U R                  R                  R&                  (       a/  UR%                  U R                  R                  R&                  5        U R                  R)                  UUUU R                  R*                  R,                  U R                  R.                  US9nU R                  R                  R0                   H  n	U	" XaU5      nM     UR3                  UU R                  R5                  U5      U R                  R7                  U5      S9n
Xj4$ )a  Performs run actions common to all commands.

Parses the resource argument into a resource reference
Prompts the user to continue (if applicable)
Calls the API method with the request generated from the parsed arguments

Args:
  args: The argparse parser.
  existing_message: the apitools message returned from previous request.
  update_mask: auto-generated mask from updated fields.

Returns:
  (resources.Resource, response), A tuple of the parsed resource reference
  and the API response from the method call.
T)messagedefaultthrow_if_unattendedcancel_on_noexisting_message)limit	page_size)r
  r   r   r   r}   r  r#   inputconfirmation_promptr   PromptContinue_Format_GetDisplayResourceType_GetDisplayNamedefault_continuer   issue_request_hookcreate_request_hookupdatestatic_fieldsCreateRequestr   labelsrd   r   r   LimitPageSize)r    ru   r  update_maskr   r}   r   r   r  r   r   s              r$   
_CommonRunBaseCommandGenerator._CommonRun  s     **40DL!!44T\\4HH__F
..
Cyy**,,iioo113**40""3-/ ))//22"7 yy++))##66sAAAyy,,		!!55c@gm	[)				(	(TYY..<<=""00



))


$
$
))
 
 + 1 -g ))##88$s'* 9 {{  &&t,$$--d3  5H =r'   c                 0    [         R                  " XXC5      $ rP   )r   FormatResourceAttrStr)r    format_stringr?   display_typedisplay_names        r$   r  BaseCommandGenerator._Format  s    #99\A Ar'   c                     U R                   R                  U R                  U5      R                  nU(       a"  UR                  (       a  UR	                  X5      $ U(       a  UR                  5       $ S $ rP   )r   r   r   primary_resourcedisplay_name_hookName)r    r?   ru   primary_resource_args       r$   r  $BaseCommandGenerator._GetDisplayName  s]    --@@d,,  4 F F!33LGG".<8D8r'   c                     U R                   R                  R                  =n(       a  U$ U R                  R	                  U R
                  U5      R                  nU(       a  UR                  (       d  UR                  $ g rP   )	r#   r   display_resource_typer   r   r   r.  is_parent_resourcer   )r    ru   spec_displayr1  s       r$   r  ,BaseCommandGenerator._GetDisplayResourceType  sf    yy((>>>|>--@@d,, $8$K$K!&&&r'   c                    U R                   R                  R                  (       Ga  U R                  XR                   R                  R                  R                  R                  S5      5      nU(       GaX  / nU R                   R                  R                  R                  (       aQ  UR                  SR                  [        X0R                   R                  R                  R                  5      5      5        U R                   R                  R                  R                  (       aQ  UR                  SR                  [        X0R                   R                  R                  R                  5      5      5        U(       a%  [        R                  " SR                  U5      5      e[        R                  " [        R                  " U5      5      eU R                   R                  R                   (       a)  [        XR                   R                  R                   5      nU R                   R                  R"                   H  nU" X5      nM     U$ )a  Process the API response.

Args:
  response: The apitools message object containing the API response.
  args: argparse.Namespace, The parsed args.

Raises:
  core.exceptions.Error: If an error was detected and extracted from the
    response.

Returns:
  A possibly modified response.
r   z
Code: [{}]zMessage: [{}]rj   )r#   r   r   _FindPopulatedAttributer   r   coder   rf   r   r  r   Errorrk   r   	text_typer   modify_response_hooks)r    r   ru   r   r   r   s         r$   _HandleResponse$BaseCommandGenerator._HandleResponse  s    yy**
II&&,,2288=?e	99##((
//,--E99#5#5#;#;#@#@AC D99##++
///00E99#5#5#;#;#C#CDF G  (!34
4s}}U344yy**x););)L)LMh		""88h%h 9Or'   c                 .   [        U R                  R                  R                  5       H  u  p# [        R
                  R                  [        XR                  R                  R                  5      UU R                  R                  R                  =(       d     U R                  R                  R                  S9nXC4s  $    g ! [        R                   a=  nU[        U R                  R                  R                  5      S-
  :X  a  Ue S nAM  S nAff = f)N)ry   r      )	enumerater#   rv   r   r   REGISTRYr  r   response_name_fieldr   r   	UserErrorlen)r    r   iry   r   es         r$   _GetOperationRef%BaseCommandGenerator._GetOperationRef  s    "499#3#3#?#?@	%%++Iyy//CCD!		  ,,M		0A0A0M0M	 , P
 %% A    DII$$001A55' 6s   BCD2DDc                    U R                  U5      u  pgU R                  R                  R                  =(       d    UnU(       aN  [        R
                  R                  U R                  XBU R                  U5      U R                  X!5      5      5        UR                  (       a]  [        R
                  R                  U R                  SR                  [        R                  5      X`R                  U5      5      5        U$ U R                  R                  U R                  U5      R                   n[#        U R                  U(       a  UOSUUU5      n	U	R%                  U5      (       a  U	R'                  U5      $ U R)                  XUS9$ )a  Handles polling for operations if the async flag is provided.

Args:
  args: argparse.Namespace, The parsed args.
  resource_ref: resources.Resource, The resource reference for the resource
    being operated on (not the operation itself)
  operation: The operation message response.
  request_string: The format string to print indicating a request has been
    issued for the resource. If None, nothing is printed.
  extract_resource_result: bool, True to return the original resource as
    the result or False to just return the operation response when it is
    done. You would set this to False for things like Delete where the
    resource no longer exists when the operation is done.

Returns:
  The response (either the operation or the original resource).
z$Check operation [{{{}}}] for status.Nru   )rI  r#   rv   request_issued_messager   statusPrintr  r  r  rf   r   REL_NAME_FORMAT_KEYr   r   r   r}   rr   r   r   _WaitForOperationWithPoller)
r    ru   r?   r   request_stringrw   r   r|   r}   pollers
             r$   _HandleAsync!BaseCommandGenerator._HandleAsync  sC   & +/*?*?	*J'MYY%%<<NN	jjt||N$($@$@$F$($8$8$LN O {{	jjt||
06*>>?
55d;= > 224<<FMMF!		/TF }}Yi((++D , * *r'   c                 J   U R                  SR                  [        R                  5      X R	                  U5      5      nU(       a  U R                  UR                  U5      OS n[        R                  " XU R                  XAR                  U R	                  U5      U5      5      $ )Nz*Waiting for operation [{{{}}}] to complete)	r  rf   r   rP  r  r  r?   r
   WaitFor)r    rS  r   ru   progress_stringr+  s         r$   rQ  0BaseCommandGenerator._WaitForOperationWithPoller@  s    ll4;;$88	:33D9;O
  (()<)<dC!% >>00((.	>? ?r'   c                     U(       d  U$ US   n [        X5      n[        U[        5      (       a(  U H"  nU R	                  XBSS 5      nU(       d  M   Us  $    U R	                  XSS 5      $ ! [         a     gf = f)a  Searches the given object for an attribute that is non-None.

This digs into the object search for the given attributes. If any attribute
along the way is a list, it will search for sub-attributes in each item
of that list. The first match is returned.

Args:
  obj: The object to search
  attributes: [str], A sequence of attributes to use to dig into the
    resource.

Returns:
  The first matching instance of the attribute that is non-None, or None
  if one could nto be found.
r   NrA  )r   r   r   listr9  )r    r   
attributesr   xs        r$   r9  ,BaseCommandGenerator._FindPopulatedAttributeM  s      ja=DCc #t!**1n=3*  ''^<<  s   A, ,
A98A9c                    SSK Jn  U R                  S5      nU R                  R	                  X15      nUR
                  nU(       a  U/O/ nUR                  U5      nUR                  nUR                  UR                  X5      5      $ )Nr   r   r   )
r   r   r   r   r   r.  r   r}   r   r   )	r    ru   r   get_methodsr  r1  r   get_arg_generatorr   s	            r$   _GetExistingResource)BaseCommandGenerator._GetExistingResourcek  s    D ""5)K--k@ $55';"#F'DDVL!!J??,::4LMMr'   c                    U R                   R                  (       a  [        R                  " U5      nU R                   R                  (       a  [        R
                  " U5      nU R                   R                  bH  U R                   R                  (       a  [        R                  " U5      nO[        R                  " U5      nU R                   R                  (       a-  [        R                  " U R                   R                  6 " U5      nU R                   R                  (       a0  [        R                  " S0 U R                   R                  D6" U5      n[        US5      (       dS  SSS.nU R                   R                  R                  5        VVs0 s H  u  p4UR!                  X35      U_M     snnUl        U R$                  (       a  ['        S U R(                   5       5      n['        S U R(                   5       5      nSR+                  U5      nSR+                  U5      n[-        U5      S:  a	  S	U S
U 3n	OSU SU 3n	XR"                  S'   U$ s  snnf )zConfigures top level attributes of the generated command.

Args:
  command: The command being generated.

Returns:
  calliope.base.Command, The command that implements the spec.
detailed_helpDESCRIPTIONEXAMPLES)descriptionexamplesc              3      #    U  H4  nUR                   R                   S UR                   R                   3v   M6     g7f)/N)ry   api_namer   .0r}   s     r$   	<genexpr>9BaseCommandGenerator._ConfigureCommand.<locals>.<genexpr>  s<      &$f ''(&*;*;*G*G)H
I$s   <>c              3   L   #    U  H  oR                   R                  v   M     g 7frP   )ry   docs_urlrm  s     r$   ro  rp    s     KlF&&//ls   "$z, rA  zThis command uses *z?* APIs. The full documentation for these APIs can be found at: zThis command uses the *z<* API. The full documentation for this API can be found at: zAPI REFERENCEr(   )r#   hiddenr   Hiddenauto_generatedAutogenerateduniverse_compatibleUniverseCompatibleDefaultUniverseOnlyrelease_tracksReleaseTracksdeprecated_data	Deprecatehasattr	help_textrH   r   re  r   setr   rk   rF  )
r    rG   key_mapkv	api_namesdoc_urlsapi_name_strdoc_url_strapi_infos
             r$   _ConfigureCommand&BaseCommandGenerator._ConfigureCommandz  s    yyG$gyy""7+gyy$$0		&	&))'2**73yy""DII$<$<=gFgyy  ;!:!:;GDg7O,,& g
 ,099+>+>+D+D+F+F41'++a
Q
+Fg  && &i KdllKKhYYy)lIIh'k	Y!	!, 0==HMK 	
 &l^ 4;;F-I 	 08O,N+s   Ic                     g rP   r(   ra   s    r$   	_GenerateBaseCommandGenerator._Generate  s    r'   c                 H    U R                  5       nU R                  U5        U$ rP   )r  r  )r    rG   s     r$   r   BaseCommandGenerator.Generate  s!    nnG7#Nr'   )r   r   r   r#   rP   )NN)T)r)   r*   r+   r,   r-   r4   r   r   r   r   r   r
  r%  r  r  r  r>  rI  rT  rQ  r9  rb  r  abcabstractmethodr  r   r.   r(   r'   r$   r   r   /  s    *)$?*0,-:z  A
9	 D <@+*Z?=<N0d 	 	r'   r   c                   V    \ rS rSrSr\R                  R                  rS r	S r
S rSrg)rY   i  z&Generator for generic/custom commands.c                 z    U R                   R                  (       a   [        R                  R	                  U5        g g rP   )r#   rv   r   
ASYNC_FLAGr   )r    r   s     r$   _AddAsyncFlag%GenericCommandGenerator._AddAsyncFlag  s&    yy
oo!!&) r'   c                 *   [        S U R                   5       5      nU R                  R                  nU(       a  U(       a  UR                  (       a  g [
        R                  R                  U5        [
        R                  R                  U5        [
        R                  R                  U5        [
        R                  R                  U5        U R                  R                  R                  (       a   [
        R                  R                  U5        g g )Nc              3   p   #    U  H,  nUR                  5       =(       a    UR                  5       v   M.     g 7frP   )ListItemFieldHasTokenizedRequestrm  s     r$   ro  :GenericCommandGenerator._AddPagingFlags.<locals>.<genexpr>  s1      $"F 	?6#=#=#??"s   46)anyr   r#   genericdisable_paging_flagsr   FILTER_FLAGr   
LIMIT_FLAGPAGE_SIZE_FLAGSORT_BY_FLAGr   r   URI_FLAG)r    r   is_paginatedr  s       r$   _AddPagingFlags'GenericCommandGenerator._AddPagingFlags  s     $ll$ $L iiGG(D(D  (OO'##F+!!&)yy""
mm' #r'   c                 @   ^   " U 4S jS[         R                  5      nU$ )aX  Generates a generic command.

A generic command has a resource argument, additional fields, and calls an
API method. It supports async if the async configuration is given. Any
fields is message_params will be generated as arguments and inserted into
the request message.

Returns:
  calliope.base.Command, The command that implements the spec.
c                   8   > \ rS rSr\U 4S j5       rU 4S jrSrg)2GenericCommandGenerator._Generate.<locals>.Commandi  c                 l   > TR                  U 5        TR                  U 5        TR                  U 5        g rP   )r   r  r  r   r    s    r$   Args7GenericCommandGenerator._Generate.<locals>.Command.Args  s-     6"V$r'   c                   > TR                  U5        TR                  U5      u  p#TR                  R                  (       a8  S nU(       a  SR	                  [
        R                  5      nTR                  XX4S9nTR                  X15      $ )NRequest issued for: [{{{}}}]rR  )	r   r%  r#   rv   rf   r   NAME_FORMAT_KEYrT  r>  )self_ru   r   r   rR  r    s        r$   Run6GenericCommandGenerator._Generate.<locals>.Command.Run  s{    d#-99.;BB(88:N&& ' B(##H33r'   r(   Nr)   r*   r+   r,   staticmethodr  r  r.   ra   s   r$   Commandr    s!     % %

4 
4r'   r  r   r  r    r  s   ` r$   r  !GenericCommandGenerator._Generate  s     4$,, 4* Nr'   r(   N)r)   r*   r+   r,   r-   r   r   GENERICrd   r  r  r  r.   r(   r'   r$   rY   rY     s%    .$0088,*(%r'   rY   c                   J    \ rS rSrSr\R                  R                  rS r	Sr
g)rS   i  z Generator for describe commands.c                 @   ^   " U 4S jS[         R                  5      nU$ )a  Generates a Describe command.

A describe command has a single resource argument and an API method to call
to get the resource. The result is returned using the default output format.

Returns:
  calliope.base.Command, The command that implements the spec.
c                   8   > \ rS rSr\U 4S j5       rU 4S jrSrg)3DescribeCommandGenerator._Generate.<locals>.Commandi  c                 (   > TR                  U 5        g rP   r   r  s    r$   r  8DescribeCommandGenerator._Generate.<locals>.Command.Args
       r'   c                 L   > TR                  U5      u  p#TR                  X15      $ rP   )r%  r>  r  ru   
unused_refr   r    s       r$   r  7DescribeCommandGenerator._Generate.<locals>.Command.Run  s%    #t4
##H33r'   r(   Nr  ra   s   r$   r  r    s    ! !4 4r'   r  )r   DescribeCommandr  s   ` r$   r  "DescribeCommandGenerator._Generate  s    4$&& 4 Nr'   r(   N)r)   r*   r+   r,   r-   r   r   DESCRIBErd   r  r.   r(   r'   r$   rS   rS     s    ($0099,r'   rS   c                   J    \ rS rSrSr\R                  R                  rS r	Sr
g)rT   i  zGenerator for list commands.c                 @   ^   " U 4S jS[         R                  5      nU$ )a  Generates a List command.

A list command operates on a single resource and has flags for the parent
collection of that resource. Because it extends the calliope base List
command, it gets flags for things like limit, filter, and page size. A
list command should register a table output format to display the result.
If arguments.resource.response_id_field is specified, a --uri flag will also
be enabled.

Returns:
  calliope.base.Command, The command that implements the spec.
c                   8   > \ rS rSr\U 4S j5       rU 4S jrSrg)/ListCommandGenerator._Generate.<locals>.Commandi,  c                    > TR                  U 5        TR                  R                  R                  (       d   [        R
                  R                  U 5        g g rP   )r   r#   r   r   r   r  r  r  s    r$   r  4ListCommandGenerator._Generate.<locals>.Command.Args/  s=      yy!!**
--
(
(
0 +r'   c                 n   > TR                  U5        TR                  U5      u  p#TR                  X15      $ rP   )r   r%  r>  r  s       r$   r  3ListCommandGenerator._Generate.<locals>.Command.Run7  s3    d##t4
##H33r'   r(   Nr  ra   s   r$   r  r  ,  s!     1 14 4r'   r  )r   ListCommandr  s   ` r$   r  ListCommandGenerator._Generate  s    $4$"" 4  Nr'   r(   N)r)   r*   r+   r,   r-   r   r   LISTrd   r  r.   r(   r'   r$   rT   rT     s    $$0055,"r'   rT   c                   J    \ rS rSrSr\R                  R                  rS r	Sr
g)rU   i?  zGenerator for delete commands.c                 @   ^   " U 4S jS[         R                  5      nU$ )a  Generates a Delete command.

A delete command has a single resource argument and an API to call to
perform the delete. If the async section is given in the spec, an --async
flag is added and polling is automatically done on the response. For APIs
that adhere to standards, no further configuration is necessary. If the API
uses custom operations, you may need to provide extra configuration to
describe how to poll the operation.

Returns:
  calliope.base.Command, The command that implements the spec.
c                   8   > \ rS rSr\U 4S j5       rU 4S jrSrg)1DeleteCommandGenerator._Generate.<locals>.CommandiV  c                    > TR                  U 5        TR                  R                  (       a   [        R                  R                  U 5        g g rP   )r   r#   rv   r   r  r   r  s    r$   r  6DeleteCommandGenerator._Generate.<locals>.Command.ArgsY  s5     99
//
%
%f
- r'   c                   > TR                  U5      u  p#TR                  R                  (       aR  TR                  UUUSR	                  [
        R                  5      SS9nUR                  (       a  TR                  X15      $ TR                  X15      n[        R                  " TR                  X!5      TR                  U5      S9  U$ )Nz#Delete request issued for: [{{{}}}]F)rR  rw   kind)r%  r#   rv   rT  rf   r   r  r>  r   DeletedResourcer  r  )r  ru   r   r   r    s       r$   r  5DeleteCommandGenerator._Generate.<locals>.Command.Run_  s    -99&&Bv.>>?&+ ' -( [[''77''7D00;!%!=!=d!C	Er'   r(   Nr  ra   s   r$   r  r  V  s!     . .
 r'   r  )r   DeleteCommandr  s   ` r$   r   DeleteCommandGenerator._GenerateD  s    $$$$ 6 Nr'   r(   N)r)   r*   r+   r,   r-   r   r   DELETErd   r  r.   r(   r'   r$   rU   rU   ?  s    &$0077,-r'   rU   c                   J    \ rS rSrSr\R                  R                  rS r	Sr
g)rV   it  zGenerator for create commands.c                 @   ^   " U 4S jS[         R                  5      nU$ )a  Generates a Create command.

A create command has a single resource argument and an API to call to
perform the creation. If the async section is given in the spec, an --async
flag is added and polling is automatically done on the response. For APIs
that adhere to standards, no further configuration is necessary. If the API
uses custom operations, you may need to provide extra configuration to
describe how to poll the operation.

Returns:
  calliope.base.Command, The command that implements the spec.
c                   8   > \ rS rSr\U 4S j5       rU 4S jrSrg)1CreateCommandGenerator._Generate.<locals>.Commandi  c                   > TR                  U 5        TR                  R                  (       a  [        R                  R                  U 5        TR                  R                  R                  (       a  [        R                  " U 5        g g rP   )
r   r#   rv   r   r  r   r   r!  r   AddCreateLabelsFlagsr  s    r$   r  6CreateCommandGenerator._Generate.<locals>.Command.Args  V     99
//
%
%f
-99%%

*
*6
2 &r'   c                   > T
R                  U5      u  p#T
R                  R                  T
R                  U5      R                  nU=(       a    UR
                  nT
R                  R                  (       a_  Ub'  U(       d   SR                  [        R                  5      nOSnT
R                  XUUS9nUR                  (       a  T
R                  X15      $ U(       af  [        R                  " U5      nUR                  S0 5      R                  S5      nU(       d  UR                  S5      n[         R"                  " U5      n	OT
R%                  X!5      n	[&        R(                  " U	T
R+                  U5      S9  T
R                  X15      nU$ )Nz#Create request issued for: [{{{}}}]zCreate request issuedr  r   r   r  )r%  r   r   r   r.  r5  r#   rv   rf   r   r  rT  r>  r   r   r   r   TransformBaseNamer  r   CreatedResourcer  )r  ru   r   r   r1  r5  rR  response_objrz   resource_namer    s             r$   r  5CreateCommandGenerator._Generate.<locals>.Command.Run  sY   -#11DDLL$   0 0 	2 F2EE 	99_%7BII(88:N 5N&&+ ' -( [[''77 "//9, #&&z26::6B)$((0I,>>yI-..s9-M!%!=!=d!C	E''7r'   r(   Nr  ra   s   r$   r  r    s!     3 3! !r'   r  )r   CreateCommandr  s   ` r$   r   CreateCommandGenerator._Generatey  s    $,$$$ ,\ Nr'   r(   N)r)   r*   r+   r,   r-   r   r   CREATErd   r  r.   r(   r'   r$   rV   rV   t  s    &$0077,@r'   rV   c                   V    \ rS rSrSr\R                  R                  r SS jr	S r
Srg)rW   i  zGenerator for wait commands.Nc                     [        U R                  U(       a  UOS UUR                  5       R                  U5      nU R	                  XaUS9$ )NrL  )rr   r#   GetCollectionInforz   rQ  )r    r   r?   rw   r}   ru   rS  s          r$   _WaitForOperation&WaitCommandGenerator._WaitForOperation  sI    !		#:<d'')33F ++F+MMr'   c                 @   ^   " U 4S jS[         R                  5      nU$ )a,  Generates a wait command for polling operations.

A wait command takes an operation reference and polls the status until it
is finished or errors out. This follows the exact same spec as in other
async commands except the primary operation (create, delete, etc) has
already been done. For APIs that adhere to standards, no further async
configuration is necessary. If the API uses custom operations, you may need
to provide extra configuration to describe how to poll the operation.

Returns:
  calliope.base.Command, The command that implements the spec.
c                   8   > \ rS rSr\U 4S j5       rU 4S jrSrg)/WaitCommandGenerator._Generate.<locals>.Commandi  c                 (   > TR                  U 5        g rP   r  r  s    r$   r  4WaitCommandGenerator._Generate.<locals>.Command.Args  r  r'   c                    > TR                   R                  TR                  U5      nUR                  nUR	                  U5      nTR                  US SX1S9nTR                  XQ5      nU$ )NF)r?   rw   r}   ru   )r   r   r   r}   r  r  r>  )r  ru   specified_resourcer}   r   r   r    s         r$   r  3WaitCommandGenerator._Generate.<locals>.Command.Run  st    !//BBLL$ #** &&t,))dE * & ''7r'   r(   Nr  ra   s   r$   r  r    s!     ! !
 
r'   r  r  r  s   ` r$   r  WaitCommandGenerator._Generate  s    $$,, & Nr'   r(   rP   )r)   r*   r+   r,   r-   r   r   WAITrd   r  r  r.   r(   r'   r$   rW   rW     s'    $$0055, ?CN%r'   rW   c                   J    \ rS rSrSr\R                  R                  rS r	Sr
g)rX   i  zGenerator for update commands.c                 P   ^ ^ SSK Jm   " U U4S jS[        R                  5      nU$ )a  Generates an update command.

An update command has a resource argument, additional fields, and calls an
API method. It supports async if the async configuration is given. Any
fields is message_params will be generated as arguments and inserted into
the request message.

Currently, the Update command is the same as Generic command.

Returns:
  calliope.base.Command, The command that implements the spec.
r   )r  c                   :   > \ rS rSr\U 4S j5       rU U4S jrSrg)1UpdateCommandGenerator._Generate.<locals>.Commandi  c                   > TR                  U 5        TR                  R                  (       a  [        R                  R                  U 5        TR                  R                  R                  (       a  [        R                  " U 5        g g rP   )
r   r#   rv   r   r  r   r   r!  r   AddUpdateLabelsFlagsr  s    r$   r  6UpdateCommandGenerator._Generate.<locals>.Command.Args  r  r'   c                   > S nT
R                   R                  (       a6  T
R                   R                  R                  (       a  T
R                  U5      nT
R	                  U5      T
l        T
R                  R                  T
R
                  U5      R                  nTR                  U5      nU(       ad  T
R                   R                  (       a(  T
R                   R                  R                  (       a  SnOTR                  UT
R                   U5      nXE0nOS nT
R                  XU5      u  pxT
R                   R                  (       a8  S n	U(       a  SR                  [        R                   5      n	T
R#                  XXS9n[$        R&                  " T
R)                  Xq5      T
R+                  U5      S9  T
R-                  X5      $ )Nr   r  r  r  )r#   r  read_modify_updaterb  r
  r   r   r   r}   GetMaskFieldPathdisable_auto_field_maskGetMaskStringr%  rv   rf   r   r  rT  r   UpdatedResourcer  r  r>  )r  ru   r  r}   	mask_pathmask_stringr$  r   r   rR  r    r  s             r$   r  5UpdateCommandGenerator._Generate.<locals>.Command.Run  sp   99YY00#88>..t4 ##66LL$  & 	++F3	 YY$))"2"2"J"JK ..tTYY	JK"0++K199.;BB(88:N&& ' B( 	  +--d3	5 ##H33r'   )r   Nr  )r    r  s   r$   r  r    s!     3 3%4 %4r'   r  )r   r  r   r  )r    r  r  s   ` @r$   r   UpdateCommandGenerator._Generate  s%     <04 04$,, 04d Nr'   r(   N)r)   r*   r+   r,   r-   r   r   UPDATErd   r  r.   r(   r'   r$   rX   rX     s    &$0077,Gr'   rX   c                   J    \ rS rSrSr\R                  R                  rS r	Sr
g)rZ   i@  z&Generator for get-iam-policy commands.c                 L   ^  SSK Jn   " U 4S jS[        R                  5      nU$ )a  Generates a get-iam-policy command.

A get-iam-policy command has a single resource argument and an API method
to call to get the resource. The result is returned using the default
output format.

Returns:
  calliope.base.Command, The command that implements the spec.
r   iam_utilc                   <   > \ rS rSrSr\U 4S j5       rU 4S jrSrg)7GetIamPolicyCommandGenerator._Generate.<locals>.CommandiW  zGet IAM policy command closure.c                 f   > TR                  U 5        [        R                  R                  U 5        g rP   )r   r   r  r  r  s    r$   r  <GetIamPolicyCommandGenerator._Generate.<locals>.Command.ArgsZ  s#     &&v.r'   c                   > TR                   R                  (       a  TR                   R                  R                  (       a_  TR                   R                  R                  TR                   R                  R                  TR                   R                  R
                  '   TR                  U5      u  p#TR                  X15      $ rP   )r#   r;   policy_versionr   r  get_iam_policy_version_pathr%  r>  )r  ru   _r   r    s       r$   r  ;GetIamPolicyCommandGenerator._Generate.<locals>.Command.Run_  s    99==TYY]]99 /3iimm.J.J ))


)
)iimm**, ood+##H33r'   r(   N	r)   r*   r+   r,   r-   r  r  r  r.   ra   s   r$   r  r  W  s"    +/ /4 4r'   r  )googlecloudsdk.command_lib.iamr  r   r  )r    r  r  s   `  r$   r  &GetIamPolicyCommandGenerator._GenerateE  s!     84$"" 4" Nr'   r(   N)r)   r*   r+   r,   r-   r   r   GET_IAM_POLICYrd   r  r.   r(   r'   r$   rZ   rZ   @  s    .$00??,#r'   rZ   c                   P    \ rS rSrSr\R                  R                  rS r	S r
Srg)r[   ik  z&Generator for set-iam-policy commands.c                    SnSnU R                   R                  (       a]  U R                   R                  R                  nSU;   a  US   =(       d    UnU R                   R                  R                  =(       d    UnSR	                  U5      nUR                  U5      n[        US5      (       a#  XR                   R                  R                  U'   gg)a5  Set Field Mask on SetIamPolicy request message.

If the API supports update_masks then adds the update_mask to the
SetIamPolicy request (via static fields).

Args:
  update_mask: str, comma separated string listing the Policy fields to be
    updated.
  method: APIMethod, used to identify update mask field.
SetIamPolicyRequestsetIamPolicyRequestset_iam_policy_requestz{}.updateMask
updateMaskN)	r#   r;   message_type_overridesset_iam_policy_request_pathrf   GetMessageByNamer~  r   r  )r    r$  r}   r+  policy_request_path	overridesmask_field_pathupdate_requests           r$   _SetPolicyUpdateMask1SetIamPolicyCommandGenerator._SetPolicyUpdateMaskp  s     3/ yy}}))--66i	!Y	."+,D"E #<%; 	!YY]]FF 4 3  &,,-@AO,,-CDN~|,,9Dii%%o6 -r'   c                 P   ^ ^ SSK Jm   " UU 4S jS[        R                  5      nU$ )a9  Generates a set-iam-policy command.

A set-iam-policy command takes a resource argument, a policy to set on that
resource, and an API method to call to set the policy on the resource. The
result is returned using the default output format.

Returns:
  calliope.base.Command, The command that implements the spec.
r   r  c                   @   > \ rS rSrSr\U U4S j5       rU U4S jrSrg)7SetIamPolicyCommandGenerator._Generate.<locals>.Commandi  zSet IAM policy command closure.c                    > TR                  U 5        TR                  U 5        [        R                  R	                  U 5        g rP   )r   AddArgForPolicyFiler   r  r  r   r  r    s    r$   r  <SetIamPolicyCommandGenerator._Generate.<locals>.Command.Args  s1     $$V,&&v.r'   c                 ~  > SnSnTR                   R                  (       ay  STR                   R                  R                  ;   a,  TR                   R                  R                  S   =(       d    UnTR                   R                  R                  =(       d    UnUS-   nTR                  R                  TR                  U5      R                  nUR                  U5      nU(       d  [        SR                  U5      5      eTR                  UR                  U5      u  pxTR                   R                  (       aJ  TR                   R                  R                  (       a%  TR                   R                  R                  Ul        UTR                   R                  R                   U'   TR#                  X5         TR%                  U5      u  pTR/                  U	R1                  5       TR3                  U5      5        TR5                  X5      $ ! [&         a&  n[(        R*                  R-                  S5        UeSnAff = f) Called when command is executed.Policyr*  policy.policyzPolicy type [{}] not found.zERROR: Policy modification failed. For bindings with conditions, run "gcloud alpha iam policies lint-condition" to identify issues in conditions.N)r#   r;   r-  r.  r   r   r   r}   r/  re   rf   ParsePolicyFileWithUpdateMaskpolicy_filer  versionr   r  r4  r%  r	   r   errrO  LogSetIamPolicyr0  r  r>  )r  ru   policy_type_namer0  policy_field_pathr}   policy_typer@  r$  r   r   exr  r    s               r$   r  ;SetIamPolicyCommandGenerator._Generate.<locals>.Command.Run  s    $3 99===== $		!7!7!B !1 0  "&!J!J "5!4  0);##66LL$  & 	--.>?8??  ! !&DDk+ 99==TYY]]9999==77&.=C		''(9:!!+6	//$/-# 	  T-I-I$-OP##H33 # 	
''--&
 (	s   9H 
H<!H77H<r(   Nr#  r  r    s   r$   r  r8    s"    +/ /
+4 +4r'   r  r$  r  r   r  r    r  r  s   ` @r$   r  &SetIamPolicyCommandGenerator._Generate  s%     844 44$,, 44l Nr'   r(   N)r)   r*   r+   r,   r-   r   r   SET_IAM_POLICYrd   r4  r  r.   r(   r'   r$   r[   r[   k  s#    .$00??,E@Hr'   r[   c                   J    \ rS rSrSr\S 5       r\S 5       rS rS r	S r
Srg	)
$BaseIamPolicyBindingCommandGeneratori  z.Base class for iam binding command generators.c                 |    U R                   R                  =(       a     U R                   R                  R                  $ rP   )r#   r;   enable_conditionra   s    r$   _add_condition3BaseIamPolicyBindingCommandGenerator._add_condition  s#    99==;TYY]];;;r'   c                 |    U R                   R                  =(       a     U R                   R                  R                  $ rP   )r#   r;   hide_special_member_typesra   s    r$   _hide_special_member_types?BaseIamPolicyBindingCommandGenerator._hide_special_member_types  s#    99==DTYY]]DDDr'   c                 x    U R                  U5      nU R                  R                  X!5      R                  U5      $ rP   )r
  r   r   r  )r    ru   r   s      r$   _GetResourceRef4BaseIamPolicyBindingCommandGenerator._GetResourceRef  s4    %%d+G00?EEdKKr'   c                 H   ^^ U R                   m " UU4S jS[        5      mT$ )zGenerate a IAM role completer.c                   .   >^  \ rS rSrUU U4S jrSrU =r$ )]BaseIamPolicyBindingCommandGenerator._GenerateDeclarativeIamRolesCompleter.<locals>.Completeri  c                 *   > [         TU ]  " SST0UD6  g )Nr6   r(   )r3   r4   )r    r7   	Completerr8   r6   s     r$   r4   fBaseIamPolicyBindingCommandGenerator._GenerateDeclarativeIamRolesCompleter.<locals>.Completer.__init__  s"    i' 	9-	917	9r'   r(   )r)   r*   r+   r,   r4   r.   rL   )r8   rb  r6   s   @r$   rb  r`    s    9 9r'   rb  )r\  r0   )r    rb  r6   s    @@r$   %_GenerateDeclarativeIamRolesCompleterJBaseIamPolicyBindingCommandGenerator._GenerateDeclarativeIamRolesCompleter  s+     ++9 90 9 r'   c                    U R                  S5      nU R                  R                  X!5      R                  nU R                  R	                  X5      nU R
                  R                  (       ay  U R
                  R                  R                  (       aT  [        R                  " UU R
                  R                  R                  U R
                  R                  R                  5        UR                  U5      nU$ )z4GetIamPolicy helper function for add/remove binding.getIamPolicy)r   r   r   r}   r   r#   r;   r  r   SetFieldInMessager   r   )r    ru   get_iam_methodsget_iam_methodget_iam_requestr@  s         r$   _GetIamPolicy2BaseIamPolicyBindingCommandGenerator._GetIamPolicy  s    &&~6O''::%v ((66O yy}}55!!

))--
3
3
))--
&
&(
   1FMr'   r(   N)r)   r*   r+   r,   r-   r   rU  rY  r\  rd  rl  r.   r(   r'   r$   rR  rR    s=    6< < E ELr'   rR  c                   T    \ rS rSrSr\R                  R                  rSS jr	S r
Srg)r\   i	  z.Generator for add-iam-policy binding commands.c                    SSK Jn  U R                  R                  U R                  U5      R
                  nUR                  S5      nU(       a]  UR                  U5      nU R                  U5      nUR                  S5      nUR                  XXXqR                  UR                  U5        U$ U R                  U5      nUR                  XWUR                  UR                  5        U$ )zGet the IAM policy and add the specified binding to it.

Args:
  args: an argparse namespace.
  add_condition: True if support condition.

Returns:
  IAM policy.
r   r  BindingExpr)r$  r  r   r   r   r}   r/  $ValidateAndExtractConditionMutexRolerl  "AddBindingToIamPolicyWithConditionmemberroleAddBindingToIamPolicy)	r    ru   add_conditionr  r}   binding_message_type	conditionr@  condition_message_types	            r$   "_GetModifiedIamPolicyAddIamBindingFAddIamPolicyBindingCommandGenerator._GetModifiedIamPolicyAddIamBinding  s     8 224<<FMMF!229=??Ei!!$'f%66v>11

))Y  M !!$'f$$%94;;%)YY0Mr'   c                 P   ^ ^ SSK Jm   " UU 4S jS[        R                  5      nU$ )a  Generates an add-iam-policy-binding command.

An add-iam-policy-binding command adds a binding to a IAM policy. A
binding consists of a member, a role to define the role of the member, and
an optional condition to define in what condition the binding is valid.
Two API methods are called to get and set the policy on the resource.

Returns:
  calliope.base.Command, The command that implements the spec.
r   r  c                   @   > \ rS rSrSr\U U4S j5       rU U4S jrSrg)>AddIamPolicyBindingCommandGenerator._Generate.<locals>.Commandi>  z'Add IAM policy binding command closure.c                    > TR                  U TR                  5       TR                  TR                  S9  TR	                  U 5        [
        R                  R                  U 5        g N)role_completerrw  rX  )AddArgsForAddIamPolicyBindingrd  rU  rY  r   r   r  r  r;  s    r$   r  CAddIamPolicyBindingCommandGenerator._Generate.<locals>.Command.ArgsA  sZ    ..EEG--&*&E&E	 	/ 	G
 	 &&v.r'   c                   > SnT	R                   R                  (       a)  T	R                   R                  R                  =(       d    UnUS-   nT	R                  UT	R                  S9nT	R                   R                  (       aJ  T	R                   R                  R
                  (       a%  T	R                   R                  R
                  Ul        UT	R                   R                  R                  U'    T	R                  U5      u  pVTR                  UR                  5       T	R!                  U5      5        T	R#                  Xa5      $ ! [         a&  n[        R                  R                  S5        UeSnAff = f)r>  r*  rA  rw  zERROR: Policy modification failed. For a binding with condition, run "gcloud alpha iam policies lint-condition" to identify issues in condition.N)r#   r;   r.  r{  rU  r  rD  r   r  r%  r	   r   rE  rO  rF  r0  r  r>  )
r  ru   r0  rH  r@  r   r   rJ  r  r    s
           r$   r  BAddIamPolicyBindingCommandGenerator._Generate.<locals>.Command.RunK  s!    499==iimm77N;N /);88 3 3 9 5 99==TYY]]9999==77&.=C		''(9:	//$/-# 	  T-I-I$-OP##H33 # 	
''--%
 (	s   0E 
E3!E..E3r(   Nr#  rL  s   r$   r  r  >  s"    3/ /4 4r'   r  rM  rN  s   ` @r$   r  -AddIamPolicyBindingCommandGenerator._Generate+  s%     8+4 +4$,, +4Z Nr'   r(   NF)r)   r*   r+   r,   r-   r   r   ADD_IAM_POLICY_BINDINGrd   r{  r  r.   r(   r'   r$   r\   r\   	  s!    6$00GG,:@r'   r\   c                   T    \ rS rSrSr\R                  R                  rSS jr	S r
Srg)r]   in  z1Generator for remove-iam-policy binding commands.c                 4   SSK Jn  U(       aS  UR                  U5      nU R                  U5      nUR	                  XQR
                  UR                  XAR                  S9  U$ U R                  U5      nUR                  XQR
                  UR                  5        U$ )zGet the IAM policy and remove the specified binding to it.

Args:
  args: an argparse namespace.
  add_condition: True if support condition.

Returns:
  IAM policy.
r   r  )all_conditions)	r$  r  ValidateAndExtractConditionrl  'RemoveBindingFromIamPolicyWithConditionrt  ru  allRemoveBindingFromIamPolicy)r    ru   rw  r  ry  r@  s         r$   %_GetModifiedIamPolicyRemoveIamBindingLRemoveIamPolicyBindingCommandGenerator._GetModifiedIamPolicyRemoveIamBindingt  s     866t<i!!$'f66
++tyy)HH 7 N
 M !!$'f))&++tyyIMr'   c                 P   ^ ^ SSK Jm   " UU 4S jS[        R                  5      nU$ )a  Generates a remove-iam-policy-binding command.

A remove-iam-policy-binding command removes a binding from a IAM policy. A
binding consists of a member, a role to define the role of the member, and
an optional condition to define in what condition the binding is valid.
Two API methods are called to get and set the policy on the resource.

Returns:
  calliope.base.Command, The command that implements the spec.
r   r  c                   @   > \ rS rSrSr\U U4S j5       rU U4S jrSrg)ARemoveIamPolicyBindingCommandGenerator._Generate.<locals>.Commandi  z*Remove IAM policy binding command closure.c                    > TR                  U TR                  5       TR                  TR                  S9  TR	                  U 5        [
        R                  R                  U 5        g r  ) AddArgsForRemoveIamPolicyBindingrd  rU  rY  r   r   r  r  r;  s    r$   r  FRemoveIamPolicyBindingCommandGenerator._Generate.<locals>.Command.Args  sZ    11EEG--&*&E&E	 	2 	G
 	 &&v.r'   c                   > SnTR                   R                  (       a)  TR                   R                  R                  =(       d    UnUS-   nTR                  UTR                  S9nTR                   R                  (       aJ  TR                   R                  R
                  (       a%  TR                   R                  R
                  Ul        UTR                   R                  R                  U'   TR                  U5      u  pVTR                  UR                  5       TR                  U5      5        TR                  Xa5      $ )r>  r*  rA  r  )r#   r;   r.  r  rU  r  rD  r   r  r%  rF  r0  r  r>  )	r  ru   r0  rH  r@  r   r   r  r    s	          r$   r  ERemoveIamPolicyBindingCommandGenerator._Generate.<locals>.Command.Run  s     499==iimm77N;N /);;; 3 3 < 5 99==TYY]]9999==77&.=C		''(9:-  T-I-I$-OP##H33r'   r(   Nr#  rL  s   r$   r  r    s"    6/ /4 4r'   r  rM  rN  s   ` @r$   r  0RemoveIamPolicyBindingCommandGenerator._Generate  s%     8"4 "4$,, "4H Nr'   r(   Nr  )r)   r*   r+   r,   r-   r   r   REMOVE_IAM_POLICY_BINDINGrd   r  r  r.   r(   r'   r$   r]   r]   n  s     9$00JJ,.7r'   r]   c                   J    \ rS rSrSr\R                  R                  rS r	Sr
g)r^   i  zGenerator for import commands.c                 P   ^ ^ SSK Jm   " UU 4S jS[        R                  5      nU$ )a4  Generates an import command.

An import command has a single resource argument and an API method to call
to get the resource. The result is from a local yaml file provided
by the `--source` flag, or from stdout if nothing is provided.

Returns:
  calliope.base.Command, The command that implements the spec.
r   utilc                   >   > \ rS rSrSr\U4S j5       rU U4S jrSrg)1ImportCommandGenerator._Generate.<locals>.Commandi  zImport command enclosure.c                    > TR                  U 5        TR                  R                  (       a  [        R                  R                  U 5        U R                  SSS9  g )Nz--sourcea  
            Path to a YAML file containing the configuration export data. The
            YAML file must not contain any output-only fields. Alternatively, you
            may omit this flag to read from standard input. For a schema
            describing the export/import format, see:
            $CLOUDSDKROOT/lib/googlecloudsdk/schemas/...

            $CLOUDSDKROOT is can be obtained with the following command:

              $ gcloud info --format='value(installation.sdk_root)'
          r   )r   r#   rv   r   r  r   add_argumentr  s    r$   r  6ImportCommandGenerator._Generate.<locals>.Command.Args  sK     99
//
%
%f
-
 	 	r'   c                 8  > TR                   R                  TR                  U5      R                  nUR	                  5       nUR
                  nUR                  U5      R                  n[        R                  " UR                  =(       d    SSS9nTR                  UR                  R                  TR                  R                  R                   UR"                  5      nTR%                  UUUS9nS n	TR                  R&                  (       a  TR                  R&                  R(                  n
TR                  R&                  R*                  n TR-                  U5      n	U
(       a=  X:X  a8  [>        R@                  RC                  SRE                  URF                  5      5      $ TRI                  XS9u  pTR                  R8                  (       a6  S nUb  SRE                  [J        RL                  5      nTRO                  XX5      nTRQ                  X5      $ ! [.        R0                   a  nUR2                  S:w  d  U(       d  UeTR                  R&                  R4                  TR                  l        TR                  R&                  R6                  (       a  S TR                  l        OTTR                  R&                  R:                  (       a/  TR                  R&                  R:                  TR                  l        TR=                  5          S nAGNS nAff = f)	N-F)binary)message_typestreamschema_pathi  z/Request not sent for [{}]: No changes detected.r  r  ))r   r   r   r}   r   request_fieldfield_by_namer   r   ReadFromFileOrStdinsourceGetSchemaPathry   rl  r#   r   r   r)   Importimport_abort_if_equivalentcreate_if_not_existsrb  apitools_exceptions	HttpErrorstatus_codecreate_requestno_create_asyncrv   create_asyncr   r   rN  rO  rf   r   r%  r   r  rT  r>  )r  ru   r}   r  r  resource_message_classdatar  imported_resourceexisting_resourcer  r  r   r   r   rR  export_utilr    s                   r$   r  5ImportCommandGenerator._Generate.<locals>.Command.Run  s   ##66LL$  & 	,,.,,!-!;!;M!J!O!O --dkk.@SO!//0A0A0J0J04		0A0A0M0M0F0O0OQ (../# / % !99 $		 1 1 E E
!%!2!2!G!G
3 $ 9 9$ ?& ! 5ZZ%%CJJ',,./ /  ( 6 99._;BB(88:N&&3( ##H33I %.. 3   C'/Ck #'))"3"3"B"Bdii ""22#'		 99$$11#'99#4#4#A#A		 00223s   H L+C#LLr(   Nr#  r  r    s   r$   r  r    s$    % $@4 @4r'   r  )!googlecloudsdk.command_lib.exportr  r   ImportCommandr    r  r  s   ` @r$   r   ImportCommandGenerator._Generate  s+     FV4 V4$$$ V4p Nr'   r(   N)r)   r*   r+   r,   r-   r   r   IMPORTrd   r  r.   r(   r'   r$   r^   r^     s    &$0077,ir'   r^   c                   J    \ rS rSrSr\R                  R                  rS r	Sr
g)r_   i6  zGenerator for export commands.c                 P   ^ ^ SSK Jm   " UU 4S jS[        R                  5      nU$ )a>  Generates an export command.

An export command has a single resource argument and an API method to call
to get the resource. The result is exported to a local yaml file provided
by the `--destination` flag, or to stdout if nothing is provided.

Returns:
  calliope.base.Command, The command that implements the spec.
r   r  c                   >   > \ rS rSrSr\U4S j5       rU U4S jrSrg)1ExportCommandGenerator._Generate.<locals>.CommandiM  zExport command enclosure.c                 H   > TR                  U 5        U R                  SSS9  g )Nz--destinationaf  
            Path to a YAML file where the configuration will be exported.
            The exported data will not contain any output-only fields.
            Alternatively, you may omit this flag to write to standard output.
            For a schema describing the export/import format, see
            $CLOUDSDKROOT/lib/googlecloudsdk/schemas/...
          r   )r   r  r  s    r$   r  6ExportCommandGenerator._Generate.<locals>.Command.ArgsP  s,      	 	r'   c                   > TR                  U5      u  p#TR                  R                  TR                  U5      R                  nTR                  UR                  R                  TR                  R                  R                  [        U5      R                  5      nUR                  S5      (       a|  [        R                  " UR                   5       nTR#                  X6US9  S S S 5        [$        R&                  R)                  SR+                  UR,                  UR                   5      5      $ TR#                  U[.        R0                  US9  g ! , (       d  f       Nq= f)Ndestination)r  r  r  zExported [{}] to '{}'.)r%  r   r   r   r}   r  ry   rl  r#   r   r   r   r)   IsSpecifiedr   
FileWriterr  Exportr   rN  rO  rf   r   sysstdout)	r  ru   r  r   r}   r  r  r  r    s	          r$   r  5ExportCommandGenerator._Generate.<locals>.Command.Run]  s!   #t4
##66LL$  & 	!//0A0A0J0J04		0A0A0M0M04X0G0GI
 M** 0 01V [  J 2 !!"<"C"CmmT--#/ 0 0 

szz{  L 21s   E
Er(   Nr#  r  s   r$   r  r  M  s$    %
 
L Lr'   r  )r  r  r   ExportCommandr  s   ` @r$   r   ExportCommandGenerator._Generate;  s+     F!L !L$$$ !LF Nr'   r(   N)r)   r*   r+   r,   r-   r   r   EXPORTrd   r  r.   r(   r'   r$   r_   r_   6  s    &$0077,5r'   r_   c                   J    \ rS rSrSr\R                  R                  rS r	Sr
g)r`   is  z%Generator for config export commands.c                 `   ^ ^^ SSK Jm  SSK Jm   " UUU 4S jS[        R                  5      nU$ )a  Generates a config export command.

A config export command has a resource argument as well as configuration
export flags (such as --output-format and --path). It will export the
configuration for one resource to stdout or to file, or will output a stream
of configurations for all resources of the same type within a project to
stdout, or to multiple files. Supported formats are `KRM` and `Terraform`.

Returns:
  calliope.base.Command, The command that implements the spec.
r   )flags)python_command_utilc                   <   > \ rS rSr\U U4S j5       rUU4S jrSrg)7ConfigExportCommandGenerator._Generate.<locals>.Commandi  c                 |  > U R                  SSS9nUR                  5       nTR                  R                  TR                  5      nU H>  nUR                  R                  5        H  u  pVSUl        M     UR                  U5        M@     TR                  USS9  TR                  U 5        TR                  U 5        g )NT)mutexrequiredFproject)ry   )	add_groupr   r   r   specsrH   r  r   
AddAllFlagAddPathFlagAddFormatFlag)	r   mutex_groupresource_groupru   r   r!  valuedeclarative_config_flagsr    s	          r$   r  <ConfigExportCommandGenerator._Generate.<locals>.Command.Args  s    &&TD&A$..0!!..t||<C))//+ha"EN ,
//.
)  	!++KI+N ,,V4 ..v6r'   c                 T  > TR                   R                  TR                  U5      R                  nU=(       a    UR                  n[        USS 5      (       a  TR                  XR                  S S9$ TR                  XR                  UR                  U5      R                  5       S9$ )Nr  )ru   ry   r?   )
r   r   r   r.  ry   r   	RunExportrz   ParseResourceArgr=   )r  ru   resource_argry   r  r    s       r$   r  ;ConfigExportCommandGenerator._Generate.<locals>.Command.Run  s    ))<<LL$  0 0 	!=l&=&=
4%%$..$8$8t / M M %..$8$8'88>GGI / K Kr'   r(   Nr  )r  r  r    s   r$   r  r    s#     7 7K Kr'   r  )+googlecloudsdk.command_lib.util.declarativer  r  r   r  )r    r  r  r  s   ` @@r$   r  &ConfigExportCommandGenerator._Generatex  s+     ^OK K$,, K> Nr'   r(   N)r)   r*   r+   r,   r-   r   r   CONFIG_EXPORTrd   r  r.   r(   r'   r$   r`   r`   s  s    -$00>>,0r'   r`   )Er-   
__future__r   r   r   r  r   r  apitools.base.protorpcliter   r   apitools.base.pyr   r   r  apitools.base.py.exceptionsr	   googlecloudsdk.api_lib.utilr
   googlecloudsdk.callioper   r   googlecloudsdk.command_lib.utilr   r   r   r   r   r   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   r   googlecloudsdk.core.consoler   googlecloudsdk.core.resourcer   googlecloudsdk.core.utilr   r   YamlCommandTranslatorr   ListCommandCompleterr0   objectr   OperationPollerrr   r   r   with_metaclassABCMetar   rY   rS   rT   rU   rV   rW   rX   rZ   r[   rR  r\   r]   r^   r_   r`   r(   r'   r$   <module>r     s    '  ' 
  
 D % > ; . ( 3 6 : 9 D I < + # ) 2 ; * 
166 1:#B#B @< V < ~cD611 cDL4D3--ckk6B DN<2 <~3 @'/ 'T21 2jE1 EP2/ 2jL1 L^(#7 (Vm#7 m`++? +\b*N bJT(Tnn1 nb:1 :z5#7 5r'   