
    `                     T    S 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.    )
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
)PermissionsHelper8   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__B   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.GetTestingPermissionsV   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)   r0   r!   r1   r2   NOT_SUPPORTEDr4   )r+   valid_permissionsr,   s      r   GetValidPermissions%PermissionsHelper.GetValidPermissionsa   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.r9   )r+   not_supported_permissionsr,   s      r   GetNotSupportedPermissions,PermissionsHelper.GetNotSupportedPermissionsl   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)   r0   r!   r1   r2   r:   apiDisabledr4   )r+   api_disabled_permissionsr,   s      r   GetApiDisabledPermissons*PermissionsHelper.GetApiDisabledPermissonsw   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)   r4   )r+   not_applicable_permissionsr,   s      r   GetNotApplicablePermissions-PermissionsHelper.GetNotApplicablePermissions   s:    !#--
	88	8"))*5 . &%r   )r!   r(   r)   N)__name__
__module____qualname____firstlineno____doc__r-   r6   r<   r@   rE   rI   __static_attributes__ r   r   r%   r%   8   s&    D(			%
$&r   r%   N)rO   apitools.base.pyr   googlecloudsdk.api_lib.utilr   googlecloudsdk.command_lib.iamr   r   r   r#   objectr%   rQ   r   r   <module>rV      s2     3 ( , 3(
(
',Q& Q&r   