From d3a9ca064a52840a7ab90330e1cd546b3674e44c Mon Sep 17 00:00:00 2001 From: Vincent Fiduccia Date: Tue, 23 Jan 2018 12:12:41 -0700 Subject: [PATCH] Add CA Certificate to kubeconfig --- .../components/modal-edit-apikey/component.js | 4 ++-- .../components/modal-kubeconfig/component.js | 24 +++++++++++++------ .../components/modal-kubeconfig/template.hbs | 2 +- lib/shared/addon/utils/constants.js | 2 +- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/shared/addon/components/modal-edit-apikey/component.js b/lib/shared/addon/components/modal-edit-apikey/component.js index f85b676d5..fadf99fe6 100644 --- a/lib/shared/addon/components/modal-edit-apikey/component.js +++ b/lib/shared/addon/components/modal-edit-apikey/component.js @@ -23,11 +23,11 @@ export default Component.extend(ModalBase, NewOrEdit, { }, displayEndpoint: function() { - return this.get('endpointService.api.display.account.current'); + return this.get('endpointService.api.display.current'); }.property(), linkEndpoint: function() { - return this.get('endpointService.api.auth.account.current'); + return this.get('endpointService.api.auth.current'); }.property(), didInsertElement() { diff --git a/lib/shared/addon/components/modal-kubeconfig/component.js b/lib/shared/addon/components/modal-kubeconfig/component.js index eafe0eb54..05d831e49 100644 --- a/lib/shared/addon/components/modal-kubeconfig/component.js +++ b/lib/shared/addon/components/modal-kubeconfig/component.js @@ -11,8 +11,7 @@ clusters: - name: "%clusterName%" cluster: server: "%baseUrl%/k8s/clusters/%clusterId%" - api-version: v1%maybeInsecure%%maybeCertificate% - certificate-authority-data: %clusterCert% + api-version: v1%maybeCertificate% users: - name: "%username%" @@ -37,6 +36,7 @@ export default Component.extend(ModalBase, { access: service(), growl: service(), scope: service(), + settings: service(), modalService: service('modal'), token: null, @@ -47,19 +47,30 @@ export default Component.extend(ModalBase, { replaceVariables(str) { let base = window.location.origin; - let insecure = false; if ( base.indexOf('http://') === 0 ) { base = base.replace(/^http:\/\//,'https://'); if ( ! window.location.port ) { base += ':80'; } - insecure = true; } const me = get(this, 'access.me'); const cluster = get(this, 'scope.currentCluster'); const tokenObj = get(this, 'token'); - const certificate = get(this, `settings.${C.SETTING.CA_CERTS}`); + + let cert = get(this, `settings.${C.SETTING.CA_CERTS}`); + let wrapped; + if ( cert && cert.length ) { + let ary = []; + cert = btoa(cert); + let split = 45; + while ( cert.length ) { + ary.push(cert.substr(0,split)) + cert = cert.substr(split); + split=72; + } + wrapped = ary.join('\\\n ').trim(); + } let token = ''; if ( tokenObj ) { @@ -68,10 +79,9 @@ export default Component.extend(ModalBase, { return str .replace(/%baseUrl%/g, base) - .replace(/%maybeInsecure%/g,(insecure ? '\n insecure-skip-tls-verify: true' : '')) .replace(/%clusterId%/g, get(cluster, 'id')) .replace(/%clusterName%/g, get(cluster, 'displayName')) - .replace(/%maybeCertificate%/g, (certificate ? '\n certificate-authority-data: ' + certificate : '')) + .replace(/%maybeCertificate%/g, (wrapped ? '\n certificate-authority-data: "' + wrapped + '"': '')) .replace(/%username%/g, get(me, 'username')) .replace(/%token%/g, token); }, diff --git a/lib/shared/addon/components/modal-kubeconfig/template.hbs b/lib/shared/addon/components/modal-kubeconfig/template.hbs index ea9debe26..74ae33872 100644 --- a/lib/shared/addon/components/modal-kubeconfig/template.hbs +++ b/lib/shared/addon/components/modal-kubeconfig/template.hbs @@ -4,7 +4,7 @@ {{/if}} {{#if (eq step 2)}}

{{t 'k8sPage.configFile.usage.helpText' htmlSafe=true}}

-
{{kubeconfig}}
+ {{code-block language="yaml" code=kubeconfig}} {{copy-to-clipboard tooltipText="" buttonText="copyToClipboard.tooltip" clipboardText=kubeconfig class="with-clip"}}

{{t 'k8sPage.configFile.usage.downloadText' downloadUrl=downloadUrl htmlSafe=true}}

{{/if}} diff --git a/lib/shared/addon/utils/constants.js b/lib/shared/addon/utils/constants.js index 5c01ce49d..4a9ef29ee 100644 --- a/lib/shared/addon/utils/constants.js +++ b/lib/shared/addon/utils/constants.js @@ -423,7 +423,7 @@ var C = { WINDOWS: 'cli-url-windows', LINUX: 'cli-url-linux', }, - CA_CERTS: 'ca-certs', + CA_CERTS: 'cacerts', API_HOST: 'api-host', ENGINE_URL: 'engine-install-url', SUPPORTED_DOCKER: 'engine-supported-range',