2023-03-01 09:39:41 -06:00
|
|
|
/**
|
|
|
|
|
* 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(
|
2023-11-22 14:07:41 -05:00
|
|
|
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;
|
|
|
|
|
}
|
2023-01-12 16:28:43 -06:00
|
|
|
} 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) {
|
2023-02-16 14:06:37 -08:00
|
|
|
const normalizedHash = structuredClone(hash);
|
2022-07-20 12:34:18 -07:00
|
|
|
const normalized = super.normalize(typeClass, normalizedHash, ...rest);
|
2022-08-30 20:40:31 -05:00
|
|
|
// 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 = '';
|
2022-08-30 20:40:31 -05:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|