open-vault/ui/app/helpers/parse-pki-cert.js
claire bontempo 42ae96ed1c
UI/ PKI UI Redesign (#12541)
* installs node-forge

* correctly displays and formats cert metadata

* removes labels

* uses helper in hbs file

* adds named arg to helper

* pki-ca-cert displays common name, issue & expiry date

* alphabetizes some attrs

* adds test for date helper
2021-10-04 14:31:36 -07:00

21 lines
609 B
JavaScript

import { helper } from '@ember/component/helper';
import { pki } from 'node-forge';
export function parsePkiCert([model]) {
// model has to be the responseJSON from PKI serializer
if (!model.certificate) {
return;
}
const cert = pki.certificateFromPem(model.certificate);
const commonName = cert.subject.getField('CN') ? cert.subject.getField('CN').value : null;
const issueDate = cert.validity.notBefore;
const expiryDate = cert.validity.notAfter;
return {
common_name: commonName,
issue_date: issueDate,
expiry_date: expiryDate,
};
}
export default helper(parsePkiCert);