2018-09-25 16:28:26 +00:00
|
|
|
import { get } from '@ember/object';
|
2018-04-20 02:26:25 +00:00
|
|
|
import ApplicationSerializer from './application';
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-04-20 02:26:25 +00:00
|
|
|
export default ApplicationSerializer.extend({
|
|
|
|
secretDataPath: 'data',
|
|
|
|
normalizeItems(payload, requestType) {
|
2019-01-10 17:18:29 +00:00
|
|
|
if (requestType !== 'queryRecord' && payload.data.keys && Array.isArray(payload.data.keys)) {
|
2018-04-20 02:26:25 +00:00
|
|
|
// 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
|
2018-04-03 14:16:57 +00:00
|
|
|
let fullSecretPath = payload.id ? payload.id + secret : secret;
|
2018-04-20 02:26:25 +00:00
|
|
|
|
|
|
|
// 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
|
2018-04-03 14:16:57 +00:00
|
|
|
if (!fullSecretPath) {
|
|
|
|
fullSecretPath = '\u0020';
|
|
|
|
}
|
2018-10-18 04:06:52 +00:00
|
|
|
return { id: fullSecretPath, backend: payload.backend };
|
2018-04-03 14:16:57 +00:00
|
|
|
});
|
|
|
|
}
|
2018-04-20 02:26:25 +00:00
|
|
|
let path = this.get('secretDataPath');
|
|
|
|
// move response that is the contents of the secret from the dataPath
|
|
|
|
// to `secret_data` so it will be `secretData` in the model
|
2018-09-25 16:28:26 +00:00
|
|
|
payload.secret_data = get(payload, path);
|
2018-04-20 02:26:25 +00:00
|
|
|
delete payload[path];
|
|
|
|
// return the payload if it's expecting a single object or wrap
|
|
|
|
// it as an array if not
|
|
|
|
return requestType === 'queryRecord' ? payload : [payload];
|
2018-04-03 14:16:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
serialize(snapshot) {
|
|
|
|
return snapshot.attr('secretData');
|
|
|
|
},
|
|
|
|
});
|