vault/ui/app/components/wizard/features-selection.js
hashicorp-copywrite[bot] 0b12cdcfd1
[COMPLIANCE] License changes (#22290)
* Adding explicit MPL license for sub-package.

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Adding explicit MPL license for sub-package.

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Updating the license from MPL to Business Source License.

Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl.

* add missing license headers

* Update copyright file headers to BUS-1.1

* Fix test that expected exact offset on hcl file

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: Sarah Thompson <sthompson@hashicorp.com>
Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
2023-08-10 18:14:03 -07:00

150 lines
4.2 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { or, not } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import Component from '@ember/component';
import { computed } from '@ember/object';
import { FEATURE_MACHINE_TIME } from 'vault/helpers/wizard-constants';
export default Component.extend({
wizard: service(),
version: service(),
permissions: service(),
init() {
this._super(...arguments);
this.maybeHideFeatures();
},
maybeHideFeatures() {
const features = this.allFeatures;
features.forEach((feat) => {
feat.disabled = this.doesNotHavePermission(feat.requiredPermissions);
});
if (this.showReplication === false) {
const feature = this.allFeatures.findBy('key', 'replication');
feature.show = false;
}
},
doesNotHavePermission(requiredPermissions) {
// requiredPermissions is an object of paths and capabilities defined within allFeatures.
// the expected shape is:
// {
// 'example/path': ['capability'],
// 'second/example/path': ['update', 'sudo'],
// }
return !Object.keys(requiredPermissions).every((path) => {
return this.permissions.hasPermission(path, requiredPermissions[path]);
});
},
estimatedTime: computed('selectedFeatures', function () {
let time = 0;
for (const feature of Object.keys(FEATURE_MACHINE_TIME)) {
if (this.selectedFeatures.includes(feature)) {
time += FEATURE_MACHINE_TIME[feature];
}
}
return time;
}),
selectProgress: computed('selectedFeatures', function () {
let bar = this.selectedFeatures.map((feature) => {
return { style: 'width:0%;', completed: false, showIcon: true, feature: feature };
});
if (bar.length === 0) {
bar = [{ style: 'width:0%;', showIcon: false }];
}
return bar;
}),
allFeatures: computed(function () {
return [
{
key: 'secrets',
name: 'Secrets',
steps: ['Enabling a Secrets Engine', 'Adding a secret'],
selected: false,
show: true,
disabled: false,
requiredPermissions: {
'sys/mounts/example': ['update'],
},
},
{
key: 'authentication',
name: 'Authentication',
steps: ['Enabling an Auth Method', 'Managing your Auth Method'],
selected: false,
show: true,
disabled: false,
requiredPermissions: {
'sys/auth': ['read'],
'sys/auth/foo': ['update', 'sudo'],
},
},
{
key: 'policies',
name: 'Policies',
steps: [
'Choosing a policy type',
'Creating a policy',
'Deleting your policy',
'Other types of policies',
],
selected: false,
show: true,
disabled: false,
requiredPermissions: {
'sys/policies/acl': ['list'],
},
},
{
key: 'replication',
name: 'Replication',
steps: ['Setting up replication', 'Your cluster information'],
selected: false,
show: true,
disabled: false,
requiredPermissions: {
'sys/replication/performance/primary/enable': ['update'],
'sys/replication/dr/primary/enable': ['update'],
},
},
{
key: 'tools',
name: 'Tools',
steps: ['Wrapping data', 'Lookup wrapped data', 'Rewrapping your data', 'Unwrapping your data'],
selected: false,
show: true,
disabled: false,
requiredPermissions: {
'sys/wrapping/wrap': ['update'],
'sys/wrapping/lookup': ['update'],
'sys/wrapping/unwrap': ['update'],
'sys/wrapping/rewrap': ['update'],
},
},
];
}),
showReplication: or('version.hasPerfReplication', 'version.hasDRReplication'),
selectedFeatures: computed('allFeatures.@each.selected', function () {
return this.allFeatures.filterBy('selected').mapBy('key');
}),
cannotStartWizard: not('selectedFeatures.length'),
actions: {
saveFeatures() {
const wizard = this.wizard;
wizard.saveFeatures(this.selectedFeatures);
wizard.transitionTutorialMachine('active.select', 'CONTINUE');
},
},
});