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

UI add custom metadata to KV2 #12169

Merged
merged 43 commits into from Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
7e39250
initial setup
Monkeychip Jul 23, 2021
975f45a
form field editType kv is very helpful
Monkeychip Jul 26, 2021
f311c18
setting up things
Monkeychip Jul 27, 2021
e74a728
setup two routes for metadata
Monkeychip Jul 28, 2021
83322b1
routing
Monkeychip Jul 28, 2021
fed0f56
clean up routing
Monkeychip Jul 29, 2021
5f26562
meh router changes not my favorite but its working
Monkeychip Jul 29, 2021
5a0cb94
merge in main
Monkeychip Jul 29, 2021
640f8eb
show metadata
Monkeychip Jul 29, 2021
d5e5ed5
add controller for backendCrumb mixin
Monkeychip Jul 30, 2021
dee6798
setting up edit metadata and trimming SecretEditMetadata component
Monkeychip Jul 30, 2021
8ccea40
add edit metadata save functionality
Monkeychip Aug 2, 2021
83af67b
create new version work
Monkeychip Aug 9, 2021
bea9f2a
setup model and formfieldgroups for added config data.
Monkeychip Aug 9, 2021
c1a256a
add config network request to secret-engine
Monkeychip Aug 9, 2021
49006b2
fix validations on config
Monkeychip Aug 10, 2021
99f92c6
add config rows
Monkeychip Aug 10, 2021
4925c7c
breaking up secret edit
Monkeychip Aug 11, 2021
7eb5ec3
merge master
Monkeychip Aug 11, 2021
fdd079c
add validation for metadata on create
Monkeychip Aug 12, 2021
053366d
stuff, but broken now on metadata tab
Monkeychip Aug 12, 2021
5e2995c
fix metadata route error
Monkeychip Aug 12, 2021
b561af9
permissions
Monkeychip Aug 13, 2021
0447232
saving small text changes
Monkeychip Aug 17, 2021
a9e9703
permissions
Monkeychip Aug 17, 2021
178d163
cleanup
Monkeychip Aug 17, 2021
1c4da5c
some test fixes and convert secret create or update to glimmer
Monkeychip Aug 18, 2021
fba9597
all these changes fix secret create kv test
Monkeychip Aug 19, 2021
25e9d45
remove alert banners per design request
Monkeychip Aug 19, 2021
e95ef3a
fix error for array instead of object in jsonEditor
Monkeychip Aug 20, 2021
d4ece1d
add changelog
Monkeychip Aug 20, 2021
bb00d9b
styling
Monkeychip Aug 23, 2021
5ef69fe
turn into glimmer component
Monkeychip Aug 23, 2021
73af76c
cleanup
Monkeychip Aug 23, 2021
be143e1
test failure fix
Monkeychip Aug 23, 2021
3523651
add delete or
Monkeychip Aug 24, 2021
5eea7df
Merge branch 'main' into ui/kv-customer-custom-metadata
Monkeychip Aug 24, 2021
d6c7543
clean up
Monkeychip Aug 24, 2021
cd534e3
remove all hardcoded for api integration
Monkeychip Aug 25, 2021
408000d
add helper and fix create mode on create new version
Monkeychip Aug 26, 2021
643faed
address chelseas pr comments
Monkeychip Aug 30, 2021
abff87d
add jsdocs to helper
Monkeychip Aug 30, 2021
89bc486
fix test
Monkeychip Aug 30, 2021
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/12169.txt
@@ -0,0 +1,3 @@
```release-note:feature
ui: Add custom metadata to KV secret engine and metadata to config
```
43 changes: 35 additions & 8 deletions ui/app/adapters/secret-engine.js
@@ -1,13 +1,18 @@
import { assign } from '@ember/polyfills';
import ApplicationAdapter from './application';
import { encodePath } from 'vault/utils/path-encoding-helpers';
import { splitObject } from 'vault/helpers/split-object';

export default ApplicationAdapter.extend({
url(path) {
const url = `${this.buildURL()}/mounts`;
return path ? url + '/' + encodePath(path) : url;
},

urlForConfig(path) {
return `/v1/${path}/config`;
},

internalURL(path) {
let url = `/${this.urlPrefix()}/internal/ui/mounts`;
if (path) {
Expand All @@ -26,15 +31,37 @@ export default ApplicationAdapter.extend({

createRecord(store, type, snapshot) {
const serializer = store.serializerFor(type.modelName);
const data = serializer.serialize(snapshot);
let data = serializer.serialize(snapshot);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

turned to let because we redefine data after abstracting the values we need for the endpoint.

const path = snapshot.attr('path');

return this.ajax(this.url(path), 'POST', { data }).then(() => {
// ember data doesn't like 204s if it's not a DELETE
return {
data: assign({}, data, { path: path + '/', id: path }),
};
});
// for kv2 we make two network requests
if (data.type === 'kv' && data.options.version !== 1) {
// data has both data for sys mount and the config, we need to separate them
let splitObjects = splitObject(data, ['max_versions', 'delete_version_after', 'cas_required']);
Monkeychip marked this conversation as resolved.
Show resolved Hide resolved
let configData;
[configData, data] = splitObjects;
// first create the engine
return this.ajax(this.url(path), 'POST', { data })
.then(() => {
// second modify config on engine
return this.ajax(this.urlForConfig(path), 'POST', { data: configData });
})
.then(() => {
// ember data doesn't like 204s if it's not a DELETE
return {
data: assign({}, data, { path: path + '/', id: path }),
};
})
.catch(e => {
console.log(e, 'error');
});
} else {
return this.ajax(this.url(path), 'POST', { data }).then(() => {
// ember data doesn't like 204s if it's not a DELETE
return {
data: assign({}, data, { path: path + '/', id: path }),
};
});
}
},

findRecord(store, type, path, snapshot) {
Expand Down
35 changes: 34 additions & 1 deletion ui/app/components/kv-object-editor.js
@@ -1,3 +1,26 @@
/**
* @module KvObjectEditor
* KvObjectEditor components are called in FormFields when the editType on the model is kv. They are used to show a key-value input field.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

added documentation to an older component.

*
* @example
* ```js
* <KvObjectEditor
* @value={{get model valuePath}}
* @onChange={{action "setAndBroadcast" valuePath }}
* @label="some label"
/>
* ```
* @param {string} value - the value is captured from the model.
* @param {function} onChange - function that captures the value on change
* @param {function} onKeyUp - function passed in that handles the dom keyup event. Used for validation on the kv custom metadata.
* @param {string} [label] - label displayed over key value inputs
* @param {string} [warning] - warning that is displayed
* @param {string} [helpText] - helper text. In tooltip.
* @param {string} [subText] - placed under label.
* @param {boolean} [small-label]- change label size.
* @param {boolean} [formSection] - if false the component is meant to live outside of a form, like in the customMetadata which is nested already inside a form-section.
*/

import { isNone } from '@ember/utils';
import { assert } from '@ember/debug';
import Component from '@ember/component';
Expand All @@ -7,12 +30,15 @@ import KVObject from 'vault/lib/kv-object';

export default Component.extend({
'data-test-component': 'kv-object-editor',
classNames: ['field', 'form-section'],
classNames: ['field'],
classNameBindings: ['formSection:form-section'],
formSection: true,
// public API
// Ember Object to mutate
value: null,
label: null,
helpText: null,
subText: null,
// onChange will be called with the changed Value
onChange() {},

Expand Down Expand Up @@ -65,5 +91,12 @@ export default Component.extend({
data.removeAt(index);
this.onChange(data.toJSON());
},

handleKeyUp(name, value) {
if (!this.onKeyUp) {
return;
}
this.onKeyUp(name, value);
},
},
});
23 changes: 18 additions & 5 deletions ui/app/components/mount-backend-form.js
Expand Up @@ -108,11 +108,24 @@ export default Component.extend({

actions: {
onKeyUp(name, value) {
this.mountModel.set('path', value);
this.mountModel.validations.attrs.path.isValid
? set(this.validationMessages, 'path', '')
: set(this.validationMessages, 'path', this.mountModel.validations.attrs.path.message);

// validate path
if (name === 'path') {
this.mountModel.set('path', value);
this.mountModel.validations.attrs.path.isValid
? set(this.validationMessages, 'path', '')
: set(this.validationMessages, 'path', this.mountModel.validations.attrs.path.message);
}
// check maxVersions is a number
Copy link
Contributor Author

Choose a reason for hiding this comment

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

add validations for mounting a secret engine. this is relevant for kv2 specifically as we now show maxVersion on the config screen. (we post to both sys/mount and now secret/config)

if (name === 'maxVersions') {
this.mountModel.set('maxVersions', value);
this.mountModel.validations.attrs.maxVersions.isValid
? set(this.validationMessages, 'maxVersions', '')
: set(
this.validationMessages,
'maxVersions',
this.mountModel.validations.attrs.maxVersions.message
);
}
this.mountModel.validate().then(({ validations }) => {
this.set('isFormInvalid', !validations.isValid);
});
Expand Down