
                            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  e	j                  e	j                   j"                  e	j                   j$                         G d de	j&                               Zy)z)Command for listing service account keys.    )absolute_import)division)unicode_literalsN)util)base)iam_util)log)	resourcesc                   N    e Zd ZdZd ej
                  d      iZed        Zd Z	y)GetPublicKeyzGet the public key for a service account key pair.

  Get the public key for a service account key pair in pem or raw format.
  EXAMPLESa  
          To get the public key for some key ID for some service account
          (to validate a blob or JWT signature, for example), run:

            $ {command} keyid --output-file=key-file --iam-account=my-iam-account@my-project.iam.gserviceaccount.com
          c                 "   | j                  ddd       | j                  ddd       | j                  d	dt        j                         d
       | j                  dddgdd       | j                  j	                  t        j
                         y )NkeyzKEY-IDzThe key to get.)metavarhelpz--output-fileTz(The output file to write the public key.)requiredr   z--iam-accountz*A textual name to display for the account.)r   typer   z--typepemrawz"The type of the public key to get.)choicesdefaultr   )add_argumentr   GetIamAccountFormatValidatordisplay_info	AddFormatSERVICE_ACCOUNT_KEY_FORMAT)parsers    7lib/surface/iam/service_accounts/keys/get_public_key.pyArgszGetPublicKey.Args0   s    
x6GH
7  9
 2249	  ; 1	  3
 !!("E"EF    c                 J   t         j                  j                  |j                  d|j                  dd      }|j
                  }t        j                         \  }}|j                  j                  |j                  |j                         t        j                  |j                                    }t        j                   |j"                  |j$                  d       t        j&                  j)                  dj+                  ||j"                  |j                               y )	Nz!iam.projects.serviceAccounts.keys-)serviceAccountsId
projectsId)
collectionparams)namepublicKeyTypeT)contentbinaryz$written key [{0}] for [{2}] as [{1}])r
   REGISTRYParser   iam_accountkeysIdr   GetClientAndMessagesprojects_serviceAccounts_keysGet(IamProjectsServiceAccountsKeysGetRequestRelativeNamer   PublicKeyTypeFromStringr   r	   WriteToFileOrStdoutoutput_filepublicKeyDatastatusPrintformat)selfargskey_refr   clientmessagesresults          r   RunzGetPublicKey.RunF   s      &&6!%!1!1
 ' G ..C002FH115599%%'"::499E 	: 	GHF &"6"6tE JJ;BBTt//1 2r    N)
__name__
__module____qualname____doc__textwrapdedentdetailed_helpstaticmethodr   rA    r    r   r   r      sA     
(//  - G G*2r    r   )rE   
__future__r   r   r   rF   googlecloudsdk.api_lib.iamr   googlecloudsdk.callioper   googlecloudsdk.command_lib.iamr   googlecloudsdk.corer	   r
   ReleaseTracksReleaseTrackALPHABETACommandr   rJ   r    r   <module>rU      sl     0 &  '  + ( 3 # ) D%%++T->->-C-CD924<< 92 E92r    