From f07baab8e012ccd14492a4ab2c764e1cff3b557f Mon Sep 17 00:00:00 2001 From: Shu Muto Date: Fri, 2 Sep 2016 17:52:29 +0900 Subject: [PATCH] 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 --- .../clusters/actions.module.js | 9 +++ .../show-certificate.service.js | 60 +++++++++++++++++++ .../container-infra/magnum.service.js | 23 ++++++- 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 magnum_ui/static/dashboard/container-infra/clusters/show-certificate/show-certificate.service.js diff --git a/magnum_ui/static/dashboard/container-infra/clusters/actions.module.js b/magnum_ui/static/dashboard/container-infra/clusters/actions.module.js index d36c0510..25eef828 100644 --- a/magnum_ui/static/dashboard/container-infra/clusters/actions.module.js +++ b/magnum_ui/static/dashboard/container-infra/clusters/actions.module.js @@ -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 diff --git a/magnum_ui/static/dashboard/container-infra/clusters/show-certificate/show-certificate.service.js b/magnum_ui/static/dashboard/container-infra/clusters/show-certificate/show-certificate.service.js new file mode 100644 index 00000000..e1fbda3f --- /dev/null +++ b/magnum_ui/static/dashboard/container-infra/clusters/show-certificate/show-certificate.service.js @@ -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); + } + } +})(); diff --git a/magnum_ui/static/dashboard/container-infra/magnum.service.js b/magnum_ui/static/dashboard/container-infra/magnum.service.js index 3a047f6a..a5a2c148 100644 --- a/magnum_ui/static/dashboard/container-infra/magnum.service.js +++ b/magnum_ui/static/dashboard/container-infra/magnum.service.js @@ -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.attr("href", fileurl); + a.attr("download", filename); + a.attr("target", "_blank"); + angular.element(document.body).append(a); + a[0].click(); + a.remove(); + }, 0); + } } }());