Files
threshold-ui/addons/api/addon/serializers/credential.js
T
Cameron Perera 50038cdf85 Icu 5646 serializer (#1257)
* feat: 🎸 Update Credential Serializer

Add support for SSH Private Key credentials

✅ Closes: ICU-5646

* test: 💍 Add normalize test for ssh private key credentials

* refactor: 💡 remove deletion of hmac attributes in serializer
2022-08-16 14:35:33 -05:00

43 lines
1.3 KiB
JavaScript

import ApplicationSerializer from './application';
import { copy } from 'ember-copy';
export default class CredentialSerializer extends ApplicationSerializer {
/**
* @override
* @method serialize
* @param {Snapshot} snapshot
*/
serialize(snapshot) {
switch (snapshot.record.type) {
case 'username_password':
return this.serializeUsernamePassword(...arguments);
case 'ssh_private_key':
default:
return this.serializeSSHPrivateKey(...arguments);
}
}
serializeUsernamePassword() {
const serialized = super.serialize(...arguments);
// Remove non-username_password type attributes
delete serialized['attributes']['private_key'];
delete serialized['attributes']['passphrase'];
return serialized;
}
serializeSSHPrivateKey() {
const serialized = super.serialize(...arguments);
// Remove non-ssh_private_key type attributes
delete serialized['attributes']['password'];
return serialized;
}
normalize(typeClass, hash, ...rest) {
const normalizedHash = copy(hash, true);
const normalized = super.normalize(typeClass, normalizedHash, ...rest);
// Remove passphrase as we don't track it after being created/updated
delete normalized['data']['attributes']['passphrase'];
return normalized;
}
}