Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add app engine credentials #46

Merged
merged 3 commits into from
Oct 24, 2016
Merged

Add app engine credentials #46

merged 3 commits into from
Oct 24, 2016

Conversation

theacodes
Copy link
Contributor

Closes #36

@theacodes theacodes added this to the 1.0.0 milestone Oct 21, 2016
from google.auth import credentials
from google.auth import exceptions


This comment was marked as spam.

This comment was marked as spam.

not available.
"""
# pylint: disable=unused-argument
if not app_identity:

This comment was marked as spam.

This comment was marked as spam.

Returns:
bool: True if there are no scopes set otherwise False.
"""
return True if not self._scopes else False

This comment was marked as spam.

This comment was marked as spam.

Raises:
EnvironmentError: If the App Engine APIs are unavailable.
"""
if not app_identity:

This comment was marked as spam.

This comment was marked as spam.

credentials.Credentials):
"""App Engine standard environment credentials.

These credentials use the App Engine App Idenity API to obtain access

This comment was marked as spam.

This comment was marked as spam.

try:
from google.appengine.api import app_identity
except ImportError:
app_identity = None

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

service_account_id (str): The service account ID passed into
:func:`google.appengine.api.app_identity.get_access_token`.
This is not required as the default application service account
ID will be used.

This comment was marked as spam.

This comment was marked as spam.

google.auth.exceptions.RefreshError: If the App Engine APIs are
not available.
"""
# pylint: disable=unused-argument

This comment was marked as spam.

This comment was marked as spam.


@property
def requires_scopes(self):
"""Checks if the credentials requires scopes.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@pytest.fixture
def app_engine(app_identity_mock):
from google.auth import app_engine
reload_module(app_engine)

This comment was marked as spam.

This comment was marked as spam.

def app_engine(app_identity_mock):
from google.auth import app_engine
reload_module(app_engine)
yield app_engine

This comment was marked as spam.

This comment was marked as spam.

@pytest.fixture
def app_engine_no_apis():
from google.auth import app_engine
reload_module(app_engine)

This comment was marked as spam.

This comment was marked as spam.



class TestCredentials(object):
def test_default_state(self, app_engine):

This comment was marked as spam.

This comment was marked as spam.

def test_refresh(self, now_mock, app_engine, app_identity_mock):
token = 'token'
ttl = 100
app_identity_mock.get_access_token.return_value = (token, ttl)

This comment was marked as spam.

This comment was marked as spam.

self._service_account_id = service_account_id

def refresh(self, request):
"""Refresh the access token and scopes.

This comment was marked as spam.

This comment was marked as spam.

"""Refresh the access token and scopes.

Args:
request (google.auth.transport.Request): Unused.

This comment was marked as spam.

This comment was marked as spam.

scopes=scopes, service_account_id=self._service_account_id)

def sign_bytes(self, message):
"""Signs the given message.

This comment was marked as spam.

This comment was marked as spam.

@theacodes
Copy link
Contributor Author

@dhermes @nathanielmanistaatgoogle PTAL, should be good to go.

@dhermes
Copy link
Contributor

dhermes commented Oct 24, 2016

LGTM

@theacodes theacodes merged commit 0471475 into master Oct 24, 2016
@theacodes theacodes deleted the gae-credentials branch October 24, 2016 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants