
                             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 ddlm	Z	 ddl
mZ ddl
mZ dd	lmZ d
 Z G d dej                         Zy)z"Create a new external account key.    )absolute_import)division)unicode_literals)base)
exceptions)log)
properties)filesc                     	 t        j                  ||        y # t         j                  t        t        f$ r% t        j                  dj                  |            w xY w)Nz-Could not write external account key to '{}'.)r
   WriteFileContentsErrorOSErrorIOErrorr   BadFileExceptionformat)external_account_keykey_output_files     4lib/surface/publicca/external_account_keys/create.py_ExportExternalAccountKeyr      sX    Q	O-AB
++w	( Q

%
%7>>OQ QQs
    AAc                   &    e Zd ZdZed        Zd Zy)CreatezCreate a new external account key.

  ## EXAMPLES

  To create an external account key:

      $ {command}

  To create an external account key and save it to a file:

      $ {command} --key-output-file=./external_account_key.txt
  c                 *    | j                  dd       y )Nz--key-output-filez=The path where the generated external account key is written.)help)add_argument)parsers    r   ArgszCreate.Args3   s    
L  N    c                 n   t        j                  | j                               }t        j                  |      | _        t        j
                  |      | _        t        j                  j                  j                  j                  d      }| j                  j                  dj                  |            }| j                  j                  j                  |      }dj                  |j                   j#                  dd      |j$                        }d	}|j'                  d
      r5|dj                  |j(                        z  }t+        ||j(                         n|dj                  |      z  }t,        j.                  j1                  |       |j                   j#                  dd      |j$                  dS )NT)requiredzprojects/{}/locations/global)parentzb64MacKey: {key}
keyId: {id}zutf-8backslashreplace)keyidzCreated an external account keyr   z and saved it to [{}]z
[{}]
)	b64MacKeykeyId)publicca_base
GetVersionReleaseTrackGetClientInstanceclientGetMessagesModulemessagesr	   VALUEScoreprojectGet9PubliccaProjectsLocationsExternalAccountKeysCreateRequestr   &projects_locations_externalAccountKeysr   r$   decoder%   IsSpecifiedr   r   r   statusPrint)selfargsapi_versionr/   requestr   
key_and_idstatus_messages           r   Runz
Create.Run9   sv   **4+<+<+>?K11+>DK!33K@DM$$,,00$0?GmmUU-44W= V ?G  ;;MMTT188 **11';MN%% 9 'J 7N)*/66t7K7KLLn
D,@,@A
))*55nJJ^$ !**11';MN &&	 r   N)__name__
__module____qualname____doc__staticmethodr   r=    r   r   r   r   %   s"     N N
r   r   N)rA   
__future__r   r   r   googlecloudsdk.api_lib.publiccar   r&   googlecloudsdk.callioper   googlecloudsdk.corer   r	   googlecloudsdk.core.utilr
   r   CreateCommandr   rC   r   r   <module>rJ      s=    ) &  ' A ( . # * *Q-T -r   