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 4 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.
```
11 changes: 11 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,14 @@ export default class SecretCreateOrUpdate extends Component {
this.transitionToRoute(LIST_ROOT_ROUTE);
}
}
pathHasWhiteSpace(value) {
let validation = new RegExp('\\s', 'g'); // search for whitespace
if (validation.test(value)) {
this.pathWhiteSpaceWarning = true;
Monkeychip marked this conversation as resolved.
Show resolved Hide resolved
} else {
this.pathWhiteSpaceWarning = false;
}
}
// 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
4 changes: 4 additions & 0 deletions ui/app/styles/core/alert-banner.scss
Expand Up @@ -4,3 +4,7 @@

color: $black;
}

.margin-top {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In helpers.scss we have .has-top-margin helpers, is there a reason we have it set here specifically rather than using a helper?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. I missed this. When I search the code I was looking for has-margin-top, I'll remove.

margin-top: $spacing-xs;
}
8 changes: 8 additions & 0 deletions ui/app/templates/components/secret-create-or-update.hbs
Expand Up @@ -28,6 +28,14 @@
The secret path may not end in <code>/</code>
</p>
{{/if}}
{{#if this.pathWhiteSpaceWarning}}
<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
/>
{{/if}}
</div>
{{#if @showAdvancedMode}}
<div class="form-section">
Expand Down
3 changes: 2 additions & 1 deletion ui/lib/core/addon/components/alert-banner.js
Expand Up @@ -17,6 +17,7 @@ import layout from '../templates/components/alert-banner';
* @param {Object} [progressBar=null] - An object containing a value and maximum for a progress bar. Will be displayed next to the message title.
* @param {String} [message=null] - The message to display within the banner.
* @param {String} [title=null] - A title to show above the message. If this is not provided, there are default values for each type of alert.
* @param [marginTop=false]{Boolean} - Whether or not to add margin above component.
*
*/

Expand All @@ -29,7 +30,7 @@ export default Component.extend({
progressBar: null,
yieldWithoutColumn: false,
marginless: false,
classNameBindings: ['containerClass'],
classNameBindings: ['containerClass', 'marginTop:margin-top'],
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer to wrap the component in classes that adjust the layout, rather than adding the need for this component to know it has a margin top (plus, that implies the need for support of all the margins in the future)


containerClass: computed('type', 'marginless', function() {
const base = this.marginless ? 'message message-marginless ' : 'message ';
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