
                             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d
lmZ ddlmZ ddlmZ d Ze	j0                   G d de	j2                               Zy)z&A command that prints identity token.
    )absolute_import)division)unicode_literals)
exceptions)base)	auth_util)flags)config_helper)config)store)clientc                 x   | j                  d      }t        j                  | j                  |d      }t	        j
                  |      }| j                  r?t	        j                  |      st        j                  d      | j                  t        _        | j                  d      s| j                  d      r*t	        j                  |      st        j                  d      | j                  dk(  r!| j                  rt        j                  d	      | j                  d
      r*t	        j
                  |      st        j                  d      t        j                   ||| j"                  | j                  | j                  d       t%        j&                  |      }|j(                  st        j*                  d      |S )%Run the print_identity_token command.impersonate_service_accountT)allow_account_impersonationuse_google_authzGInvalid account type for `--audiences`. Requires valid service account.token_formatinclude_licensezgInvalid account type for `--token-format` or `--include-license`. Requires a valid GCE service account.standardzE`--include-license` can only be specified when `--token-format=full`.include_emailzTInvalid account type for `--include-email`. Requires an impersonate service account.)is_impersonated_credentialr   gce_token_formatgce_include_license refresh_user_account_credentialsz?No identity token can be obtained from the current credentials.)IsSpecifiedc_storeLoadaccountr   IsImpersonationCredential	audiencesValidIdTokenCredentialauth_exceptionsWrongAccountTypeErrorr   CLOUDSDK_CLIENT_IDIsGceAccountCredentialsr   r   GCEIdentityTokenError_RefreshGoogleAuthIdTokenr   r
   
Credentialid_tokenInvalidIdentityTokenError)argsdo_impersonationcredis_impersonated_account
credentials        (lib/surface/auth/print_identity_token.py_Runr1   "   s   %%&CD	
ll"2
$ &??E	^^++D111,- - !%F	n%)9)9:K)L,,T21123 3 
*$11#$ $ 
o&..t41156 6 
##
!8&&((..'+ ''-*			

3
3IK K	    c                       e Zd ZdZdddZed        Z ej                  e	j                  ej                        d        Zy)IdentityTokenz2Print an identity token for the specified account.z        {description}
        a          To print identity tokens:

          $ {command}

        To print identity token for account 'foo@example.com' whose audience
        is 'https://service-hash-uc.a.run.app', run:

          $ {command} foo@example.com --audiences="https://service-hash-uc.a.run.app"

        To print identity token for an impersonated service account 'my-account@example.iam.gserviceaccount.com'
        whose audience is 'https://service-hash-uc.a.run.app', run:

          $ {command} --impersonate-service-account="my-account@example.iam.gserviceaccount.com" --audiences="https://service-hash-uc.a.run.app"

        To print identity token of a Compute Engine instance, which includes
        project and instance details as well as license codes for images
        associated with the instance, run:

          $ {command} --token-format=full --include-license

        To print identity token for an impersonated service account
        'my-account@example.iam.gserviceaccount.com', which includes the email
        address of the service account, run:

          $ {command} --impersonate-service-account="my-account@example.iam.gserviceaccount.com" --include-email
        )DESCRIPTIONEXAMPLESc                     t        j                  |        t        j                  |        t        j                  |        t        j                  |        | j
                  j                  d       y )Nzvalue(id_token))r	   AddAccountArgAddAudienceArgAddGCESpecificArgsAddIncludeEmailArgdisplay_info	AddFormat)parsers    r0   ArgszIdentityToken.Argsz   sO    		 	V$	V$
!!"34r2   c                     t        |      }|S )r   )r1   )selfr+   r/   s      r0   RunzIdentityToken.Run   s     dJr2   N)__name__
__module____qualname____doc__detailed_helpstaticmethodr?   c_excRaiseErrorInsteadOfr"   AuthenticationErrorr   ErrorrB    r2   r0   r4   r4   T   sY    :!-F 5 5 5_@@&,,O Pr2   r4   N)rF   
__future__r   r   r   googlecloudsdk.api_lib.authr   r"   googlecloudsdk.callioper   rI   googlecloudsdk.command_lib.authr   r	   !googlecloudsdk.command_lib.configr
   googlecloudsdk.corer   googlecloudsdk.core.credentialsr   r   oauth2clientr   r1   UniverseCompatibleCommandr4   rM   r2   r0   <module>rX      s[     '  ' E ( 7 5 1 ; & < /d 1DLL 1 1r2   