2023-03-15 16:00:52 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2022-04-07 17:07:33 +00:00
|
|
|
/* eslint ember/no-computed-properties-in-native-classes: 'warn' */
|
2021-08-31 15:41:41 +00:00
|
|
|
/**
|
|
|
|
* @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
|
2022-04-07 17:07:33 +00:00
|
|
|
* <SecretEdit @model={{model}} @mode="create" @baseKey={{this.baseKey}} @key={{this.model}} @initialKey={{this.initialKey}} @onRefresh={{action "refresh"}} @onToggleAdvancedEdit={{action "toggleAdvancedEdit"}} @preferAdvancedEdit={{this.preferAdvancedEdit}}/>
|
2021-08-31 15:41:41 +00:00
|
|
|
* ```
|
2022-04-07 17:07:33 +00:00
|
|
|
/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
|
2021-08-31 15:41:41 +00:00
|
|
|
*/
|
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2022-04-07 17:07:33 +00:00
|
|
|
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';
|
2022-04-07 17:07:33 +00:00
|
|
|
import { alias, or } from '@ember/object/computed';
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2022-04-07 17:07:33 +00:00
|
|
|
export default class SecretEdit extends Component {
|
|
|
|
@service store;
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2022-04-07 17:07:33 +00:00
|
|
|
@tracked secretData = null;
|
|
|
|
@tracked isV2 = false;
|
|
|
|
@tracked codemirrorString = null;
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2022-10-18 15:46:02 +00:00
|
|
|
// fired on did-insert from render modifier
|
|
|
|
@action
|
|
|
|
createKvData(elem, [model]) {
|
|
|
|
if (!model.secretData && model.selectedVersion) {
|
2022-04-07 17:07:33 +00:00
|
|
|
this.isV2 = true;
|
2022-10-18 15:46:02 +00:00
|
|
|
model.secretData = model.belongsTo('selectedVersion').value().secretData;
|
2018-10-06 03:05:53 +00:00
|
|
|
}
|
2022-10-18 15:46:02 +00:00
|
|
|
this.secretData = KVObject.create({ content: [] }).fromJSON(model.secretData);
|
|
|
|
this.codemirrorString = this.secretData.toJSONString();
|
2022-04-07 17:07:33 +00:00
|
|
|
}
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2022-04-07 17:07:33 +00:00
|
|
|
@maybeQueryRecord(
|
2018-10-09 04:21:02 +00:00
|
|
|
'capabilities',
|
2021-12-17 03:44:29 +00:00
|
|
|
(context) => {
|
2022-04-07 17:07:33 +00:00
|
|
|
if (!context.args.model || context.args.mode === 'create') {
|
2018-10-16 21:08:31 +00:00
|
|
|
return;
|
2018-10-09 04:21:02 +00:00
|
|
|
}
|
2022-11-09 23:15:31 +00:00
|
|
|
const backend = context.isV2 ? context.args.model.engine.id : context.args.model.backend;
|
|
|
|
const id = context.args.model.id;
|
|
|
|
const path = context.isV2 ? `${backend}/data/${id}` : `${backend}/${id}`;
|
2018-10-09 04:21:02 +00:00
|
|
|
return {
|
|
|
|
id: path,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
'isV2',
|
|
|
|
'model',
|
|
|
|
'model.id',
|
|
|
|
'mode'
|
2022-04-07 17:07:33 +00:00
|
|
|
)
|
|
|
|
checkSecretCapabilities;
|
|
|
|
@alias('checkSecretCapabilities.canUpdate') canUpdateSecretData;
|
|
|
|
@alias('checkSecretCapabilities.canRead') canReadSecretData;
|
2018-10-09 04:21:02 +00:00
|
|
|
|
2022-04-07 17:07:33 +00:00
|
|
|
@maybeQueryRecord(
|
2018-10-15 14:38:05 +00:00
|
|
|
'capabilities',
|
2021-12-17 03:44:29 +00:00
|
|
|
(context) => {
|
2022-04-07 17:07:33 +00:00
|
|
|
if (!context.args.model || !context.isV2) {
|
2018-10-16 21:08:31 +00:00
|
|
|
return;
|
2018-10-15 14:38:05 +00:00
|
|
|
}
|
2022-06-07 15:56:44 +00:00
|
|
|
const backend = context.args.model.backend;
|
|
|
|
const id = context.args.model.id;
|
|
|
|
const path = `${backend}/metadata/${id}`;
|
2018-10-15 14:38:05 +00:00
|
|
|
return {
|
2021-08-31 15:41:41 +00:00
|
|
|
id: path,
|
2018-10-15 14:38:05 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
'isV2',
|
|
|
|
'model',
|
|
|
|
'model.id',
|
|
|
|
'mode'
|
2022-04-07 17:07:33 +00:00
|
|
|
)
|
|
|
|
checkMetadataCapabilities;
|
|
|
|
@alias('checkMetadataCapabilities.canDelete') canDeleteSecretMetadata;
|
|
|
|
@alias('checkMetadataCapabilities.canUpdate') canUpdateSecretMetadata;
|
|
|
|
@alias('checkMetadataCapabilities.canRead') canReadSecretMetadata;
|
2018-10-15 14:38:05 +00:00
|
|
|
|
2022-04-07 17:07:33 +00:00
|
|
|
@or('model.isLoading', 'model.isReloading', 'model.isSaving') requestInFlight;
|
|
|
|
@or('requestInFlight', 'model.isFolder', 'model.flagsIsInvalid') buttonDisabled;
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2022-04-07 17:07:33 +00:00
|
|
|
get modelForData() {
|
2022-11-09 23:15:31 +00:00
|
|
|
const { model } = this.args;
|
2019-06-20 13:37:27 +00:00
|
|
|
if (!model) return null;
|
|
|
|
return this.isV2 ? model.belongsTo('selectedVersion').value() : model;
|
2022-04-07 17:07:33 +00:00
|
|
|
}
|
2018-10-06 03:05:53 +00:00
|
|
|
|
2022-04-07 17:07:33 +00:00
|
|
|
get basicModeDisabled() {
|
2018-10-06 03:05:53 +00:00
|
|
|
return this.secretDataIsAdvanced || this.showAdvancedMode === false;
|
2022-04-07 17:07:33 +00:00
|
|
|
}
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2022-04-07 17:07:33 +00:00
|
|
|
get secretDataAsJSON() {
|
2018-10-06 03:05:53 +00:00
|
|
|
return this.secretData.toJSON();
|
2022-04-07 17:07:33 +00:00
|
|
|
}
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2022-04-07 17:07:33 +00:00
|
|
|
get secretDataIsAdvanced() {
|
2018-10-06 03:05:53 +00:00
|
|
|
return this.secretData.isAdvanced();
|
2022-04-07 17:07:33 +00:00
|
|
|
}
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2022-04-07 17:07:33 +00:00
|
|
|
get showAdvancedMode() {
|
|
|
|
return this.secretDataIsAdvanced || this.args.preferAdvancedEdit;
|
|
|
|
}
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2022-04-07 17:07:33 +00:00
|
|
|
get isWriteWithoutRead() {
|
|
|
|
if (!this.args.model) {
|
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
|
|
|
}
|
2022-04-07 17:07:33 +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);
|
|
|
|
}
|
|
|
|
}
|