forked from root/acme.js
support init(deps)
This commit is contained in:
parent
90477942d1
commit
0599acab6d
56
node.js
56
node.js
|
@ -464,24 +464,48 @@ ACME._chooseChallenge = function(options, results) {
|
||||||
|
|
||||||
return challenge;
|
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) {
|
ACME._getZones = function(me, options, dnsHosts) {
|
||||||
if ('function' !== typeof options.getZones) {
|
if ('function' !== typeof options.getZones) {
|
||||||
options.getZones = function() {
|
options.getZones = function() {
|
||||||
return Promise.resolve([]);
|
return Promise.resolve([]);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return new Promise(function(resolve, reject) {
|
var challenge = { type: 'dns-01', dnsHosts: dnsHosts, request: me._request };
|
||||||
var challenge = { type: 'dns-01', dnsHosts: dnsHosts };
|
|
||||||
// back/forwards-compat
|
// back/forwards-compat
|
||||||
challenge.challenge = challenge;
|
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 {
|
try {
|
||||||
if (options.getZones.length <= 1) {
|
if (options[_name].length <= 1) {
|
||||||
options
|
return Promise.resolve(options[_name](stuff))
|
||||||
.getZones(challenge)
|
|
||||||
.then(resolve)
|
.then(resolve)
|
||||||
.catch(reject);
|
.catch(reject);
|
||||||
} else if (2 === options.getZones.length) {
|
} else if (2 === options[_name].length) {
|
||||||
options.getZones(challenge, function(err, zonenames) {
|
options[_name](stuff, function(err, zonenames) {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
|
@ -490,7 +514,7 @@ ACME._getZones = function(me, options, dnsHosts) {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
throw new Error(
|
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) {
|
} catch (e) {
|
||||||
|
@ -498,6 +522,7 @@ ACME._getZones = function(me, options, dnsHosts) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function newZoneRegExp(zonename) {
|
function newZoneRegExp(zonename) {
|
||||||
// (^|\.)example\.com$
|
// (^|\.)example\.com$
|
||||||
// which matches:
|
// which matches:
|
||||||
|
@ -577,8 +602,9 @@ ACME._challengeToAuth = function(me, options, request, challenge, dryrun) {
|
||||||
.replace(/\.$/, '');
|
.replace(/\.$/, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
// for backwards compat
|
// for backwards/forwards compat
|
||||||
auth.challenge = auth;
|
auth.challenge = auth;
|
||||||
|
auth.request = me._request;
|
||||||
return auth;
|
return auth;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1071,6 +1097,7 @@ ACME._getCertificate = function(me, options) {
|
||||||
.toString('hex') + d
|
.toString('hex') + d
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
return ACME._depInit(me, options, dnsHosts).then(function(zonenames) {
|
||||||
return ACME._getZones(me, options, dnsHosts).then(function(zonenames) {
|
return ACME._getZones(me, options, dnsHosts).then(function(zonenames) {
|
||||||
options.zonenames = zonenames;
|
options.zonenames = zonenames;
|
||||||
// Do a little dry-run / self-test
|
// Do a little dry-run / self-test
|
||||||
|
@ -1211,7 +1238,9 @@ ACME._getCertificate = function(me, options) {
|
||||||
if (!auth) {
|
if (!auth) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return ACME._postChallenge(me, options, auth).then(challengeNext);
|
return ACME._postChallenge(me, options, auth).then(
|
||||||
|
challengeNext
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// First we set every challenge
|
// First we set every challenge
|
||||||
|
@ -1234,7 +1263,11 @@ ACME._getCertificate = function(me, options) {
|
||||||
console.debug('acme-v2: order was finalized');
|
console.debug('acme-v2: order was finalized');
|
||||||
}
|
}
|
||||||
return me
|
return me
|
||||||
._request({ method: 'GET', url: me._certificate, json: true })
|
._request({
|
||||||
|
method: 'GET',
|
||||||
|
url: me._certificate,
|
||||||
|
json: true
|
||||||
|
})
|
||||||
.then(function(resp) {
|
.then(function(resp) {
|
||||||
if (me.debug) {
|
if (me.debug) {
|
||||||
console.debug(
|
console.debug(
|
||||||
|
@ -1264,6 +1297,7 @@ ACME._getCertificate = function(me, options) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
ACME.create = function create(me) {
|
ACME.create = function create(me) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "acme-v2",
|
"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.",
|
"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",
|
"homepage": "https://git.coolaj86.com/coolaj86/acme-v2.js",
|
||||||
"main": "node.js",
|
"main": "node.js",
|
||||||
|
|
Loading…
Reference in New Issue