
                             S r SSKrSSKrSSKrSSKJr  SSKJr  Sr\R                  " \
5      rSr " S S\R                  5      rg)	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)zYou 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                   t   ^  \ rS rSrSrSU 4S jjr\S 5       rS rS r	S r
S r\S	 5       rS
 rS rSrU =r$ )AppAssertionCredentials)   a  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                    > SU;   a  [         R                  " [        5        SUS'   [        [        U ]  " S/UQ70 UD6  Xl        SU l        SU l        g)a1  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    AppAssertionCredentials.__init__;   sS     vMM/*#F8 	%t5dLTLVL%*"    c                     [        S5      eNz6Cannot serialize credentials for GCE service accounts.NotImplementedError)cls	json_datas     r   	from_json!AppAssertionCredentials.from_jsonO       !DF 	Fr   c                     [        S5      er   r   r   s    r   to_jsonAppAssertionCredentials.to_jsonT   s    !DF 	Fr   c                 P    U R                  UR                  5        U R                  $ )aD  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_scopes'AppAssertionCredentials.retrieve_scopesX   s      	DLL){{r   c                     U R                   (       aD  [        R                  " UU R                  =(       d    SS9nSU l         US   U l        US   U l        gg)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'   &AppAssertionCredentials._retrieve_infoh   sR     <<55 $ : : GiID !DL)-gD&x.DK r   c                      U R                  U5        [        R                  " XR                  S9u  U l        U l        g! [        R                   a$  n[        R                  " [        U5      5      eSnAff = f)aJ  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   r1   es      r   _refresh AppAssertionCredentials._refreshx   se    	=-3<3F3F.H.H4J0Dt0%% 	=44SV<<	=s   <? A7A22A7c                     [        S5      er   r   r#   s    r   serialization_data*AppAssertionCredentials.serialization_data   r!   r   c                     g)NF r#   s    r   create_scoped_required.AppAssertionCredentials.create_scoped_required   s    r   c                     [        S5      e)a5  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_blob!AppAssertionCredentials.sign_blob   s     "?A 	Ar   )r6   r   r	   r   r7   )N)__name__
__module____qualname____firstlineno____doc__r   classmethodr   r$   r*   r'   r=   propertyr@   rD   rH   __static_attributes____classcell__)r   s   @r   r   r   )   s_    "( F FF ) =( F FA Ar   r   )rN   loggingr
   r8   oauth2clientr   oauth2client.contribr   
__author__	getLoggerrJ   loggerr   AssertionCredentialsr   rC   r   r   <module>rZ      sO   
     * 4
			8	$yAf99 yAr   