
    (phQJ                     $   S 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S	K	J
r
  SS
KJr   " S S\R                  \R                  \R                  5      rSrSr " S S\R                  \R&                  \R(                  5      rg)zGoogle Compute Engine credentials.

This module provides authentication for an application running on Google
Compute Engine using the Compute Engine metadata server.

    N)_helpers)credentials)
exceptions)iam)jwt)metrics)	_metadata)_clientc                     ^  \ rS rSrSr     SU 4S jjrS rS rS r\	S 5       r
\	S 5       r\	S	 5       r\R                  " \R                   5      S
 5       r\R                  " \R$                  5      S 5       r\R                  " \R(                  5      SS j5       r\R                  " \R,                  5      S 5       rSrU =r$ )Credentials"   a  Compute Engine Credentials.

These credentials use the Google Compute Engine metadata server to obtain
OAuth 2.0 access tokens associated with the instance's service account,
and are also used for Cloud Run, Flex and App Engine (except for the Python
2.7 runtime, which is supported only on older versions of this library).

For more information about Compute Engine authentication, including how
to configure scopes, see the `Compute Engine authentication
documentation`_.

.. note:: On Compute Engine the metadata server ignores requested scopes.
    On Cloud Run, Flex and App Engine the server honours requested scopes.

.. _Compute Engine authentication documentation:
    https://cloud.google.com/compute/docs/authentication#using
c                    > [         [        U ]  5         Xl        X l        X0l        X@l        SU l        U(       a  XPl        SU l        gg)a  
Args:
    service_account_email (str): The service account email to use, or
        'default'. A Compute Engine instance may have multiple service
        accounts.
    quota_project_id (Optional[str]): The project ID used for quota and
        billing.
    scopes (Optional[Sequence[str]]): The list of scopes for the credentials.
    default_scopes (Optional[Sequence[str]]): Default scopes passed by a
        Google client library. Use 'scopes' for user-defined scopes.
    universe_domain (Optional[str]): The universe domain. If not
        provided or None, credential will attempt to fetch the value
        from metadata server. If metadata server doesn't have universe
        domain endpoint, then the default googleapis.com will be used.
FTN)	superr   __init___service_account_email_quota_project_id_scopes_default_scopes_universe_domain_cached_universe_domain)selfservice_account_emailquota_project_idscopesdefault_scopesuniverse_domain	__class__s         Y/var/www/html/venv/lib/python3.13/site-packages/google/auth/compute_engine/credentials.pyr   Credentials.__init__9   sG    . 	k4)+&;#!1-',$$3!+/D(     c                     [         R                  " XR                  S9nUS   U l        U R                  c  US   U l        gg)zRetrieve information about the service account.

Updates the scopes and retrieves the full service account email.

Args:
    request (google.auth.transport.Request): The object used to make
        HTTP requests.
)service_accountemailNr   )r	   get_service_account_infor   r   )r   requestinfos      r   _retrieve_infoCredentials._retrieve_infoZ   sG     11%@%@
 '+7m# <<>DL  r    c                 "    [         R                  $ N)r   CRED_TYPE_SA_MDSr   s    r   _metric_header_for_usage$Credentials._metric_header_for_usagem   s    '''r    c                 2   U R                   b  U R                   OU R                  n U R                  U5        [        R                  " XR
                  US9u  U l        U l        g! [        R                   a  n[        R                  " U5      nXCeSnAff = f)a*  Refresh the access token and scopes.

Args:
    request (google.auth.transport.Request): The object used to make
        HTTP requests.

Raises:
    google.auth.exceptions.RefreshError: If the Compute Engine metadata
        service can't be reached if if the instance has not
        credentials.
N)r"   r   )r   r   r'   r	   get_service_account_tokenr   tokenexpiryr   TransportErrorRefreshError)r   r%   r   
caught_excnew_excs        r   refreshCredentials.refreshp   s     "&!9t?S?S	*(&/&I&I)D)DV'#DJ (( 	* --j9G)	*s   =A% %B9BBc                     U R                   $ )zrThe service account email.

.. note:: This is not guaranteed to be set until :meth:`refresh` has been
    called.
r   r,   s    r   r   !Credentials.service_account_email   s     ***r    c                 $    U R                   (       + $ r*   )r   r,   s    r   requires_scopesCredentials.requires_scopes   s    <<r    c                     U R                   (       a  U R                  $ SSKJn  [        R
                  " UR                  5       5      U l        SU l         U R                  $ )Nr   )requestsT)r   r   google.auth.transportr@   r	   get_universe_domainRequest)r   google_auth_requestss     r   r   Credentials.universe_domain   sO    ''(((J ) = = ((*!
 (,$$$$r    c                 "    SSU R                   S.$ )Nzmetadata serverzVM credentials)credential_sourcecredential_type	principal)r   r,   s    r   get_cred_infoCredentials.get_cred_info   s     "3/33
 	
r    c                     U R                  U R                  UU R                  U R                  S9nU R                  Ul        U R
                  Ul        U$ )N)r   r   r   r   )r   r   r   r   r   r   )r   r   credss      r   with_quota_projectCredentials.with_quota_project   sT    "&"="=-<<//	  
 "&!6!6(,(D(D%r    c                     U R                  UUU R                  U R                  S9nU R                  Ul        U R                  Ul        U$ )N)r   r   r   r   )r   r   r   r   r   )r   r   r   rM   s       r   with_scopesCredentials.with_scopes   sR    
 )"&"="=!33	  
 "&!6!6(,(D(D%r    c                 x    U R                  U R                  U R                  U R                  U R                  US9$ )N)r   r   r   r   r   )r   r   r   r   r   )r   r   s     r   with_universe_domain Credentials.with_universe_domain   s=    ~~<<//"&"="=!33+  
 	
r    )r   r   r   r   r   r   r2   r1   )defaultNNNNr*   )__name__
__module____qualname____firstlineno____doc__r   r'   r-   r7   propertyr   r=   r   r   copy_docstringr   r   rJ   CredentialsWithQuotaProjectrN   ScopedrQ   CredentialsWithUniverseDomainrT   __static_attributes____classcell__r   s   @r   r   r   "   s    
( (0B*&(*, + +     
% 
% [445
 6
 [DDE	 F	 [//0 1 [FFG
 H
r    r   i  z*https://www.googleapis.com/oauth2/v4/tokenc                   P  ^  \ rS rSrSr      SU 4S jjrS r\R                  " \	R                  5      S 5       r\R                  " \	R                  5      S 5       rS rS rS	 r\\R                  " \	R$                  5      S
 5       5       rS r\S 5       r\S 5       rSrU =r$ )IDTokenCredentials   a  Open ID Connect ID Token-based service account credentials.

These credentials relies on the default service account of a GCE instance.

ID token can be requested from `GCE metadata server identity endpoint`_, IAM
token endpoint or other token endpoints you specify. If metadata server
identity endpoint is not used, the GCE instance must have been started with
a service account that has access to the IAM Cloud API.

.. _GCE metadata server identity endpoint:
    https://cloud.google.com/compute/docs/instances/verifying-instance-identity
c	                   > [         [        U ]  5         Xl        Xpl        X l        U(       aG  U(       d  U(       d  U(       d  U(       a  [        R                  " S5      eSU l        SU l	        SU l
        Uc!  [        R                  " U5      n	U	S   U l        OXPl        U(       dW  Uc(  [        R                  " U[!        5       U R                  S9nX`l
        U=(       d    ["        U l        Ub  X@l	        g0 U l	        gg)a|  
Args:
    request (google.auth.transport.Request): The object used to make
        HTTP requests.
    target_audience (str): The intended audience for these credentials,
        used when requesting the ID Token. The ID Token's ``aud`` claim
        will be set to this string.
    token_uri (str): The OAuth 2.0 Token URI.
    additional_claims (Mapping[str, str]): Any additional claims for
        the JWT assertion used in the authorization grant.
    service_account_email (str): Optional explicit service account to
        use to sign JWT tokens.
        By default, this is the default GCE service account.
    signer (google.auth.crypt.Signer): The signer used to sign JWTs.
        In case the signer is specified, the request argument will be
        ignored.
    use_metadata_identity_endpoint (bool): Whether to use GCE metadata
        identity endpoint. For backward compatibility the default value
        is False. If set to True, ``token_uri``, ``additional_claims``,
        ``service_account_email``, ``signer`` argument should not be set;
        otherwise ValueError will be raised.
    quota_project_id (Optional[str]): The project ID used for quota and
        billing.

Raises:
    ValueError:
        If ``use_metadata_identity_endpoint`` is set to True, and one of
        ``token_uri``, ``additional_claims``, ``service_account_email``,
         ``signer`` arguments is set.
zIf use_metadata_identity_endpoint is set, token_uri, additional_claims, service_account_email, signer arguments must not be setNr#   )r%   r   r   )r   re   r   r   _use_metadata_identity_endpoint_target_audiencer   MalformedError
_token_uri_additional_claims_signerr	   r$   r   r   Signerr   _DEFAULT_TOKEN_URI)r   r%   target_audience	token_uriadditional_claimsr   signeruse_metadata_identity_endpointr   sa_infor   s             r   r   IDTokenCredentials.__init__   s    R 	 $02!1/M, /)-1F& //' 
 #DO&*D#DL (88AG*1'*:D'*?'-~# +*.*E*E
 "L'=+=DO ,*;'*,' .r    c                    U R                   (       a  U R                  SUSU R                  S9$ U R                  SU R                  U R                  UU R
                  R                  5       U R                  SU R                  S9$ )a  Create a copy of these credentials with the specified target
audience.
Args:
    target_audience (str): The intended audience for these credentials,
    used when requesting the ID Token.
Returns:
    google.auth.service_account.IDTokenCredentials: A new credentials
        instance.
NTrp   rt   r   Fr   rq   rp   rr   rs   rt   r   )rh   r   r   r   rk   rl   copyrs   )r   rp   s     r   with_target_audience'IDTokenCredentials.with_target_audience3  s     //>> //3!%!7!7	 "   >>&*&A&A// /"&"9"9">">"@{{/4!%!7!7 " 	 	r    c                    U R                   (       a  U R                  S U R                  SUS9$ U R                  S U R                  U R                  U R                  U R
                  R                  5       U R                  SUS9$ )NTrx   Fry   )rh   r   ri   r   rk   rl   rz   rs   )r   r   s     r   rN   %IDTokenCredentials.with_quota_projectR  s    
 //>> $ 5 5/3!1	 "   >>&*&A&A// $ 5 5"&"9"9">">"@{{/4!1 " 	 	r    c                     U R                   (       a  [        R                  " S5      eU R                  S U R                  UU R
                  U R                  R                  5       U R                  SU R                  S9$ )NzCIf use_metadata_identity_endpoint is set, token_uri must not be setFry   )
rh   r   rj   r   r   ri   rl   rz   rs   r   )r   rq   s     r   with_token_uri!IDTokenCredentials.with_token_urij  sx    
 //++X  >>&*&A&A# $ 5 5"&"9"9">">"@{{/4!%!6!6 " 	 	r    c                 |   [         R                  " 5       n[        R                  " [        S9nX-   n[         R
                  " U5      [         R
                  " U5      U R                  U R                  U R                  S.nUR                  U R                  5        [        R                  " U R                  U5      nU$ )zCreate the OAuth 2.0 assertion.
This assertion is used during the OAuth 2.0 grant to acquire an
ID token.
Returns:
    bytes: The authorization grant assertion.
)seconds)iatexpissaudrp   )r   utcnowdatetime	timedelta_DEFAULT_TOKEN_LIFETIME_SECSdatetime_to_secsr   rk   ri   updaterl   r   encoderm   )r   nowlifetimer2   payloadr1   s         r   #_make_authorization_grant_assertion6IDTokenCredentials._make_authorization_grant_assertion  s     oo%%.JK ,,S1,,V4--??  $44

 	t../

4<<1r    c                 ~    SnU R                   SS.n[        R                  [        R                  " 5       0n[        R
                  " XX4S9n[        R                  " U5      u  p  nU[        R                  R                  U	S   5      4$ ! [        R                   a  n[        R                  " U5      nXveSnAff = f)a  Request ID token from metadata identity endpoint.

Args:
    request (google.auth.transport.Request): The object used to make
        HTTP requests.

Returns:
    Tuple[str, datetime.datetime]: The ID token and the expiry of the ID token.

Raises:
    google.auth.exceptions.RefreshError: If the Compute Engine metadata
        service can't be reached or if the instance has no credentials.
    ValueError: If extracting expiry from the obtained ID token fails.
z*instance/service-accounts/default/identityfull)audienceformat)paramsheadersNr   )ri   r   API_CLIENT_HEADERtoken_request_id_token_mdsr	   getr   r3   r4   r   _unverified_decoder   utcfromtimestamp)
r   r%   pathr   metrics_headerid_tokenr5   r6   _r   s
             r    _call_metadata_identity_endpoint3IDTokenCredentials._call_metadata_identity_endpoint  s    	*?D"&"7"76JF))7+M+M+ON !}}fH 11(;Aq**;;GENKKK (( 	* --j9G)	*s   AB B<B77B<c                     U R                   (       a  U R                  U5      u  U l        U l        gU R	                  5       n[
        R                  " XR                  U5      u  p4nX0l        X@l        g)a'  Refreshes the ID token.

Args:
    request (google.auth.transport.Request): The object used to make
        HTTP requests.

Raises:
    google.auth.exceptions.RefreshError: If the credentials could
        not be refreshed.
    ValueError: If extracting expiry from the obtained ID token fails.
N)rh   r   r1   r2   r   r
   id_token_jwt_grantrk   )r   r%   	assertionaccess_tokenr2   r   s         r   r7   IDTokenCredentials.refresh  s^     //&*&K&KG&T#DJ@@BI&-&@&@)'#L! &J Kr    c                     U R                   $ r*   )rm   r,   s    r   rs   IDTokenCredentials.signer  s     ||r    c                     U R                   (       a  [        R                  " S5      eU R                  R	                  U5      $ )zSigns the given message.

Args:
    message (bytes): The message to sign.

Returns:
    bytes: The message's cryptographic signature.

Raises:
    ValueError:
        Signer is not available if metadata identity endpoint is used.
z=Signer is not available if metadata identity endpoint is used)rh   r   InvalidOperationrm   sign)r   messages     r   
sign_bytesIDTokenCredentials.sign_bytes  s:     //--O  ||  ))r    c                     U R                   $ )zThe service account email.r:   r,   s    r   r   (IDTokenCredentials.service_account_email  s     ***r    c                     U R                   $ r*   r:   r,   s    r   signer_emailIDTokenCredentials.signer_email  s    ***r    )	rl   r   r   rm   ri   rk   rh   r2   r1   )NNNNFN)rW   rX   rY   rZ   r[   r   r{   r   r]   r   r^   rN   CredentialsWithTokenUrir   r   r   r7   r\   Signingrs   r   r   r   ra   rb   rc   s   @r   re   re      s    
" "',M-^> [DDE F. [@@A B(:L>!, [001 2 *& + + + +r    re   )r[   r   google.authr   r   r   r   r   r   google.auth.compute_enginer	   google.oauth2r
   r_   r^   r`   r   r   ro   r   r   re    r    r   <module>r      s       # "    0 !i
++--i
X  $ A ^+++''^+r    