o
    	                     @   sh   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 G dd dej	Z
G d	d
 d
ej	ZdS )zIAM completers.    )absolute_import)division)unicode_literals)
completers)	resourcesc                       s2   e Zd ZdZd	 fdd	Zdd Zdd Z  ZS )
IamRolesCompletera(  An IAM role completer for a resource argument.

  The Complete() method override bypasses the completion cache.

  Attributes:
    _resource_dest: The argparse Namespace dest string for the resource
      argument that has the roles.
    _resource_collection: The resource argument collection.
  Nc                    s&   t t| jdi | || _|| _d S )N )superr   __init___resource_dest_resource_collection)selfresource_destresource_collectionkwargs	__class__r   F/tmp/google-cloud-sdk/lib/googlecloudsdk/command_lib/iam/completers.pyr
   %   s   
zIamRolesCompleter.__init__c                 C   s8   t jj|| j| j|jd}| }dddddd|gS )N)
collectiondefault_resolverbetaiamzlist-grantable-rolesz--quietz--flatten=namez--format=disable)r   REGISTRYParseGetValuer   r   SelfLink)r   parameter_inforesource_refresource_urir   r   r   GetListCommand*   s   
z IamRolesCompleter.GetListCommandc                    s,   |  |}| ||} fdd|pg D S )z;Bypasses the cache and returns completions matching prefix.c                    s"   g | ]}|d ur|  r|qS )N)
startswith).0itemprefixr   r   
<listcomp>7   s
    z.IamRolesCompleter.Complete.<locals>.<listcomp>)r   GetAllItems)r   r$   r   commanditemsr   r#   r   Complete3   s
   

zIamRolesCompleter.Complete)NN)__name__
__module____qualname____doc__r
   r   r)   __classcell__r   r   r   r   r      s
    
	r   c                       s   e Zd Z fddZ  ZS )IamServiceAccountCompleterc                    s   t t| jdddi| d S )Nlist_commandzBiam service-accounts list --quiet --flatten=email --format=disabler   )r	   r/   r
   )r   r   r   r   r   r
   ?   s
   
z#IamServiceAccountCompleter.__init__)r*   r+   r,   r
   r.   r   r   r   r   r/   =   s    r/   N)r-   
__future__r   r   r   googlecloudsdk.command_lib.utilr   googlecloudsdk.corer   ListCommandCompleterr   r/   r   r   r   r   <module>   s   #