Files
threshold-ui/addons/api/addon/serializers/credential.js
T

48 lines
1.3 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
2022-07-20 12:34:18 -07:00
import ApplicationSerializer from './application';
export default class CredentialSerializer extends ApplicationSerializer {
2022-08-16 14:35:33 -05:00
/**
* @override
* @method serialize
* @param {Snapshot} snapshot
*/
2022-08-18 08:23:43 -07:00
/**
* @type {boolean}
*/
serializeScopeID = false;
2022-11-21 16:28:10 -05:00
serialize() {
const serialized = super.serialize(...arguments);
if (serialized.type === 'json') {
delete serialized.attributes.username;
if (serialized?.attributes?.json_object) {
2022-12-16 15:06:19 -05:00
serialized.attributes.object = JSON.parse(
serialized.attributes.json_object,
2022-12-16 15:06:19 -05:00
);
2022-11-21 16:28:10 -05:00
delete serialized.attributes.json_object;
}
} else {
delete serialized.attributes.json_object;
2022-11-21 16:28:10 -05:00
}
return serialized;
}
2022-07-20 12:34:18 -07:00
normalize(typeClass, hash, ...rest) {
const normalizedHash = structuredClone(hash);
2022-07-20 12:34:18 -07:00
const normalized = super.normalize(typeClass, normalizedHash, ...rest);
// Remove secret fields as we don't track them after being created/updated
2022-08-24 15:50:48 -07:00
normalized.data.attributes.password = '';
normalized.data.attributes.private_key = '';
normalized.data.attributes.private_key_passphrase = '';
2022-11-21 16:28:10 -05:00
normalized.data.attributes.json_object = '';
2022-07-20 12:34:18 -07:00
return normalized;
}
}