
                             S r SSKJr  SSKJr  SSKJr  SSK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  \R$                   " S S\R&                  5      5       rg)z9Command for listing grantable roles for a given resource.    )absolute_import)division)unicode_literalsN)
list_pager)
exceptions)util)base)flags)iam_util)	resourcesc                   V    \ rS rSrSrS\R                  " S5      0r\S 5       r	S r
Srg)	ListGrantableRoles!   zList IAM grantable roles for a resource.

This command displays the list of grantable roles for a resource.
The resource can be referenced either via the full resource name or via a URI.
User can then add IAM policy bindings to grant the roles.
EXAMPLESa+            List grantable roles for a project:

            $ {command} //cloudresourcemanager.googleapis.com/projects/PROJECT_ID

          List grantable roles for a resource identified via full resource name:

            $ {command} //compute.googleapis.com/projects/example-project/zones/us-central1-f/instances/example-instance

          List grantable roles for a resource identified via URI:

            $ {command} \
            https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-f/instances/example-instance
      c                 
   [         R                  " S5      R                  U 5        [        R                  R                  U 5        [        R
                  R                  U 5        [        R
                  R                  U S5        g )Nzget the list of roles fori,  )r
   GetResourceNameFlagAddToParserr	   FILTER_FLAGPAGE_SIZE_FLAG
SetDefault)parsers    'lib/surface/iam/list_grantable_roles.pyArgsListGrantableRoles.Args;   sZ    	9:FFvN  (##F+""63/    c           	         S nUR                   R                  S5      (       a  UR                   nUR                   R                  S5      (       a?  [        R                  R	                  UR                   5      n[
        R                  " U5      nU(       d  [        R                  " S5      e[        R                  " 5       u  pE[        R                  " UR                  UR                  US9SSUR                  SS9$ )	Nz//httpz<The given resource is not a valid full resource name or URL.)fullResourceNamerolesQueryGrantableRolespageSize)fieldmethod
batch_sizebatch_size_attribute)resource
startswithr   REGISTRYParser   GetFullResourceNamer   InvalidResourceExceptionr   GetClientAndMessagesr   YieldFromListr   QueryGrantableRolesRequest	page_size)selfargsr&   resource_refclientmessagess         r   RunListGrantableRoles.RunB   s    H}}%%h}}''''--dmm<l--l;h//
H  002F##++X+F$>>' r    N)__name__
__module____qualname____firstlineno____doc__textwrapdedentdetailed_helpstaticmethodr   r5   __static_attributes__r7   r   r   r   r   !   s<     (// #
 -" 0 0r   r   )r<   
__future__r   r   r   r=   apitools.base.pyr   googlecloudsdk.api_lib.iamr   r   googlecloudsdk.callioper	   googlecloudsdk.command_lib.iamr
   r   googlecloudsdk.corer   UniverseCompatibleCommandr   r7   r   r   <module>rJ      sQ     @ &  '  ' 1 + ( 0 3 ) 7 7 7r   