
    [                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddl	mZ dd	lmZ d
diZej                   G d dej                                Zy)zACommand to create a custom role for a project or an organization.    )absolute_import)division)unicode_literals)util)base)flags)iam_util)logEXAMPLESa            To create a custom role ``ProjectUpdater'' from a YAML file, run:

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

          To create a custom role ``ProjectUpdater'' with flags, run:

            $ {command} ProjectUpdater --project=myproject --title=ProjectUpdater --description="Have access to get and update the project" --permissions=resourcemanager.projects.get,resourcemanager.projects.update
        c                   *    e Zd ZdZeZed        Zd Zy)Createz~Create a custom role for a project or an organization.

  This command creates a custom role with the provided information.
  c                 |   | j                  d      }|j                  d      }|j                  dd       |j                  dd       |j                  d	d
       |j                  dd       |j                  dd       t        j                  | d       t        j                  d      j                  |        y )NT)mutexzRoles Settingsz--titlez)The title of the role you want to create.)helpz--descriptionz/The description of the role you want to create.z--stagezThe state of the role you want to create. This represents a role's lifecycle phase: `ALPHA`, `BETA`, `GA`, `DEPRECATED`, `DISABLED`, `EAP`.z--permissionszLThe permissions of the role you want to create. Use commas to separate them.z--filezuThe JSON or YAML file with the IAM Role to create. See https://cloud.google.com/iam/reference/rest/v1/projects.roles.create)	add_groupadd_argumentr   AddParentFlagsGetCustomRoleFlagAddToParser)parserroles_groupsettings_flags_groups      lib/surface/iam/roles/create.pyArgszCreate.Args4   s    """.K&001AB%%C & E%%O & Q%% + & , %%' & ( N  O 
*	H%11&9    c                    t        j                         \  }}t        j                  |j                  |j
                        }|j                  r9t        j                  |j                  |j                        }d |_	        d |_
        n|j                  |j                  |j                        }|j                  r |j                  j                  d      |_        |j                   r$t        j"                  |j                         |_        |j                  s|j$                  |_        |j&                  st        j(                  ||t        j*                  |j
                  |j                        |j                        }|j-                         }t        j.                  |       |j1                         }t        j2                  |       |j4                  j7                  |j9                  |j;                  ||j$                        |            }	t=        j>                  |j$                  d       t        j@                  |	       |	S )N)titledescription,)roleroleId)createRoleRequestparentr!   )kind)!r   GetClientAndMessagesr	   GetParentNameorganizationprojectfileParseYamlToRoleRolenameetagr   r   permissionssplitincludedPermissionsstageStageTypeFromStringr!   quietPermissionsHelperGetResourceReferenceGetApiDisabledPermissonsApiDisabledPermissionsWarningGetTestingPermissionsTestingPermissionsWarningorganizations_rolesr   "IamOrganizationsRolesCreateRequestCreateRoleRequestr
   CreatedResourceSetRoleStageIfAlpha)
selfargsclientmessagesparent_namer!   permissions_helperapi_diabled_permissionstesting_permissionsresults
             r   Runz
Create.RunK   s   002FH(():):DLLIKyy%%dii?ddidi]]9I9I]Jd			#'#3#3#9#9##> 	11$**=
::99dj::11&(2:2O2O6:ll6:6G6G3I 372J2J	L
 !3 K K M,,-DE.DDF(()<=''..33&88$)) 9 - 	4 	 !F
 		/  (Mr   N)	__name__
__module____qualname____doc__DETAILED_HELPdetailed_helpstaticmethodr   rI    r   r   r   r   +   s%    
  -: :,#r   r   N)rM   
__future__r   r   r   googlecloudsdk.api_lib.iamr   googlecloudsdk.callioper   googlecloudsdk.command_lib.iamr   r	   googlecloudsdk.corer
   rN   UniverseCompatibleCommandr   rQ   r   r   <module>rY      s\     H &  ' + ( 0 3 # 	 BT\\ B Br   