mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-30 18:17:55 +00:00 
			
		
		
		
	 92cc175eb6
			
		
	
	92cc175eb6
	
	
	
		
			
			* 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
		
			
				
	
	
		
			52 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			52 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| import { parseCertificate } from 'vault/utils/parse-pki-cert';
 | |
| import ApplicationSerializer from '../application';
 | |
| 
 | |
| export default class PkiIssuerSerializer extends ApplicationSerializer {
 | |
|   primaryKey = 'issuer_id';
 | |
| 
 | |
|   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;
 | |
|     }, {});
 | |
|   }
 | |
| 
 | |
|   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
 | |
|   normalizeItems(payload) {
 | |
|     if (payload.data) {
 | |
|       if (payload.data?.keys && Array.isArray(payload.data.keys)) {
 | |
|         return payload.data.keys.map((issuer_id) => ({
 | |
|           issuer_id,
 | |
|           ...payload.data.key_info[issuer_id],
 | |
|         }));
 | |
|       }
 | |
|       Object.assign(payload, payload.data);
 | |
|       delete payload.data;
 | |
|     }
 | |
|     return payload;
 | |
|   }
 | |
| }
 |