
    &g                         d Z ddl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 n# e	$ r dZY nw xY w G d d	ej
                  Z
d
 Z G d dej        ej        ej                  ZdS )a  Google App Engine standard environment support.

This module provides authentication and signing for applications running on App
Engine in the standard environment using the `App Identity API`_.


.. _App Identity API:
    https://cloud.google.com/appengine/docs/python/appidentity/
    N)_helpers)credentials)crypt)
exceptions)app_identityc                   d    e Zd ZdZed             Z ej        ej	                  d             Z
dS )SignerzSigns messages using the App Engine App Identity service.

    This can be used in place of :class:`google.auth.crypt.Signer` when
    running in the App Engine standard environment.
    c                     dS )zOptional[str]: The key ID used to identify this private key.

        .. warning::
           This is always ``None``. The key ID used by App Engine can not
           be reliably determined ahead of time.
        N selfs    H/var/www/api/venv/lib/python3.11/site-packages/google/auth/app_engine.pykey_idzSigner.key_id/   s	     t    c                 \    t          j        |          }t          j        |          \  }}|S N)r   to_bytesr   	sign_blob)r   message_	signatures       r   signzSigner.sign9   s,    #G,,#-g669r   N)__name__
__module____qualname____doc__propertyr   r   copy_docstringr   r	   r   r   r   r   r	   r	   (   sd            X XU\**  +*  r   r	   c                  ^    t           t          j        d          t          j                    S )zGets the project ID for the current App Engine application.

    Returns:
        str: The project ID

    Raises:
        google.auth.exceptions.OSError: If the App Engine APIs are unavailable.
    N&The App Engine APIs are not available.)r   r   OSErrorget_application_idr   r   r   get_project_idr#   @   s+      !IJJJ*,,,r   c                       e Zd ZdZ	 	 	 	 d fd	Z ej        ej                  d             Z	e
d             Ze
d             Z ej        ej                  dd            Z ej        ej                  d             Z ej        ej                  d	             Ze
 ej        ej                  d
                         Ze
 ej        ej                  d                         Z xZS )CredentialszApp Engine standard environment credentials.

    These credentials use the App Engine App Identity API to obtain access
    tokens.
    Nc                     t           t          j        d          t          t          |                                            || _        || _        || _        t                      | _
        || _        dS )a  
        Args:
            scopes (Sequence[str]): Scopes to request from the App Identity
                API.
            default_scopes (Sequence[str]): Default scopes passed by a
                Google client library. Use 'scopes' for user-defined scopes.
            service_account_id (str): The service account ID passed into
                :func:`google.appengine.api.app_identity.get_access_token`.
                If not specified, the default application service account
                ID will be used.
            quota_project_id (Optional[str]): The project ID used for quota
                and billing.

        Raises:
            google.auth.exceptions.OSError: If the App Engine APIs are unavailable.
        Nr    )r   r   r!   superr%   __init___scopes_default_scopes_service_account_idr	   _signer_quota_project_id)r   scopesdefault_scopesservice_account_idquota_project_id	__class__s        r   r(   zCredentials.__init__Z   si    4 $%MNNNk4  ))+++-#5 xx!1r   c                     | j         | j         n| j        }t          j        || j                  \  }}t
          j                            |          }||c| _        | _        d S r   )	r)   r*   r   get_access_tokenr+   datetimeutcfromtimestamptokenexpiry)r   requestr.   r7   ttlr8   s         r   refreshzCredentials.refresh~   sZ    !%!9t?S!264;STT
s"33C88"'
DKKKr   c                 N    | j         t          j                    | _         | j         S )zThe service account email.)r+   r   get_service_account_namer   s    r   service_account_emailz!Credentials.service_account_email   s'     #+'3'L'N'ND$''r   c                 "    | j          o| j         S )zChecks if the credentials requires scopes.

        Returns:
            bool: True if there are no scopes set otherwise False.
        )r)   r*   r   s    r   requires_scopeszCredentials.requires_scopes   s     <<(<$<<r   c                 H    |                      ||| j        | j                  S )N)r.   r/   r0   r1   )r2   r+   r1   )r   r.   r/   s      r   with_scopeszCredentials.with_scopes   s/    ~~)#7!2	  
 
 	
r   c                 F    |                      | j        | j        |          S )N)r.   r0   r1   )r2   r)   r+   )r   r1   s     r   with_quota_projectzCredentials.with_quota_project   s+    ~~<#7-  
 
 	
r   c                 6    | j                             |          S r   )r,   r   )r   r   s     r   
sign_byteszCredentials.sign_bytes   s    |  )))r   c                     | j         S r   )r>   r   s    r   signer_emailzCredentials.signer_email   s     ))r   c                     | j         S r   )r,   r   s    r   signerzCredentials.signer   s     |r   )NNNNr   )r   r   r   r   r(   r   r   r   r%   r;   r   r>   r@   ScopedrB   CredentialsWithQuotaProjectrD   SigningrF   rH   rJ   __classcell__)r2   s   @r   r%   r%   Q   s         "2 "2 "2 "2 "2 "2H X[4550 0 650 ( ( X( = = X= X[/00
 
 
 10
 X[DEE
 
 FE
 X[011* * 21* X[011* * 21 X* X[011  21 X    r   r%   )r   r5   google.authr   r   r   r   google.appengine.apir   ImportErrorr	   r#   rK   rM   rL   r%   r   r   r   <module>rR      s'                 # # # # # #       " " " " " "1111111   LLL
    U\   0- - -"c c c c c+[-Tc c c c cs   ' 11