-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathmetadata.js
39 lines (36 loc) · 1.44 KB
/
metadata.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { assert } from '@ember/debug';
import ApplicationSerializer from '../application';
import { kvMetadataPath } from 'vault/utils/kv-path';
export default class KvMetadataSerializer extends ApplicationSerializer {
attrs = {
backend: { serialize: false },
path: { serialize: false },
oldestVersion: { serialize: false },
createdTime: { serialize: false },
updatedTime: { serialize: false },
currentVersion: { serialize: false },
versions: { serialize: false },
};
normalizeItems(payload) {
if (payload.data.keys) {
assert('payload.backend must be provided on kv/metadata list response', !!payload.backend);
return payload.data.keys.map((secret) => {
// If there is no payload.path then we're either on a "top level" secret or the first level directory of a nested secret.
// We set the path to the current secret or pathToSecret. e.g. my-secret or beep/boop/
// We add a param called full_secret_path to the model which we use to navigate to the nested secret. e.g. beep/boop/bop.
const fullSecretPath = payload.path ? payload.path + secret : secret;
return {
id: kvMetadataPath(payload.backend, fullSecretPath),
path: secret,
backend: payload.backend,
full_secret_path: fullSecretPath,
};
});
}
return super.normalizeItems(payload);
}
}