1309d724e3
* refactor parser to pull serial number from subject * refactor pki parser * uninstall pvtutils * remove hideFormSection as attr * remove hideFormSection as attr * add string-list * test removing issueDate * update tests * final answer - make number types * change to unix time - since valueOf() is typically used internally * add algo mapping * add comment to complete in followon * add attrs to pki parser * add conditional operands so parser continues when values dont exist * add error handling WIP * finish tests, add error handling * revert to helper * move helper to util * add parseSubject test * finish tests * move certs to pki helper file * wrap parsing functions in try...catch
69 lines
2.4 KiB
JavaScript
69 lines
2.4 KiB
JavaScript
import { parsePkiCert } from 'vault/utils/parse-pki-cert';
|
|
import ApplicationAdapter from './application';
|
|
|
|
export default ApplicationAdapter.extend({
|
|
namespace: 'v1',
|
|
|
|
url(snapshot, action) {
|
|
const { backend, caType, type } = snapshot.attributes();
|
|
if (action === 'sign-intermediate') {
|
|
return `/v1/${backend}/root/sign-intermediate`;
|
|
}
|
|
if (action === 'set-signed-intermediate') {
|
|
return `/v1/${backend}/intermediate/set-signed`;
|
|
}
|
|
if (action === 'upload') {
|
|
return `/v1/${backend}/config/ca`;
|
|
}
|
|
return `/v1/${backend}/${caType}/generate/${type}`;
|
|
},
|
|
|
|
createRecordOrUpdate(store, type, snapshot, requestType) {
|
|
const serializer = store.serializerFor('application');
|
|
const isUpload = snapshot.attr('uploadPemBundle');
|
|
const isSetSignedIntermediate = snapshot.adapterOptions.method === 'setSignedIntermediate';
|
|
let action = snapshot.adapterOptions.method === 'signIntermediate' ? 'sign-intermediate' : null;
|
|
let data;
|
|
if (isUpload) {
|
|
action = 'upload';
|
|
data = { pem_bundle: snapshot.attr('pemBundle') };
|
|
} else if (isSetSignedIntermediate) {
|
|
action = 'set-signed-intermediate';
|
|
data = { certificate: snapshot.attr('certificate') };
|
|
} else {
|
|
data = serializer.serialize(snapshot, requestType);
|
|
|
|
// The type parameter is serialized but is part of the URL. This means
|
|
// we'll get an unknown parameter warning back from the server if we
|
|
// send it. Remove it instead.
|
|
delete data.type;
|
|
}
|
|
|
|
return this.ajax(this.url(snapshot, action), 'POST', { data }).then((response) => {
|
|
// uploading CA, setting signed intermediate cert, and attempting to generate
|
|
// a new CA if one exists, all return a 204
|
|
if (!response) {
|
|
response = {};
|
|
}
|
|
response.id = snapshot.id;
|
|
response.modelName = type.modelName;
|
|
// only parse if certificate is attached to response
|
|
if (response.data && response.data.certificate) {
|
|
const caCertMetadata = parsePkiCert(response.data);
|
|
const transformedResponse = { ...response, ...caCertMetadata };
|
|
store.pushPayload(type.modelName, transformedResponse);
|
|
} else {
|
|
store.pushPayload(type.modelName, response);
|
|
}
|
|
});
|
|
},
|
|
|
|
createRecord() {
|
|
return this.createRecordOrUpdate(...arguments);
|
|
},
|
|
|
|
updateRecord() {
|
|
return this.createRecordOrUpdate(...arguments);
|
|
},
|
|
});
|