a959d2d908
* create generate key form * disable key bits unless key type selected * add create method to adapter, update serializer to remove type * refactor key parameters component * convert to typescript * refactor routes to add controller breadcrumbs * remove unnecessary attr * revert typescript changes * add validations to key type * fix tests * cleanup breadcrumbs * update tests, change all bit types to strings * add form test
43 lines
1.4 KiB
JavaScript
43 lines
1.4 KiB
JavaScript
import Component from '@glimmer/component';
|
|
import { action } from '@ember/object';
|
|
|
|
/**
|
|
* @module PkiKeyParameters
|
|
* 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.
|
|
* If the component renders in a group, other attrs may be passed in and will be rendered using the <FormField> component
|
|
* @example
|
|
* ```js
|
|
* <PkiKeyParameters @model={{@model}} @fields={{fields}}/>
|
|
* ```
|
|
* @param {class} model - The pki/role model.
|
|
* @param {string} fields - Array of attributes from a formFieldGroup generated by the @withFormFields decorator ex: [{ name: 'attrName', type: 'string', options: {...} }]
|
|
*/
|
|
|
|
// first value in array is the default bits for that key type
|
|
const KEY_BITS_OPTIONS = {
|
|
rsa: ['2048', '3072', '4096'],
|
|
ec: ['256', '224', '384', '521'],
|
|
ed25519: ['0'],
|
|
any: ['0'],
|
|
};
|
|
|
|
export default class PkiKeyParameters extends Component {
|
|
get keyBitOptions() {
|
|
return KEY_BITS_OPTIONS[this.args.model.keyType];
|
|
}
|
|
|
|
@action handleSelection(name, selection) {
|
|
this.args.model[name] = selection;
|
|
|
|
if (name === 'keyType') {
|
|
this.args.model.keyBits = Object.keys(KEY_BITS_OPTIONS).includes(selection)
|
|
? KEY_BITS_OPTIONS[selection][0]
|
|
: '';
|
|
}
|
|
}
|
|
|
|
@action onKeyBitsChange({ target }) {
|
|
this.handleSelection(target.name, target.value);
|
|
}
|
|
}
|