2023-03-15 16:00:52 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
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-04-11 21:04:35 +00:00
|
|
|
attrs = {
|
|
|
|
caChain: { serialize: false },
|
|
|
|
certificate: { serialize: false },
|
|
|
|
issuerId: { serialize: false },
|
|
|
|
keyId: { serialize: false },
|
|
|
|
parsedCertificate: { serialize: false },
|
|
|
|
commonName: { serialize: false },
|
2023-04-28 15:05:12 +00:00
|
|
|
isRoot: { serialize: false },
|
2023-04-11 21:04:35 +00:00
|
|
|
};
|
2023-01-12 23:33:14 +00:00
|
|
|
|
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);
|
2023-04-11 21:04:35 +00:00
|
|
|
const data = {
|
|
|
|
...payload.data,
|
|
|
|
parsed_certificate: parsedCert,
|
|
|
|
common_name: parsedCert.common_name,
|
|
|
|
};
|
|
|
|
return super.normalizeResponse(store, primaryModelClass, { ...payload, data }, id, requestType);
|
2022-12-21 16:30:24 +00:00
|
|
|
}
|
|
|
|
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)) {
|
2023-04-28 15:05:12 +00:00
|
|
|
return payload.data.keys.map((key) => {
|
|
|
|
return {
|
|
|
|
issuer_id: key,
|
|
|
|
...payload.data.key_info[key],
|
|
|
|
};
|
|
|
|
});
|
2022-09-20 15:25:57 +00:00
|
|
|
}
|
|
|
|
Object.assign(payload, payload.data);
|
|
|
|
delete payload.data;
|
|
|
|
}
|
|
|
|
return payload;
|
|
|
|
}
|
|
|
|
}
|