open-vault/ui/app/components/tool-actions-form.js
Jordan Reimer 5c2a08de6d
Ember Upgrade to 3.24 (#13443)
* Update browserslist

* Add browserslistrc

* ember-cli-update --to 3.26, fix conflicts

* Run codemodes that start with ember-*

* More codemods - before cp*

* More codemods (curly data-test-*)

* WIP ember-basic-dropdown template errors

* updates ember-basic-dropdown and related deps to fix build issues

* updates basic dropdown instances to new version API

* updates more deps -- ember-template-lint is working again

* runs no-implicit-this codemod

* creates and runs no-quoteless-attributes codemod

* runs angle brackets codemod

* updates lint:hbs globs to only touch hbs files

* removes yield only templates

* creates and runs deprecated args transform

* supresses lint error for invokeAction on LinkTo component

* resolves remaining ambiguous path lint errors

* resolves simple-unless lint errors

* adds warnings for deprecated tagName arg on LinkTo components

* adds warnings for remaining curly component invocation

* updates global template lint rules

* resolves remaining template lint errors

* disables some ember specfic lint rules that target pre octane patterns

* js lint fix run

* resolves remaining js lint errors

* fixes test run

* adds npm-run-all dep

* fixes test attribute issues

* fixes console acceptance tests

* fixes tests

* adds yield only wizard/tutorial-active template

* fixes more tests

* attempts to fix more flaky tests

* removes commented out settled in transit test

* updates deprecations workflow and adds initializer to filter by version

* updates flaky policies acl old test

* updates to flaky transit test

* bumps ember deps down to LTS version

* runs linters after main merge

* fixes client count tests after bad merge conflict fixes

* fixes client count history test

* more updates to lint config

* another round of hbs lint fixes after extending stylistic rule

* updates lint-staged commands

* removes indent eslint rule since it seems to break things

* fixes bad attribute in transform-edit-form template

* test fixes

* fixes enterprise tests

* adds changelog

* removes deprecated ember-concurrency-test-waiters dep and adds @ember/test-waiters

* flaky test fix

Co-authored-by: hashishaw <cshaw@hashicorp.com>
2021-12-16 20:44:29 -07:00

153 lines
3.9 KiB
JavaScript

import { match } from '@ember/object/computed';
import { assign } from '@ember/polyfills';
import { inject as service } from '@ember/service';
import Component from '@ember/component';
import { setProperties, computed, set } from '@ember/object';
import { addSeconds, parseISO } from 'date-fns';
import { A } from '@ember/array';
const DEFAULTS = {
token: null,
rewrap_token: null,
errors: A(),
wrap_info: null,
creation_time: null,
creation_ttl: null,
data: '{\n}',
unwrap_data: null,
details: null,
wrapTTL: null,
sum: null,
random_bytes: null,
input: null,
};
const WRAPPING_ENDPOINTS = ['lookup', 'wrap', 'unwrap', 'rewrap'];
export default Component.extend(DEFAULTS, {
store: service(),
wizard: service(),
// putting these attrs here so they don't get reset when you click back
//random
bytes: 32,
//hash
format: 'base64',
algorithm: 'sha2-256',
tagName: '',
unwrapActiveTab: 'data',
didReceiveAttrs() {
this._super(...arguments);
this.checkAction();
},
selectedAction: null,
reset() {
if (this.isDestroyed || this.isDestroying) {
return;
}
setProperties(this, DEFAULTS);
},
checkAction() {
const currentAction = this.selectedAction;
const oldAction = this.oldSelectedAction;
if (currentAction !== oldAction) {
this.reset();
}
set(this, 'oldSelectedAction', currentAction);
},
dataIsEmpty: match('data', new RegExp(DEFAULTS.data)),
expirationDate: computed('creation_time', 'creation_ttl', function () {
const { creation_time, creation_ttl } = this;
if (!(creation_time && creation_ttl)) {
return null;
}
// returns new Date with seconds added.
return addSeconds(parseISO(creation_time), creation_ttl);
}),
handleError(e) {
set(this, 'errors', e.errors);
},
handleSuccess(resp, action) {
let props = {};
let secret = (resp && resp.data) || resp.auth;
if (secret && action === 'unwrap') {
let details = {
'Request ID': resp.request_id,
'Lease ID': resp.lease_id || 'None',
Renewable: resp.renewable ? 'Yes' : 'No',
'Lease Duration': resp.lease_duration || 'None',
};
props = assign({}, props, { unwrap_data: secret }, { details: details });
}
props = assign({}, props, secret);
if (resp && resp.wrap_info) {
const keyName = action === 'rewrap' ? 'rewrap_token' : 'token';
props = assign({}, props, { [keyName]: resp.wrap_info.token });
}
if (props.token || props.rewrap_token || props.unwrap_data || action === 'lookup') {
this.wizard.transitionFeatureMachine(this.wizard.featureState, 'CONTINUE');
}
setProperties(this, props);
},
getData() {
const action = this.selectedAction;
if (WRAPPING_ENDPOINTS.includes(action)) {
return this.dataIsEmpty ? { token: (this.token || '').trim() } : JSON.parse(this.data);
}
if (action === 'random') {
return { bytes: this.bytes, format: this.format };
}
if (action === 'hash') {
return { input: this.input, format: this.format, algorithm: this.algorithm };
}
},
actions: {
doSubmit(evt) {
evt.preventDefault();
const action = this.selectedAction;
const wrapTTL = action === 'wrap' ? this.wrapTTL : null;
const data = this.getData();
setProperties(this, {
errors: null,
wrap_info: null,
creation_time: null,
creation_ttl: null,
});
this.store
.adapterFor('tools')
.toolAction(action, data, { wrapTTL })
.then(
(resp) => this.handleSuccess(resp, action),
(...errArgs) => this.handleError(...errArgs)
);
},
onClear() {
this.reset();
},
updateTtl(ttl) {
set(this, 'wrapTTL', ttl);
},
codemirrorUpdated(val, hasErrors) {
setProperties(this, {
buttonDisabled: hasErrors,
data: val,
});
},
},
});