a
    !f7                     @   s\   d Z ddlZddlZddlmZ ddlmZ ddlmZ e	e
ZdZG dd dejZdS )	zoUtilities for Google Compute Engine

Utilities for making it easier to use OAuth 2.0 on Google Compute Engine.
    N)http_client)client)	_metadatazYou have requested explicit scopes to be used with a GCE service account.
Using this argument will have no effect on the actual scopes for tokens
requested. These scopes are set at VM instance creation time and
can't be overridden in the request.
c                       sj   e Zd ZdZd fdd	Zedd Zdd Zd	d
 Zdd Z	dd Z
edd Zdd Zdd Z  ZS )AppAssertionCredentialsa  Credentials object for Compute Engine Assertion Grants

    This object will allow a Compute Engine instance to identify itself to
    Google and other OAuth 2.0 servers that can verify assertions. It can be
    used for the purpose of accessing data stored under an account assigned to
    the Compute Engine instance itself.

    This credential does not require a flow to instantiate because it
    represents a two legged flow, and therefore has all of the required
    information to generate and refresh its own access tokens.

    Note that :attr:`service_account_email` and :attr:`scopes`
    will both return None until the credentials have been refreshed.
    To check whether credentials have previously been refreshed use
    :attr:`invalid`.
    Nc                    sN   d|v rt t d|d< tt| jdg|R i | || _d| _d| _dS )aY  Constructor for AppAssertionCredentials

        Args:
            email: an email that specifies the service account to use.
                   Only necessary if using custom service accounts
                   (see https://cloud.google.com/compute/docs/access/create-enable-service-accounts-for-instances#createdefaultserviceaccount).
        scopesNT)	warningswarn_SCOPES_WARNINGsuperr   __init__service_account_emailr   invalid)selfemailargskwargs	__class__ Y/var/www/html/python-backend/venv/lib/python3.9/site-packages/oauth2client/contrib/gce.pyr   9   s    
z AppAssertionCredentials.__init__c                 C   s   t dd S Nz6Cannot serialize credentials for GCE service accounts.NotImplementedError)clsZ	json_datar   r   r   	from_jsonM   s    z!AppAssertionCredentials.from_jsonc                 C   s   t dd S r   r   r   r   r   r   to_jsonR   s    zAppAssertionCredentials.to_jsonc                 C   s   |  | | jS )a  Retrieves the canonical list of scopes for this access token.

        Overrides client.Credentials.retrieve_scopes. Fetches scopes info
        from the metadata server.

        Args:
            http: httplib2.Http, an http object to be used to make the refresh
                  request.

        Returns:
            A set of strings containing the canonical list of scopes.
        )_retrieve_infor   )r   httpr   r   r   retrieve_scopesV   s    
z'AppAssertionCredentials.retrieve_scopesc                 C   s8   | j r4tj|| jpdd}d| _ |d | _|d | _dS )zRetrieves service account info for invalid credentials.

        Args:
            http: an object to be used to make HTTP requests.
        defaultZservice_accountFr   r   N)r   r   Zget_service_account_infor   r   )r   r   infor   r   r   r   f   s    
z&AppAssertionCredentials._retrieve_infoc              
   C   s`   z&|  | tj|| jd\| _| _W n4 tjyZ } zt	t
|W Y d}~n
d}~0 0 dS )a  Refreshes the access token.

        Skip all the storage hoops and just refresh using the API.

        Args:
            http: an object to be used to make HTTP requests.

        Raises:
            HttpAccessTokenRefreshError: When the refresh fails.
        r!   N)r   r   	get_tokenr   Zaccess_tokenZtoken_expiryr   HTTPExceptionr   ZHttpAccessTokenRefreshErrorstr)r   r   errr   r   r   _refresht   s    
z AppAssertionCredentials._refreshc                 C   s   t dd S r   r   r   r   r   r   serialization_data   s    z*AppAssertionCredentials.serialization_datac                 C   s   dS )NFr   r   r   r   r   create_scoped_required   s    z.AppAssertionCredentials.create_scoped_requiredc                 C   s   t ddS )au  Cryptographically sign a blob (of bytes).

        This method is provided to support a common interface, but
        the actual key used for a Google Compute Engine service account
        is not available, so it can't be used to sign content.

        Args:
            blob: bytes, Message to be signed.

        Raises:
            NotImplementedError, always.
        z1Compute Engine service accounts cannot sign blobsNr   )r   Zblobr   r   r   	sign_blob   s    z!AppAssertionCredentials.sign_blob)N)__name__
__module____qualname____doc__r   classmethodr   r   r   r   r'   propertyr(   r)   r*   __classcell__r   r   r   r   r   '   s   

r   )r.   loggingr   Z	six.movesr   Zoauth2clientr   Zoauth2client.contribr   	getLoggerr+   loggerr	   ZAssertionCredentialsr   r   r   r   r   <module>   s   
