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.contrib import oauth1
|
||||||
from keystone import exception
|
from keystone import exception
|
||||||
from keystone import policy
|
from keystone import policy
|
||||||
from keystone import token
|
|
||||||
|
|
||||||
|
|
||||||
class TestDrivers(testtools.TestCase):
|
class TestDrivers(testtools.TestCase):
|
||||||
@ -54,10 +53,6 @@ class TestDrivers(testtools.TestCase):
|
|||||||
interface = policy.Driver()
|
interface = policy.Driver()
|
||||||
self.assertInterfaceNotImplemented(interface)
|
self.assertInterfaceNotImplemented(interface)
|
||||||
|
|
||||||
def test_token_driver_unimplemented(self):
|
|
||||||
interface = token.Driver()
|
|
||||||
self.assertInterfaceNotImplemented(interface)
|
|
||||||
|
|
||||||
def test_oauth1_driver_unimplemented(self):
|
def test_oauth1_driver_unimplemented(self):
|
||||||
interface = oauth1.Driver()
|
interface = oauth1.Driver()
|
||||||
self.assertInterfaceNotImplemented(interface)
|
self.assertInterfaceNotImplemented(interface)
|
||||||
|
@ -65,6 +65,15 @@ class Token(kvs.Base, token.Driver):
|
|||||||
except exception.NotFound:
|
except exception.NotFound:
|
||||||
raise exception.TokenNotFound(token_id=token_id)
|
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):
|
def is_not_expired(self, now, ref):
|
||||||
return not ref.get('expires') and ref.get('expires') < now
|
return not ref.get('expires') and ref.get('expires') < now
|
||||||
|
|
||||||
|
@ -178,6 +178,15 @@ class Token(token.Driver):
|
|||||||
self._add_to_revocation_list(data)
|
self._add_to_revocation_list(data)
|
||||||
return result
|
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,
|
def list_tokens(self, user_id, tenant_id=None, trust_id=None,
|
||||||
consumer_id=None):
|
consumer_id=None):
|
||||||
tokens = []
|
tokens = []
|
||||||
@ -216,3 +225,8 @@ class Token(token.Driver):
|
|||||||
if list_json:
|
if list_json:
|
||||||
return jsonutils.loads('[%s]' % list_json)
|
return jsonutils.loads('[%s]' % list_json)
|
||||||
return []
|
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."""
|
"""Main entry point into the Token service."""
|
||||||
|
|
||||||
|
import abc
|
||||||
import copy
|
import copy
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
from keystone.common import cache
|
from keystone.common import cache
|
||||||
from keystone.common import cms
|
from keystone.common import cms
|
||||||
from keystone.common import dependency
|
from keystone.common import dependency
|
||||||
@ -191,9 +194,11 @@ class Manager(manager.Manager):
|
|||||||
self.token_provider_api.invalidate_individual_token_cache(token_id)
|
self.token_provider_api.invalidate_individual_token_cache(token_id)
|
||||||
|
|
||||||
|
|
||||||
|
@six.add_metaclass(abc.ABCMeta)
|
||||||
class Driver(object):
|
class Driver(object):
|
||||||
"""Interface description for a Token driver."""
|
"""Interface description for a Token driver."""
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
def get_token(self, token_id):
|
def get_token(self, token_id):
|
||||||
"""Get a token by id.
|
"""Get a token by id.
|
||||||
|
|
||||||
@ -205,6 +210,7 @@ class Driver(object):
|
|||||||
"""
|
"""
|
||||||
raise exception.NotImplemented()
|
raise exception.NotImplemented()
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
def create_token(self, token_id, data):
|
def create_token(self, token_id, data):
|
||||||
"""Create a token by id and data.
|
"""Create a token by id and data.
|
||||||
|
|
||||||
@ -228,6 +234,7 @@ class Driver(object):
|
|||||||
"""
|
"""
|
||||||
raise exception.NotImplemented()
|
raise exception.NotImplemented()
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
def delete_token(self, token_id):
|
def delete_token(self, token_id):
|
||||||
"""Deletes a token by id.
|
"""Deletes a token by id.
|
||||||
|
|
||||||
@ -239,6 +246,7 @@ class Driver(object):
|
|||||||
"""
|
"""
|
||||||
raise exception.NotImplemented()
|
raise exception.NotImplemented()
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
def delete_tokens(self, user_id, tenant_id=None, trust_id=None,
|
def delete_tokens(self, user_id, tenant_id=None, trust_id=None,
|
||||||
consumer_id=None):
|
consumer_id=None):
|
||||||
"""Deletes tokens by user.
|
"""Deletes tokens by user.
|
||||||
@ -264,11 +272,6 @@ class Driver(object):
|
|||||||
:raises: keystone.exception.TokenNotFound
|
: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,
|
token_list = self.list_tokens(user_id,
|
||||||
tenant_id=tenant_id,
|
tenant_id=tenant_id,
|
||||||
trust_id=trust_id,
|
trust_id=trust_id,
|
||||||
@ -280,6 +283,7 @@ class Driver(object):
|
|||||||
except exception.NotFound:
|
except exception.NotFound:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
def list_tokens(self, user_id, tenant_id=None, trust_id=None,
|
def list_tokens(self, user_id, tenant_id=None, trust_id=None,
|
||||||
consumer_id=None):
|
consumer_id=None):
|
||||||
"""Returns a list of current token_id's for a user
|
"""Returns a list of current token_id's for a user
|
||||||
@ -301,6 +305,7 @@ class Driver(object):
|
|||||||
"""
|
"""
|
||||||
raise exception.NotImplemented()
|
raise exception.NotImplemented()
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
def list_revoked_tokens(self):
|
def list_revoked_tokens(self):
|
||||||
"""Returns a list of all revoked tokens
|
"""Returns a list of all revoked tokens
|
||||||
|
|
||||||
@ -309,6 +314,7 @@ class Driver(object):
|
|||||||
"""
|
"""
|
||||||
raise exception.NotImplemented()
|
raise exception.NotImplemented()
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
def flush_expired_tokens(self):
|
def flush_expired_tokens(self):
|
||||||
"""Archive or delete tokens that have expired.
|
"""Archive or delete tokens that have expired.
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user