Merge "Move the revoke abstract base class out of core"

This commit is contained in:
Jenkins 2016-05-18 17:09:33 +00:00 committed by Gerrit Code Review
commit 6d07233f53
3 changed files with 72 additions and 42 deletions

View File

@ -0,0 +1,60 @@
# Copyright 2012 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import abc
import datetime
from oslo_config import cfg
from oslo_utils import timeutils
import six
from keystone import exception
CONF = cfg.CONF
def revoked_before_cutoff_time():
expire_delta = datetime.timedelta(
seconds=CONF.token.expiration + CONF.revoke.expiration_buffer)
oldest = timeutils.utcnow() - expire_delta
return oldest
@six.add_metaclass(abc.ABCMeta)
class RevokeDriverV8(object):
"""Interface for recording and reporting revocation events."""
@abc.abstractmethod
def list_events(self, last_fetch=None):
"""return the revocation events, as a list of objects.
:param last_fetch: Time of last fetch. Return all events newer.
:returns: A list of keystone.revoke.model.RevokeEvent
newer than `last_fetch.`
If no last_fetch is specified, returns all events
for tokens issued after the expiration cutoff.
"""
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def revoke(self, event):
"""register a revocation event.
:param event: An instance of
keystone.revoke.model.RevocationEvent
"""
raise exception.NotImplemented() # pragma: no cover

View File

@ -12,7 +12,7 @@
from keystone.common import sql
from keystone.models import revoke_model
from keystone import revoke
from keystone.revoke.backends import base
class RevocationEvent(sql.ModelBase, sql.ModelDictMixin):
@ -36,7 +36,7 @@ class RevocationEvent(sql.ModelBase, sql.ModelDictMixin):
audit_chain_id = sql.Column(sql.String(32))
class Revoke(revoke.RevokeDriverV8):
class Revoke(base.RevokeDriverV8):
def _flush_batch_size(self, dialect):
batch_size = 0
if dialect == 'ibm_db_sa':
@ -56,7 +56,7 @@ class Revoke(revoke.RevokeDriverV8):
return batch_size
def _prune_expired_events(self):
oldest = revoke.revoked_before_cutoff_time()
oldest = base.revoked_before_cutoff_time()
with sql.session_for_write() as session:
dialect = session.bind.dialect.name

View File

@ -12,13 +12,8 @@
"""Main entry point into the Revoke service."""
import abc
import datetime
from oslo_config import cfg
from oslo_log import versionutils
from oslo_utils import timeutils
import six
from keystone.common import cache
from keystone.common import dependency
@ -28,6 +23,7 @@ from keystone import exception
from keystone.i18n import _
from keystone.models import revoke_model
from keystone import notifications
from keystone.revoke.backends import base
CONF = cfg.CONF
@ -54,13 +50,6 @@ extension.register_public_extension(EXTENSION_DATA['alias'], EXTENSION_DATA)
MEMOIZE = cache.get_memoization_decorator(group='revoke')
def revoked_before_cutoff_time():
expire_delta = datetime.timedelta(
seconds=CONF.token.expiration + CONF.revoke.expiration_buffer)
oldest = timeutils.utcnow() - expire_delta
return oldest
@dependency.provider('revoke_api')
class Manager(manager.Manager):
"""Default pivot point for the Revoke backend.
@ -230,32 +219,13 @@ class Manager(manager.Manager):
self._get_revoke_tree.invalidate(self)
@six.add_metaclass(abc.ABCMeta)
class RevokeDriverV8(object):
"""Interface for recording and reporting revocation events."""
@abc.abstractmethod
def list_events(self, last_fetch=None):
"""return the revocation events, as a list of objects.
:param last_fetch: Time of last fetch. Return all events newer.
:returns: A list of keystone.revoke.model.RevokeEvent
newer than `last_fetch.`
If no last_fetch is specified, returns all events
for tokens issued after the expiration cutoff.
"""
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def revoke(self, event):
"""register a revocation event.
:param event: An instance of
keystone.revoke.model.RevocationEvent
"""
raise exception.NotImplemented() # pragma: no cover
@versionutils.deprecated(
versionutils.deprecated.NEWTON,
what='keystone.revoke.RevokeDriverV8',
in_favor_of='keystone.revoke.backends.base.RevokeDriverV8',
remove_in=+1)
class RevokeDriverV8(base.RevokeDriverV8):
pass
Driver = manager.create_legacy_driver(RevokeDriverV8)
Driver = manager.create_legacy_driver(base.RevokeDriverV8)