
                             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)z2Command for creating a role from an existing role.    )absolute_import)division)unicode_literals)util)base)RequiredArgumentException)iam_util)logEXAMPLESaB            To create a copy of an existing role ``spanner.databaseAdmin'' into an organization
          with ``1234567'', run:

            $ {command} --source="roles/spanner.databaseAdmin" --destination=CustomViewer --dest-organization=1234567

          To create a copy of an existing role ``spanner.databaseAdmin'' into a project with
          ``PROJECT_ID'', run:

            $ {command} --source="roles/spanner.databaseAdmin" --destination=CustomSpannerDbAdmin --dest-project=PROJECT_ID

          To modify the newly created role see the roles update command.
        c                   *    e Zd ZdZeZed        Zd Zy)Copyz]Create a role from an existing role.

  This command creates a role from an existing role.
  c                     | j                  dd       | j                  dd       | j                  dd       | j                  dd	       | j                  d
d       | j                  dd       y )Nz--sourcezsThe source role ID. For predefined roles, for example: roles/viewer. For custom roles, for example: myCompanyAdmin.)helpz--destinationzEThe destination role ID for the new custom role. For example: viewer.z--source-organizationz<The organization of the source role if it is an custom role.z--dest-organizationz)The organization of the destination role.z--source-projectz7The project of the source role if it is an custom role.z--dest-projectz$The project of the destination role.)add_argument)parsers    lib/surface/iam/roles/copy.pyArgsz	Copy.Args8   s    
9  :
 %  & #  $ $O  Q
#  $ E  G    c                    t        j                         \  }}|j                  t        dd      |j                  t        dd      t        j                  |j                  |j                  |j                  dd      }t        j                  |j                  |j                  d      }|j                  j                  |j                  |	            }|j                  |j                   |j"                  
      }t        j$                  ||t        j&                  |j                  |j                        |j(                        }|j+                         }	|	r*t-        j.                  ddj1                  |	      z   dz          |j3                         }
|
r*t-        j.                  ddj1                  |
      z   dz          |j5                         }t        j6                  |       |j9                         }t        j:                  |       |j=                         }||_        |j                  j?                  |jA                  |jC                  ||j                        |            }t        jD                  |       |S )Nsourcezthe source role is required.destinationz!the destination role is required.zthe source custom role)	attributeparameter_namezthe destination custom role)r   )name)titledescriptionz<Permissions don't support custom roles and won't be added: [z, z] 
zHPermissions not applicable to the current resource and won't be added: [)roleroleId)createRoleRequestparent)#r   GetClientAndMessagesr   r   r   r	   GetRoleNamesource_organizationsource_projectGetParentNamedest_organizationdest_projectorganizations_rolesGetIamOrganizationsRolesGetRequestRoler   r   PermissionsHelperGetResourceReferenceincludedPermissionsGetNotSupportedPermissionsr
   warningjoinGetNotApplicablePermissionsGetApiDisabledPermissonsApiDisabledPermissionsWarningGetTestingPermissionsTestingPermissionsWarningGetValidPermissionsCreate"IamOrganizationsRolesCreateRequestCreateRoleRequestSetRoleStageIfAlpha)selfargsclientmessagessource_role_namedest_parentsource_rolenew_rolepermissions_helpernot_supported_permissionsnot_applicable_permissionsapi_diabled_permissionstesting_permissionsvalid_permissionsresults                  r   RunzCopy.RunP   so   002FH{{%h0NOO%m&IK K++  *! ((/1K
 ,,00006F0GIK }}++  -H //080M0M484E4E484J4J1L 1<0O0O	Q
 !3 M M O 	kk
JII/0139:; "4!O!O "!	kk99%?@ACIJK 1IIK**+BC,BBD&&':;*>>@#4H ''..33&88d&6&6 9 8 	4 	 !F
   (Mr   N)	__name__
__module____qualname____doc__DETAILED_HELPdetailed_helpstaticmethodr   rK    r   r   r   r   /   s'    
  -G G.6r   r   N)rO   
__future__r   r   r   googlecloudsdk.api_lib.iamr   googlecloudsdk.callioper   "googlecloudsdk.calliope.exceptionsr   googlecloudsdk.command_lib.iamr	   googlecloudsdk.corer
   rP   UniverseCompatibleCommandr   rS   r   r   <module>r\      s[     9 &  ' + ( H 3 # 	$ V4<< V Vr   