Ë
    €Ï¦  ã                   óŽ   — d Z ddlZddlZddlZddlmZ ddlmZ dZ ej                  e
«      ZdZ G d„ dej                  «      Zy)	zoUtilities for Google Compute Engine

Utilities for making it easier to use OAuth 2.0 on Google Compute Engine.
é    N)Úclient)Ú	_metadataz$jcgregorio@google.com (Joe Gregorio)z÷You 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                   óh   ‡ — e Zd ZdZdˆ fd„	Zed„ «       Zd„ Zd„ Zd„ Z	d„ Z
ed„ «       Zd	„ Zd
„ Zˆ x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`.
    c                 ó¢   •— d|v rt        j                  t        «       d|d<   t        t        |   dg|¢­i |¤Ž || _        d| _        d| _        y)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__s       €ú+lib/third_party/oauth2client/contrib/gce.pyr   z AppAssertionCredentials.__init__;   sU   ø€ ð vÑÜM‰Mœ/Ô*Ø#ˆF8Ñô 	Ô% tÑ5°dÐL¸TÒLÀVÒLà%*ˆÔ"ØˆŒØˆó    c                 ó   — t        d«      ‚©Nz6Cannot serialize credentials for GCE service accounts.©ÚNotImplementedError)ÚclsÚ	json_datas     r   Ú	from_jsonz!AppAssertionCredentials.from_jsonO   ó   € ä!ØDóFð 	Fr   c                 ó   — t        d«      ‚r   r   ©r   s    r   Úto_jsonzAppAssertionCredentials.to_jsonT   s   € Ü!ØDóFð 	Fr   c                 óP   — | j                  |j                  «       | 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_infoÚrequestr   )r   Úhttps     r   Úretrieve_scopesz'AppAssertionCredentials.retrieve_scopesX   s    € ð 	×Ñ˜DŸL™LÔ)Ø{‰{Ðr   c                 óž   — | j                   rAt        j                  || j                  xs d¬«      }d| _         |d   | _        |d   | _        yy)a-  Validates invalid service accounts by retrieving service account info.

        Args:
            http_request: callable, a callable that matches the method
                          signature of httplib2.Http.request, used to make the
                          request to the metadata server
        Údefault©Úservice_accountFr   r   N)r   r   Úget_service_account_infor   r   )r   Úhttp_requestÚinfos      r   r#   z&AppAssertionCredentials._retrieve_infoh   sR   € ð <Š<Ü×5Ñ5ØØ $× :Ñ :Ò G¸iôIˆDð !ˆDŒLØ)-¨g©ˆDÔ&Ø˜x™.ˆDKð r   c                 óö   — 	 | j                  |«       t        j                  || j                  ¬«      \  | _        | _        y# t        j                  $ r#}t        j                  t        |«      «      ‚d}~ww xY w)aŠ  Refreshes the access_token.

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

        Args:
            http_request: callable, a callable that matches the method
                          signature of httplib2.Http.request, used to make
                          the refresh request.

        Raises:
            HttpAccessTokenRefreshError: When the refresh fails.
        r)   N)r#   r   Ú	get_tokenr   Úaccess_tokenÚtoken_expiryÚhttplib2ÚHttpLib2Errorr   ÚHttpAccessTokenRefreshErrorÚstr)r   r,   Úes      r   Ú_refreshz AppAssertionCredentials._refreshx   sg   € ð	=Ø×Ñ Ô-Ü3<×3FÑ3FØ¨d×.HÑ.Hô4JÑ0ˆDÔ˜tÕ0øä×%Ñ%ò 	=Ü×4Ñ4´S¸³VÓ<Ð<ûð	=ús   ‚?A ÁA8ÁA3Á3A8c                 ó   — t        d«      ‚r   r   r    s    r   Úserialization_dataz*AppAssertionCredentials.serialization_dataŒ   r   r   c                  ó   — y)NF© r    s    r   Úcreate_scoped_requiredz.AppAssertionCredentials.create_scoped_required‘   s   € Ør   c                 ó   — t        d«      ‚)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 blobsr   )r   Úblobs     r   Ú	sign_blobz!AppAssertionCredentials.sign_blob”   s   € ô "Ø?óAð 	Ar   )N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úclassmethodr   r!   r&   r#   r7   Úpropertyr9   r<   r?   Ú__classcell__)r   s   @r   r   r   )   sY   ø„ ñõ"ð( ñFó ðFòFòò )ò =ð( ñFó ðFòöAr   r   )rC   Úloggingr	   r2   Úoauth2clientr   Úoauth2client.contribr   Ú
__author__Ú	getLoggerr@   Úloggerr   ÚAssertionCredentialsr   r;   r   r   Ú<module>rN      sQ   ðñó
 Û ã å Ý *ð 4€
à	ˆ×	Ñ	˜8Ó	$€ð€ôyA˜f×9Ñ9õ yAr   