Skip to content
Permalink
Browse files

Refactor revoke_model to remove circular dependency

In the process of caching service providers, a circular dependency was
uncovered between keystone's caching module and the revoke_model. This change
isolates the refactor to fix the circular dependency into it's own patch. A
separate follow on patch will add caching to service providers on token
creation and validation.

Change-Id: Iaa3c30d51270089b2d5999383d60ed0b2f7f56c8
  • Loading branch information...
lbragstad committed Jun 3, 2016
1 parent c1e712e commit 510f00f365cd988ca2a5d22413d488e8d78c9a89
Showing with 34 additions and 25 deletions.
  1. +7 −25 keystone/common/cache/_context_cache.py
  2. +3 −0 keystone/common/cache/core.py
  3. +24 −0 keystone/models/revoke_model.py
@@ -17,33 +17,15 @@
from oslo_serialization import msgpackutils


from keystone.models import revoke_model


class _RevokeEventHandler(object):
# NOTE(morganfainberg): There needs to be reserved "registry" entries set
# in oslo_serialization for application-specific handlers. We picked 127
# here since it's waaaaaay far out before oslo_serialization will use it.
identity = 127
handles = (revoke_model.RevokeEvent,)

def __init__(self, registry):
self._registry = registry

def serialize(self, obj):
return msgpackutils.dumps(obj.__dict__, registry=self._registry)

def deserialize(self, data):
revoke_event_data = msgpackutils.loads(data, registry=self._registry)
revoke_event = revoke_model.RevokeEvent(**revoke_event_data)
return revoke_event


# Register our new handler.
_registry = msgpackutils.default_registry
_registry.frozen = False
_registry.register(_RevokeEventHandler(registry=_registry))
_registry.frozen = True


def _register_model_handler(handler_class):
"""Register a new model handler."""
_registry.frozen = False
_registry.register(handler_class(registry=_registry))
_registry.frozen = True


class _ResponseCacheProxy(proxy.ProxyBackend):
@@ -25,6 +25,9 @@
CACHE_REGION = cache.create_region()


register_model_handler = _context_cache._register_model_handler


def configure_cache(region=None):
if region is None:
region = CACHE_REGION
@@ -10,9 +10,11 @@
# License for the specific language governing permissions and limitations
# under the License.

from oslo_serialization import msgpackutils
from oslo_utils import timeutils
from six.moves import map

from keystone.common import cache
from keystone.common import utils


@@ -323,3 +325,25 @@ def build_token_values(token_data):
token_values['consumer_id'] = oauth1['consumer_id']
token_values['access_token_id'] = oauth1['access_token_id']
return token_values


class _RevokeEventHandler(object):
# NOTE(morganfainberg): There needs to be reserved "registry" entries set
# in oslo_serialization for application-specific handlers. We picked 127
# here since it's waaaaaay far out before oslo_serialization will use it.
identity = 127
handles = (RevokeEvent,)

def __init__(self, registry):
self._registry = registry

def serialize(self, obj):
return msgpackutils.dumps(obj.__dict__, registry=self._registry)

def deserialize(self, data):
revoke_event_data = msgpackutils.loads(data, registry=self._registry)
revoke_event = RevokeEvent(**revoke_event_data)
return revoke_event


cache.register_model_handler(_RevokeEventHandler)

0 comments on commit 510f00f

Please sign in to comment.
You can’t perform that action at this time.