From 54198e0499ff2a27d0d9fbabb09de81f5c0709dd Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 17 Dec 2015 04:44:28 +0000 Subject: [PATCH] handle alternate challenge store func sig --- index.js | 26 +++++++++++++++++++++++--- lib/letiny-core.js | 20 ++++++++++++++++++-- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 3ad21e8..6cd77fa 100644 --- a/index.js +++ b/index.js @@ -97,8 +97,17 @@ LE.create = function (defaults, handlers, backend) { // but realistically there only needs to be one handler and one // "directory" for this. It's not that big of a deal. var defaultos = LE.merge(defaults, {}); + var getChallenge = require('./lib/default-handlers').getChallenge; defaultos.domains = [hostname]; - require('./lib/default-handlers').getChallenge(defaultos, key, done); + if (3 === getChallenge.length) { + getChallenge(defaultos, key, done); + } + else if (4 === getChallenge.length) { + getChallenge(defaultos, hostname, key, done); + } + else { + done(new Error("handlers.getChallenge [1] receives the wrong number of arguments")); + } }; } if (!handlers.setChallenge) { @@ -216,14 +225,25 @@ LE.create = function (defaults, handlers, backend) { //args.domains = [req.hostname]; //console.log('[LE middleware]:', req.hostname, req.url, req.url.slice(prefix.length)); - handlers.getChallenge(req.hostname, req.url.slice(prefix.length), function (err, token) { + function done(err, token) { if (err) { res.send("Error: These aren't the tokens you're looking for. Move along."); return; } res.send(token); - }); + } + + if (3 === handlers.getChallenge.length) { + handlers.getChallenge(req.hostname, req.url.slice(prefix.length), done); + } + else if (4 === handlers.getChallenge.length) { + handlers.getChallenge(defaults, req.hostname, req.url.slice(prefix.length), done); + } + else { + console.error("handlers.getChallenge [2] receives the wrong number of arguments"); + done(new Error("handlers.getChallenge [2] receives the wrong number of arguments")); + } }; } , SNICallback: sniCallback diff --git a/lib/letiny-core.js b/lib/letiny-core.js index 6be57e0..337109d 100644 --- a/lib/letiny-core.js +++ b/lib/letiny-core.js @@ -152,12 +152,28 @@ function getCertificateAsync(account, args, defaults, handlers) { , setChallenge: function (domain, key, value, done) { args.domains = [domain]; args.webrootPath = args.webrootPath || defaults.webrootPath; - handlers.setChallenge(args, key, value, done); + if (4 === handlers.setChallenge.length) { + handlers.setChallenge(args, key, value, done); + } + else if (5 === handlers.setChallenge.length) { + handlers.setChallenge(args, domain, key, value, done); + } + else { + done(new Error("handlers.setChallenge receives the wrong number of arguments")); + } } , removeChallenge: function (domain, key, done) { args.domains = [domain]; args.webrootPath = args.webrootPath || defaults.webrootPath; - handlers.removeChallenge(args, key, done); + if (3 === handlers.removeChallenge.length) { + handlers.removeChallenge(args, key, done); + } + else if (4 === handlers.removeChallenge.length) { + handlers.removeChallenge(args, domain, key, done); + } + else { + done(new Error("handlers.removeChallenge receives the wrong number of arguments")); + } } }).then(function (result) { // TODO write pems={ca,cert,key} to disk