mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-25 00:21:07 +02:00
* Update add-to-array and remove-from-array helpers * remove search-select-has-many, moved logic directly into mfa-login-enforcement-form (see #16470) * Replace add/remove object in MFA files - All MFA tests pass * Replace in PKI components (pki tests all passing) * Replace in core addon where applicable * glimmerize console service -- console tests pass * more replacements * update string-list, add comment to vertical-bar-chart * Refactor CSP Event service - only used one place (auth-form) so simplified that usage - glimmerize and refactor so that the tests work * small updates * more cleanup * Fix tests * Remove objectAt from console-helpers * Address PR comments * move commandIndex clearing back * Remove extra model set
94 lines
3.0 KiB
JavaScript
94 lines
3.0 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import Model, { attr } from '@ember-data/model';
|
|
import { computed } from '@ember/object';
|
|
import fieldToAttrs, { expandAttributeMeta } from 'vault/utils/field-to-attrs';
|
|
import apiPath from 'vault/utils/api-path';
|
|
import lazyCapabilities from 'vault/macros/lazy-capabilities';
|
|
import { removeManyFromArray } from 'vault/helpers/remove-from-array';
|
|
|
|
export const COMPUTEDS = {
|
|
operationFields: computed('newFields', function () {
|
|
return this.newFields.filter((key) => key.startsWith('operation'));
|
|
}),
|
|
|
|
operationFieldsWithoutSpecial: computed('operationFields', function () {
|
|
return removeManyFromArray(this.operationFields, ['operationAll', 'operationNone']);
|
|
}),
|
|
|
|
tlsFields: computed(function () {
|
|
return ['tlsClientKeyBits', 'tlsClientKeyType', 'tlsClientTtl'];
|
|
}),
|
|
|
|
// For rendering on the create/edit pages
|
|
defaultFields: computed('newFields', 'operationFields', 'tlsFields', function () {
|
|
const excludeFields = ['role'].concat(this.operationFields, this.tlsFields);
|
|
return removeManyFromArray(this.newFields, excludeFields);
|
|
}),
|
|
|
|
// For adapter/serializer
|
|
nonOperationFields: computed('newFields', 'operationFields', function () {
|
|
return removeManyFromArray(this.newFields, this.operationFields);
|
|
}),
|
|
};
|
|
|
|
export default Model.extend(COMPUTEDS, {
|
|
useOpenAPI: true,
|
|
backend: attr({ readOnly: true }),
|
|
scope: attr({ readOnly: true }),
|
|
name: attr({ readOnly: true }),
|
|
getHelpUrl(path) {
|
|
return `/v1/${path}/scope/example/role/example?help=1`;
|
|
},
|
|
fieldGroups: computed('fields', 'defaultFields.length', 'tlsFields', function () {
|
|
const groups = [{ TLS: this.tlsFields }];
|
|
if (this.defaultFields.length) {
|
|
groups.unshift({ default: this.defaultFields });
|
|
}
|
|
const ret = fieldToAttrs(this, groups);
|
|
return ret;
|
|
}),
|
|
|
|
operationFormFields: computed('operationFieldsWithoutSpecial', function () {
|
|
const objects = [
|
|
'operationCreate',
|
|
'operationActivate',
|
|
'operationGet',
|
|
'operationLocate',
|
|
'operationRekey',
|
|
'operationRevoke',
|
|
'operationDestroy',
|
|
];
|
|
|
|
const attributes = ['operationAddAttribute', 'operationGetAttributes'];
|
|
const server = ['operationDiscoverVersions'];
|
|
const others = removeManyFromArray(this.operationFieldsWithoutSpecial, [
|
|
...objects,
|
|
...attributes,
|
|
...server,
|
|
]);
|
|
const groups = [
|
|
{ 'Managed Cryptographic Objects': objects },
|
|
{ 'Object Attributes': attributes },
|
|
{ Server: server },
|
|
];
|
|
if (others.length) {
|
|
groups.push({
|
|
Other: others,
|
|
});
|
|
}
|
|
return fieldToAttrs(this, groups);
|
|
}),
|
|
tlsFormFields: computed('tlsFields', function () {
|
|
return expandAttributeMeta(this, this.tlsFields);
|
|
}),
|
|
fields: computed('defaultFields', function () {
|
|
return expandAttributeMeta(this, this.defaultFields);
|
|
}),
|
|
|
|
updatePath: lazyCapabilities(apiPath`${'backend'}/scope/${'scope'}/role/${'id'}`, 'backend', 'scope', 'id'),
|
|
});
|