
                          f   S 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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SKJr  SSKJr  SSKJr  SSKJr  \" \R:                  5      \R<                  /-   r " S S\ 5      r!\RD                   " S S\RF                  5      5       r$g)z$A command that prints access tokens.    )absolute_import)division)unicode_literals)credentials)
exceptions)util)arg_parsers)base)config)log)
properties)creds)store)clientc                       \ rS rSrSrS rSrg)FakeCredentials)   a  An access token container.

oauth2client and google-auth are both supported by gcloud as the auth library.
credentials in oauth2client store the access token in the "access_token"
filed. google-auth stores it in the "token" filed. We use this fake
credentials class to unify them.
c                     Xl         g )Ntoken)selfr   s     &lib/surface/auth/print_access_token.py__init__FakeCredentials.__init__2   s    J    r   N)__name__
__module____qualname____firstlineno____doc__r   __static_attributes__ r   r   r   r   )   s    r   r   c                       \ rS rSrSrSSS.r\S 5       r\R                  " \
R                  \R                  \R                  5      S 5       rSrg	)
AccessToken6   z0Print an access token for the specified account.at          {description}
        See [RFC6749](https://tools.ietf.org/html/rfc6749) for more
        information about access tokens.

        Note that token itself may not be enough to access some services.
        If you use the token with curl or similar tools, you may see
        permission errors similar to "API has not been used in
        project 32555940559 before or it is disabled.". If it happens, you may
        need to provide a quota project in the "X-Goog-User-Project" header.
        For example,

          $ curl -H "X-Goog-User-Project: your-project" -H "Authorization: Bearer $(gcloud auth print-access-token)" foo.googleapis.com

        The identity that granted the token must have the
        serviceusage.services.use permission on the provided project. See
        https://cloud.google.com/apis/docs/system-parameters for more
        information.
        z?        To print access tokens:

          $ {command}
        )DESCRIPTIONEXAMPLESc           	         U R                  SSSS9  U R                  S[        R                  " SS9SS	9  U R                  S
S[        R                  " SS9SSR	                  [
        5      S9  U R                  R                  S5        g )Naccount?z_Account to get the access token for. If not specified, the current active account will be used.)nargshelp
--lifetime43200s)upper_bounda  Access token lifetime. The default access token lifetime is 3600 seconds, but you can use this flag to reduce the lifetime or extend it up to 43200 seconds (12 hours). The org policy constraint `constraints/iam.allowServiceAccountCredentialLifetimeExtension` must be set if you want to extend the lifetime beyond 3600 seconds. Note that this flag is for service account impersonation only, so it must be used together with the `--impersonate-service-account` flag.)typer,   --scopesT   )
min_lengthSCOPEa  The scopes to authorize for. This flag is supported for user accounts and service accounts only. The list of possible scopes can be found at: https://developers.google.com/identity/protocols/googlescopes.

For end-user accounts the provided scopes must from [{0}])hiddenr0   metavarr,   zvalue(token))add_argumentr	   DurationArgListformat_TRUSTED_SCOPESdisplay_info	AddFormat)parsers    r   ArgsAccessToken.ArgsU   s    
7	   !!h74	     A.E FLVF   !!.1r   c                    [         R                  R                  R                  R	                  5       (       a0  [         R
                  " 5       (       a  [        R                  " S5        UR                  (       a(  UR                  (       d  [        R                  " SS5      eUR                  (       a  SOSn[        R                  " UR                  SSUS9nSnUR                  (       GaZ  Sn[         R"                  R%                  U5      nU[         R"                  R&                  [         R"                  R(                  4;  a/  [        R                  " SR+                  UR,                  5      5        UR                  [.        R0                  [.        R2                  /-   n[5        U[6        R8                  5      (       a  UR;                  U5      nOt[=        UR                  5      n[=        [>        5      nURA                  U5      (       d4  [        R                  " SS	R+                  [B        RD                  5      5      eXcl#        [         RH                  " U5      (       a$  UR                  (       a  SnUR                  Ul%        U(       a  [        RL                  " U5        [         RN                  " U5      (       a  URP                  n	OURR                  n	U	(       d  [T        RV                  " S
5      e[Y        U	5      $ )zRun the helper command.a)  Warning: This access token is for the gcloud CLI tool itself and is bound to its specific client ID, which requires mTLS. This means it can only be used with mTLS-enabled API endpoints.

If you need a token for your own application code or scripts, you should use Application Default Credentials (ADC). Obtain an ADC token by running:
  1.  gcloud auth application-default login (if you haven't already)
  2.  gcloud auth application-default print-access-token

ADC tokens are intended for local development and does not have the same mTLS restrictions.r-   z~Lifetime flag is for service account impersonation only. It must be used together with the --impersonate-service-account flag.TF)allow_account_impersonationuse_google_authcache_only_raptzQ`--scopes` flag may not work as expected and will be ignored for account type {}.r1   z@Invalid scopes value. Please make sure the scopes are from [{0}]z?No access token could be obtained from the current credentials.)-r   VALUEScontext_awareuse_client_certificateGetBoolIsInternalUserCheckr   warninglifetimeimpersonate_service_accountc_excInvalidArgumentExceptionscopesc_storeLoadr)   c_credsCredentialTypeGoogleAuthFromCredentialsUSER_ACCOUNTSERVICE_ACCOUNTr:   key	auth_utilOPENIDUSER_EMAIL_SCOPE
isinstancer   Scopedwith_scopessetr;   issubsetr   CLOUDSDK_SCOPES_scopes IsImpersonatedAccountCredentials	_lifetimeRefreshIsOauth2ClientCredentialsaccess_tokenr   auth_exceptionsInvalidCredentialsErrorr   )
r   argsrD   credshould_refresh_again	cred_typerO   requested_scopestrusted_scopesr   s
             r   RunAccessToken.Run   s:    	''>>FFHH**,,	kk;
 }}T==**
G  #kkduO<<$('	D !{{{!22BB4Hi	

*
*
7
7

*
*
:
: 

 	##)6)--#8	
 {{i..	0J0JKKf 
D+,,	-	-'t{{+_-((88..Pvf,,-  //55$--!}}dnood((..ejje33
K  5!!r   r"   N)r   r   r   r   r    detailed_helpstaticmethodr?   rM   RaiseErrorInsteadOfrg   AuthenticationErrorr   Errorgoogle_auth_exceptionsGoogleAuthErrorro   r!   r"   r   r   r$   r$   6   se    8&)-6 '2 '2R 	))ll,,
W"
W"r   r$   N)%r    
__future__r   r   r   google.authr   r   rv   googlecloudsdk.api_lib.authrg   r   rX   googlecloudsdk.callioper	   r
   rM   googlecloudsdk.corer   r   r   googlecloudsdk.core.credentialsr   rR   r   rP   oauth2clientr   listr`   GOOGLE_DRIVE_SCOPEr;   objectr   UniverseCompatibleCommandr$   r"   r   r   <module>r      s     + &  ' # < E 9 / ( 7 & # * < <  v--.)2N2N1OO
f 
 d"$,, d" d"r   