-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathchoose-pgp-key-form.js
57 lines (49 loc) · 1.67 KB
/
choose-pgp-key-form.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { action } from '@ember/object';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
const pgpKeyFileDefault = () => ({ value: '' });
/**
* @module ChoosePgpKeyForm
* ChoosePgpKeyForm component is used for DR Operation Token Generation workflow. It provides
* an interface for the user to upload or paste a PGP key for use
*
* @example
* <ChoosePgpKeyForm @onCancel={{log "cancel!"}} @onSubmit={{log "submit!"}} />
*
* @param {function} onCancel - required - This function will be triggered when the modal intends to be closed
* @param {function} onSubmit - required - When the PGP key is confirmed, it will call this method with the pgpKey value as the only param
* @param {string} buttonText - Button text for onSubmit. Defaults to "Continue with key"
* @param {string} formText - Form text above where the users uploads or pastes the key. Has default
*/
export default class ChoosePgpKeyForm extends Component {
@tracked pgpKeyFile = pgpKeyFileDefault();
@tracked selectedPgp = '';
get pgpKey() {
return this.pgpKeyFile.value;
}
get buttonText() {
return this.args.buttonText || 'Continue with key';
}
get formText() {
return (
this.args.formText ||
'Choose a PGP Key from your computer or paste the contents of one in the form below.'
);
}
@action setKey(_, keyFile) {
this.pgpKeyFile = keyFile;
}
// Form submit actions:
@action usePgpKey(evt) {
evt.preventDefault();
this.selectedPgp = this.pgpKey;
}
@action handleSubmit(evt) {
evt.preventDefault();
this.args.onSubmit(this.pgpKey);
}
}