2018-09-25 16:28:26 +00:00
|
|
|
import { computed } from '@ember/object';
|
|
|
|
import Component from '@ember/component';
|
2018-04-03 14:16:57 +00:00
|
|
|
import utils from 'vault/lib/key-utils';
|
2019-03-01 16:08:30 +00:00
|
|
|
import { encodePath } from 'vault/utils/path-encoding-helpers';
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
export default Component.extend({
|
2018-04-03 14:16:57 +00:00
|
|
|
tagName: 'nav',
|
|
|
|
classNames: 'key-value-header breadcrumb',
|
|
|
|
ariaLabel: 'breadcrumbs',
|
|
|
|
attributeBindings: ['ariaLabel:aria-label', 'aria-hidden'],
|
|
|
|
|
|
|
|
baseKey: null,
|
|
|
|
path: null,
|
|
|
|
showCurrent: true,
|
|
|
|
linkToPaths: true,
|
|
|
|
|
|
|
|
stripTrailingSlash(str) {
|
|
|
|
return str[str.length - 1] === '/' ? str.slice(0, -1) : str;
|
|
|
|
},
|
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
currentPath: computed('mode', 'path', 'showCurrent', function() {
|
2018-04-03 14:16:57 +00:00
|
|
|
const mode = this.get('mode');
|
|
|
|
const path = this.get('path');
|
|
|
|
const showCurrent = this.get('showCurrent');
|
|
|
|
if (!mode || showCurrent === false) {
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
return `vault.cluster.secrets.backend.${mode}`;
|
|
|
|
}),
|
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
secretPath: computed('baseKey', 'baseKey.{display,id}', 'root', 'showCurrent', function() {
|
2018-04-03 14:16:57 +00:00
|
|
|
let crumbs = [];
|
|
|
|
const root = this.get('root');
|
|
|
|
const baseKey = this.get('baseKey.display') || this.get('baseKey.id');
|
2019-03-01 16:08:30 +00:00
|
|
|
const baseKeyModel = encodePath(this.get('baseKey.id'));
|
2018-04-03 14:16:57 +00:00
|
|
|
|
|
|
|
if (root) {
|
|
|
|
crumbs.push(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!baseKey) {
|
|
|
|
return crumbs;
|
|
|
|
}
|
|
|
|
|
|
|
|
const path = this.get('path');
|
|
|
|
const currentPath = this.get('currentPath');
|
|
|
|
const showCurrent = this.get('showCurrent');
|
|
|
|
const ancestors = utils.ancestorKeysForKey(baseKey);
|
|
|
|
const parts = utils.keyPartsForKey(baseKey);
|
2019-08-01 20:49:37 +00:00
|
|
|
if (ancestors.length === 0) {
|
2018-04-03 14:16:57 +00:00
|
|
|
crumbs.push({
|
|
|
|
label: baseKey,
|
|
|
|
text: this.stripTrailingSlash(baseKey),
|
|
|
|
path: currentPath,
|
|
|
|
model: baseKeyModel,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!showCurrent) {
|
|
|
|
crumbs.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
return crumbs;
|
|
|
|
}
|
|
|
|
|
|
|
|
ancestors.forEach((ancestor, index) => {
|
|
|
|
crumbs.push({
|
|
|
|
label: parts[index],
|
|
|
|
text: this.stripTrailingSlash(parts[index]),
|
|
|
|
path: path,
|
|
|
|
model: ancestor,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
crumbs.push({
|
|
|
|
label: utils.keyWithoutParentKey(baseKey),
|
|
|
|
text: this.stripTrailingSlash(utils.keyWithoutParentKey(baseKey)),
|
|
|
|
path: currentPath,
|
|
|
|
model: baseKeyModel,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!showCurrent) {
|
|
|
|
crumbs.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
return crumbs;
|
|
|
|
}),
|
|
|
|
});
|