Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

Commit 81b0ad1

Browse files
committed
use cloud credentials to store apikeys
1 parent 47d9c1c commit 81b0ad1

File tree

2 files changed

+42
-19
lines changed

2 files changed

+42
-19
lines changed

component/component.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import NodeDriver from 'shared/mixins/node-driver';
1+
import NodeDriver, { DynamicDependentKeysProperty, registerDisplayLocation, registerDisplaySize } from 'shared/mixins/node-driver';
22
import fetch from '@rancher/ember-api-store/utils/fetch';
33
const LAYOUT;
44

5+
registerDisplayLocation(new DynamicDependentKeysProperty({ driver: '%%DRIVERNAME%%', keyOrKeysToWatch: 'config.facilityCode' }));
6+
registerDisplaySize(new DynamicDependentKeysProperty({ driver: '%%DRIVERNAME%%', keyOrKeysToWatch: 'config.plan' }));
7+
58
const OS_WHITELIST = ['centos_7', 'coreos_stable', 'ubuntu_14_04', 'ubuntu_16_04', 'ubuntu_18_04', 'rancher'];
69
const PLAN_BLACKLIST = ['baremetal_2a']; // quick wheres james spader?
710
const DEFAULTS = {
@@ -21,12 +24,15 @@ const isEmpty = Ember.isEmpty;
2124

2225
export default Ember.Component.extend(NodeDriver, {
2326
driverName: 'packet',
27+
cloudCredentials: null,
2428
facilityChoices: null,
2529
planChoices: null,
2630
osChoices: null,
2731
step: 1,
2832

2933
config: alias('model.packetConfig'),
34+
app: service(),
35+
intl: service(),
3036

3137
init() {
3238
const decodedLayout = window.atob(LAYOUT);
@@ -46,7 +52,19 @@ export default Ember.Component.extend(NodeDriver, {
4652
},
4753

4854
actions: {
55+
finishAndSelectCloudCredential(cred) {
56+
if (cred) {
57+
set(this, 'model.cloudCredentialId', get(cred, 'id'));
58+
59+
this.send('authPacket');
60+
}
61+
},
4962
authPacket(savedCB) {
63+
const auth = {
64+
type: 'cloud',
65+
token: get(this, 'model.cloudCredentialId'),
66+
};
67+
5068
if (!this.validateAuthentication()) {
5169
savedCB(false);
5270
return;
@@ -160,10 +178,10 @@ export default Ember.Component.extend(NodeDriver, {
160178

161179
bootstrap() {
162180
let store = get(this, 'globalStore');
181+
set(this, 'cloudCredentials', this.globalStore.all('cloudCredential'));
163182
let config = store.createRecord({
164183
type: 'packetConfig',
165184
projectId: '',
166-
apiKey: '',
167185
hwReservationId: '',
168186
deviceType: 'on-demand',
169187
});
@@ -267,6 +285,10 @@ export default Ember.Component.extend(NodeDriver, {
267285
errors.push('Plan is requried');
268286
}
269287

288+
if (!this.validateCloudCredentials()) {
289+
errors.push(this.intl.t('nodeDriver.cloudCredentialError'));
290+
}
291+
270292
if (errors.length) {
271293
set(this, 'errors', errors.uniq());
272294

component/template.hbs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,24 @@
2121
}}
2222
{{/input-or-display}}
2323
</div>
24-
<div class="col span-6">
25-
<label class="acc-label">
26-
{{t "nodeDriver.packet.apiKey.label"}}{{field-required}}
27-
</label>
28-
{{#input-or-display editable=(not dataFetched) value=config.apiKey obfuscate=true}}
29-
{{input
30-
type="password"
31-
name="password"
32-
value=config.apiKey
33-
classNames="form-control"
34-
placeholder=(t "nodeDriver.packet.apiKey.placeholder")
35-
}}
36-
{{/input-or-display}}
37-
<p class="text-info">
38-
{{t "nodeDriver.packet.apiKeyHelp" htmlSafe=true}}
39-
</p>
40-
</div>
24+
{{#accordion-list-item
25+
title=(t "modalAddCloudKey.packet.token.label")
26+
detail=(t "modalAddCloudKey.packet.token.help" htmlSafe=true)
27+
expandAll=expandAll
28+
expand=(action expandFn)
29+
expandOnInit=true
30+
}}
31+
{{form-auth-cloud-credential
32+
driverName=driverName
33+
parseAndCollectErrors=(action "errorHandler")
34+
primaryResource=primaryResource
35+
cloudCredentials=cloudCredentials
36+
finishAndSelectCloudCredential=(action "finishAndSelectCloudCredential")
37+
progressStep=(action "authPacket")
38+
cancel=(action "cancel")
39+
createLabel="modalAddCloudKey.packet.authAccountButton"
40+
}}
41+
{{/accordion-list-item}}
4142
</div>
4243
</div>
4344

0 commit comments

Comments
 (0)