2022-07-20 12:34:18 -07:00
|
|
|
import ApplicationSerializer from './application';
|
|
|
|
|
import { copy } from 'ember-copy';
|
|
|
|
|
|
|
|
|
|
export default class CredentialSerializer extends ApplicationSerializer {
|
2022-08-16 14:35:33 -05:00
|
|
|
/**
|
|
|
|
|
* @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);
|
2022-08-12 15:56:19 -05:00
|
|
|
}
|
2022-08-16 14:35:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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'];
|
2022-07-20 12:34:18 -07:00
|
|
|
return serialized;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
normalize(typeClass, hash, ...rest) {
|
|
|
|
|
const normalizedHash = copy(hash, true);
|
|
|
|
|
const normalized = super.normalize(typeClass, normalizedHash, ...rest);
|
2022-08-16 14:35:33 -05:00
|
|
|
// Remove passphrase as we don't track it after being created/updated
|
|
|
|
|
delete normalized['data']['attributes']['passphrase'];
|
2022-07-20 12:34:18 -07:00
|
|
|
return normalized;
|
|
|
|
|
}
|
|
|
|
|
}
|