
                         x    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 rS	 rS
 r " S S\5      rg)z,Utilities for IAM commands to call IAM APIs.    )absolute_import)division)unicode_literals)
list_pager)apis)iam_utilc                  J    [         R                  " SS5      n X R                  4$ )Niamv1r   GetClientInstanceMESSAGES_MODULEclients    &lib/googlecloudsdk/api_lib/iam/util.pyGetClientAndMessagesr      s#    !!%.&	''	''    c                  J    [         R                  " SS5      n X R                  4$ )Niamcredentialsr   r   r   s    r   "GetIamCredentialsClientAndMessagesr       s$    !!"2D9&	''	''r   c           	          [         R                  " U R                  UR                  [        R
                  " U5      SS9SSSSS9$ )zReturns the testable permissions for a resource.

Args:
  iam_client: The iam client.
  messages: The iam messages.
  resource: Resource reference.

Returns:
  List of permissions.
i  )fullResourceNamepageSizeQueryTestablePermissionspermissionsr   )
batch_sizemethodfieldbatch_size_attribute)r   YieldFromListr   QueryTestablePermissionsRequestr   GetFullResourceName)
iam_clientmessagesresources      r   GetTestablePermissionsr&   %   sR     
	!	!..#77A /  '%
' 'r   c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)PermissionsHelper;   a  Get different kinds of permissions list from permissions provided.

Attributes:
  messages: The iam messages.
  source_permissions: A list of permissions to inspect.
  testable_permissions_map: A dict maps from permissions name string to
      Permission message provided by the API.
c                     X l         X@l        0 U l        U(       a,  [        XU5       H  nXPR                  UR                  '   M     gg)aI  Create a PermissionsHelper object.

To get the testable permissions for the given resource and store as a dict.

Args:
  iam_client: The iam client.
  messages: The iam messages.
  resource: Resource reference for the project/organization whose
  permissions are being inspected.
  permissions: A list of permissions to inspect.
N)r$   source_permissionstestable_permissions_mapr&   name)selfr#   r$   r%   r   
permissions         r   __init__PermissionsHelper.__init__E   sC     M)$&D!.zXN*9C%%joo6 O r   c                    / nU R                    Hl  nX R                  ;   d  M  U R                  U   R                  U R                  R                  R
                  R                  :X  d  M[  UR                  U5        Mn     U$ )z?Returns the TESTING permissions among the permissions provided.)r+   r,   customRolesSupportLevelr$   
Permission&CustomRolesSupportLevelValueValuesEnumTESTINGappend)r.   testing_permissionsr/   s      r   GetTestingPermissions'PermissionsHelper.GetTestingPermissionsY   sm    --

55
5((4LL==##JJ7 	"":. . r   c                    / nU R                    Hl  nX R                  ;   d  M  U R                  U   R                  U R                  R                  R
                  R                  :w  d  M[  UR                  U5        Mn     U$ )z=Returns the valid permissions among the permissions provided.r+   r,   r3   r$   r4   r5   NOT_SUPPORTEDr7   )r.   valid_permissionsr/   s      r   GetValidPermissions%PermissionsHelper.GetValidPermissionsd   sm    --

55
5((4LL==##JJ= 	  , . r   c                    / nU R                    Hl  nX R                  ;   d  M  U R                  U   R                  U R                  R                  R
                  R                  :X  d  M[  UR                  U5        Mn     U$ )zEReturns the not supported permissions among the permissions provided.r<   )r.   not_supported_permissionsr/   s      r   GetNotSupportedPermissions,PermissionsHelper.GetNotSupportedPermissionso   sm     "--

55
5((4LL==##JJ= 	"((4 . %$r   c                 B   / nU R                    H  nX R                  ;   d  M  U R                  U   R                  U R                  R                  R
                  R                  :w  d  M[  U R                  U   R                  (       d  M{  UR                  U5        M     U$ )zDReturns the API disabled permissions among the permissions provided.)	r+   r,   r3   r$   r4   r5   r=   apiDisabledr7   )r.   api_disabled_permissionsr/   s      r   GetApiDisabledPermissons*PermissionsHelper.GetApiDisabledPermissonsz   s    !--

55
5((4LL==##JJ= 
'
'

3
?
?
? ''
3 . $#r   c                 t    / nU R                    H%  nX R                  ;  d  M  UR                  U5        M'     U$ )zFReturns the not applicable permissions among the permissions provided.)r+   r,   r7   )r.   not_applicable_permissionsr/   s      r   GetNotApplicablePermissions-PermissionsHelper.GetNotApplicablePermissions   s:    !#--
	88	8"))*5 . &%r   )r$   r+   r,   N)__name__
__module____qualname____firstlineno____doc__r0   r9   r?   rC   rH   rL   __static_attributes__ r   r   r(   r(   ;   s&    D(			%
$&r   r(   N)rR   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.utilr   googlecloudsdk.command_lib.iamr   r   r   r&   objectr(   rT   r   r   <module>rZ      s9     3 &  ' ' , 3(
(
',Q& Q&r   