2022-10-19 21:28:43 +00:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import { action } from '@ember/object';
|
|
|
|
|
|
|
|
/**
|
2022-11-18 00:50:58 +00:00
|
|
|
* @module PkiKeyParameters
|
2022-12-08 22:22:33 +00:00
|
|
|
* PkiKeyParameters components are used to display a list of key bit options depending on the selected key type. The key bits field is disabled until a key type is selected.
|
2022-11-21 22:58:34 +00:00
|
|
|
* If the component renders in a group, other attrs may be passed in and will be rendered using the <FormField> component
|
2022-10-19 21:28:43 +00:00
|
|
|
* @example
|
|
|
|
* ```js
|
2022-11-21 22:58:34 +00:00
|
|
|
* <PkiKeyParameters @model={{@model}} @fields={{fields}}/>
|
2022-10-19 21:28:43 +00:00
|
|
|
* ```
|
2022-11-10 21:27:19 +00:00
|
|
|
* @param {class} model - The pki/role model.
|
2022-12-08 22:22:33 +00:00
|
|
|
* @param {string} fields - Array of attributes from a formFieldGroup generated by the @withFormFields decorator ex: [{ name: 'attrName', type: 'string', options: {...} }]
|
2022-10-19 21:28:43 +00:00
|
|
|
*/
|
|
|
|
|
2022-12-08 22:22:33 +00:00
|
|
|
// first value in array is the default bits for that key type
|
2022-10-19 21:28:43 +00:00
|
|
|
const KEY_BITS_OPTIONS = {
|
2022-12-08 22:22:33 +00:00
|
|
|
rsa: ['2048', '3072', '4096'],
|
|
|
|
ec: ['256', '224', '384', '521'],
|
|
|
|
ed25519: ['0'],
|
|
|
|
any: ['0'],
|
2022-10-19 21:28:43 +00:00
|
|
|
};
|
|
|
|
|
2022-11-18 00:50:58 +00:00
|
|
|
export default class PkiKeyParameters extends Component {
|
2022-10-19 21:28:43 +00:00
|
|
|
get keyBitOptions() {
|
|
|
|
return KEY_BITS_OPTIONS[this.args.model.keyType];
|
|
|
|
}
|
|
|
|
|
2022-12-08 22:22:33 +00:00
|
|
|
@action handleSelection(name, selection) {
|
|
|
|
this.args.model[name] = selection;
|
2022-10-19 21:28:43 +00:00
|
|
|
|
|
|
|
if (name === 'keyType') {
|
2022-12-08 22:22:33 +00:00
|
|
|
this.args.model.keyBits = Object.keys(KEY_BITS_OPTIONS).includes(selection)
|
|
|
|
? KEY_BITS_OPTIONS[selection][0]
|
|
|
|
: '';
|
2022-10-19 21:28:43 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-08 22:22:33 +00:00
|
|
|
|
|
|
|
@action onKeyBitsChange({ target }) {
|
|
|
|
this.handleSelection(target.name, target.value);
|
|
|
|
}
|
2022-10-19 21:28:43 +00:00
|
|
|
}
|