diff --git a/keystone/notifications.py b/keystone/notifications.py index eab62fcfbc..30d1713cc9 100644 --- a/keystone/notifications.py +++ b/keystone/notifications.py @@ -196,74 +196,6 @@ class Audit(object): public) -class ManagerNotificationWrapper(object): - """Send event notifications for ``Manager`` methods. - - Sends a notification if the wrapped Manager method does not raise an - :class:`Exception` (such as :class:`keystone.exception.NotFound`). - - :param operation: one of the values from ACTIONS - :param resource_type: type of resource being affected - :param public: If True (default), the event will be sent to the notifier - API. If False, the event will only be sent via - notify_event_callbacks to in process listeners - - """ - - def __init__(self, operation, resource_type, public=True, - resource_id_arg_index=1, result_id_arg_attr=None): - self.operation = operation - self.resource_type = resource_type - self.public = public - self.resource_id_arg_index = resource_id_arg_index - self.result_id_arg_attr = result_id_arg_attr - - def __call__(self, f): - @functools.wraps(f) - def wrapper(*args, **kwargs): - """Send a notification if the wrapped callable is successful.""" - try: - result = f(*args, **kwargs) - except Exception: - raise - else: - if self.result_id_arg_attr is not None: - resource_id = result[self.result_id_arg_attr] - else: - resource_id = args[self.resource_id_arg_index] - - # NOTE(stevemar): the _send_notification function is - # overloaded, it's used to register callbacks and to actually - # send the notification externally. Thus, we should check - # the desired notification format in the function instead - # of before it. - _send_notification( - self.operation, - self.resource_type, - resource_id, - public=self.public) - - # Only emit CADF notifications for public events - if CONF.notification_format == 'cadf' and self.public: - outcome = taxonomy.OUTCOME_SUCCESS - # NOTE(morganfainberg): The decorator form will always use - # a 'None' initiator, since we do not pass context around - # in a manner that allows the decorator to inspect context - # and extract the needed information. - initiator = None - _create_cadf_payload(self.operation, self.resource_type, - resource_id, outcome, initiator) - return result - - return wrapper - - -def internal(*args, **kwargs): - """Decorator to send notifications for internal notifications only.""" - kwargs['public'] = False - return ManagerNotificationWrapper(ACTIONS.internal, *args, **kwargs) - - def _get_callback_info(callback): """Return list containing callback's module and name.