From 5a66693cdb14f0959f6a9c5058d8ad7c877cdd42 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sun, 7 Apr 2019 11:32:57 -0600 Subject: [PATCH] v3.0.1: clarify comments and docs --- index.js | 29 +++++++++++++++++------------ package-lock.json | 2 +- package.json | 6 +++--- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index 91a27fc..492193f 100644 --- a/index.js +++ b/index.js @@ -37,14 +37,19 @@ module.exports.create = function (opts) { - // This is our in-memory storage. - // We take it from the outside to make testing the dummy module easier. + // This is our dummy in-memory storage. + // (we optionally receive it as an option so that it can be defined outside to make testing easier) var cache = opts.cache || {}; if (!cache.accounts) { cache.accounts = {}; } if (!cache.certificates) { cache.certificates = {}; } // Although we could have two collections of keypairs, - // it's also fine to store both types together. + // it's also fine to store both types together (their ids will be distinct). if (!cache.keypairs) { cache.keypairs = {}; } + // This is an in-memory store, hence we don't actually save it. + function saveCertificate(id, blob) { cache.certificates[id] = blob; return null; } + function getCertificate(id) { return cache.certificates[id]; } + function saveKeypair(id, blob) { cache.keypairs[id] = blob; return null; } + function getKeypair(id) { return cache.keypairs[id]; } @@ -64,10 +69,10 @@ module.exports.create = function (opts) { var id = opts.account.id || opts.email || 'default'; var keypair = opts.keypair; - cache.keypairs[id] = JSON.stringify({ + saveKeypair(id, JSON.stringify({ privateKeyPem: keypair.privateKeyPem , privateKeyJwk: keypair.privateKeyJwk - }); + })); return null; // or Promise.resolve(null); }; @@ -79,7 +84,7 @@ module.exports.create = function (opts) { console.log('accounts.checkKeypair:', opts.account, opts.email); var id = opts.account.id || opts.email || 'default'; - var keyblob = cache.keypairs[id]; + var keyblob = getKeypair(id); if (!keyblob) { return null; } @@ -116,10 +121,10 @@ module.exports.create = function (opts) { var id = opts.certificate.kid || opts.certificate.id || opts.subject; var keypair = opts.keypair; - cache.keypairs[id] = JSON.stringify({ + saveKeypair(id, JSON.stringify({ privateKeyPem: keypair.privateKeyPem , privateKeyJwk: keypair.privateKeyJwk - }); + })); // Note: you can use the "keypairs" package to convert between // public and private for jwk and pem, as well as convert JWK <-> PEM @@ -133,7 +138,7 @@ module.exports.create = function (opts) { console.log('certificates.checkKeypair:', opts.certificate, opts.subject); var id = opts.certificate.kid || opts.certificate.id || opts.subject; - var keyblob = cache.keypairs[id]; + var keyblob = getKeypair(id); if (!keyblob) { return null; } @@ -150,14 +155,14 @@ module.exports.create = function (opts) { var id = opts.certificate.id || opts.subject; var pems = opts.pems; - cache.certificates[id] = JSON.stringify({ + saveCertificate(id, JSON.stringify({ cert: pems.cert , chain: pems.chain , subject: pems.subject , altnames: pems.altnames , issuedAt: pems.issuedAt // a.k.a. NotBefore , expiresAt: pems.expiresAt // a.k.a. NotAfter - }); + })); return null; }; @@ -171,7 +176,7 @@ module.exports.create = function (opts) { console.log('certificates.check:', opts.certificate, opts.subject); var id = opts.certificate.id || opts.subject; - var certblob = cache.certificates[id]; + var certblob = getCertificate(id); if (!certblob) { return null; } diff --git a/package-lock.json b/package-lock.json index aa12a70..a2c609a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { "name": "greenlock-store-memory", - "version": "3.0.0", + "version": "3.0.1", "lockfileVersion": 1 } diff --git a/package.json b/package.json index 4bfacf4..7450ff7 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "greenlock-store-memory", - "version": "3.0.0", + "version": "3.0.1", "description": "An in-memory reference implementation for account, certificate, and keypair storage strategies in Greenlock", - "homepage": "https://git.coolaj86.com/coolaj86/le-store-memory.js", + "homepage": "https://git.coolaj86.com/coolaj86/greenlock-store-memory.js", "main": "index.js", "directories": { "test": "tests" @@ -12,7 +12,7 @@ }, "repository": { "type": "git", - "url": "https://git.coolaj86.com/coolaj86/le-store-memory.js.git" + "url": "https://git.coolaj86.com/coolaj86/greenlock-store-memory.js.git" }, "keywords": [ "greenlock",