Add show certification action to cluster panel
This patch adds show certification action as item action to cluster table view and details view. Change-Id: Iafb316152a1a16e6a056ea490adfc682fa68f5c9 Partial-Implements: blueprint cluster-certificates
This commit is contained in:
parent
da0c4c8406
commit
f07baab8e0
@ -30,6 +30,7 @@
|
||||
'horizon.framework.util.i18n.gettext',
|
||||
'horizon.dashboard.container-infra.clusters.create.service',
|
||||
'horizon.dashboard.container-infra.clusters.delete.service',
|
||||
'horizon.dashboard.container-infra.clusters.show-certificate.service',
|
||||
'horizon.dashboard.container-infra.clusters.resourceType',
|
||||
];
|
||||
|
||||
@ -38,6 +39,7 @@
|
||||
gettext,
|
||||
createClusterService,
|
||||
deleteClusterService,
|
||||
showCertificateService,
|
||||
resourceType)
|
||||
{
|
||||
var clusterResourceType = registry.getResourceType(resourceType);
|
||||
@ -49,6 +51,13 @@
|
||||
type: 'delete',
|
||||
text: gettext('Delete Cluster')
|
||||
}
|
||||
})
|
||||
.append({
|
||||
id: 'showCertificateAction',
|
||||
service: showCertificateService,
|
||||
template: {
|
||||
text: gettext('Show Certificate')
|
||||
}
|
||||
});
|
||||
|
||||
clusterResourceType.batchActions
|
||||
|
@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License. You may obtain
|
||||
* a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @ngdoc overview
|
||||
* @name horizon.dashboard.container-infra.clusters.show-certificate.service
|
||||
* @description Service for the container-infra cluster show certificate modal
|
||||
*/
|
||||
angular
|
||||
.module('horizon.dashboard.container-infra.clusters')
|
||||
.factory('horizon.dashboard.container-infra.clusters.show-certificate.service', showCertificateService);
|
||||
|
||||
showCertificateService.$inject = [
|
||||
'horizon.framework.util.q.extensions',
|
||||
'horizon.app.core.openstack-service-api.magnum'
|
||||
];
|
||||
|
||||
function showCertificateService(
|
||||
$qExtensions, magnum
|
||||
) {
|
||||
|
||||
var service = {
|
||||
initScope: initScope,
|
||||
perform: perform,
|
||||
allowed: allowed
|
||||
};
|
||||
|
||||
return service;
|
||||
|
||||
//////////////
|
||||
|
||||
function initScope($scope) {
|
||||
}
|
||||
|
||||
function perform(selected) {
|
||||
// get certificate
|
||||
return magnum.showCertificate(selected.id).success(function(response) {
|
||||
magnum.downloadTextAsFile(response.pem, selected.name + "_ca.pem");
|
||||
});
|
||||
}
|
||||
|
||||
function allowed() {
|
||||
return $qExtensions.booleanAsPromise(true);
|
||||
}
|
||||
}
|
||||
})();
|
@ -21,12 +21,13 @@
|
||||
.factory('horizon.app.core.openstack-service-api.magnum', MagnumAPI);
|
||||
|
||||
MagnumAPI.$inject = [
|
||||
'$timeout',
|
||||
'horizon.framework.util.http.service',
|
||||
'horizon.framework.widgets.toast.service',
|
||||
'horizon.framework.util.i18n.gettext'
|
||||
];
|
||||
|
||||
function MagnumAPI(apiService, toastService, gettext) {
|
||||
function MagnumAPI($timeout, apiService, toastService, gettext) {
|
||||
var service = {
|
||||
createCluster: createCluster,
|
||||
getCluster: getCluster,
|
||||
@ -40,6 +41,7 @@
|
||||
deleteClusterTemplates: deleteClusterTemplates,
|
||||
showCertificate: showCertificate,
|
||||
signCertificate: signCertificate,
|
||||
downloadTextAsFile: downloadTextAsFile,
|
||||
};
|
||||
|
||||
return service;
|
||||
@ -143,5 +145,24 @@
|
||||
toastService.add('error', gettext('Unable to retrieve the certificate.'));
|
||||
});
|
||||
}
|
||||
|
||||
function downloadTextAsFile(text, filename){
|
||||
// create text file as object url
|
||||
var blob = new Blob([ text ], { "type" : "text/plain" });
|
||||
window.URL = window.URL || window.webkitURL;
|
||||
var fileurl = window.URL.createObjectURL(blob);
|
||||
|
||||
// provide text as downloaded file
|
||||
$timeout(function() {
|
||||
//Update view
|
||||
var a = angular.element('<a></a>');
|
||||
a.attr("href", fileurl);
|
||||
a.attr("download", filename);
|
||||
a.attr("target", "_blank");
|
||||
angular.element(document.body).append(a);
|
||||
a[0].click();
|
||||
a.remove();
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
}());
|
||||
|
Loading…
Reference in New Issue
Block a user