open-vault/ui/app/components/secret-edit.js

147 lines
4.7 KiB
JavaScript
Raw Normal View History

/* eslint ember/no-computed-properties-in-native-classes: 'warn' */
/**
* @module SecretEdit
* SecretEdit component manages the secret and model data, and displays either the create, update, empty state or show view of a KV secret.
*
* @example
* ```js
* <SecretEdit @model={{model}} @mode="create" @baseKey={{this.baseKey}} @key={{this.model}} @initialKey={{this.initialKey}} @onRefresh={{action "refresh"}} @onToggleAdvancedEdit={{action "toggleAdvancedEdit"}} @preferAdvancedEdit={{this.preferAdvancedEdit}}/>
* ```
/This component is initialized from the secret-edit-layout.hbs file
* @param {object} model - Model returned from secret-v2 which is generated in the secret-edit route
* @param {string} mode - Edit, create, etc.
* @param {string} baseKey - Provided for navigation.
* @param {object} key - Passed through, copy of the model.
* @param {string} initialKey - model's name.
* @param {function} onRefresh - action that refreshes the model
* @param {function} onToggleAdvancedEdit - changes the preferAdvancedEdit to true or false
* @param {boolean} preferAdvancedEdit - property set from the controller of show/edit/create route passed in through secret-edit-layout
*/
import { inject as service } from '@ember/service';
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
2018-04-03 14:16:57 +00:00
import KVObject from 'vault/lib/kv-object';
2018-10-16 21:08:31 +00:00
import { maybeQueryRecord } from 'vault/macros/maybe-query-record';
import { alias, or } from '@ember/object/computed';
2018-04-03 14:16:57 +00:00
export default class SecretEdit extends Component {
@service wizard;
@service store;
2018-04-03 14:16:57 +00:00
@tracked secretData = null;
@tracked isV2 = false;
@tracked codemirrorString = null;
2018-04-03 14:16:57 +00:00
constructor() {
super(...arguments);
let secrets = this.args.model.secretData;
if (!secrets && this.args.model.selectedVersion) {
this.isV2 = true;
secrets = this.args.model.belongsTo('selectedVersion').value().secretData;
}
2018-04-03 14:16:57 +00:00
const data = KVObject.create({ content: [] }).fromJSON(secrets);
this.secretData = data;
this.codemirrorString = data.toJSONString();
if (this.wizard.featureState === 'details' && this.args.mode === 'create') {
let engine = this.args.model.backend.includes('kv') ? 'kv' : this.args.model.backend;
2018-10-08 18:20:55 +00:00
this.wizard.transitionFeatureMachine('details', 'CONTINUE', engine);
2018-08-28 05:03:55 +00:00
}
}
2018-04-03 14:16:57 +00:00
@maybeQueryRecord(
'capabilities',
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-17 03:44:29 +00:00
(context) => {
if (!context.args.model || context.args.mode === 'create') {
2018-10-16 21:08:31 +00:00
return;
}
let backend = context.isV2 ? context.args.model.engine.id : context.args.model.backend;
let id = context.args.model.id;
let path = context.isV2 ? `${backend}/data/${id}` : `${backend}/${id}`;
return {
id: path,
};
},
'isV2',
'model',
'model.id',
'mode'
)
checkSecretCapabilities;
@alias('checkSecretCapabilities.canUpdate') canUpdateSecretData;
@alias('checkSecretCapabilities.canRead') canReadSecretData;
@maybeQueryRecord(
'capabilities',
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-17 03:44:29 +00:00
(context) => {
if (!context.args.model || !context.isV2) {
2018-10-16 21:08:31 +00:00
return;
}
let backend = context.args.model.backend;
let path = `${backend}/metadata/`;
return {
id: path,
};
},
'isV2',
'model',
'model.id',
'mode'
)
checkMetadataCapabilities;
@alias('checkMetadataCapabilities.canDelete') canDeleteSecretMetadata;
@alias('checkMetadataCapabilities.canUpdate') canUpdateSecretMetadata;
@alias('checkMetadataCapabilities.canRead') canReadSecretMetadata;
@or('model.isLoading', 'model.isReloading', 'model.isSaving') requestInFlight;
@or('requestInFlight', 'model.isFolder', 'model.flagsIsInvalid') buttonDisabled;
2018-04-03 14:16:57 +00:00
get modelForData() {
let { model } = this.args;
if (!model) return null;
return this.isV2 ? model.belongsTo('selectedVersion').value() : model;
}
get basicModeDisabled() {
return this.secretDataIsAdvanced || this.showAdvancedMode === false;
}
2018-04-03 14:16:57 +00:00
get secretDataAsJSON() {
return this.secretData.toJSON();
}
2018-04-03 14:16:57 +00:00
get secretDataIsAdvanced() {
return this.secretData.isAdvanced();
}
2018-04-03 14:16:57 +00:00
get showAdvancedMode() {
return this.secretDataIsAdvanced || this.args.preferAdvancedEdit;
}
2018-04-03 14:16:57 +00:00
get isWriteWithoutRead() {
if (!this.args.model) {
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-17 03:44:29 +00:00
return false;
Update ui dependencies (#7244) * be more specific about node version, and specify a yarn version * update ember, ember-cli, ember-data, ember-data-model-fragments * use router handlers to access transition information * fix shadowing of component helper * update ivy-codemirror, ember-cli-inject-live-reload * remove custom router service * don't use transition.queryParams * update ember-cli-deprecation-workflow * refactor kv v1 to use 'path' instead of 'id' on creation * fix auth-jwt-test and toolbar-link-test * update ember composable helpers * remove Ember.copy from test file * no more deprecations in the workflow * fix more secret tests * fix remaining failed tests * move select component to core because it's used by ttl-picker * generate new model class for each test instead of reusing an existing one * fix selectors on kmip tests * refactor how control groups construct urls from the new transition objects * add router service override back in, and have it be evented so that we can trigger router events on it * move stories and markdown files to core if the component lives in core * update ember-cli, ember-cli-babel, ember-auto-import * update base64js, date-fns, deepmerge, codemirror, broccoli-asset-rev * update linting rules * fix test selectors * update ember-api-actions, ember-concurrency, ember-load-initializers, escape-string-regexp, normalize.css, prettier-eslint-cli, jsdoc-to-markdown * remove test-results dir * update base64js, ember-cli-clipboard, ember-cli-sass, ember-cli-string-helpers, ember-cli-template-lint, ember-cli-uglify, ember-link-action * fix linting * run yarn install without restoring from cache * refactor how tests are run and handle the vault server subprocess * update makefile for new test task names * update circle config to use the new yarn task * fix writing the seal keys when starting the dev server * remove optional deps from the lockfile * don't ignore-optional on yarn install * remove errant console.log * update ember-basic-dropdown-hover, jsonlint, yargs-parser * update ember-cli-flash * add back optionalDeps * update @babel/core@7.5.5, ember-basic-dropdown@1.1.3, eslint-plugin-ember@6.8.2 * update storybook to the latest release * add a babel config with targets so that the ember babel plugin works properly * update ember-resolver, move ember-cli-storybook to devDependencies * revert normalize.css upgrade * silence fetchadapter warning for now * exclude 3rd party array helper now that ember includes one * fix switch and entity lookup styling * only add -root suffix if it's not in versions mode * make sure drop always has an array on the aws role form * fix labels like we did with the backport * update eslintignore * update the yarn version in the docker build file * update eslint ignore
2019-08-19 20:45:39 +00:00
}
// if the version couldn't be read from the server
if (this.isV2 && this.modelForData.failedServerRead) {
return true;
}
// if the model couldn't be read from the server
if (!this.isV2 && this.args.model.failedServerRead) {
return true;
}
return false;
}
@action
refresh() {
this.args.onRefresh();
}
@action
toggleAdvanced(bool) {
this.args.onToggleAdvancedEdit(bool);
}
}