2020-08-24 18:03:45 -04:00
|
|
|
import ApplicationSerializer from './application';
|
|
|
|
|
|
|
|
|
|
export default class TargetSerializer extends ApplicationSerializer {
|
|
|
|
|
// =methods
|
|
|
|
|
|
|
|
|
|
/**
|
2020-08-26 13:52:54 -04:00
|
|
|
* If `adapterOptions.hostSets` is set to an array of host set models,
|
|
|
|
|
* the resulting target serialization should include **only host sets**
|
2021-07-20 16:09:59 -04:00
|
|
|
* and the version.
|
|
|
|
|
* If `adapterOptions.credentialLibraries` is set to an array of
|
|
|
|
|
* credential library models, the resulting target serialization should
|
|
|
|
|
* include **only credential libraries** and the version.
|
|
|
|
|
* Normally, neither host sets or credential libraries are not serialized.
|
2020-08-24 18:03:45 -04:00
|
|
|
* @override
|
|
|
|
|
* @param {Snapshot} snapshot
|
|
|
|
|
* @return {object}
|
|
|
|
|
*/
|
|
|
|
|
serialize(snapshot) {
|
|
|
|
|
let serialized = super.serialize(...arguments);
|
2021-09-22 08:49:38 -04:00
|
|
|
const hostSourceIDs = snapshot?.adapterOptions?.hostSetIDs;
|
|
|
|
|
if (hostSourceIDs) {
|
|
|
|
|
serialized = this.serializeWithHostSources(snapshot, hostSourceIDs);
|
|
|
|
|
}
|
|
|
|
|
const credentialSourceIDs = snapshot?.adapterOptions?.credentialLibraryIDs;
|
|
|
|
|
if (credentialSourceIDs)
|
|
|
|
|
serialized = this.serializeWithCredentialSources(
|
2021-07-20 16:09:59 -04:00
|
|
|
snapshot,
|
2021-09-22 08:49:38 -04:00
|
|
|
credentialSourceIDs
|
2021-07-20 16:09:59 -04:00
|
|
|
);
|
2020-08-24 18:03:45 -04:00
|
|
|
return serialized;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-09-23 10:04:23 -04:00
|
|
|
* Returns a payload containing only version and an array of passed IDs,
|
|
|
|
|
* rather than existing instances on the model.
|
2020-08-24 18:03:45 -04:00
|
|
|
* @param {Snapshot} snapshot
|
2020-08-26 14:03:43 -04:00
|
|
|
* @param {[string]} hostSetIDs
|
2020-08-24 18:03:45 -04:00
|
|
|
* @return {object}
|
|
|
|
|
*/
|
2021-09-22 08:49:38 -04:00
|
|
|
serializeWithHostSources(snapshot, hostSourceIDs) {
|
2020-08-24 18:03:45 -04:00
|
|
|
return {
|
|
|
|
|
version: snapshot.attr('version'),
|
2021-09-22 19:15:09 -04:00
|
|
|
host_source_ids: hostSourceIDs,
|
2020-08-24 18:03:45 -04:00
|
|
|
};
|
|
|
|
|
}
|
2021-07-20 16:09:59 -04:00
|
|
|
|
|
|
|
|
/**
|
2021-09-23 10:04:23 -04:00
|
|
|
* Returns a payload containing only version and an array of passed IDs,
|
|
|
|
|
* rather than existing instances on the model.
|
2021-07-20 16:09:59 -04:00
|
|
|
* @param {Snapshot} snapshot
|
2021-09-23 10:04:23 -04:00
|
|
|
* @param {[string]} credentialSourceIDs
|
2021-07-20 16:09:59 -04:00
|
|
|
* @return {object}
|
|
|
|
|
*/
|
2021-09-22 08:49:38 -04:00
|
|
|
serializeWithCredentialSources(snapshot, credentialSourceIDs) {
|
2021-07-20 16:09:59 -04:00
|
|
|
return {
|
|
|
|
|
version: snapshot.attr('version'),
|
2021-09-22 17:39:15 -04:00
|
|
|
application_credential_source_ids: credentialSourceIDs,
|
2021-07-20 16:09:59 -04:00
|
|
|
};
|
|
|
|
|
}
|
2020-08-24 18:03:45 -04:00
|
|
|
}
|