
    !                         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rSS0r\R,                   " S S\R.                  5      5       rg)z#Command for updating a custom role.    )absolute_import)division)unicode_literals)
exceptions)util)
http_retry)base)flags)iam_util)
console_ioNEXAMPLESaD            To update the role ``ProjectUpdater'' from a YAML file, run:

            $ {command} ProjectUpdater --organization=123 --file=role_file_path

          To update the role ``ProjectUpdater'' with flags, run:

            $ {command} ProjectUpdater --project=myproject --permissions=permission1,permission2
        c                       \ rS rSrSr\r\S 5       rS r	\
R                  " \R                  R                  R                  5      S 5       rS rS rSrg	)
Update0   zFUpdate an IAM custom role.

This command updates an IAM custom role.

c                 ~   U R                  S5      nUR                  SSS9  UR                  SSS9  UR                  SSS9  UR                  S	S
S9  UR                  SSS9  UR                  SSS9  U R                  SSS9  [        R                  " U S5        [        R                  " S5      R                  U 5        g )NzThe following flags determine the fields need to be updated. You can update a role by specifying the following flags, or you can update a role from a YAML file by specifying the file flag.z--titlez)The title of the role you want to update.)helpz--descriptionz/The description of the role you want to update.z--stagez)The state of the role you want to update.--permissionszIThe permissions of the role you want to set. Use commas to separate them.z--add-permissionszIThe permissions you want to add to the role. Use commas to separate them.z--remove-permissionszNThe permissions you want to remove from the role. Use commas to separate them.z--filezeThe YAML file you want to use to update a role. Can not be specified with other flags except role-id.update)add_argument_groupadd_argumentr
   AddParentFlagsGetCustomRoleFlagAddToParser)parserupdateds     lib/surface/iam/roles/update.pyArgsUpdate.Args:   s   ''	NOG C  EO  QC  E'  ( '  ( -  . @  A 
*	H%11&9    c                    [         R                  " 5       u  p#[        R                  " UR                  UR
                  UR                  5      nUR                  5       nUR                  (       GaU  UR                  (       dU  UR                  (       dD  UR                  (       d3  UR                  (       d"  UR                  (       d  UR                  (       a  [        R                   " SS5      e[        R"                  " UR                  UR                  5      nUR$                  (       d  Sn[&        R(                  " USSS9  UR*                  (       d2  U R-                  X#UR.                  UR
                  UR                  5         UR0                  R3                  UR5                  XES95      n[        R6                  " U5        U$ U RA                  XXRU5      n[        R6                  " U5        U$ ! [8        R:                   a  n[        R<                  " USS	9eS nAf[8        R>                   a  n[        R<                  " U5      eS nAff = f)
NfileotherszThe specified role does not contain an "etag" field identifying a specific version to replace. Updating a role without an "etag" can overwrite concurrent role changes.zReplace existing roleT)messageprompt_stringcancel_on_no)namerolezStale "etag": Please use the etag from your latest describe response. Or new changes have been made since your latest describe operation. Please retry the whole describe-update process. Or you can leave the etag blank to overwrite concurrent role changes.)error_format)!r   GetClientAndMessagesr   GetRoleNameorganizationprojectr'   Roler!   titledescriptionstagepermissionsadd_permissionsremove_permissionsr   ConflictingArgumentsExceptionParseYamlToRoleetagr   PromptContinuequietWarnPermissionsincludedPermissionsorganizations_rolesPatch!IamOrganizationsRolesPatchRequestSetRoleStageIfAlphaapitools_exceptionsHttpConflictErrorHttpException	HttpErrorUpdateWithFlags)	selfargsclientmessages	role_namer'   msgreses	            r   Run
Update.RunY   s   002F$$T%6%6diiPI==?Dyyy
**((DJJ$:J:J


$"9"966vxHH%%dii?dYY 	!!1	 ZZVt/G/G!\\4+<+<	>*((..66 7 +, 	$$S)
 

th
GC  %J !22 /&& -/ 	/ !** *&&q))*s$   ?G0 0IHI0IIc           	          U R                  XUXE5      u  p6UR                  R                  UR                  X#SR	                  U5      S95      $ )N,)r&   r'   
updateMask)GetUpdatedRoler;   r<   r=   join)rD   rE   rH   r'   
iam_clientrG   changed_fieldss          r   rC   Update.UpdateWithFlags   sZ    ..t/9ED))//22#((>2J 	3 	LM Mr   c                 v   / nUR                   b"  UR                  S5        UR                   Ul         UR                  b"  UR                  S5        UR                  Ul        UR                  (       a6  UR                  S5        [        R
                  " UR                  5      Ul        UR                  b9  UR                  (       d  UR                  (       a  [        R                  " SS5      eUR                  b  UR                  S5        UR                  R                  S5      Ul        UR                  (       d  / Ul        UR                  (       d2  U R                  XEUR                  UR                  UR                   5        UR"                  R%                  UR'                  US95      nUR                  (       d  UR                  (       GaU  [)        UR                  5      nS	n	[)        5       n
UR                  (       aM  UR                  R                  S5       H.  nX;  d  M
  UR+                  U5        U
R+                  U5        S
n	M0     UR                  (       aR  UR                  R                  S5       H3  nX;   a  UR-                  U5        S
n	X;   d  M"  U
R-                  U5        M5     U	(       a  UR                  S5        [/        [1        U5      5      Ul        UR                  (       d1  U R                  XE[/        U
5      UR                  UR                   5        UR2                  Ul        X64$ )z!Gets the updated role from flags.r/   r.   r0   r   z(-add-permissions or --remove-permissionsr:   rO   )r&   FT)r/   appendr.   r0   r   StageTypeFromStringr1   r2   r3   r   r4   splitr:   r8   r9   r,   r+   r;   GetIamOrganizationsRolesGetRequestsetaddremovelistsortedr6   )rD   rE   rH   r'   rS   rG   rT   origin_roler1   changednewly_added_permissions
permissions               r   rQ   Update.GetUpdatedRole   s   N#M*))dzzG$::djzzG$//

;dj#)=)=)-)@)@44
EG G#12!%!1!1!7!7!<d#% ZZZ43K3K!\\4+<+<	>004400i0@BKt666778kg #			..44S9J*OOJ'#''
3G	 :
 
	 	 1177<J&z*G2#**:6 = 
34!%f[&9!:dZZZ!"9:DLL!..	0   DIr   c                     [         R                  " X[        R                  " XE5      U5      nUR	                  5       n[        R
                  " U5        UR                  5       n[        R                  " U5        g )N)r   PermissionsHelperr   GetResourceReferenceGetApiDisabledPermissonsApiDisabledPermissionsWarningGetTestingPermissionsTestingPermissionsWarning)	rD   rS   rG   r1   r,   r+   permissions_helperapi_disabled_permissionstesting_permissionss	            r   r9   Update.WarnPermissions   sh    //
080M0M4;1K0;=  2JJL**+CD,BBD&&':;r    N)__name__
__module____qualname____firstlineno____doc__DETAILED_HELPdetailed_helpstaticmethodr   rL   r   RetryOnHttpStatussixmoveshttp_clientCONFLICTrC   rQ   r9   __static_attributes__rq   r   r   r   r   0   sc      -: :<)V 		 5 5 > >?M @M3 j	<r   r   )rv   
__future__r   r   r   apitools.base.pyr   r?   googlecloudsdk.api_lib.iamr   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper	   googlecloudsdk.command_lib.iamr
   r   googlecloudsdk.core.consoler   six.moves.http_clientr{   rw   UniverseCompatibleCommandr   rq   r   r   <module>r      sg     * &  ' > + 2 ( . 0 3 2  	 Y<T\\ Y< Y<r   