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';
|
2023-01-18 00:52:47 +00:00
|
|
|
import ApplicationSerializer from '../../application';
|
|
|
|
|
|
|
|
export default class PkiCertificateBaseSerializer extends ApplicationSerializer {
|
|
|
|
primaryKey = 'serial_number';
|
|
|
|
|
|
|
|
attrs = {
|
|
|
|
role: { serialize: false },
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
return super.normalizeResponse(
|
2023-01-18 00:52:47 +00:00
|
|
|
store,
|
|
|
|
primaryModelClass,
|
2023-04-11 21:04:35 +00:00
|
|
|
{ ...payload, parsed_certificate: parsedCert, common_name: parsedCert.common_name },
|
2023-01-18 00:52:47 +00:00
|
|
|
id,
|
|
|
|
requestType
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return super.normalizeResponse(...arguments);
|
|
|
|
}
|
|
|
|
}
|