
                            S r SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSKJr  SSK	J
r  SS	K	Jr  SS
KJr  SSKJr  Sr " S S\R$                  5      r " S S\5      r " S S\5      r " S S\5      rS rS rS rS rSS jrg)z#Manages logic for service accounts.    )absolute_import)division)unicode_literalsN)config)
exceptions)creds)p12_service_account)filesservice_accountr   c                       \ rS rSrSrSrg)Error"   zErrors raised by this module. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       2lib/googlecloudsdk/api_lib/auth/service_account.pyr   r   "   s    %r   r   c                       \ rS rSrSrSrg)UnsupportedCredentialsType&   z5Raised when given type credentials cannot be created.r   Nr   r   r   r   r   r   &   s    =r   r   c                       \ rS rSrSrSrg)BadCredentialFileException*    Raised when file cannot be read.r   Nr   r   r   r   r   r   *       (r   r   c                       \ rS rSrSrSrg)BadCredentialJsonFileException.   r    r   Nr   r   r   r   r#   r#   .   r!   r   r#   c                 D    U =(       d    0 R                  S5      [        :H  $ )zFReturns whether a JSON content corresponds to an service account cred.type)get_SERVICE_ACCOUNT_TYPE)content_jsons    r   IsServiceAccountConfigr*   2   s    

"	!	!&	)-B	BBr   c                     [         R                  " U 5      n [        R                  " U5      n[	        U5      $ ! [
         a  n[        SR                  X5      5      eSnAff = f)z6Load credentials from given service account json file.z!Could not read json file {0}: {1}N)r
   ReadFileContentsjsonloadsCredentialsFromAdcDict
ValueErrorr   format)filenamecontentjson_keyes       r   CredentialsFromAdcFiler6   7   s^    ""8,'zz'"H!(++	 
$%H%O%O&  s    9 
A"AA"c                     SU ;  a  [        S5      e[        R                  " U 5      U S'   [        R                  R                  U [        R                  S9n[        R                  =Ul	        Ul
        U$ )zDCreates oauth2client creds from a dict of application default creds.client_email,The .json key file is not in a valid format.	token_uriscopes)r#   c_credsGetEffectiveTokenUriFromCredsr   ServiceAccountCredentialsfrom_json_keyfile_dictr   CLOUDSDK_SCOPESCLOUDSDK_USER_AGENT
user_agent_user_agent)r4   r   s     r   r/   r/   B   su    8#
(68 8 "??I(;

3
3
J
Jv-- K /%
 *0)C)CC%U&	,r   c                 @   SSK Jn  SU ;  a  [        S5      e[        R                  " U 5      U S'   UR
                  R                  nU" U [        R                  S9nU R                  S5      Ul
        U R                  S5      Ul        U R                  S	5      Ul        U$ )
zCCreates google-auth creds from a dict of application default creds.r   r   r8   r9   r:   r;   private_keyprivate_key_id	client_id)google.oauth2r   r#   r=   r>   Credentialsfrom_service_account_infor   rA   r'   rF   rG   rH   )r4   google_auth_service_accountservice_account_credentialsr   s       r    CredentialsFromAdcDictGoogleAuthrN   S   s    
 K 8#
(68 8 "??I(; "--GG 
%hv7M7M
N% ll=1%!&67%LL-%/	,r   c                 v    [         R                  " U UU[        R                  " 0 5      [        R
                  S9$ )zGCreates credentials object from given p12 private key and account name.)service_account_emailr:   r<   )r	   CreateP12ServiceAccountr=   r>   r   rA   )rF   accountpasswords      r   CredentialsFromP12KeyrT   r   s7     
	4	4#55b9##
 r   )N)r   
__future__r   r   r   r-   googlecloudsdk.corer   r   googlecloudsdk.core.credentialsr   r=   r	   googlecloudsdk.core.utilr
   oauth2clientr   r(   r   r   r   r#   r*   r6   r/   rN   rT   r   r   r   <module>rZ      s~    * &  '  & * < ? * () &J &> >) ))U )C
">	r   