Skip to content

Conversation

@theacodes
Copy link
Contributor

Resolves #136.

Note: this adds a new dependency on cachetools.

@theacodes
Copy link
Contributor Author

/cc @jboeuf

@jboeuf
Copy link

jboeuf commented Mar 23, 2017

waow. Awesome. thanks much for the quick turnaround!

@theacodes
Copy link
Contributor Author

waow. Awesome. thanks much for the quick turnaround!

We had most of this code already, we just needed justification for it.

@jboeuf
Copy link

jboeuf commented Mar 23, 2017 via email

@theacodes
Copy link
Contributor Author

@dhermes @lukesneeringer re-based and should be ready for review. :)

Copy link
Contributor

@dhermes dhermes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should I know about cachetools (never having used it)? Worth making it an optional dependency?



_DEFAULT_TOKEN_LIFETIME_SECS = 3600 # 1 hour in seconds
_DEFAULT_TOKEN_LIFETIME_SECS = 3600 # 1 hour in sections

This comment was marked as spam.

This comment was marked as spam.

Args:
signer (google.auth.crypt.Signer): The signer used to sign JWTs.
issuer (str): The `iss` claim.
subject (str): The `sub` claim.

This comment was marked as spam.

This comment was marked as spam.

signer (google.auth.crypt.Signer): The signer used to sign JWTs.
issuer (str): The `iss` claim.
subject (str): The `sub` claim.
additional_claims (Mapping[str, str]): Any additional claims for

This comment was marked as spam.

This comment was marked as spam.

max_cache_size (int): The maximum number of JWT tokens to keep in
cache. Tokens are cached using :class:`cachetools.LRUCache`.
"""
super(OnDemandCredentials, self).__init__()

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

if additional_claims is not None:
self._additional_claims = additional_claims
else:
self._additional_claims = {}

This comment was marked as spam.

This comment was marked as spam.

def valid(self):
"""Checks the validity of the credentials.
These credentials are always valid.

This comment was marked as spam.

This comment was marked as spam.

Returns:
bytes: The encoded JWT.
"""

This comment was marked as spam.

This comment was marked as spam.

google.auth.RefreshError
"""
# pylint: disable=unused-argument
# (pylint doesn't correctly recognize overridden methods.)

This comment was marked as spam.

This comment was marked as spam.

assert self.credentials.valid


class TestOnDemandCredentials:

This comment was marked as spam.

This comment was marked as spam.

SERVICE_ACCOUNT_EMAIL = '[email protected]'
SUBJECT = 'subject'
ADDITIONAL_CLAIMS = {'meta': 'data'}
credentials = None

This comment was marked as spam.

This comment was marked as spam.

@theacodes
Copy link
Contributor Author

What should I know about cachetools (never having used it)? Worth making it an optional dependency?

It's a very well tested, maintained, and focused library that provides a pretty damn good implementation of an LRU cache. We could alternatively just pull in the LRUCache class (and associated tests) into this library.

@dhermes
Copy link
Contributor

dhermes commented Mar 28, 2017

Your call

@theacodes
Copy link
Contributor Author

I'm okay with the dependency. @lukesneeringer WDYT?

@lukesneeringer
Copy link

Just did some quick research. I prefer the dep over vendoring.

@theacodes theacodes merged commit cfbfd25 into master Mar 28, 2017
@theacodes theacodes deleted the on-demand-jwt branch March 28, 2017 20:03
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.

4 participants