support init(deps)

This commit is contained in:
AJ ONeal 2019-06-15 14:31:03 -06:00
parent 20f006b1a0
commit a060ecd130
2 changed files with 226 additions and 192 deletions

56
node.js
View File

@ -464,24 +464,48 @@ ACME._chooseChallenge = function(options, results) {
return challenge;
};
ACME._depInit = function(me, options) {
if ('function' !== typeof options.init) {
options.init = function() {
return Promise.resolve(null);
};
}
// back/forwards-compat
return ACME._wrapCb(
me,
options,
'init',
{ type: '*', request: me._request },
'null'
);
};
ACME._getZones = function(me, options, dnsHosts) {
if ('function' !== typeof options.getZones) {
options.getZones = function() {
return Promise.resolve([]);
};
}
return new Promise(function(resolve, reject) {
var challenge = { type: 'dns-01', dnsHosts: dnsHosts };
var challenge = { type: 'dns-01', dnsHosts: dnsHosts, request: me._request };
// back/forwards-compat
challenge.challenge = challenge;
return ACME._wrapCb(
me,
options,
'getZones',
challenge,
'an array of zone names'
);
};
ACME._wrapCb = function(me, options, _name, stuff, _desc) {
return new Promise(function(resolve, reject) {
try {
if (options.getZones.length <= 1) {
options
.getZones(challenge)
if (options[_name].length <= 1) {
return Promise.resolve(options[_name](stuff))
.then(resolve)
.catch(reject);
} else if (2 === options.getZones.length) {
options.getZones(challenge, function(err, zonenames) {
} else if (2 === options[_name].length) {
options[_name](stuff, function(err, zonenames) {
if (err) {
reject(err);
} else {
@ -490,7 +514,7 @@ ACME._getZones = function(me, options, dnsHosts) {
});
} else {
throw new Error(
'options.getZones should accept opts and Promise an array of zone names'
'options.' + _name + ' should accept opts and Promise ' + _desc
);
}
} catch (e) {
@ -498,6 +522,7 @@ ACME._getZones = function(me, options, dnsHosts) {
}
});
};
function newZoneRegExp(zonename) {
// (^|\.)example\.com$
// which matches:
@ -577,8 +602,9 @@ ACME._challengeToAuth = function(me, options, request, challenge, dryrun) {
.replace(/\.$/, '');
}
// for backwards compat
// for backwards/forwards compat
auth.challenge = auth;
auth.request = me._request;
return auth;
};
@ -1071,6 +1097,7 @@ ACME._getCertificate = function(me, options) {
.toString('hex') + d
);
});
return ACME._depInit(me, options, dnsHosts).then(function(zonenames) {
return ACME._getZones(me, options, dnsHosts).then(function(zonenames) {
options.zonenames = zonenames;
// Do a little dry-run / self-test
@ -1211,7 +1238,9 @@ ACME._getCertificate = function(me, options) {
if (!auth) {
return;
}
return ACME._postChallenge(me, options, auth).then(challengeNext);
return ACME._postChallenge(me, options, auth).then(
challengeNext
);
}
// First we set every challenge
@ -1234,7 +1263,11 @@ ACME._getCertificate = function(me, options) {
console.debug('acme-v2: order was finalized');
}
return me
._request({ method: 'GET', url: me._certificate, json: true })
._request({
method: 'GET',
url: me._certificate,
json: true
})
.then(function(resp) {
if (me.debug) {
console.debug(
@ -1264,6 +1297,7 @@ ACME._getCertificate = function(me, options) {
});
});
});
});
};
ACME.create = function create(me) {

View File

@ -1,6 +1,6 @@
{
"name": "acme-v2",
"version": "1.8.1",
"version": "1.8.2",
"description": "A lightweight library for getting Free SSL certifications through Let's Encrypt, using the ACME protocol.",
"homepage": "https://git.coolaj86.com/coolaj86/acme-v2.js",
"main": "node.js",