2018-10-04 04:32:55 +00:00
|
|
|
import ApplicationSerializer from './application';
|
|
|
|
import DS from 'ember-data';
|
2018-04-20 02:26:25 +00:00
|
|
|
|
2018-10-04 04:32:55 +00:00
|
|
|
export default ApplicationSerializer.extend(DS.EmbeddedRecordsMixin, {
|
|
|
|
attrs: {
|
|
|
|
versions: { embedded: 'always' },
|
|
|
|
},
|
|
|
|
secretDataPath: 'data',
|
|
|
|
normalizeItems(payload, requestType) {
|
|
|
|
if (payload.data.keys && Array.isArray(payload.data.keys)) {
|
|
|
|
// if we have data.keys, it's a list of ids, so we map over that
|
|
|
|
// and create objects with id's
|
|
|
|
return payload.data.keys.map(secret => {
|
|
|
|
// secrets don't have an id in the response, so we need to concat the full
|
|
|
|
// path of the secret here - the id in the payload is added
|
|
|
|
// in the adapter after making the request
|
|
|
|
let fullSecretPath = payload.id ? payload.id + secret : secret;
|
|
|
|
|
|
|
|
// if there is no path, it's a "top level" secret, so add
|
|
|
|
// a unicode space for the id
|
|
|
|
// https://github.com/hashicorp/vault/issues/3348
|
|
|
|
if (!fullSecretPath) {
|
|
|
|
fullSecretPath = '\u0020';
|
|
|
|
}
|
2018-10-18 04:06:52 +00:00
|
|
|
return {
|
|
|
|
id: fullSecretPath,
|
|
|
|
engine_id: payload.backend,
|
|
|
|
};
|
2018-10-04 04:32:55 +00:00
|
|
|
});
|
|
|
|
}
|
2018-10-06 03:02:23 +00:00
|
|
|
// transform versions to an array with composite IDs
|
2018-10-04 04:32:55 +00:00
|
|
|
if (payload.data.versions) {
|
|
|
|
payload.data.versions = Object.keys(payload.data.versions).map(version => {
|
|
|
|
let body = payload.data.versions[version];
|
|
|
|
body.version = version;
|
2018-10-06 03:02:23 +00:00
|
|
|
body.path = payload.id;
|
2018-10-04 04:32:55 +00:00
|
|
|
body.id = JSON.stringify([payload.backend, payload.id, version]);
|
|
|
|
return body;
|
|
|
|
});
|
|
|
|
}
|
2018-10-19 22:24:57 +00:00
|
|
|
payload.data.engine_id = payload.backend;
|
2018-10-04 04:32:55 +00:00
|
|
|
payload.data.id = payload.id;
|
|
|
|
return requestType === 'queryRecord' ? payload.data : [payload.data];
|
|
|
|
},
|
2018-10-15 14:40:18 +00:00
|
|
|
serializeHasMany() {
|
|
|
|
return;
|
|
|
|
},
|
2018-04-20 02:26:25 +00:00
|
|
|
});
|