
    U                         S r SSKrSSKrSSKJr  SSKJr  SSKJ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)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                   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       7platform/bq/third_party/oauth2client_4_0/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_jsonN       !DF 	Fr   c                     [        S5      er   r   r   s    r   to_jsonAppAssertionCredentials.to_jsonS   s    !DF 	Fr   c                 <    U R                  U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_infor
   )r   https     r   retrieve_scopes'AppAssertionCredentials.retrieve_scopesW   s     	D!{{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)zuRetrieves service account info for invalid credentials.

Args:
    http: an object to be used to make HTTP requests.
defaultservice_accountFr   r
   N)r   r   get_service_account_infor   r
   )r   r)   infos      r   r(   &AppAssertionCredentials._retrieve_infog   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)zRefreshes 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   access_tokentoken_expiryr   HTTPExceptionr   HttpAccessTokenRefreshErrorstr)r   r)   errs      r   _refresh AppAssertionCredentials._refreshu   se    	?%3<3F3F&@&@4B0Dt0(( 	?44SX>>	?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   )r5   r   r
   r   r6   )N)__name__
__module____qualname____firstlineno____doc__r   classmethodr    r%   r*   r(   r;   propertyr>   rB   rF   __static_attributes____classcell__)r   s   @r   r   r   (   s_    "( F FF )?$ F FA Ar   r   )rL   loggingr   	six.movesr   oauth2client_4_0r   oauth2client_4_0.contribr   	getLoggerrH   loggerr   AssertionCredentialsr   rA   r   r   <module>rX      sJ    
   ! # . 
		8	$uAf99 uAr   