From 7e3925007ed8ee9dda83331f78922660b6a921cf Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Fri, 23 Jul 2021 15:31:32 -0600 Subject: [PATCH 01/40] initial setup --- ui/app/components/secret-edit.js | 11 +- ui/app/lib/kv-metadata-object.js | 28 ++++ ui/app/models/secret-v2.js | 1 + .../components/secret-edit-display.hbs | 115 ---------------- .../components/secret-edit-metadata.hbs | 98 ++++++++++++++ ui/app/templates/components/secret-edit.hbs | 126 +++++++++++++++--- 6 files changed, 243 insertions(+), 136 deletions(-) create mode 100644 ui/app/lib/kv-metadata-object.js delete mode 100644 ui/app/templates/components/secret-edit-display.hbs create mode 100644 ui/app/templates/components/secret-edit-metadata.hbs diff --git a/ui/app/components/secret-edit.js b/ui/app/components/secret-edit.js index d8ca7cceaffc..abc11e69bcec 100644 --- a/ui/app/components/secret-edit.js +++ b/ui/app/components/secret-edit.js @@ -9,6 +9,7 @@ import FocusOnInsertMixin from 'vault/mixins/focus-on-insert'; import WithNavToNearestAncestor from 'vault/mixins/with-nav-to-nearest-ancestor'; import keys from 'vault/lib/keycodes'; import KVObject from 'vault/lib/kv-object'; +import KVMetadataObject from 'vault/lib/kv-metadata-object'; import { maybeQueryRecord } from 'vault/macros/maybe-query-record'; import ControlGroupError from 'vault/lib/control-group-error'; @@ -35,12 +36,13 @@ export default Component.extend(FocusOnInsertMixin, WithNavToNearestAncestor, { mode: null, secretData: null, + customMetadata: null, wrappedData: null, isWrapping: false, showWrapButton: not('wrappedData'), - // called with a bool indicating if there's been a change in the secretData + // called with a bool indicating if there's been a change in the secretData and customMetadata onDataChange() {}, onRefresh() {}, onToggleAdvancedEdit() {}, @@ -73,6 +75,11 @@ export default Component.extend(FocusOnInsertMixin, WithNavToNearestAncestor, { } const data = KVObject.create({ content: [] }).fromJSON(secrets); this.set('secretData', data); + // sets up the customMetadata class with the content of one empty array value + const customMetadata = KVMetadataObject.create({ content: [] }).createClass(); + this.set('customMetadata', customMetadata); + this.customMetadata.pushObject({ name: '', value: '' }); + this.set('codemirrorString', data.toJSONString()); if (data.isAdvanced()) { this.set('preferAdvancedEdit', true); @@ -365,6 +372,7 @@ export default Component.extend(FocusOnInsertMixin, WithNavToNearestAncestor, { } this.persistKey(() => { + debugger; this.transitionToRoute(SHOW_ROUTE, this.model.path || this.model.id); }); }, @@ -382,6 +390,7 @@ export default Component.extend(FocusOnInsertMixin, WithNavToNearestAncestor, { addRow() { const data = this.secretData; + // fired off on init if (isNone(data.findBy('name', ''))) { data.pushObject({ name: '', value: '' }); this.send('handleChange'); diff --git a/ui/app/lib/kv-metadata-object.js b/ui/app/lib/kv-metadata-object.js new file mode 100644 index 000000000000..9adf366d818d --- /dev/null +++ b/ui/app/lib/kv-metadata-object.js @@ -0,0 +1,28 @@ +import ArrayProxy from '@ember/array/proxy'; +import { guidFor } from '@ember/object/internals'; + +export default ArrayProxy.extend({ + createClass() { + let contents = Object.keys([]).map(key => { + let obj = { + name: key, + value: '', + }; + guidFor(obj); + return obj; + }); + this.setObjects( + // ARG TODO not sure I need the sorting + contents.sort((a, b) => { + if (a.name === '') { + return 1; + } + if (b.name === '') { + return -1; + } + return a.name.localeCompare(b.name); + }) + ); + return this; + }, +}); diff --git a/ui/app/models/secret-v2.js b/ui/app/models/secret-v2.js index d6ed6c28df28..d5052365bb77 100644 --- a/ui/app/models/secret-v2.js +++ b/ui/app/models/secret-v2.js @@ -41,6 +41,7 @@ export default Model.extend(KeyMixin, Validations, { helpText: 'Writes will only be allowed if the key’s current version matches the version specified in the cas parameter', }), + customMetadata: attr('object'), fields: computed(function() { return expandAttributeMeta(this, ['maxVersions', 'casRequired']); }), diff --git a/ui/app/templates/components/secret-edit-display.hbs b/ui/app/templates/components/secret-edit-display.hbs deleted file mode 100644 index 30e16b28ac25..000000000000 --- a/ui/app/templates/components/secret-edit-display.hbs +++ /dev/null @@ -1,115 +0,0 @@ -{{#if (and (or @model.isNew @canEditV2Secret) @isV2 (not @model.failedServerRead))}} -
- - {{#each @model.fields as |attr|}} - - {{/each}} -
-{{/if}} - -{{#if @showWriteWithoutReadWarning}} - {{#if (and @isV2 @model.failedServerRead)}} - - {{else if @isV2}} - - {{else}} - - {{/if}} -{{/if}} - -{{#if @showAdvancedMode}} -
- - -
-{{else}} -
- - {{#each @secretData as |secret index|}} -
-
- -
-
- -
-
- {{#if (eq @secretData.length (inc index))}} - - {{else}} - - {{/if}} -
-
- {{#if @validationMessages.key}} - - {{/if}} - {{/each}} -
-{{/if}} diff --git a/ui/app/templates/components/secret-edit-metadata.hbs b/ui/app/templates/components/secret-edit-metadata.hbs new file mode 100644 index 000000000000..825756c9d4bf --- /dev/null +++ b/ui/app/templates/components/secret-edit-metadata.hbs @@ -0,0 +1,98 @@ +{{#if (and (or @model.isNew @canEditV2Secret) @isV2 (not @model.failedServerRead))}} +{{!-- Angel beginning of custom metadata --}} +
+ + {{#each @customMetadata as |metadata index|}} +
+
+ +
+
+