2023-03-01 09:39:41 -06:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2021-07-01 14:28:53 -04:00
|
|
|
import ApplicationSerializer from './application';
|
2022-06-28 19:30:26 -04:00
|
|
|
export default class CredentialStoreSerializer extends ApplicationSerializer {
|
|
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
* @method serialize
|
|
|
|
|
* @param {Snapshot} snapshot
|
|
|
|
|
*/
|
2022-07-15 13:24:04 -07:00
|
|
|
serialize(snapshot) {
|
|
|
|
|
switch (snapshot.record.type) {
|
|
|
|
|
case 'vault':
|
|
|
|
|
return this.serializeVault(...arguments);
|
|
|
|
|
case 'static':
|
|
|
|
|
default:
|
|
|
|
|
return this.serializeStatic(...arguments);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serializeVault() {
|
2022-06-28 19:30:26 -04:00
|
|
|
const serialized = super.serialize(...arguments);
|
|
|
|
|
if (serialized.attributes) {
|
|
|
|
|
// Client certificate key cannot be unset when certificate is set.
|
|
|
|
|
// If it's falsy, it must be removed.
|
|
|
|
|
if (
|
|
|
|
|
!serialized.attributes?.client_certificate_key &&
|
|
|
|
|
serialized.attributes?.client_certificate
|
|
|
|
|
)
|
|
|
|
|
delete serialized.attributes.client_certificate_key;
|
|
|
|
|
}
|
|
|
|
|
return serialized;
|
|
|
|
|
}
|
2022-07-15 13:24:04 -07:00
|
|
|
|
|
|
|
|
serializeStatic() {
|
|
|
|
|
const serialized = super.serialize(...arguments);
|
|
|
|
|
// Delete attributes for static cred store
|
|
|
|
|
delete serialized.attributes;
|
|
|
|
|
return serialized;
|
|
|
|
|
}
|
2022-09-26 18:25:02 -07:00
|
|
|
|
|
|
|
|
normalize(typeClass, hash, ...rest) {
|
2023-02-16 14:06:37 -08:00
|
|
|
const normalizedHash = structuredClone(hash);
|
2022-09-26 18:25:02 -07:00
|
|
|
const normalized = super.normalize(typeClass, normalizedHash, ...rest);
|
|
|
|
|
// Remove secret fields as we don't track them after being created/updated
|
|
|
|
|
normalized.data.attributes.token = '';
|
|
|
|
|
return normalized;
|
|
|
|
|
}
|
2022-06-28 19:30:26 -04:00
|
|
|
}
|