2015-02-19 21:21:54 +00:00
|
|
|
/**
|
|
|
|
* Service which defines the various kinds of external notification and provides methods for
|
|
|
|
* easily looking up information about those kinds.
|
|
|
|
*/
|
2015-10-13 22:14:52 +00:00
|
|
|
angular.module('quay').factory('ExternalNotificationData', ['Config', 'Features','VulnerabilityService',
|
2015-02-19 21:21:54 +00:00
|
|
|
|
2015-10-13 22:14:52 +00:00
|
|
|
function(Config, Features, VulnerabilityService) {
|
2015-02-19 21:21:54 +00:00
|
|
|
var externalNotificationData = {};
|
|
|
|
|
|
|
|
var events = [
|
|
|
|
{
|
|
|
|
'id': 'repo_push',
|
|
|
|
'title': 'Push to Repository',
|
|
|
|
'icon': 'fa-upload'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
if (Features.BUILD_SUPPORT) {
|
|
|
|
var buildEvents = [
|
|
|
|
{
|
|
|
|
'id': 'build_queued',
|
|
|
|
'title': 'Dockerfile Build Queued',
|
2016-09-14 20:48:17 +00:00
|
|
|
'icon': 'fa-tasks',
|
|
|
|
'fields': [
|
|
|
|
{
|
|
|
|
'name': 'ref-regex',
|
|
|
|
'type': 'regex',
|
|
|
|
'title': 'matching ref(s)',
|
|
|
|
'help_text': 'An optional regular expression for matching the git branch or tag ' +
|
|
|
|
'git ref. If left blank, the notification will fire for all builds.',
|
|
|
|
'optional': true,
|
2016-09-14 21:07:14 +00:00
|
|
|
'placeholder': '(refs/heads/somebranch)|(refs/tags/sometag)'
|
2016-09-14 20:48:17 +00:00
|
|
|
}
|
|
|
|
]
|
2015-02-19 21:21:54 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'id': 'build_start',
|
|
|
|
'title': 'Dockerfile Build Started',
|
2016-09-14 20:48:17 +00:00
|
|
|
'icon': 'fa-circle-o-notch',
|
|
|
|
'fields': [
|
|
|
|
{
|
|
|
|
'name': 'ref-regex',
|
|
|
|
'type': 'regex',
|
|
|
|
'title': 'matching ref(s)',
|
|
|
|
'help_text': 'An optional regular expression for matching the git branch or tag ' +
|
|
|
|
'git ref. If left blank, the notification will fire for all builds.',
|
|
|
|
'optional': true,
|
|
|
|
}
|
|
|
|
]
|
2015-02-19 21:21:54 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'id': 'build_success',
|
|
|
|
'title': 'Dockerfile Build Successfully Completed',
|
2016-09-14 20:48:17 +00:00
|
|
|
'icon': 'fa-check-circle-o',
|
|
|
|
'fields': [
|
|
|
|
{
|
|
|
|
'name': 'ref-regex',
|
|
|
|
'type': 'regex',
|
|
|
|
'title': 'matching ref(s)',
|
|
|
|
'help_text': 'An optional regular expression for matching the git branch or tag ' +
|
|
|
|
'git ref. If left blank, the notification will fire for all builds.',
|
|
|
|
'optional': true,
|
|
|
|
}
|
|
|
|
]
|
2015-02-19 21:21:54 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'id': 'build_failure',
|
|
|
|
'title': 'Dockerfile Build Failed',
|
2016-09-14 20:48:17 +00:00
|
|
|
'icon': 'fa-times-circle-o',
|
|
|
|
'fields': [
|
|
|
|
{
|
|
|
|
'name': 'ref-regex',
|
|
|
|
'type': 'regex',
|
|
|
|
'title': 'matching ref(s)',
|
|
|
|
'help_text': 'An optional regular expression for matching the git branch or tag ' +
|
|
|
|
'git ref. If left blank, the notification will fire for all builds.',
|
|
|
|
'optional': true,
|
|
|
|
}
|
|
|
|
]
|
2015-02-19 21:21:54 +00:00
|
|
|
}];
|
|
|
|
|
|
|
|
for (var i = 0; i < buildEvents.length; ++i) {
|
|
|
|
events.push(buildEvents[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-13 22:14:52 +00:00
|
|
|
if (Features.SECURITY_SCANNER) {
|
|
|
|
events.push({
|
|
|
|
'id': 'vulnerability_found',
|
|
|
|
'title': 'Package Vulnerability Found',
|
2015-11-12 20:42:45 +00:00
|
|
|
'icon': 'fa-bug',
|
2015-10-13 22:14:52 +00:00
|
|
|
'fields': [
|
|
|
|
{
|
|
|
|
'name': 'level',
|
|
|
|
'type': 'enum',
|
2016-09-14 20:48:17 +00:00
|
|
|
'title': 'minimum severity level',
|
2015-10-13 22:14:52 +00:00
|
|
|
'values': VulnerabilityService.LEVELS,
|
2016-09-14 20:06:52 +00:00
|
|
|
'help_text': 'A vulnerability must have a severity of the chosen level (or higher) ' +
|
|
|
|
'for this notification to fire. Defcon 1 is a special severity level ' +
|
|
|
|
'manually tagged by the ' + Config.REGISTRY_TITLE_SHORT + ' team for ' +
|
|
|
|
'above-critical issues',
|
2015-10-13 22:14:52 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-02-19 21:21:54 +00:00
|
|
|
var methods = [
|
|
|
|
{
|
|
|
|
'id': 'quay_notification',
|
2016-08-25 18:57:48 +00:00
|
|
|
'title': Config.REGISTRY_TITLE_SHORT + ' Notification',
|
2015-02-19 21:21:54 +00:00
|
|
|
'icon': 'quay-icon',
|
|
|
|
'fields': [
|
|
|
|
{
|
|
|
|
'name': 'target',
|
|
|
|
'type': 'entity',
|
2016-09-14 20:06:52 +00:00
|
|
|
'title': 'Recipient',
|
|
|
|
'help_text': 'The ' + Config.REGISTRY_TITLE_SHORT + ' user to notify'
|
2015-02-19 21:21:54 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'id': 'email',
|
|
|
|
'title': 'E-mail',
|
|
|
|
'icon': 'fa-envelope',
|
|
|
|
'fields': [
|
|
|
|
{
|
|
|
|
'name': 'email',
|
|
|
|
'type': 'email',
|
|
|
|
'title': 'E-mail address'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'enabled': Features.MAILING
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'id': 'webhook',
|
|
|
|
'title': 'Webhook POST',
|
|
|
|
'icon': 'fa-link',
|
|
|
|
'fields': [
|
|
|
|
{
|
|
|
|
'name': 'url',
|
|
|
|
'type': 'url',
|
|
|
|
'title': 'Webhook URL'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'id': 'flowdock',
|
|
|
|
'title': 'Flowdock Team Notification',
|
|
|
|
'icon': 'flowdock-icon',
|
|
|
|
'fields': [
|
|
|
|
{
|
|
|
|
'name': 'flow_api_token',
|
|
|
|
'type': 'string',
|
|
|
|
'title': 'Flow API Token',
|
|
|
|
'help_url': 'https://www.flowdock.com/account/tokens'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'id': 'hipchat',
|
|
|
|
'title': 'HipChat Room Notification',
|
|
|
|
'icon': 'hipchat-icon',
|
|
|
|
'fields': [
|
|
|
|
{
|
|
|
|
'name': 'room_id',
|
2016-09-14 20:06:52 +00:00
|
|
|
'type': 'pattern',
|
2015-02-26 17:35:28 +00:00
|
|
|
'title': 'Room ID #',
|
2016-09-14 20:06:52 +00:00
|
|
|
'pattern': '^[0-9]+$',
|
2015-02-26 17:35:28 +00:00
|
|
|
'help_url': 'https://hipchat.com/admin/rooms',
|
2016-09-14 20:06:52 +00:00
|
|
|
'pattern_fail_message': 'We require the HipChat room <b>number</b>, not name.'
|
2015-02-19 21:21:54 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'notification_token',
|
|
|
|
'type': 'string',
|
|
|
|
'title': 'Room Notification Token',
|
|
|
|
'help_url': 'https://hipchat.com/rooms/tokens/{room_id}'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'id': 'slack',
|
|
|
|
'title': 'Slack Room Notification',
|
|
|
|
'icon': 'slack-icon',
|
|
|
|
'fields': [
|
|
|
|
{
|
|
|
|
'name': 'url',
|
2016-09-14 20:06:52 +00:00
|
|
|
'type': 'pattern',
|
2015-02-19 21:21:54 +00:00
|
|
|
'title': 'Webhook URL',
|
2016-09-14 20:06:52 +00:00
|
|
|
'pattern': '^https://hooks\\.slack\\.com/services/[A-Z0-9]+/[A-Z0-9]+/[a-zA-Z0-9]+$',
|
2015-02-19 21:21:54 +00:00
|
|
|
'help_url': 'https://slack.com/services/new/incoming-webhook',
|
|
|
|
'placeholder': 'https://hooks.slack.com/service/{some}/{token}/{here}'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
var methodMap = {};
|
|
|
|
var eventMap = {};
|
|
|
|
|
|
|
|
for (var i = 0; i < methods.length; ++i) {
|
|
|
|
methodMap[methods[i].id] = methods[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < events.length; ++i) {
|
|
|
|
eventMap[events[i].id] = events[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
externalNotificationData.getSupportedEvents = function() {
|
|
|
|
return events;
|
|
|
|
};
|
|
|
|
|
|
|
|
externalNotificationData.getSupportedMethods = function() {
|
|
|
|
var filtered = [];
|
|
|
|
for (var i = 0; i < methods.length; ++i) {
|
|
|
|
if (methods[i].enabled !== false) {
|
|
|
|
filtered.push(methods[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return filtered;
|
|
|
|
};
|
|
|
|
|
|
|
|
externalNotificationData.getEventInfo = function(event) {
|
|
|
|
return eventMap[event];
|
|
|
|
};
|
|
|
|
|
|
|
|
externalNotificationData.getMethodInfo = function(method) {
|
|
|
|
return methodMap[method];
|
|
|
|
};
|
|
|
|
|
|
|
|
return externalNotificationData;
|
|
|
|
}]);
|