From afb258d834a688b32a98bca37dbba0f68783ce5c Mon Sep 17 00:00:00 2001 From: Matthew Irish Date: Fri, 19 Oct 2018 09:55:37 -0500 Subject: [PATCH 1/7] add versions routes --- ui/app/router.js | 4 +++ .../cluster/secrets/backend/versions-root.js | 1 + .../vault/cluster/secrets/backend/versions.js | 29 +++++++++++++++++++ ui/app/serializers/secret-v2.js | 1 + 4 files changed, 35 insertions(+) create mode 100644 ui/app/routes/vault/cluster/secrets/backend/versions-root.js create mode 100644 ui/app/routes/vault/cluster/secrets/backend/versions.js diff --git a/ui/app/router.js b/ui/app/router.js index 5660a3e2c228..1301330180d4 100644 --- a/ui/app/router.js +++ b/ui/app/router.js @@ -92,6 +92,10 @@ Router.map(function() { this.route('credentials-root', { path: '/credentials/' }); this.route('credentials', { path: '/credentials/*secret' }); + // kv v2 versions + this.route('versions-root', { path: '/versions/' }); + this.route('versions', { path: '/versions/*secret' }); + // ssh sign this.route('sign-root', { path: '/sign/' }); this.route('sign', { path: '/sign/*secret' }); diff --git a/ui/app/routes/vault/cluster/secrets/backend/versions-root.js b/ui/app/routes/vault/cluster/secrets/backend/versions-root.js new file mode 100644 index 000000000000..69de93ac8a8a --- /dev/null +++ b/ui/app/routes/vault/cluster/secrets/backend/versions-root.js @@ -0,0 +1 @@ +export { default } from './version'; diff --git a/ui/app/routes/vault/cluster/secrets/backend/versions.js b/ui/app/routes/vault/cluster/secrets/backend/versions.js new file mode 100644 index 000000000000..bea5ef3c7d31 --- /dev/null +++ b/ui/app/routes/vault/cluster/secrets/backend/versions.js @@ -0,0 +1,29 @@ +import { set } from '@ember/object'; +import { hash, resolve } from 'rsvp'; +import Route from '@ember/routing/route'; +import utils from 'vault/lib/key-utils'; +import UnloadModelRoute from 'vault/mixins/unload-model-route'; + +export default Route.extend(UnloadModelRoute, { + templateName: 'vault/cluster/secrets/backend/versions', + + beforeModel() { + let backendModel = this.modelFor('vault.cluster.secrets.backend'); + const { secret } = this.paramsFor(this.routeName); + const parentKey = utils.parentKeyForKey(secret); + if (backendModel.get('isV2KV')) { + return; + } + if (parentKey) { + return this.transitionTo('vault.cluster.secrets.backend.list', parentKey); + } else { + return this.transitionTo('vault.cluster.secrets.backend.list-root'); + } + }, + + model(params) { + let { secret } = params; + const { backend } = this.paramsFor('vault.cluster.secrets.backend'); + return this.store.queryRecord('secret-v2', { id: secret, backend }); + }, +}); diff --git a/ui/app/serializers/secret-v2.js b/ui/app/serializers/secret-v2.js index e1d7fc7f6cec..0be535c778a5 100644 --- a/ui/app/serializers/secret-v2.js +++ b/ui/app/serializers/secret-v2.js @@ -38,6 +38,7 @@ export default ApplicationSerializer.extend(DS.EmbeddedRecordsMixin, { return body; }); } + payload.data.engine_id = payload.backend; payload.data.id = payload.id; return requestType === 'queryRecord' ? payload.data : [payload.data]; }, From 795f6262db8e5e704bd169a281aad85eea83e9c8 Mon Sep 17 00:00:00 2001 From: Matthew Irish Date: Fri, 19 Oct 2018 15:51:51 -0500 Subject: [PATCH 2/7] move commands and permissions check to stand-alone menu component --- ui/app/components/secret-edit.js | 51 +----- ui/app/components/secret-version-menu.js | 58 ++++++ ui/app/templates/components/secret-edit.hbs | 165 +++++------------- .../components/secret-version-menu.hbs | 96 ++++++++++ 4 files changed, 199 insertions(+), 171 deletions(-) create mode 100644 ui/app/components/secret-version-menu.js create mode 100644 ui/app/templates/components/secret-version-menu.hbs diff --git a/ui/app/components/secret-edit.js b/ui/app/components/secret-edit.js index b83d451ee622..4b0e684778a3 100644 --- a/ui/app/components/secret-edit.js +++ b/ui/app/components/secret-edit.js @@ -1,9 +1,8 @@ -import { or } from '@ember/object/computed'; import { isBlank, isNone } from '@ember/utils'; import { inject as service } from '@ember/service'; import Component from '@ember/component'; import { computed, set } from '@ember/object'; -import { alias } from '@ember/object/computed'; +import { alias, or } from '@ember/object/computed'; import { task, waitForEvent } from 'ember-concurrency'; import FocusOnInsertMixin from 'vault/mixins/focus-on-insert'; import keys from 'vault/lib/keycodes'; @@ -127,49 +126,6 @@ export default Component.extend(FocusOnInsertMixin, { ), canEditV2Secret: alias('v2UpdatePath.canUpdate'), - deleteVersionPath: maybeQueryRecord( - 'capabilities', - context => { - let backend = context.get('model.engine.id'); - let id = context.model.id; - return { - id: `${backend}/delete/${id}`, - }; - }, - 'model.id' - ), - canDeleteVersion: alias('deleteVersionPath.canUpdate'), - destroyVersionPath: maybeQueryRecord( - 'capabilities', - context => { - let backend = context.get('model.engine.id'); - let id = context.model.id; - return { - id: `${backend}/destroy/${id}`, - }; - }, - 'model.id' - ), - canDestroyVersion: alias('destroyVersionPath.canUpdate'), - undeleteVersionPath: maybeQueryRecord( - 'capabilities', - context => { - let backend = context.get('model.engine.id'); - let id = context.model.id; - return { - id: `${backend}/undelete/${id}`, - }; - }, - 'model.id' - ), - canUndeleteVersion: alias('undeleteVersionPath.canUpdate'), - - isFetchingVersionCapabilities: or( - 'deleteVersionPath.isPending', - 'destroyVersionPath.isPending', - 'undeleteVersionPath.isPending' - ), - requestInFlight: or('model.isLoading', 'model.isReloading', 'model.isSaving'), buttonDisabled: or( @@ -299,11 +255,6 @@ export default Component.extend(FocusOnInsertMixin, { }); }, - deleteVersion(deleteType = 'destroy') { - let id = this.modelForData.id; - return this.store.adapterFor('secret-v2-version').v2DeleteOperation(this.store, id, deleteType); - }, - refresh() { this.onRefresh(); }, diff --git a/ui/app/components/secret-version-menu.js b/ui/app/components/secret-version-menu.js new file mode 100644 index 000000000000..5b13c6cd214b --- /dev/null +++ b/ui/app/components/secret-version-menu.js @@ -0,0 +1,58 @@ +import { maybeQueryRecord } from 'vault/macros/maybe-query-record'; +import Component from '@ember/component'; +import { inject as service } from '@ember/service'; +import { alias, or } from '@ember/object/computed'; + +export default Component.extend({ + tagName: '', + store: service(), + version: null, + useDefaultTrigger: false, + + deleteVersionPath: maybeQueryRecord( + 'capabilities', + context => { + let [backend, id] = JSON.parse(context.version.id); + return { + id: `${backend}/delete/${id}`, + }; + }, + 'version.id' + ), + canDeleteVersion: alias('deleteVersionPath.canUpdate'), + destroyVersionPath: maybeQueryRecord( + 'capabilities', + context => { + let [backend, id] = JSON.parse(context.version.id); + return { + id: `${backend}/destroy/${id}`, + }; + }, + 'version.id' + ), + canDestroyVersion: alias('destroyVersionPath.canUpdate'), + undeleteVersionPath: maybeQueryRecord( + 'capabilities', + context => { + let [backend, id] = JSON.parse(context.version.id); + return { + id: `${backend}/undelete/${id}`, + }; + }, + 'version.id' + ), + canUndeleteVersion: alias('undeleteVersionPath.canUpdate'), + + isFetchingVersionCapabilities: or( + 'deleteVersionPath.isPending', + 'destroyVersionPath.isPending', + 'undeleteVersionPath.isPending' + ), + actions: { + deleteVersion(deleteType = 'destroy') { + return this.store + .adapterFor('secret-v2-version') + .v2DeleteOperation(this.store, this.version.id, deleteType); + }, + }, +}); diff --git a/ui/app/templates/components/secret-edit.hbs b/ui/app/templates/components/secret-edit.hbs index 582a6fc9fcb1..d814e73c2218 100644 --- a/ui/app/templates/components/secret-edit.hbs +++ b/ui/app/templates/components/secret-edit.hbs @@ -77,130 +77,53 @@ {{/if}} {{#if (and (eq @mode "show") this.isV2)}}
- - - Version {{this.modelForData.version}} - - - - - - +
- - - History - - - - - + + History + + + + +
{{/if}} diff --git a/ui/app/templates/components/secret-version-menu.hbs b/ui/app/templates/components/secret-version-menu.hbs new file mode 100644 index 000000000000..60e94794bf4d --- /dev/null +++ b/ui/app/templates/components/secret-version-menu.hbs @@ -0,0 +1,96 @@ + + + {{#if useDefaultTrigger}} + + {{else}} + Version {{this.version.version}} + + {{/if}} + + + + + \ No newline at end of file From 30bfea9b2ea3e8efd2b70fd51e756bb3d7add99e Mon Sep 17 00:00:00 2001 From: Matthew Irish Date: Fri, 19 Oct 2018 15:53:32 -0500 Subject: [PATCH 3/7] add versions template --- .../cluster/secrets/backend/versions.hbs | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 ui/app/templates/vault/cluster/secrets/backend/versions.hbs diff --git a/ui/app/templates/vault/cluster/secrets/backend/versions.hbs b/ui/app/templates/vault/cluster/secrets/backend/versions.hbs new file mode 100644 index 000000000000..12e2ccea5a40 --- /dev/null +++ b/ui/app/templates/vault/cluster/secrets/backend/versions.hbs @@ -0,0 +1,73 @@ + + + {{key-value-header + baseKey=(hash id=model.id) + path="vault.cluster.secrets.backend.list" + mode="show" + root=(hash + label=model.engineId + text=model.engineId + path="vault.cluster.secrets.backend.list-root" + model=model.engineId + ) + showCurrent=true + }} + + +

+ Version History +

+
+
+ + + +
+
+ Version {{list.item.version}} +
+
+ {{#if (eq list.item.version model.currentVersion)}} + + Current Version + + {{/if}} + {{#if list.item.deleted}} + + Deleted + + {{/if}} + {{#if list.item.destroyed}} + + Destroyed + + {{/if}} +
+
+
+ + +
  • + + View version {{list.item.version}} + +
  • +
  • + + Create new version from {{list.item.version}} + +
  • +
    +
    +
    +
    \ No newline at end of file From 67382850ac5c885e290d8aaef79a7c56202702bc Mon Sep 17 00:00:00 2001 From: Matthew Irish Date: Fri, 19 Oct 2018 15:54:16 -0500 Subject: [PATCH 4/7] make list-item component more flexible and use hasMenu to optionally render the menu --- ui/app/components/list-item.js | 2 +- ui/app/components/list-item/popup-menu.js | 2 ++ .../cluster/secrets/backend/secret-edit.js | 6 ++--- ui/app/styles/core/helpers.scss | 6 +++++ ui/app/templates/components/list-item.hbs | 24 +++++++------------ .../components/list-item/popup-menu.hbs | 18 ++++++++------ .../templates/partials/secret-list/item.hbs | 10 +++++--- 7 files changed, 39 insertions(+), 29 deletions(-) diff --git a/ui/app/components/list-item.js b/ui/app/components/list-item.js index e4f1f0c0fa4e..c0a4396d1110 100644 --- a/ui/app/components/list-item.js +++ b/ui/app/components/list-item.js @@ -7,7 +7,7 @@ export default Component.extend({ tagName: '', linkParams: null, componentName: null, - hasMenu: false, + hasMenu: true, callMethod: task(function*(method, model, successMessage, failureMessage, successCallback = () => {}) { let flash = this.get('flashMessages'); diff --git a/ui/app/components/list-item/popup-menu.js b/ui/app/components/list-item/popup-menu.js index 4798652642ba..b1f4a59f1d96 100644 --- a/ui/app/components/list-item/popup-menu.js +++ b/ui/app/components/list-item/popup-menu.js @@ -2,4 +2,6 @@ import Component from '@ember/component'; export default Component.extend({ tagName: '', + item: null, + hasMenu: null, }); diff --git a/ui/app/routes/vault/cluster/secrets/backend/secret-edit.js b/ui/app/routes/vault/cluster/secrets/backend/secret-edit.js index 42da97bf16c3..873fc305f6bb 100644 --- a/ui/app/routes/vault/cluster/secrets/backend/secret-edit.js +++ b/ui/app/routes/vault/cluster/secrets/backend/secret-edit.js @@ -140,7 +140,7 @@ export default Route.extend(UnloadModelRoute, { }, willTransition(transition) { - let model = this.controller.model; + let { mode, model } = this.controller; let version = model.get('selectedVersion'); let changed = model.changedAttributes(); let changedKeys = Object.keys(changed); @@ -148,8 +148,8 @@ export default Route.extend(UnloadModelRoute, { // it's going to dirty the model state, so we need to look for it // and explicity ignore it here if ( - (changedKeys.length && changedKeys[0] !== 'backend') || - (version && Object.keys(version.changedAttributes()).length) + (mode !== 'show' && (changedKeys.length && changedKeys[0] !== 'backend')) || + (mode !== 'show' && version && Object.keys(version.changedAttributes()).length) ) { if ( window.confirm( diff --git a/ui/app/styles/core/helpers.scss b/ui/app/styles/core/helpers.scss index b45b46732d80..3f94d9115af2 100644 --- a/ui/app/styles/core/helpers.scss +++ b/ui/app/styles/core/helpers.scss @@ -4,12 +4,18 @@ .is-underline { text-decoration: underline; } +.is-no-underline { + text-decoration: none; +} .is-sideless { box-shadow: 0 2px 0 -1px $grey-light, 0 -2px 0 -1px $grey-light; } .is-bottomless { box-shadow: 0 -1px 0 0 $grey-light; } +.has-bottom-shadow { + box-shadow: $box-shadow !important; +} .is-borderless { border: none !important; } diff --git a/ui/app/templates/components/list-item.hbs b/ui/app/templates/components/list-item.hbs index dbb4e13072b8..fa760d3c567c 100644 --- a/ui/app/templates/components/list-item.hbs +++ b/ui/app/templates/components/list-item.hbs @@ -3,18 +3,14 @@ {{else if linkParams}}
    -
    -
    - {{#link-to params=linkParams class="has-text-weight-semibold"}} - {{yield (hash content=(component "list-item/content"))}} - {{/link-to}} -
    -
    +
    + {{#link-to params=linkParams class="has-text-weight-semibold has-text-black is-display-flex is-flex-1 is-no-underline"}} + {{yield (hash content=(component "list-item/content"))}} + {{/link-to}} +
    - {{#if hasBlock}} - {{yield (hash callMethod=callMethod menu=(component "list-item/popup-menu"))}} - {{/if}} + {{yield (hash callMethod=callMethod menu=(component "list-item/popup-menu" item=item hasMenu=hasMenu))}}
    @@ -22,14 +18,12 @@ {{else}}
    -
    -
    - {{yield (hash content=(component "list-item/content"))}} -
    +
    + {{yield (hash content=(component "list-item/content"))}}
    - {{yield (hash callMethod=callMethod menu=(component "list-item/popup-menu"))}} + {{yield (hash callMethod=callMethod menu=(component "list-item/popup-menu" item=item hasMenu=hasMenu))}}
    diff --git a/ui/app/templates/components/list-item/popup-menu.hbs b/ui/app/templates/components/list-item/popup-menu.hbs index c45c50ca9640..9823c5e91c61 100644 --- a/ui/app/templates/components/list-item/popup-menu.hbs +++ b/ui/app/templates/components/list-item/popup-menu.hbs @@ -1,7 +1,11 @@ - - - +{{#if hasMenu}} + + + +{{else}} + {{yield item}} +{{/if}} diff --git a/ui/app/templates/partials/secret-list/item.hbs b/ui/app/templates/partials/secret-list/item.hbs index 8c60ef3844f0..95b028f64f73 100644 --- a/ui/app/templates/partials/secret-list/item.hbs +++ b/ui/app/templates/partials/secret-list/item.hbs @@ -52,13 +52,17 @@ Details - {{!-- // will add a link to the history view once it exists {{#if backendModel.isV2KV}}
  • - Verion History + + View version history +
  • {{/if}} - --}} {{/if}} {{#if item.canEdit}}
  • From df5bf54d0e0b7bb327718d2b28fed5fd7525ef14 Mon Sep 17 00:00:00 2001 From: Matthew Irish Date: Fri, 19 Oct 2018 16:05:06 -0500 Subject: [PATCH 5/7] move current check next to the version --- .../templates/vault/cluster/secrets/backend/versions.hbs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ui/app/templates/vault/cluster/secrets/backend/versions.hbs b/ui/app/templates/vault/cluster/secrets/backend/versions.hbs index 12e2ccea5a40..2645bd5255c9 100644 --- a/ui/app/templates/vault/cluster/secrets/backend/versions.hbs +++ b/ui/app/templates/vault/cluster/secrets/backend/versions.hbs @@ -25,13 +25,13 @@
    Version {{list.item.version}} -
    -
    {{#if (eq list.item.version model.currentVersion)}} - - Current Version + + Current {{/if}} +
    +
    {{#if list.item.deleted}} Deleted From 0260e4f5860968a3d28c524b324f47acf9fc1566 Mon Sep 17 00:00:00 2001 From: Matthew Irish Date: Fri, 19 Oct 2018 16:06:27 -0500 Subject: [PATCH 6/7] fix linting --- ui/app/routes/vault/cluster/secrets/backend/versions.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/ui/app/routes/vault/cluster/secrets/backend/versions.js b/ui/app/routes/vault/cluster/secrets/backend/versions.js index bea5ef3c7d31..da1d44097e81 100644 --- a/ui/app/routes/vault/cluster/secrets/backend/versions.js +++ b/ui/app/routes/vault/cluster/secrets/backend/versions.js @@ -1,5 +1,3 @@ -import { set } from '@ember/object'; -import { hash, resolve } from 'rsvp'; import Route from '@ember/routing/route'; import utils from 'vault/lib/key-utils'; import UnloadModelRoute from 'vault/mixins/unload-model-route'; From afd8b272499b1a18feb9d2b145c1e754827e2120 Mon Sep 17 00:00:00 2001 From: Matthew Irish Date: Fri, 19 Oct 2018 17:13:58 -0500 Subject: [PATCH 7/7] remove is-wide from secret list popup --- ui/app/templates/partials/secret-list/item.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/app/templates/partials/secret-list/item.hbs b/ui/app/templates/partials/secret-list/item.hbs index 95b028f64f73..0363fe2b52a8 100644 --- a/ui/app/templates/partials/secret-list/item.hbs +++ b/ui/app/templates/partials/secret-list/item.hbs @@ -23,7 +23,7 @@
    - +