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',
|
|
|
|
'icon': 'fa-tasks'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'id': 'build_start',
|
|
|
|
'title': 'Dockerfile Build Started',
|
|
|
|
'icon': 'fa-circle-o-notch'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'id': 'build_success',
|
|
|
|
'title': 'Dockerfile Build Successfully Completed',
|
|
|
|
'icon': 'fa-check-circle-o'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'id': 'build_failure',
|
|
|
|
'title': 'Dockerfile Build Failed',
|
|
|
|
'icon': 'fa-times-circle-o'
|
|
|
|
}];
|
|
|
|
|
|
|
|
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',
|
2015-11-12 20:42:45 +00:00
|
|
|
'title': 'Minimum Priority Level',
|
2015-10-13 22:14:52 +00:00
|
|
|
'values': VulnerabilityService.LEVELS,
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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',
|
|
|
|
'title': 'Recipient'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'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',
|
2015-02-26 17:35:28 +00:00
|
|
|
'type': 'regex',
|
|
|
|
'title': 'Room ID #',
|
|
|
|
'regex': '^[0-9]+$',
|
|
|
|
'help_url': 'https://hipchat.com/admin/rooms',
|
|
|
|
'regex_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',
|
|
|
|
'type': 'regex',
|
|
|
|
'title': 'Webhook URL',
|
|
|
|
'regex': '^https://hooks\\.slack\\.com/services/[A-Z0-9]+/[A-Z0-9]+/[a-zA-Z0-9]+$',
|
|
|
|
'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;
|
|
|
|
}]);
|