Merge "Pass auth context to the event publishers"
This commit is contained in:
commit
f5d1ebd1bb
@ -77,5 +77,5 @@ class NotificationPublisher(object):
|
|||||||
"""Notifier plugin interface."""
|
"""Notifier plugin interface."""
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def publish(self, ex_id, data, event, timestamp, **kwargs):
|
def publish(self, ctx, ex_id, data, event, timestamp, **kwargs):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
@ -16,6 +16,7 @@ import copy
|
|||||||
|
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
|
||||||
|
from mistral import context as auth_ctx
|
||||||
from mistral.notifiers import base
|
from mistral.notifiers import base
|
||||||
|
|
||||||
|
|
||||||
@ -26,6 +27,8 @@ class DefaultNotifier(base.Notifier):
|
|||||||
"""Local notifier that process notification request."""
|
"""Local notifier that process notification request."""
|
||||||
|
|
||||||
def notify(self, ex_id, data, event, timestamp, publishers):
|
def notify(self, ex_id, data, event, timestamp, publishers):
|
||||||
|
ctx = auth_ctx.ctx()
|
||||||
|
|
||||||
for entry in publishers:
|
for entry in publishers:
|
||||||
params = copy.deepcopy(entry)
|
params = copy.deepcopy(entry)
|
||||||
publisher_name = params.pop('type', None)
|
publisher_name = params.pop('type', None)
|
||||||
@ -36,7 +39,7 @@ class DefaultNotifier(base.Notifier):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
publisher = base.get_notification_publisher(publisher_name)
|
publisher = base.get_notification_publisher(publisher_name)
|
||||||
publisher.publish(ex_id, data, event, timestamp, **params)
|
publisher.publish(ctx, ex_id, data, event, timestamp, **params)
|
||||||
except Exception:
|
except Exception:
|
||||||
LOG.exception(
|
LOG.exception(
|
||||||
'Unable to process event for publisher "%s".',
|
'Unable to process event for publisher "%s".',
|
||||||
|
@ -22,7 +22,7 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class NoopPublisher(base.NotificationPublisher):
|
class NoopPublisher(base.NotificationPublisher):
|
||||||
|
|
||||||
def publish(self, ex_id, data, event, timestamp, **kwargs):
|
def publish(self, ctx, ex_id, data, event, timestamp, **kwargs):
|
||||||
LOG.info(
|
LOG.info(
|
||||||
'The event %s for [name=%s, id=%s] is published by the '
|
'The event %s for [name=%s, id=%s] is published by the '
|
||||||
'noop notification publisher.',
|
'noop notification publisher.',
|
||||||
|
@ -26,7 +26,7 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class WebhookPublisher(base.NotificationPublisher):
|
class WebhookPublisher(base.NotificationPublisher):
|
||||||
|
|
||||||
def publish(self, ex_id, data, event, timestamp, **kwargs):
|
def publish(self, ctx, ex_id, data, event, timestamp, **kwargs):
|
||||||
url = kwargs.get('url')
|
url = kwargs.get('url')
|
||||||
headers = kwargs.get('headers', {})
|
headers = kwargs.get('headers', {})
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ import mock
|
|||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from stevedore import exception as sd_exc
|
from stevedore import exception as sd_exc
|
||||||
|
|
||||||
|
from mistral import context
|
||||||
from mistral.db.v2 import api as db_api
|
from mistral.db.v2 import api as db_api
|
||||||
from mistral.notifiers import base as notif
|
from mistral.notifiers import base as notif
|
||||||
from mistral.notifiers import default_notifier as d_notif
|
from mistral.notifiers import default_notifier as d_notif
|
||||||
@ -33,7 +34,10 @@ cfg.CONF.set_default('auth_enable', False, group='pecan')
|
|||||||
EVENT_LOGS = []
|
EVENT_LOGS = []
|
||||||
|
|
||||||
|
|
||||||
def publisher_process(ex_id, data, event, timestamp, **kwargs):
|
def publisher_process(ctx, ex_id, data, event, timestamp, **kwargs):
|
||||||
|
if not isinstance(ctx, context.MistralContext):
|
||||||
|
raise TypeError('ctx is not type of MistralContext.')
|
||||||
|
|
||||||
EVENT_LOGS.append((ex_id, event))
|
EVENT_LOGS.append((ex_id, event))
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ import mock
|
|||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
|
||||||
|
from mistral import context
|
||||||
from mistral.db.v2 import api as db_api
|
from mistral.db.v2 import api as db_api
|
||||||
from mistral.notifiers import base as notif
|
from mistral.notifiers import base as notif
|
||||||
from mistral.notifiers import notification_events as events
|
from mistral.notifiers import notification_events as events
|
||||||
@ -33,7 +34,10 @@ cfg.CONF.set_default('auth_enable', False, group='pecan')
|
|||||||
EVENT_LOGS = []
|
EVENT_LOGS = []
|
||||||
|
|
||||||
|
|
||||||
def log_event(ex_id, data, event, timestamp, **kwargs):
|
def log_event(ctx, ex_id, data, event, timestamp, **kwargs):
|
||||||
|
if not isinstance(ctx, context.MistralContext):
|
||||||
|
raise TypeError('ctx is not type of MistralContext.')
|
||||||
|
|
||||||
EVENT_LOGS.append((ex_id, event))
|
EVENT_LOGS.append((ex_id, event))
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user