Skip to content

Commit

Permalink
feat: implement possibility to add additional ssh keys (#108)
Browse files Browse the repository at this point in the history
Co-authored-by: Max Schmitt <max@schmitt.mx>
  • Loading branch information
Audifire and mxschmitt committed Jan 22, 2021
1 parent 55886d7 commit 8697b94
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
27 changes: 22 additions & 5 deletions component/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
Expand All @@ -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,
Expand All @@ -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) {
Expand All @@ -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, {
Expand Down
10 changes: 10 additions & 0 deletions component/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@
</label>
</div>
</div>
<div class="col-md-2">
<label class="form-control-static">Additional SSH Keys</label>
</div>
<div class="col-md-4">
<select class="form-control" onchange={{action 'modifyKeys' }} multiple="true">
{{#each keyChoices as |key|}}
<option value={{key.id}} selected={{array-includes model.hetznerConfig.additionalKey key.public_key}}>{{key.name}} ({{key.fingerprint}})</option>
{{/each}}
</select>
</div>
</div>
{{!-- This following contains the Name, Labels and Engine Options fields --}}
{{form-name-description model=model nameRequired=true}}
Expand Down

0 comments on commit 8697b94

Please sign in to comment.