normalize

This commit is contained in:
AJ ONeal 2016-08-05 18:50:42 -04:00
parent a654891cfa
commit 56736c4f98
1 changed files with 23 additions and 16 deletions

View File

@ -1,9 +1,10 @@
'use strict'; 'use strict';
var PromiseA = require('bluebird');
var leCore = require('letiny-core'); var leCore = require('letiny-core');
var LE = module.exports; var LE = module.exports;
// in-process cache, shared between all instances
var ipc = {};
LE.defaults = { LE.defaults = {
productionServerUrl: leCore.productionServerUrl productionServerUrl: leCore.productionServerUrl
@ -33,6 +34,7 @@ LE._undefined = {
, rsaKeySize: u , rsaKeySize: u
, challengeType: u , challengeType: u
, server: u , server: u
, _ipc: u
}; };
LE._undefine = function (le) { LE._undefine = function (le) {
Object.keys(LE._undefined).forEach(function (key) { Object.keys(LE._undefined).forEach(function (key) {
@ -44,14 +46,17 @@ LE._undefine = function (le) {
return le; return le;
}; };
LE.create = function (le) { LE.create = function (le) {
le = LE._undefine(le); var PromiseA = require('bluebird');
var store = le.store || require('le-store-certbot').create({ debug: le.debug });
var challenger = le.challenge || require('le-store-certbot').create({ debug: le.debug });
var core = le.core = require('./lib/core');
le.store = le.store || require('le-store-certbot').create({ debug: le.debug });
le.challenger = le.challenger || require('le-store-certbot').create({ debug: le.debug });
le.core = require('./lib/core');
le = LE._undefine(le);
le.acmeChallengePrefix = LE.acmeChallengePrefix; le.acmeChallengePrefix = LE.acmeChallengePrefix;
le.rsaKeySize = le.rsaKeySize || LE.rsaKeySize; le.rsaKeySize = le.rsaKeySize || LE.rsaKeySize;
le.challengeType = le.challengeType || LE.challengeType; le.challengeType = le.challengeType || LE.challengeType;
le._ipc = ipc;
if (!le.renewWithin) { le.renewWithin = 3 * 24 * 60 * 60 * 1000; } if (!le.renewWithin) { le.renewWithin = 3 * 24 * 60 * 60 * 1000; }
if (!le.memorizeFor) { le.memorizeFor = 1 * 24 * 60 * 60 * 1000; } if (!le.memorizeFor) { le.memorizeFor = 1 * 24 * 60 * 60 * 1000; }
@ -66,37 +71,39 @@ LE.create = function (le) {
le.server = LE.productionServerUrl; le.server = LE.productionServerUrl;
} }
if (store.create) { if (le.store.create) {
store = store.create(le); le.store = le.store.create(le);
} }
store = PromiseA.promisifyAll(store); le.store = PromiseA.promisifyAll(le.store);
le._storeOpts = store.getOptions(); le._storeOpts = le.store.getOptions();
Object.keys(le._storeOpts).forEach(function (key) { Object.keys(le._storeOpts).forEach(function (key) {
if (!(key in le._storeOpts)) { if (!(key in le._storeOpts)) {
le[key] = le._storeOpts[key]; le[key] = le._storeOpts[key];
} }
}); });
if (challenger.create) { if (le.challenger.create) {
challenger = challenger.create(le); le.challenger = le.challenger.create(le);
} }
challenger = PromiseA.promisifyAll(challenger); le.challenger = PromiseA.promisifyAll(le.challenger);
le._challengerOpts = challenger.getOptions(); le._challengerOpts = le.challenger.getOptions();
Object.keys(le._storeOpts).forEach(function (key) { Object.keys(le._storeOpts).forEach(function (key) {
if (!(key in le._challengerOpts)) { if (!(key in le._challengerOpts)) {
le[key] = le._challengerOpts[key]; le[key] = le._challengerOpts[key];
} }
}); });
core = le.core = core.create(le); if (le.core.create) {
le.core = le.core.create(le);
}
le.register = function (args) { le.register = function (args) {
return core.registerAsync(args); return le.core.registerAsync(args);
}; };
le.check = function (args) { le.check = function (args) {
// TODO must return email, domains, tos, pems // TODO must return email, domains, tos, pems
return core.fetchAsync(args); return le.core.fetchAsync(args);
}; };
le.middleware = function () { le.middleware = function () {