vault/ui/app/serializers/secret.js
Angel Garbarino 3850d41a87
Upgrade Ember data 4.11.x to 4.12.x (#25272)
* add target to tsconfig

* initial setup

* fix shamir test

* fix auth test with title case header

* fix mfa-login-test

* fix auth-form-test with title case header

* fix service auth-form test with title case header

* fix test with mfa

* Update package.json

* fix failing cubbyhole tests

* changelog

* fix pki configuration test failure

* update yarn lock

* userpass-rest-password test

* missed

* wip sync issues

* sync stablized
2024-02-20 12:37:50 -07:00

48 lines
1.5 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { get } from '@ember/object';
import ApplicationSerializer from './application';
export default ApplicationSerializer.extend({
secretDataPath: 'data',
normalizeItems(payload, requestType) {
if (
requestType !== 'queryRecord' &&
payload.data &&
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';
}
return { id: fullSecretPath, backend: payload.backend };
});
}
const path = this.secretDataPath;
// move response that is the contents of the secret from the dataPath
// to `secret_data` so it will be `secretData` in the model
payload.secret_data = get(payload, path);
delete payload[path];
return payload;
},
serialize(snapshot) {
return snapshot.attr('secretData');
},
});