Add CA Certificate to kubeconfig

This commit is contained in:
Vincent Fiduccia 2018-01-23 12:12:41 -07:00
parent 1b9cd1b2d2
commit d3a9ca064a
No known key found for this signature in database
GPG Key ID: 2B29AD6BB2BB2582
4 changed files with 21 additions and 11 deletions

View File

@ -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() {

View File

@ -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);
},

View File

@ -4,7 +4,7 @@
{{/if}}
{{#if (eq step 2)}}
<p>{{t 'k8sPage.configFile.usage.helpText' htmlSafe=true}}</p>
<pre><code>{{kubeconfig}}</code></pre>
{{code-block language="yaml" code=kubeconfig}}
{{copy-to-clipboard tooltipText="" buttonText="copyToClipboard.tooltip" clipboardText=kubeconfig class="with-clip"}}
<p class="mt-10 mb-0">{{t 'k8sPage.configFile.usage.downloadText' downloadUrl=downloadUrl htmlSafe=true}}</p>
{{/if}}

View File

@ -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',