Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KV alert banner for white space in KV path #12921

Merged
merged 9 commits into from Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/12921.txt
@@ -0,0 +1,3 @@
```release-note:improvement
ui: Adds warning about white space in KV secret engine.
```
7 changes: 7 additions & 0 deletions ui/app/components/secret-create-or-update.js
Expand Up @@ -44,6 +44,7 @@ export default class SecretCreateOrUpdate extends Component {
@tracked codemirrorString = null;
@tracked error = null;
@tracked secretPaths = null;
@tracked pathWhiteSpaceWarning = false;
@tracked validationErrorCount = 0;
@tracked validationMessages = null;

Expand Down Expand Up @@ -82,6 +83,8 @@ export default class SecretCreateOrUpdate extends Component {
}
checkValidation(name, value) {
if (name === 'path') {
// check for whitespace
this.pathHasWhiteSpace(value);
!value
? set(this.validationMessages, name, `${name} can't be blank.`)
: set(this.validationMessages, name, '');
Expand All @@ -106,6 +109,10 @@ export default class SecretCreateOrUpdate extends Component {
this.transitionToRoute(LIST_ROOT_ROUTE);
}
}
pathHasWhiteSpace(value) {
let validation = new RegExp('\\s', 'g'); // search for whitespace
this.pathWhiteSpaceWarning = validation.test(value);
}
// successCallback is called in the context of the component
persistKey(successCallback) {
let secret = this.args.model;
Expand Down
2 changes: 1 addition & 1 deletion ui/app/models/secret-engine.js
Expand Up @@ -52,7 +52,7 @@ export default Model.extend(Validations, {
defaultValue: 0,
label: 'Maximum number of versions',
subText:
'The number of versions to keep per key. Once the number of keys exceeds the maximum number set here, the oldest version will be permanently deleted. This value applies to all keys, but a key’s metadata settings can overwrite this value.',
'The number of versions to keep per key. Once the number of keys exceeds the maximum number set here, the oldest version will be permanently deleted. This value applies to all keys, but a key’s metadata settings can overwrite this value. When 0 is used or the value is unset, Vault will keep 10 versions.',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a quick fix on the max_version message that I confirmed with design.

}),
casRequired: attr('boolean', {
defaultValue: false,
Expand Down
10 changes: 10 additions & 0 deletions ui/app/templates/components/secret-create-or-update.hbs
Expand Up @@ -28,6 +28,16 @@
The secret path may not end in <code>/</code>
</p>
{{/if}}
{{#if this.pathWhiteSpaceWarning}}
<div class="has-top-margin-m">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had to add the div to add the margin, unable to add margin class to component itself.

<AlertBanner
@type="warning"
@message="Your secret path contains whitespace. If this is desired, you'll need to encode it with %20 in API calls."
@marginTop=true
data-test-whitespace-warning
/>
</div>
{{/if}}
</div>
{{#if @showAdvancedMode}}
<div class="form-section">
Expand Down
10 changes: 8 additions & 2 deletions ui/tests/acceptance/secrets/backend/kv/secret-test.js
Expand Up @@ -440,7 +440,7 @@ module('Acceptance | secrets/secret/create', function(hooks) {
}
});

test('create secret with space shows version data', async function(assert) {
test('create secret with space shows version data and shows space warning', async function(assert) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

let enginePath = `kv-${new Date().getTime()}`;
let secretPath = 'space space';
// mount version 2
Expand All @@ -452,7 +452,13 @@ module('Acceptance | secrets/secret/create', function(hooks) {
.submit();
await settled();
await listPage.create();
await editPage.createSecret(secretPath, 'foo', 'bar');
await editPage.createSecretDontSave(secretPath, 'foo', 'bar');
// to trigger warning need to hit keyup on the secret path
await triggerKeyEvent('[data-test-secret-path="true"]', 'keyup', 65);
await settled();
assert.dom('[data-test-whitespace-warning]').exists('renders warning about their being a space');
await settled();
await click('[data-test-secret-save="true"]');
await settled();
await click('[data-test-popup-menu-trigger="version"]');
await settled();
Expand Down
5 changes: 5 additions & 0 deletions ui/tests/pages/secrets/backend/kv/edit-secret.js
Expand Up @@ -29,6 +29,11 @@ export default create({
.secretValue(value)
.save();
},
createSecretDontSave: async function(path, key, value) {
return this.path(path)
.secretKey(key)
.secretValue(value);
},
createSecretWithMetadata: async function(path, key, value, maxVersion) {
return this.path(path)
.secretKey(key)
Expand Down