889d82aca5
* Update role toolbar, serialization for special mongo values * Only show defaultShown if no value on info table row * Remove root_rotation_statements from mongo connection fields * Wrap this.router in try/catch if in then statement * Add changelog
65 lines
2.3 KiB
JavaScript
65 lines
2.3 KiB
JavaScript
/**
|
|
* @module DatabaseRoleSettingForm
|
|
* DatabaseRoleSettingForm components are used to handle the role settings section on the database/role form
|
|
*
|
|
* @example
|
|
* ```js
|
|
* <DatabaseRoleSettingForm @requiredParam={requiredParam} @optionalParam={optionalParam} @param1={{param1}}/>
|
|
* ```
|
|
* @param {Array<object>} attrs - all available attrs from the model to iterate over
|
|
* @param {object} model - ember data model which should be updated on change
|
|
* @param {string} [roleType] - role type controls which attributes are shown
|
|
* @param {string} [mode=create] - mode of the form (eg. create or edit)
|
|
* @param {string} [dbType=default] - type of database, eg 'mongodb-database-plugin'
|
|
*/
|
|
|
|
import Component from '@glimmer/component';
|
|
|
|
// Below fields are intended to be dynamic based on type of role and db.
|
|
// example of usage: FIELDS[roleType][db]
|
|
const ROLE_FIELDS = {
|
|
static: {
|
|
default: ['ttl', 'max_ttl', 'username', 'rotation_period'],
|
|
'mongodb-database-plugin': ['username', 'rotation_period'],
|
|
},
|
|
dynamic: {
|
|
default: ['ttl', 'max_ttl', 'username', 'rotation_period'],
|
|
'mongodb-database-plugin': ['ttl', 'max_ttl'],
|
|
},
|
|
};
|
|
|
|
const STATEMENT_FIELDS = {
|
|
static: {
|
|
default: ['creation_statements', 'revocation_statements', 'rotation_statements'],
|
|
'mongodb-database-plugin': 'NONE', // will not show the section
|
|
},
|
|
dynamic: {
|
|
default: ['creation_statements', 'revocation_statements', 'rotation_statements'],
|
|
'mongodb-database-plugin': ['creation_statement', 'revocation_statement'],
|
|
},
|
|
};
|
|
|
|
export default class DatabaseRoleSettingForm extends Component {
|
|
get settingFields() {
|
|
const type = this.args.roleType;
|
|
if (!type) return null;
|
|
const db = this.args.dbType || 'default';
|
|
const dbValidFields = ROLE_FIELDS[type][db];
|
|
if (!Array.isArray(dbValidFields)) return dbValidFields;
|
|
return this.args.attrs.filter(a => {
|
|
return dbValidFields.includes(a.name);
|
|
});
|
|
}
|
|
|
|
get statementFields() {
|
|
const type = this.args.roleType;
|
|
if (!type) return null;
|
|
const db = this.args.dbType || 'default';
|
|
const dbValidFields = STATEMENT_FIELDS[type][db];
|
|
if (!Array.isArray(dbValidFields)) return dbValidFields;
|
|
return this.args.attrs.filter(a => {
|
|
return dbValidFields.includes(a.name);
|
|
});
|
|
}
|
|
}
|