o
    <^öhé  ã                   @   sœ   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 zddlmZ W n e	y1   dZY nw G dd	„ d	ej
ƒZ
d
d„ ZG d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                   @   s0   e Zd ZdZedd„ ƒZe ej	¡dd„ ƒZ
dS )ÚSignerz»Signs 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                 C   s   dS )zÖOptional[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© ©Úselfr   r   úV/home/air/websocket/korean/venv/lib/python3.10/site-packages/google/auth/app_engine.pyÚkey_id/   s   zSigner.key_idc                 C   s   t  |¡}t |¡\}}|S ©N)r   Úto_bytesr   Ú	sign_blob)r
   ÚmessageÚ_Ú	signaturer   r   r   Úsign9   s   
zSigner.signN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr   r   Úcopy_docstringr   r   r   r   r   r   r   r   (   s    

	r   c                   C   s   t du r	t d¡‚t  ¡ S )zÇGets 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   r   Úget_project_id@   s   
r   c                       sÄ   e Zd ZdZ				d‡ fdd„	Ze ej¡dd„ ƒZ	e
dd„ ƒZe
d	d
„ ƒZe ej¡ddd„ƒZe ej¡dd„ ƒZe ej¡dd„ ƒZe
e ej¡dd„ ƒƒZe
e ej¡dd„ ƒƒZ‡  ZS )ÚCredentialsz‰App Engine standard environment credentials.

    These credentials use the App Engine App Identity API to obtain access
    tokens.
    Nc                    sD   t du r	t 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__r   r   r    Z   s   

zCredentials.__init__c                 C   sF   | j d ur| j n| j}t || j¡\}}tj |¡}||| _| _d S r   )	r!   r"   r   Úget_access_tokenr#   ÚdatetimeÚutcfromtimestampÚtokenÚexpiry)r
   Úrequestr&   r/   Úttlr0   r   r   r   Úrefresh~   s   zCredentials.refreshc                 C   s   | j du r
t ¡ | _ | j S )zThe service account email.N)r#   r   Úget_service_account_namer	   r   r   r   Úservice_account_email‡   s   

z!Credentials.service_account_emailc                 C   s   | j  o| j S )zˆChecks if the credentials requires scopes.

        Returns:
            bool: True if there are no scopes set otherwise False.
        )r!   r"   r	   r   r   r   Úrequires_scopesŽ   s   zCredentials.requires_scopesc                 C   s   | j ||| j| jdS )N)r&   r'   r(   r)   )r+   r#   r)   )r
   r&   r'   r   r   r   Úwith_scopes—   s   üzCredentials.with_scopesc                 C   s   | j | j| j|dS )N)r&   r(   r)   )r+   r!   r#   )r
   r)   r   r   r   Úwith_quota_project    s
   ýzCredentials.with_quota_projectc                 C   s   | j  |¡S r   )r$   r   )r
   r   r   r   r   Ú
sign_bytes¨   s   zCredentials.sign_bytesc                 C   ó   | j S r   )r5   r	   r   r   r   Úsigner_email¬   ó   zCredentials.signer_emailc                 C   r:   r   )r$   r	   r   r   r   Úsigner±   r<   zCredentials.signer)NNNNr   )r   r   r   r   r    r   r   r   r   r3   r   r5   r6   ÚScopedr7   ÚCredentialsWithQuotaProjectr8   ÚSigningr9   r;   r=   Ú__classcell__r   r   r*   r   r   Q   s2    û
$









r   )r   r-   Úgoogle.authr   r   r   r   Úgoogle.appengine.apir   ÚImportErrorr   r   r>   r@   r?   r   r   r   r   r   Ú<module>   s    
ÿ
ÿ