Notification cleanup: namespace actions
Update the notification actions to be properly namespaced rather than simple constant strings. This is a followup to the general notification constant cleanup changeset. Change-Id: Ife7597eba4a797b6909acd76720e46ee20a91727 bp: non-persistent-tokens
This commit is contained in:
parent
cd612aeb90
commit
7b609714b2
|
@ -26,10 +26,10 @@ class EndpointFilterV3Controller(controller.V3Controller):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(EndpointFilterV3Controller, self).__init__()
|
super(EndpointFilterV3Controller, self).__init__()
|
||||||
notifications.register_event_callback(
|
notifications.register_event_callback(
|
||||||
notifications.DELETED, 'project',
|
notifications.ACTIONS.deleted, 'project',
|
||||||
self._on_project_or_endpoint_delete)
|
self._on_project_or_endpoint_delete)
|
||||||
notifications.register_event_callback(
|
notifications.register_event_callback(
|
||||||
notifications.DELETED, 'endpoint',
|
notifications.ACTIONS.deleted, 'endpoint',
|
||||||
self._on_project_or_endpoint_delete)
|
self._on_project_or_endpoint_delete)
|
||||||
|
|
||||||
def _on_project_or_endpoint_delete(self, service, resource_type, operation,
|
def _on_project_or_endpoint_delete(self, service, resource_type, operation,
|
||||||
|
|
|
@ -17,6 +17,7 @@ from keystone.common import dependency
|
||||||
from keystone.common import manager
|
from keystone.common import manager
|
||||||
from keystone import exception
|
from keystone import exception
|
||||||
from keystone.i18n import _
|
from keystone.i18n import _
|
||||||
|
from keystone import notifications
|
||||||
from keystone.openstack.common import log
|
from keystone.openstack.common import log
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,12 +48,13 @@ class ExampleManager(manager.Manager):
|
||||||
# This information is used when the @dependency.provider decorator acts
|
# This information is used when the @dependency.provider decorator acts
|
||||||
# on the class.
|
# on the class.
|
||||||
self.event_callbacks = {
|
self.event_callbacks = {
|
||||||
'deleted': {
|
notifications.ACTIONS.deleted: {
|
||||||
'project': [
|
'project': [self.project_deleted_callback],
|
||||||
self.project_deleted_callback]},
|
},
|
||||||
'created': {
|
notifications.ACTIONS.created: {
|
||||||
'project': [
|
'project': [self.project_created_callback],
|
||||||
self.project_created_callback]}}
|
},
|
||||||
|
}
|
||||||
super(ExampleManager, self).__init__(
|
super(ExampleManager, self).__init__(
|
||||||
'keystone.contrib.example.core.ExampleDriver')
|
'keystone.contrib.example.core.ExampleDriver')
|
||||||
|
|
||||||
|
|
|
@ -119,7 +119,7 @@ class Manager(manager.Manager):
|
||||||
|
|
||||||
def _register_listeners(self):
|
def _register_listeners(self):
|
||||||
callbacks = {
|
callbacks = {
|
||||||
notifications.DELETED: [
|
notifications.ACTIONS.deleted: [
|
||||||
['OS-TRUST:trust', self._trust_callback],
|
['OS-TRUST:trust', self._trust_callback],
|
||||||
['OS-OAUTH1:consumer', self._consumer_callback],
|
['OS-OAUTH1:consumer', self._consumer_callback],
|
||||||
['OS-OAUTH1:access_token', self._access_token_callback],
|
['OS-OAUTH1:access_token', self._access_token_callback],
|
||||||
|
@ -127,12 +127,12 @@ class Manager(manager.Manager):
|
||||||
['user', self._user_callback],
|
['user', self._user_callback],
|
||||||
['project', self._project_callback],
|
['project', self._project_callback],
|
||||||
],
|
],
|
||||||
notifications.DISABLED: [
|
notifications.ACTIONS.disabled: [
|
||||||
['user', self._user_callback],
|
['user', self._user_callback],
|
||||||
['project', self._project_callback],
|
['project', self._project_callback],
|
||||||
['domain', self._domain_callback]
|
['domain', self._domain_callback]
|
||||||
],
|
],
|
||||||
notifications.INTERNAL: [
|
notifications.ACTIONS.internal: [
|
||||||
[notifications.INVALIDATE_USER_TOKEN_PERSISTENCE,
|
[notifications.INVALIDATE_USER_TOKEN_PERSISTENCE,
|
||||||
self._user_callback]
|
self._user_callback]
|
||||||
]
|
]
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
"""Notifications module for OpenStack Identity Service resources"""
|
"""Notifications module for OpenStack Identity Service resources"""
|
||||||
|
|
||||||
|
import collections
|
||||||
import inspect
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
import socket
|
import socket
|
||||||
|
@ -38,13 +39,12 @@ notifier_opts = [
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
# NOTE(gyee): actions that can be notified. One must update this list whenever
|
# NOTE(gyee): actions that can be notified. One must update this list whenever
|
||||||
# a new action is supported.
|
# a new action is supported.
|
||||||
CREATED = 'created'
|
_ACTIONS = collections.namedtuple(
|
||||||
DELETED = 'deleted'
|
'NotificationActions',
|
||||||
DISABLED = 'disabled'
|
'created, deleted, disabled, updated, internal')
|
||||||
UPDATED = 'updated'
|
ACTIONS = _ACTIONS(created='created', deleted='deleted', disabled='disabled',
|
||||||
INTERNAL = 'internal'
|
updated='updated', internal='internal')
|
||||||
|
|
||||||
ACTIONS = frozenset([CREATED, DELETED, DISABLED, UPDATED, INTERNAL])
|
|
||||||
# resource types that can be notified
|
# resource types that can be notified
|
||||||
_SUBSCRIBERS = {}
|
_SUBSCRIBERS = {}
|
||||||
_notifier = None
|
_notifier = None
|
||||||
|
@ -127,28 +127,28 @@ class ManagerNotificationWrapper(object):
|
||||||
|
|
||||||
def created(*args, **kwargs):
|
def created(*args, **kwargs):
|
||||||
"""Decorator to send notifications for ``Manager.create_*`` methods."""
|
"""Decorator to send notifications for ``Manager.create_*`` methods."""
|
||||||
return ManagerNotificationWrapper(CREATED, *args, **kwargs)
|
return ManagerNotificationWrapper(ACTIONS.created, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def updated(*args, **kwargs):
|
def updated(*args, **kwargs):
|
||||||
"""Decorator to send notifications for ``Manager.update_*`` methods."""
|
"""Decorator to send notifications for ``Manager.update_*`` methods."""
|
||||||
return ManagerNotificationWrapper(UPDATED, *args, **kwargs)
|
return ManagerNotificationWrapper(ACTIONS.updated, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def disabled(*args, **kwargs):
|
def disabled(*args, **kwargs):
|
||||||
"""Decorator to send notifications when an object is disabled."""
|
"""Decorator to send notifications when an object is disabled."""
|
||||||
return ManagerNotificationWrapper(DISABLED, *args, **kwargs)
|
return ManagerNotificationWrapper(ACTIONS.disabled, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def deleted(*args, **kwargs):
|
def deleted(*args, **kwargs):
|
||||||
"""Decorator to send notifications for ``Manager.delete_*`` methods."""
|
"""Decorator to send notifications for ``Manager.delete_*`` methods."""
|
||||||
return ManagerNotificationWrapper(DELETED, *args, **kwargs)
|
return ManagerNotificationWrapper(ACTIONS.deleted, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def internal(*args, **kwargs):
|
def internal(*args, **kwargs):
|
||||||
"""Decorator to send notifications for internal notifications only."""
|
"""Decorator to send notifications for internal notifications only."""
|
||||||
kwargs['public'] = False
|
kwargs['public'] = False
|
||||||
return ManagerNotificationWrapper(INTERNAL, *args, **kwargs)
|
return ManagerNotificationWrapper(ACTIONS.internal, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def _get_callback_info(callback):
|
def _get_callback_info(callback):
|
||||||
|
@ -164,7 +164,8 @@ def register_event_callback(event, resource_type, callbacks):
|
||||||
if event not in ACTIONS:
|
if event not in ACTIONS:
|
||||||
raise ValueError(_('%(event)s is not a valid notification event, must '
|
raise ValueError(_('%(event)s is not a valid notification event, must '
|
||||||
'be one of: %(actions)s') %
|
'be one of: %(actions)s') %
|
||||||
{'event': event, 'actions': ', '.join(ACTIONS)})
|
{'event': event,
|
||||||
|
'actions': ', '.join(str(a) for a in ACTIONS)})
|
||||||
|
|
||||||
if not hasattr(callbacks, '__iter__'):
|
if not hasattr(callbacks, '__iter__'):
|
||||||
callbacks = [callbacks]
|
callbacks = [callbacks]
|
||||||
|
|
|
@ -31,9 +31,9 @@ from keystone.tests import test_v3
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
|
|
||||||
EXP_RESOURCE_TYPE = uuid.uuid4().hex
|
EXP_RESOURCE_TYPE = uuid.uuid4().hex
|
||||||
CREATED_OPERATION = 'created'
|
CREATED_OPERATION = notifications.ACTIONS.created
|
||||||
UPDATED_OPERATION = 'updated'
|
UPDATED_OPERATION = notifications.ACTIONS.updated
|
||||||
DELETED_OPERATION = 'deleted'
|
DELETED_OPERATION = notifications.ACTIONS.deleted
|
||||||
|
|
||||||
|
|
||||||
class ArbitraryException(Exception):
|
class ArbitraryException(Exception):
|
||||||
|
|
|
@ -150,27 +150,37 @@ class Manager(manager.Manager):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(Manager, self).__init__(self.get_token_provider())
|
super(Manager, self).__init__(self.get_token_provider())
|
||||||
|
self._register_callback_listeners()
|
||||||
|
|
||||||
|
def _register_callback_listeners(self):
|
||||||
# This is used by the @dependency.provider decorator to register the
|
# This is used by the @dependency.provider decorator to register the
|
||||||
# provider (token_provider_api) manager to listen for trust deletions.
|
# provider (token_provider_api) manager to listen for trust deletions.
|
||||||
self.event_callbacks = {
|
callbacks = {
|
||||||
notifications.DELETED: {
|
notifications.ACTIONS.deleted: [
|
||||||
'OS-TRUST:trust': [self._trust_deleted_event_callback],
|
['OS-TRUST:trust', self._trust_deleted_event_callback],
|
||||||
'user': [self._delete_user_tokens_callback],
|
['user', self._delete_user_tokens_callback],
|
||||||
'domain': [self._delete_domain_tokens_callback]},
|
['domain', self._delete_domain_tokens_callback],
|
||||||
notifications.DISABLED: {
|
],
|
||||||
'user': [self._delete_user_tokens_callback],
|
notifications.ACTIONS.disabled: [
|
||||||
'domain': [self._delete_domain_tokens_callback],
|
['user', self._delete_user_tokens_callback],
|
||||||
'project': [self._delete_project_tokens_callback]},
|
['domain', self._delete_domain_tokens_callback],
|
||||||
notifications.INTERNAL: {
|
['project', self._delete_project_tokens_callback],
|
||||||
notifications.INVALIDATE_USER_TOKEN_PERSISTENCE: [
|
],
|
||||||
|
notifications.ACTIONS.internal: [
|
||||||
|
[notifications.INVALIDATE_USER_TOKEN_PERSISTENCE,
|
||||||
self._delete_user_tokens_callback],
|
self._delete_user_tokens_callback],
|
||||||
notifications.INVALIDATE_USER_PROJECT_TOKEN_PERSISTENCE: [
|
[notifications.INVALIDATE_USER_PROJECT_TOKEN_PERSISTENCE,
|
||||||
self._delete_user_project_tokens_callback],
|
self._delete_user_project_tokens_callback],
|
||||||
notifications.INVALIDATE_USER_OAUTH_CONSUMER_TOKENS: [
|
[notifications.INVALIDATE_USER_OAUTH_CONSUMER_TOKENS,
|
||||||
self._delete_user_oauth_consumer_tokens_callback]}
|
self._delete_user_oauth_consumer_tokens_callback],
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for event, cb_info in six.iteritems(callbacks):
|
||||||
|
for resource_type, callback_fns in cb_info:
|
||||||
|
notifications.register_event_callback(event, resource_type,
|
||||||
|
callback_fns)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _persistence(self):
|
def _persistence(self):
|
||||||
# NOTE(morganfainberg): This should not be handled via __init__ to
|
# NOTE(morganfainberg): This should not be handled via __init__ to
|
||||||
|
|
Loading…
Reference in New Issue