-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI: add subkey request to kv v2 adapter (#27804)
* add subkey request to ui * WIP kv subkey display * revert subkey changes to see view in ui * finish subkey component * remove reamining user facing changes * update jsdoc * add subtext depending on toggle * finish tests * organize adapter tests into modules * add adapter tests * woops, make beforeEach * encode paths and add wrap secret test * reword subkey component * extract subkey path logic into util * extract subkey path logic into util * rename yielded subtext block
- Loading branch information
1 parent
7d093f4
commit fe18e6c
Showing
13 changed files
with
571 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{{! | ||
Copyright (c) HashiCorp, Inc. | ||
SPDX-License-Identifier: BUSL-1.1 | ||
~}} | ||
|
||
<OverviewCard @cardTitle="Subkeys"> | ||
<:customSubtext> | ||
<Hds::Text::Body @color="faint" data-test-overview-card-subtitle="Subkeys"> | ||
{{#if this.showJson}} | ||
These are the subkeys within this secret. All underlying values of leaf keys are not retrieved and are replaced with | ||
<code>null</code> | ||
instead. Subkey | ||
<Hds::Link::Inline | ||
@icon="docs-link" | ||
@iconPosition="trailing" | ||
@href={{doc-link "/vault/api-docs/secret/kv/kv-v2#read-secret-subkeys"}} | ||
>API documentation</Hds::Link::Inline>. | ||
{{else}} | ||
The table is displaying the top level subkeys. Toggle on the JSON view to see the full depth. | ||
{{/if}} | ||
</Hds::Text::Body> | ||
</:customSubtext> | ||
<:action> | ||
<div> | ||
<Toggle @name="kv-subkeys" @checked={{this.showJson}} @onChange={{fn (mut this.showJson)}}> | ||
<p class="has-text-grey">JSON</p> | ||
</Toggle> | ||
</div> | ||
</:action> | ||
<:content> | ||
<div class="has-top-margin-s" data-test-overview-card-content="Subkeys"> | ||
{{#if this.showJson}} | ||
<Hds::CodeBlock @value={{stringify @subkeys}} @hasLineNumbers={{false}} /> | ||
{{else}} | ||
<Hds::Text::Display @tag="p" @size="200" @weight="semibold" @color="faint" class="has-bottom-margin-s"> | ||
Keys | ||
</Hds::Text::Display> | ||
<hr class="has-background-gray-100 is-marginless" /> | ||
{{#each-in @subkeys as |key|}} | ||
<Hds::Text::Display @tag="p" @size="200" @weight="semibold" class="has-top-bottom-margin-12"> | ||
{{key}} | ||
</Hds::Text::Display> | ||
<hr class="has-background-gray-100 is-marginless" /> | ||
{{/each-in}} | ||
{{/if}} | ||
</div> | ||
</:content> | ||
</OverviewCard> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright (c) HashiCorp, Inc. | ||
* SPDX-License-Identifier: BUSL-1.1 | ||
*/ | ||
|
||
import Component from '@glimmer/component'; | ||
import { tracked } from '@glimmer/tracking'; | ||
|
||
/** | ||
* @module KvSubkeys | ||
* @description | ||
sample secret data: | ||
``` | ||
{ | ||
"foo": "abc", | ||
"bar": { | ||
"baz": "def" | ||
}, | ||
"quux": {} | ||
} | ||
``` | ||
sample subkeys: | ||
``` | ||
this.subkeys = { | ||
"bar": { | ||
"baz": null | ||
}, | ||
"foo": null, | ||
"quux": null | ||
} | ||
``` | ||
* | ||
* @example | ||
* <KvSubkeys @subkeys={{this.subkeys}} /> | ||
* | ||
* @param {object} subkeys - leaf keys of a kv v2 secret, all values (unless a nested object with more keys) return null | ||
*/ | ||
|
||
export default class KvSubkeys extends Component { | ||
@tracked showJson = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Copyright (c) HashiCorp, Inc. | ||
* SPDX-License-Identifier: BUSL-1.1 | ||
*/ | ||
|
||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'vault/tests/helpers'; | ||
import { setupEngine } from 'ember-engines/test-support'; | ||
import { render, click } from '@ember/test-helpers'; | ||
import { hbs } from 'ember-cli-htmlbars'; | ||
import { GENERAL } from 'vault/tests/helpers/general-selectors'; | ||
|
||
const { overviewCard } = GENERAL; | ||
module('Integration | Component | kv | kv-subkeys', function (hooks) { | ||
setupRenderingTest(hooks); | ||
setupEngine(hooks, 'kv'); | ||
hooks.beforeEach(function () { | ||
this.subkeys = { | ||
foo: null, | ||
bar: { | ||
baz: null, | ||
}, | ||
}; | ||
this.renderComponent = async () => { | ||
return render(hbs`<KvSubkeys @subkeys={{this.subkeys}} />`, { | ||
owner: this.engine, | ||
}); | ||
}; | ||
}); | ||
|
||
test('it renders', async function (assert) { | ||
assert.expect(4); | ||
await this.renderComponent(); | ||
|
||
assert.dom(overviewCard.title('Subkeys')).exists(); | ||
assert | ||
.dom(overviewCard.description('Subkeys')) | ||
.hasText( | ||
'The table is displaying the top level subkeys. Toggle on the JSON view to see the full depth.' | ||
); | ||
assert.dom(overviewCard.content('Subkeys')).hasText('Keys foo bar'); | ||
assert.dom(GENERAL.toggleInput('kv-subkeys')).isNotChecked('JSON toggle is not checked by default'); | ||
}); | ||
|
||
test('it toggles to JSON', async function (assert) { | ||
assert.expect(4); | ||
await this.renderComponent(); | ||
|
||
assert.dom(GENERAL.toggleInput('kv-subkeys')).isNotChecked(); | ||
await click(GENERAL.toggleInput('kv-subkeys')); | ||
assert.dom(GENERAL.toggleInput('kv-subkeys')).isChecked('JSON toggle is checked'); | ||
assert.dom(overviewCard.description('Subkeys')).hasText( | ||
'These are the subkeys within this secret. All underlying values of leaf keys are not retrieved and are replaced with null instead. Subkey API documentation .' // space is intentional because a trailing icon renders after the inline link | ||
); | ||
assert.dom(overviewCard.content('Subkeys')).hasText(JSON.stringify(this.subkeys, null, 2)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.