
    Q                         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  G d
 de	j                        Zy)z'Command to create service account keys.    )absolute_import)division)unicode_literalsN)util)base)iam_util)logc                   p    e Zd ZdZ ej
                  d       ej
                  d      dZed        Zd Z	y)Createz~Create a service account key.

  If the service account does not exist, this command returns a
  `PERMISSION_DENIED` error.
  z
          The option --key-file-type=p12 is available here only for legacy
          reasons; all new use cases are encouraged to use the default 'json'
          format.
          z
          To create a new service account key and save the private
          portion of the key locally, run:

            $ {command} key.json --iam-account=my-iam-account@my-project.iam.gserviceaccount.com
          )NOTESEXAMPLESc                     | j                  dddgdd       | j                  ddt        j                         d	       | j                  d
dt        j                         d       y )Nz--key-file-typejsonp12zThe type of key to create.)choicesdefaulthelpz--iam-accountTz                        The service account for which to create a key.

                        To list all service accounts in the project, run:

                          $ gcloud iam service-accounts list
                        )requiredtyper   outputzOUTPUT-FILEzThe path where the resulting private key should be written. File system write permission will be checked on the specified path prior to the key creation.)metavarr   r   )add_argumentr   GetIamAccountFormatValidatorGetIamOutputFileValidator)parsers    /lib/surface/iam/service_accounts/keys/create.pyArgszCreate.Args3   s{    
)!' &9  ;
 !%%BBD  	  -%??A$  %    c                    t        j                         \  }}|j                  j                  |j	                  t        j                  |j                        |j                  t        j                  t        j                  |j                                                }t        j                  |j                  |j                  dd       t        j                   j#                  dj%                  t        j&                  |j(                        t        j*                  |j,                        |j                  |j                               y )N)privateKeyType)namecreateServiceAccountKeyRequestT)contentbinaryprivatez2created key [{0}] of type [{1}] as [{2}] for [{3}])r   GetClientAndMessagesprojects_serviceAccounts_keysr   +IamProjectsServiceAccountsKeysCreateRequestr   EmailToAccountResourceNameiam_accountCreateServiceAccountKeyRequestKeyTypeToCreateKeyTypeKeyTypeFromStringkey_file_typer	   WriteToFileOrStdoutr   privateKeyDatastatusPrintformatGetKeyIdFromResourceNamer!   KeyTypeToStringr    )selfargsclientmessagesresults        r   Runz
Create.RunM   s   002FH1188<<44T5E5EF33'>>..t/A/AB D 4 E 	= 	FGF V224OJJ<CC--fkk:$$V%:%:;KK		r   N)
__name__
__module____qualname____doc__textwrapdedentdetailed_helpstaticmethodr   r;    r   r   r   r      sQ     x   
 "(// # - % %2r   r   )r?   
__future__r   r   r   r@   googlecloudsdk.api_lib.iamr   googlecloudsdk.callioper   googlecloudsdk.command_lib.iamr   googlecloudsdk.corer	   Commandr   rD   r   r   <module>rK      s4     . &  '  + ( 3 #AT\\ Ar   