From 8697b9489d6abef3861ea34322389efc3e6b0588 Mon Sep 17 00:00:00 2001 From: Audifire Date: Fri, 22 Jan 2021 12:09:57 +0100 Subject: [PATCH] feat: implement possibility to add additional ssh keys (#108) Co-authored-by: Max Schmitt --- component/component.js | 27 ++++++++++++++++++++++----- component/template.hbs | 10 ++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/component/component.js b/component/component.js index 54079a4..b462529 100644 --- a/component/component.js +++ b/component/component.js @@ -46,6 +46,7 @@ export default Ember.Component.extend(NodeDriver, { // bootstrap is called by rancher ui on 'init', you're better off doing your setup here rather then the init function to ensure everything is setup correctly let config = get(this, 'globalStore').createRecord({ type: '%%DRIVERNAME%%Config', + additionalKey: [], serverType: 'cx21', // 4 GB Ram serverLocation: 'nbg1', // Nuremberg imageId: "168855", // ubuntu-18.04 @@ -71,6 +72,10 @@ export default Ember.Component.extend(NodeDriver, { this.set('model.%%DRIVERNAME%%Config.serverLabel', []) } + if (!this.get('model.%%DRIVERNAME%%Config.additionalKey')) { + this.set('model.%%DRIVERNAME%%Config.additionalKey', []) + } + var errors = get(this, 'errors') || []; if (!get(this, 'model.name')) { errors.push('Name is required'); @@ -90,7 +95,7 @@ export default Ember.Component.extend(NodeDriver, { getData() { this.set('gettingData', true); let that = this; - Promise.all([this.apiRequest('/v1/locations'), this.apiRequest('/v1/images'), this.apiRequest('/v1/server_types'), this.apiRequest('/v1/networks')]).then(function (responses) { + Promise.all([this.apiRequest('/v1/locations'), this.apiRequest('/v1/images'), this.apiRequest('/v1/server_types'), this.apiRequest('/v1/networks'), this.apiRequest('/v1/ssh_keys')]).then(function (responses) { that.setProperties({ errors: [], needAPIToken: false, @@ -102,10 +107,16 @@ export default Ember.Component.extend(NodeDriver, { id: image.id.toString() })), sizeChoices: responses[2].server_types, - networkChoices: responses[3].networks.map(network => ({ - ...network, - id: network.id.toString() - })) + networkChoices: responses[3].networks + .map(network => ({ + ...network, + id: network.id.toString() + })), + keyChoices: responses[4].ssh_keys + .map(key => ({ + ...key, + id: key.id.toString() + })) }); }).catch(function (err) { err.then(function (msg) { @@ -126,6 +137,12 @@ export default Ember.Component.extend(NodeDriver, { this._super(labels); }, + modifyKeys: function (select) { + let options = [...select.target.options] + .filter(o => o.selected) + .map(o => this.keyChoices.find(keyChoice => keyChoice.id == o.value)["public_key"]); + this.set('model.%%DRIVERNAME%%Config.additionalKey', options); + }, }, apiRequest(path) { return fetch('https://api.hetzner.cloud' + path, { diff --git a/component/template.hbs b/component/template.hbs index f45dd97..11f8da5 100644 --- a/component/template.hbs +++ b/component/template.hbs @@ -94,6 +94,16 @@ +
+ +
+
+ +
{{!-- This following contains the Name, Labels and Engine Options fields --}} {{form-name-description model=model nameRequired=true}}