2023-01-24 00:49:16 +00:00
|
|
|
import { parseCertificate } from 'vault/utils/parse-pki-cert';
|
2022-09-20 15:25:57 +00:00
|
|
|
import ApplicationSerializer from '../application';
|
|
|
|
|
2022-11-10 21:27:19 +00:00
|
|
|
export default class PkiIssuerSerializer extends ApplicationSerializer {
|
2022-12-21 16:30:24 +00:00
|
|
|
primaryKey = 'issuer_id';
|
|
|
|
|
2023-01-12 23:33:14 +00:00
|
|
|
constructor() {
|
|
|
|
super(...arguments);
|
|
|
|
// remove following attrs from serialization
|
|
|
|
const attrs = [
|
|
|
|
'caChain',
|
|
|
|
'certificate',
|
|
|
|
'commonName',
|
|
|
|
'issuerId',
|
|
|
|
'keyId',
|
|
|
|
'notValidAfter',
|
|
|
|
'notValidBefore',
|
|
|
|
'serialNumber',
|
|
|
|
];
|
|
|
|
this.attrs = attrs.reduce((attrObj, attr) => {
|
|
|
|
attrObj[attr] = { serialize: false };
|
|
|
|
return attrObj;
|
|
|
|
}, {});
|
|
|
|
}
|
|
|
|
|
2022-12-21 16:30:24 +00:00
|
|
|
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
|
|
|
|
if (payload.data.certificate) {
|
|
|
|
// Parse certificate back from the API and add to payload
|
|
|
|
const parsedCert = parseCertificate(payload.data.certificate);
|
|
|
|
const data = { issuer_ref: payload.issuer_id, ...payload.data, ...parsedCert };
|
|
|
|
const json = super.normalizeResponse(store, primaryModelClass, { ...payload, data }, id, requestType);
|
|
|
|
return json;
|
|
|
|
}
|
|
|
|
return super.normalizeResponse(...arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
// rehydrate each issuers model so all model attributes are accessible from the LIST response
|
2022-09-20 15:25:57 +00:00
|
|
|
normalizeItems(payload) {
|
|
|
|
if (payload.data) {
|
|
|
|
if (payload.data?.keys && Array.isArray(payload.data.keys)) {
|
2022-12-21 16:30:24 +00:00
|
|
|
return payload.data.keys.map((issuer_id) => ({
|
|
|
|
issuer_id,
|
|
|
|
...payload.data.key_info[issuer_id],
|
|
|
|
}));
|
2022-09-20 15:25:57 +00:00
|
|
|
}
|
|
|
|
Object.assign(payload, payload.data);
|
|
|
|
delete payload.data;
|
|
|
|
}
|
|
|
|
return payload;
|
|
|
|
}
|
|
|
|
}
|