Merge pull request #2777 from coreos-inc/joseph.schorr/QUAY-618/notificationworker-data-interface

Change notificationworker to use data interface
This commit is contained in:
josephschorr 2017-07-13 00:23:15 +03:00 committed by GitHub
commit fdb21aa5dc
13 changed files with 167 additions and 87 deletions

View file

@ -132,7 +132,7 @@ class VulnerabilityFoundEvent(NotificationEvent):
return 'info'
def get_sample_data(self, notification):
event_config = json.loads(notification.event_config_json)
event_config = notification.event_config_dict
# TODO(jzelinskie): remove when more endpoints have been converted to using
# interfaces
@ -154,7 +154,7 @@ class VulnerabilityFoundEvent(NotificationEvent):
})
def should_perform(self, event_data, notification_data):
event_config = json.loads(notification_data.event_config_json)
event_config = notification_data.event_config_dict
if VulnerabilityFoundEvent.CONFIG_LEVEL not in event_config:
return True
@ -197,10 +197,10 @@ class BaseBuildEvent(NotificationEvent):
return None
def should_perform(self, event_data, notification_data):
if not notification_data.event_config_json:
if not notification_data.event_config_dict:
return True
event_config = json.loads(notification_data.event_config_json)
event_config = notification_data.event_config_dict
ref_regex = event_config.get('ref-regex') or None
if ref_regex is None:
return True

View file

@ -56,7 +56,7 @@ class NotificationMethod(object):
"""
Performs the notification method.
notification_obj: The noticication record itself.
notification_obj: The noticication namedtuple.
event_handler: The NotificationEvent handler.
notification_data: The dict of notification data placed in the queue.
"""
@ -122,7 +122,7 @@ class QuayNotificationMethod(NotificationMethod):
return
# Lookup the target user or team to which we'll send the notification.
config_data = json.loads(notification_obj.config_json)
config_data = notification_obj.method_config_dict
status, err_message, target_users = self.find_targets(repository, config_data)
if not status:
raise NotificationMethodPerformException(err_message)
@ -151,7 +151,7 @@ class EmailMethod(NotificationMethod):
'notifications for this repository')
def perform(self, notification_obj, event_handler, notification_data):
config_data = json.loads(notification_obj.config_json)
config_data = notification_obj.method_config_dict
email = config_data.get('email', '')
if not email:
return
@ -179,7 +179,7 @@ class WebhookMethod(NotificationMethod):
raise CannotValidateNotificationMethodException('Missing webhook URL')
def perform(self, notification_obj, event_handler, notification_data):
config_data = json.loads(notification_obj.config_json)
config_data = notification_obj.method_config_dict
url = config_data.get('url', '')
if not url:
return
@ -216,7 +216,7 @@ class FlowdockMethod(NotificationMethod):
raise CannotValidateNotificationMethodException('Missing Flowdock API Token')
def perform(self, notification_obj, event_handler, notification_data):
config_data = json.loads(notification_obj.config_json)
config_data = notification_obj.method_config_dict
token = config_data.get('flow_api_token', '')
if not token:
return
@ -270,8 +270,7 @@ class HipchatMethod(NotificationMethod):
raise CannotValidateNotificationMethodException('Missing Hipchat Room ID')
def perform(self, notification_obj, event_handler, notification_data):
config_data = json.loads(notification_obj.config_json)
config_data = notification_obj.method_config_dict
token = config_data.get('notification_token', '')
room_id = config_data.get('room_id', '')
@ -385,8 +384,7 @@ class SlackMethod(NotificationMethod):
return adjust_tags(message)
def perform(self, notification_obj, event_handler, notification_data):
config_data = json.loads(notification_obj.config_json)
config_data = notification_obj.method_config_dict
url = config_data.get('url', '')
if not url:
return

View file

@ -12,9 +12,9 @@ def test_all_notifications(app):
'namespace_user': AttrDict(dict(username='foo')),
'name': 'bar',
}),
'event_config_json': json.dumps({
'event_config_dict': {
'level': 'low',
}),
},
})
for subc in NotificationEvent.__subclasses__():