Files
threshold-ui/addons/api/addon/serializers/credential.js
T
Zhihe Li bcf004b8a4 Reformat codebase with trailing commas in functions (#2006)
* style: 💄 Update trailing commas in API

* style: 💄 Update trailing commas in core

* style: 💄 Update trailing commas in rose

* style: 💄 Update trailing commas in admin

* style: 💄 Update trailing commas in desktop
2023-11-22 14:07:41 -05:00

49 lines
1.3 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import ApplicationSerializer from './application';
export default class CredentialSerializer extends ApplicationSerializer {
/**
* @override
* @method serialize
* @param {Snapshot} snapshot
*/
/**
* @type {boolean}
*/
serializeScopeID = false;
serialize() {
const serialized = super.serialize(...arguments);
if (serialized.type === 'json') {
delete serialized.attributes.username;
if (serialized?.attributes?.json_object) {
serialized.attributes.object = JSON.parse(
serialized.attributes.json_object,
);
delete serialized.attributes.json_object;
}
} else {
delete serialized.attributes.json_object;
}
return serialized;
}
normalize(typeClass, hash, ...rest) {
const normalizedHash = structuredClone(hash);
const normalized = super.normalize(typeClass, normalizedHash, ...rest);
// Remove secret fields as we don't track them after being created/updated
normalized.data.attributes.password = '';
normalized.data.attributes.private_key = '';
normalized.data.attributes.private_key_passphrase = '';
normalized.data.attributes.json_object = '';
return normalized;
}
}