Merge "Pass auth context to the event publishers"

This commit is contained in:
Zuul 2019-05-17 13:46:37 +00:00 committed by Gerrit Code Review
commit f5d1ebd1bb
6 changed files with 17 additions and 6 deletions

View File

@ -77,5 +77,5 @@ class NotificationPublisher(object):
"""Notifier plugin interface."""
@abc.abstractmethod
def publish(self, ex_id, data, event, timestamp, **kwargs):
def publish(self, ctx, ex_id, data, event, timestamp, **kwargs):
raise NotImplementedError()

View File

@ -16,6 +16,7 @@ import copy
from oslo_log import log as logging
from mistral import context as auth_ctx
from mistral.notifiers import base
@ -26,6 +27,8 @@ class DefaultNotifier(base.Notifier):
"""Local notifier that process notification request."""
def notify(self, ex_id, data, event, timestamp, publishers):
ctx = auth_ctx.ctx()
for entry in publishers:
params = copy.deepcopy(entry)
publisher_name = params.pop('type', None)
@ -36,7 +39,7 @@ class DefaultNotifier(base.Notifier):
try:
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:
LOG.exception(
'Unable to process event for publisher "%s".',

View File

@ -22,7 +22,7 @@ LOG = logging.getLogger(__name__)
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(
'The event %s for [name=%s, id=%s] is published by the '
'noop notification publisher.',

View File

@ -26,7 +26,7 @@ LOG = logging.getLogger(__name__)
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')
headers = kwargs.get('headers', {})

View File

@ -17,6 +17,7 @@ import mock
from oslo_config import cfg
from stevedore import exception as sd_exc
from mistral import context
from mistral.db.v2 import api as db_api
from mistral.notifiers import base as 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 = []
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))

View File

@ -17,6 +17,7 @@ import mock
from oslo_config import cfg
from mistral import context
from mistral.db.v2 import api as db_api
from mistral.notifiers import base as notif
from mistral.notifiers import notification_events as events
@ -33,7 +34,10 @@ cfg.CONF.set_default('auth_enable', False, group='pecan')
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))