v3.0.1: clarify comments and docs

This commit is contained in:
AJ ONeal 2019-04-07 11:32:57 -06:00
parent 169cdb6c6a
commit 5a66693cdb
3 changed files with 21 additions and 16 deletions

View File

@ -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; }

2
package-lock.json generated
View File

@ -1,5 +1,5 @@
{
"name": "greenlock-store-memory",
"version": "3.0.0",
"version": "3.0.1",
"lockfileVersion": 1
}

View File

@ -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",