Merge "Use abstract base class for token driver"
This commit is contained in:
commit
ed912ff8f5
@ -21,7 +21,6 @@ from keystone.contrib import endpoint_filter
|
||||
from keystone.contrib import oauth1
|
||||
from keystone import exception
|
||||
from keystone import policy
|
||||
from keystone import token
|
||||
|
||||
|
||||
class TestDrivers(testtools.TestCase):
|
||||
@ -54,10 +53,6 @@ class TestDrivers(testtools.TestCase):
|
||||
interface = policy.Driver()
|
||||
self.assertInterfaceNotImplemented(interface)
|
||||
|
||||
def test_token_driver_unimplemented(self):
|
||||
interface = token.Driver()
|
||||
self.assertInterfaceNotImplemented(interface)
|
||||
|
||||
def test_oauth1_driver_unimplemented(self):
|
||||
interface = oauth1.Driver()
|
||||
self.assertInterfaceNotImplemented(interface)
|
||||
|
@ -65,6 +65,15 @@ class Token(kvs.Base, token.Driver):
|
||||
except exception.NotFound:
|
||||
raise exception.TokenNotFound(token_id=token_id)
|
||||
|
||||
def delete_tokens(self, user_id, tenant_id=None, trust_id=None,
|
||||
consumer_id=None):
|
||||
return super(Token, self).delete_tokens(
|
||||
user_id=user_id,
|
||||
tenant_id=tenant_id,
|
||||
trust_id=trust_id,
|
||||
consumer_id=consumer_id,
|
||||
)
|
||||
|
||||
def is_not_expired(self, now, ref):
|
||||
return not ref.get('expires') and ref.get('expires') < now
|
||||
|
||||
|
@ -178,6 +178,15 @@ class Token(token.Driver):
|
||||
self._add_to_revocation_list(data)
|
||||
return result
|
||||
|
||||
def delete_tokens(self, user_id, tenant_id=None, trust_id=None,
|
||||
consumer_id=None):
|
||||
return super(Token, self).delete_tokens(
|
||||
user_id=user_id,
|
||||
tenant_id=tenant_id,
|
||||
trust_id=trust_id,
|
||||
consumer_id=consumer_id,
|
||||
)
|
||||
|
||||
def list_tokens(self, user_id, tenant_id=None, trust_id=None,
|
||||
consumer_id=None):
|
||||
tokens = []
|
||||
@ -216,3 +225,8 @@ class Token(token.Driver):
|
||||
if list_json:
|
||||
return jsonutils.loads('[%s]' % list_json)
|
||||
return []
|
||||
|
||||
def flush_expired_tokens(self):
|
||||
"""Archive or delete tokens that have expired.
|
||||
"""
|
||||
raise exception.NotImplemented()
|
||||
|
@ -16,9 +16,12 @@
|
||||
|
||||
"""Main entry point into the Token service."""
|
||||
|
||||
import abc
|
||||
import copy
|
||||
import datetime
|
||||
|
||||
import six
|
||||
|
||||
from keystone.common import cache
|
||||
from keystone.common import cms
|
||||
from keystone.common import dependency
|
||||
@ -191,9 +194,11 @@ class Manager(manager.Manager):
|
||||
self.token_provider_api.invalidate_individual_token_cache(token_id)
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class Driver(object):
|
||||
"""Interface description for a Token driver."""
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_token(self, token_id):
|
||||
"""Get a token by id.
|
||||
|
||||
@ -205,6 +210,7 @@ class Driver(object):
|
||||
"""
|
||||
raise exception.NotImplemented()
|
||||
|
||||
@abc.abstractmethod
|
||||
def create_token(self, token_id, data):
|
||||
"""Create a token by id and data.
|
||||
|
||||
@ -228,6 +234,7 @@ class Driver(object):
|
||||
"""
|
||||
raise exception.NotImplemented()
|
||||
|
||||
@abc.abstractmethod
|
||||
def delete_token(self, token_id):
|
||||
"""Deletes a token by id.
|
||||
|
||||
@ -239,6 +246,7 @@ class Driver(object):
|
||||
"""
|
||||
raise exception.NotImplemented()
|
||||
|
||||
@abc.abstractmethod
|
||||
def delete_tokens(self, user_id, tenant_id=None, trust_id=None,
|
||||
consumer_id=None):
|
||||
"""Deletes tokens by user.
|
||||
@ -264,11 +272,6 @@ class Driver(object):
|
||||
:raises: keystone.exception.TokenNotFound
|
||||
|
||||
"""
|
||||
# TODO(henry-nash): The SQL driver already has a more efficient
|
||||
# implementation of this, although this is missing from the other
|
||||
# backends. These should be completed and then this should become
|
||||
# a virtual method. This is raised as bug #1227507.
|
||||
|
||||
token_list = self.list_tokens(user_id,
|
||||
tenant_id=tenant_id,
|
||||
trust_id=trust_id,
|
||||
@ -280,6 +283,7 @@ class Driver(object):
|
||||
except exception.NotFound:
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def list_tokens(self, user_id, tenant_id=None, trust_id=None,
|
||||
consumer_id=None):
|
||||
"""Returns a list of current token_id's for a user
|
||||
@ -301,6 +305,7 @@ class Driver(object):
|
||||
"""
|
||||
raise exception.NotImplemented()
|
||||
|
||||
@abc.abstractmethod
|
||||
def list_revoked_tokens(self):
|
||||
"""Returns a list of all revoked tokens
|
||||
|
||||
@ -309,6 +314,7 @@ class Driver(object):
|
||||
"""
|
||||
raise exception.NotImplemented()
|
||||
|
||||
@abc.abstractmethod
|
||||
def flush_expired_tokens(self):
|
||||
"""Archive or delete tokens that have expired.
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user