Implement setup tool support for Clair

Fixes #1387
This commit is contained in:
Joseph Schorr 2016-05-02 15:29:31 -04:00
parent 53ce4de6aa
commit 2cbdecb043
23 changed files with 584 additions and 116 deletions

View file

@ -61,6 +61,10 @@ angular.module("core-config-setup", ['angularFileUpload'])
{'id': 'gitlab-trigger', 'title': 'GitLab Build Triggers', 'condition': function(config) {
return config.FEATURE_GITLAB_BUILD;
}},
{'id': 'security-scanner', 'title': 'Quay Security Scanner', 'condition': function(config) {
return config.FEATURE_SECURITY_SCANNER;
}}
];
@ -1029,6 +1033,87 @@ angular.module("core-config-setup", ['angularFileUpload'])
return directiveDefinitionObject;
})
.directive('configServiceKeyField', function (ApiService) {
var directiveDefinitionObject = {
priority: 0,
templateUrl: '/static/directives/config/config-service-key-field.html',
replace: false,
transclude: false,
restrict: 'C',
scope: {
'serviceName': '@serviceName',
},
controller: function($scope, $element) {
$scope.foundKeys = [];
$scope.loading = false;
$scope.loadError = false;
$scope.hasValidKey = false;
$scope.hasValidKeyStr = null;
$scope.updateKeys = function() {
$scope.foundKeys = [];
$scope.loading = true;
ApiService.listServiceKeys().then(function(resp) {
$scope.loading = false;
$scope.loadError = false;
resp['keys'].forEach(function(key) {
if (key['service'] == $scope.serviceName) {
$scope.foundKeys.push(key);
}
});
$scope.hasValidKey = checkValidKey($scope.foundKeys);
$scope.hasValidKeyStr = $scope.hasValidKey ? 'true' : '';
}, function() {
$scope.loading = false;
$scope.loadError = true;
});
};
// Perform initial loading of the keys.
$scope.updateKeys();
$scope.isKeyExpired = function(key) {
if (key.expiration_date != null) {
var expiration_date = moment(key.expiration_date);
return moment().isAfter(expiration_date);
}
return false;
};
$scope.showRequestServiceKey = function() {
$scope.requestKeyInfo = {
'service': $scope.serviceName
};
};
$scope.handleKeyCreated = function() {
$scope.updateKeys();
};
var checkValidKey = function(keys) {
for (var i = 0; i < keys.length; ++i) {
var key = keys[i];
if (!key.approval) {
continue;
}
if ($scope.isKeyExpired(key)) {
continue;
}
return true;
}
return false;
};
}
};
return directiveDefinitionObject;
})
.directive('configStringField', function () {
var directiveDefinitionObject = {
priority: 0,

View file

@ -0,0 +1,120 @@
/**
* An element which displays a dialog for requesting or creating a service key.
*/
angular.module('quay').directive('requestServiceKeyDialog', function () {
var directiveDefinitionObject = {
priority: 0,
templateUrl: '/static/directives/request-service-key-dialog.html',
replace: false,
transclude: true,
restrict: 'C',
scope: {
'requestKeyInfo': '=requestKeyInfo',
'keyCreated': '&keyCreated'
},
controller: function($scope, $element, $timeout, ApiService) {
var handleNewKey = function(key) {
var data = {
'notes': 'Approved during setup of service ' + key.service
};
var params = {
'kid': key.kid
};
ApiService.approveServiceKey(data, params).then(function(resp) {
$scope.keyCreated({'key': key});
$scope.step = 2;
}, ApiService.errorDisplay('Could not approve service key'));
};
var checkKeys = function() {
var isShown = ($element.find('.modal').data('bs.modal') || {}).isShown;
if (!isShown) {
return;
}
// TODO: filter by service.
ApiService.listServiceKeys().then(function(resp) {
var keys = resp['keys'];
for (var i = 0; i < keys.length; ++i) {
var key = keys[i];
if (key.service == $scope.requestKeyInfo.service && !key.approval && key.rotation_duration) {
handleNewKey(key);
return;
}
}
$timeout(checkKeys, 1000);
}, ApiService.errorDisplay('Could not list service keys'));
};
$scope.show = function() {
$scope.working = false;
$scope.step = 0;
$scope.requestKind = null;
$scope.preshared = {
'name': $scope.requestKeyInfo.service + ' Service Key',
'notes': 'Created during setup for service `' + $scope.requestKeyInfo.service + '`'
};
$element.find('.modal').modal({});
};
$scope.hide = function() {
$scope.loading = false;
$element.find('.modal').modal('hide');
};
$scope.showGenerate = function() {
$scope.step = 1;
};
$scope.startApproval = function() {
$scope.step = 1;
checkKeys();
};
$scope.isDownloadSupported = function() {
var isSafari = /^((?!chrome).)*safari/i.test(navigator.userAgent);
if (isSafari) {
// Doesn't work properly in Safari, sadly.
return false;
}
try { return !!new Blob(); } catch(e) {}
return false;
};
$scope.downloadPrivateKey = function(key) {
var blob = new Blob([key.private_key]);
saveAs(blob, key.service + '.pem');
};
$scope.createPresharedKey = function() {
$scope.working = true;
var data = {
'name': $scope.preshared.name,
'service': $scope.requestKeyInfo.service,
'expiration': $scope.preshared.expiration || null,
'notes': $scope.preshared.notes
};
ApiService.createServiceKey(data).then(function(resp) {
$scope.working = false;
$scope.step = 2;
$scope.createdKey = resp;
$scope.keyCreated({'key': resp});
}, ApiService.errorDisplay('Could not create service key'));
};
$scope.$watch('requestKeyInfo', function(info) {
if (info && info.service) {
$scope.show();
}
});
}
};
return directiveDefinitionObject;
});

View file

@ -1,13 +1,12 @@
(function() {
/**
* The Setup page provides a nice GUI walkthrough experience for setting up the Enterprise
* Registry.
* The Setup page provides a nice GUI walkthrough experience for setting up Quay Enterprise.
*/
angular.module('quayPages').config(['pages', function(pages) {
pages.create('setup', 'setup.html', SetupCtrl,
{
'newLayout': true,
'title': 'Enterprise Registry Setup'
'title': 'Quay Enterprise Setup'
})
}]);

View file

@ -1,6 +1,6 @@
(function() {
/**
* The superuser admin page provides a new management UI for the Enterprise Registry.
* The superuser admin page provides a new management UI for Quay Enterprise.
*/
angular.module('quayPages').config(['pages', function(pages) {
pages.create('superuser', 'super-user.html', SuperuserCtrl,