lighten the load

This commit is contained in:
AJ ONeal 2018-07-04 02:13:11 -06:00
parent 331a0ba166
commit c90cad6852
3 changed files with 30 additions and 9 deletions

View File

@ -9,6 +9,17 @@ try {
} catch(e) {
PromiseA = global.Promise;
}
var util = require('util');
function promisifyAllSelf(obj) {
if (obj.__promisified) { return obj; }
Object.keys(obj).forEach(function (key) {
if ('function' === typeof obj[key]) {
obj[key + 'Async'] = util.promisify(obj[key]);
}
});
obj.__promisified = true;
return obj;
}
var Greenlock = module.exports;
Greenlock.Greenlock = Greenlock;
@ -240,7 +251,7 @@ Greenlock.create = function (gl) {
if (gl.acme.create) {
gl.acme = gl.acme.create(gl);
}
gl.acme = PromiseA.promisifyAll(gl.acme);
gl.acme = promisifyAllSelf(gl.acme);
gl._acmeOpts = gl.acme.getOptions();
Object.keys(gl._acmeOpts).forEach(function (key) {
if (!(key in gl)) {
@ -251,9 +262,9 @@ Greenlock.create = function (gl) {
if (gl.store.create) {
gl.store = gl.store.create(gl);
}
gl.store = PromiseA.promisifyAll(gl.store);
gl.store.accounts = PromiseA.promisifyAll(gl.store.accounts);
gl.store.certificates = PromiseA.promisifyAll(gl.store.certificates);
gl.store = promisifyAllSelf(gl.store);
gl.store.accounts = promisifyAllSelf(gl.store.accounts);
gl.store.certificates = promisifyAllSelf(gl.store.certificates);
gl._storeOpts = gl.store.getOptions();
Object.keys(gl._storeOpts).forEach(function (key) {
if (!(key in gl)) {
@ -280,7 +291,9 @@ Greenlock.create = function (gl) {
if (challenger.create) {
challenger = gl.challenges[challengeType] = challenger.create(gl);
}
challenger = gl.challenges[challengeType] = PromiseA.promisifyAll(challenger);
if (!challenger.getOptionsAsync) {
challenger = gl.challenges[challengeType] = promisifyAllSelf(challenger);
}
gl['_challengeOpts_' + challengeType] = challenger.getOptions();
Object.keys(gl['_challengeOpts_' + challengeType]).forEach(function (key) {
if (!(key in gl)) {

View File

@ -6,6 +6,14 @@ try {
} catch(e) {
PromiseA = global.Promise;
}
var util = require('util');
function promisifyAll(obj) {
var aobj = {};
Object.keys(obj).forEach(function (key) {
aobj[key + 'Async'] = util.promisify(obj[key]);
});
return aobj;
}
function _log(debug) {
if (debug) {
@ -18,7 +26,7 @@ function _log(debug) {
module.exports.create = function (gl) {
var utils = require('./utils');
var RSA = PromiseA.promisifyAll(require('rsa-compat').RSA);
var RSA = promisifyAll(require('rsa-compat').RSA);
var log = gl.log || _log; // allow custom log
var pendingRegistrations = {};

View File

@ -61,18 +61,18 @@
"request": "^2.75.0"
},
"trulyOptionalDependencies": {
"bluebird": "^3.5.1",
"le-acme-core": "^2.1.3",
"ursa": "^0.9.4"
},
"dependencies": {
"acme": "^1.0.6",
"acme-v2": "^1.0.6",
"acme-v2": "^1.1.1",
"asn1js": "^1.2.12",
"bluebird": "^3.5.1",
"certpem": "^1.0.0",
"le-challenge-fs": "^2.0.2",
"le-sni-auto": "^2.1.3",
"le-store-certbot": "^2.1.0",
"le-store-certbot": "^2.1.7",
"node.extend": "^1.1.5",
"pkijs": "^1.3.27",
"rsa-compat": "^1.4.0"