From 3590842ce8964395efcd574c847b14789f570723 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 8 Aug 2016 11:21:33 -0400 Subject: [PATCH] make shim of letiny-core possible #37 --- index.js | 21 +++++++++++++++++---- lib/core.js | 7 +++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 341d1dc..d1774fd 100644 --- a/index.js +++ b/index.js @@ -24,7 +24,8 @@ Object.keys(LE.defaults).forEach(function (key) { // show all possible options var u; // undefined LE._undefined = { - store: u + acme: u +, store: u , challenger: u , register: u , check: u @@ -49,6 +50,7 @@ LE._undefine = function (le) { LE.create = function (le) { var PromiseA = require('bluebird'); + le.acme = le.acme || leCore; 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'); @@ -72,13 +74,24 @@ LE.create = function (le) { le.server = LE.productionServerUrl; } + if (le.acme.create) { + le.acme = le.acme.create(le); + } + le.acme = PromiseA.promisifyAll(le.acme); + le._acmeOpts = le.acme.getOptions(); + Object.keys(le._acmeOpts).forEach(function (key) { + if (!(key in le)) { + le[key] = le._acmeOpts[key]; + } + }); + if (le.store.create) { le.store = le.store.create(le); } le.store = PromiseA.promisifyAll(le.store); le._storeOpts = le.store.getOptions(); Object.keys(le._storeOpts).forEach(function (key) { - if (!(key in le._storeOpts)) { + if (!(key in le)) { le[key] = le._storeOpts[key]; } }); @@ -88,8 +101,8 @@ LE.create = function (le) { } le.challenger = PromiseA.promisifyAll(le.challenger); le._challengerOpts = le.challenger.getOptions(); - Object.keys(le._storeOpts).forEach(function (key) { - if (!(key in le._challengerOpts)) { + Object.keys(le._challengerOpts).forEach(function (key) { + if (!(key in le)) { le[key] = le._challengerOpts[key]; } }); diff --git a/lib/core.js b/lib/core.js index ed1f9d3..15ff111 100644 --- a/lib/core.js +++ b/lib/core.js @@ -4,7 +4,6 @@ module.exports.create = function (le) { var PromiseA = require('bluebird'); var utils = require('./utils'); // merge, tplCopy; var RSA = PromiseA.promisifyAll(require('rsa-compat').RSA); - var LeCore = PromiseA.promisifyAll(require('letiny-core')); var crypto = require('crypto'); var core = { @@ -19,7 +18,7 @@ module.exports.create = function (le) { return PromiseA.resolve(le._ipc.acmeUrls); } - return LeCore.getAcmeUrlsAsync(args.server).then(function (data) { + return le.acme.getAcmeUrlsAsync(args.server).then(function (data) { le._ipc.acmeUrlsUpdatedAt = Date.now(); le._ipc.acmeUrls = data; @@ -39,7 +38,7 @@ module.exports.create = function (le) { registerAsync: function (args) { return RSA.generateKeypairAsync(args.rsaKeySize, 65537, { public: true, pem: true }).then(function (keypair) { - return LeCore.registerNewAccountAsync({ + return le.acme.registerNewAccountAsync({ email: args.email , newRegUrl: args._acmeUrls.newReg , agreeToTerms: function (tosUrl, agreeCb) { @@ -151,7 +150,7 @@ module.exports.create = function (le) { args.domainKeypair = domainKeypair; //args.registration = domainKey; - return LeCore.getCertificateAsync({ + return le.acme.getCertificateAsync({ debug: args.debug || le.debug , newAuthzUrl: args._acmeUrls.newAuthz