mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-17 20:17:00 +02:00
* octanify and add serialize false to readonly attrs * alphabetize * stuff * adds back payload.data check in normalizeResponse method of clients config serializer * test things * fix * clean up * Update ui/app/serializers/clients/config.js Co-authored-by: claire bontempo <68122737+hellobontempo@users.noreply.github.com> --------- Co-authored-by: Jordan Reimer <zofskeez@gmail.com> Co-authored-by: claire bontempo <68122737+hellobontempo@users.noreply.github.com>
44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
*/
|
|
|
|
import ApplicationSerializer from '../application';
|
|
|
|
export default class ClientsConfigSerializer extends ApplicationSerializer {
|
|
// these attrs are readOnly
|
|
attrs = {
|
|
billingStartTimestamp: { serialize: false },
|
|
minimumRetentionMonths: { serialize: false },
|
|
reportingEnabled: { serialize: false },
|
|
};
|
|
|
|
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
|
|
if (!payload.data) {
|
|
return super.normalizeResponse(...arguments);
|
|
}
|
|
const normalizedPayload = {
|
|
id: payload.id,
|
|
data: {
|
|
...payload.data,
|
|
enabled: payload.data.enabled?.includes('enable') ? 'On' : 'Off',
|
|
},
|
|
};
|
|
return super.normalizeResponse(store, primaryModelClass, normalizedPayload, id, requestType);
|
|
}
|
|
|
|
serialize() {
|
|
const json = super.serialize(...arguments);
|
|
if (json.enabled === 'On' || json.enabled === 'Off') {
|
|
const oldEnabled = json.enabled;
|
|
json.enabled = oldEnabled === 'On' ? 'enable' : 'disable';
|
|
}
|
|
json.retention_months = parseInt(json.retention_months, 10);
|
|
if (isNaN(json.retention_months)) {
|
|
throw new Error('Invalid number value');
|
|
}
|
|
delete json.queries_available;
|
|
return json;
|
|
}
|
|
}
|