
                             d Z ddlmZ ddlmZ ddlmZ ddl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 ej$                   G d dej&                               Zy)z9Command for listing grantable roles for a given resource.    )absolute_import)division)unicode_literalsN)
list_pager)
exceptions)util)base)flags)iam_util)	resourcesc                   N    e Zd ZdZd ej
                  d      iZed        Zd Z	y)ListGrantableRoleszList 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                    t        j                  d      j                  |        t        j                  j                  |        t        j
                  j                  |        t        j
                  j                  | d       y )Nzget the list of roles fori,  )r
   GetResourceNameFlagAddToParserr	   FILTER_FLAGPAGE_SIZE_FLAG
SetDefault)parsers    'lib/surface/iam/list_grantable_roles.pyArgszListGrantableRoles.Args;   sZ    	9:FFvN  (##F+""63/    c                    d }|j                   j                  d      r|j                   }|j                   j                  d      r>t        j                  j	                  |j                         }t        j                  |      }|st        j                  d      t        j                         \  }}t        j                  |j                  |j                  |      dd|j                  d      S )	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   RunzListGrantableRoles.RunB   s    H}}%h}}'''--dmm<l--l;h//
H  002FH##++X+F$>>' r   N)
__name__
__module____qualname____doc__textwrapdedentdetailed_helpstaticmethodr   r3    r   r   r   r   !   s>     /(// #
 -" 0 0r   r   )r7   
__future__r   r   r   r8   apitools.base.pyr   googlecloudsdk.api_lib.iamr   r   googlecloudsdk.callioper	   googlecloudsdk.command_lib.iamr
   r   googlecloudsdk.corer   UniverseCompatibleCommandr   r<   r   r   <module>rE      sQ     @ &  '  ' 1 + ( 0 3 ) 7 7 7r   