update handlers to le v2.x style

This commit is contained in:
AJ ONeal 2016-08-09 20:04:08 -04:00
parent 093c85ef91
commit 9ec3ed7975
1 changed files with 20 additions and 12 deletions

View File

@ -9,9 +9,12 @@ module.exports.create = function (defaults) {
//
// set,get,remove challenges
//
_challenges: {}
, setChallenge: function (args, key, value, cb) {
var challengePath = path.join(defaults.webrootPath, '.well-known', 'acme-challenge');
getOptions: function () {
return { webrootPath: defaults.webrootPath };
}
, set: function (args, domain, token, secret, cb) {
var challengePath = path.join(args.webrootPath || defaults.webrootPath, '.well-known', 'acme-challenge');
mkdirp(challengePath, function (err) {
if (err) {
console.error("Could not create --webroot-path '" + challengePath + "':", err.code);
@ -20,11 +23,11 @@ module.exports.create = function (defaults) {
return;
}
var keyfile = path.join(challengePath, key);
var tokenfile = path.join(challengePath, token);
fs.writeFile(keyfile, value, 'utf8', function (err) {
fs.writeFile(tokenfile, secret, 'utf8', function (err) {
if (err) {
console.error("Could not write '" + keyfile + "':", err.code);
console.error("Could not write '" + tokenfile + "':", err.code);
cb(err);
return;
}
@ -33,14 +36,19 @@ module.exports.create = function (defaults) {
});
});
}
// handled as file read by web server
// , getChallenge: function (args, key, cb) {}
, removeChallenge: function (args, key, cb) {
var keyfile = path.join(defaults.webrootPath, '.well-known', 'acme-challenge', key);
fs.unlink(keyfile, function (err) {
// handled as file read by web server
, get: function (args, domain, token, cb) {
// see https://github.com/Daplie/node-letsencrypt/issues/41
cb(new Error("get not implemented (on purpose) in le-cli/lib/webroot.js"));
}
, remove: function (args, domain, token, cb) {
var tokenfile = path.join(args.webrootPath || defaults.webrootPath, '.well-known', 'acme-challenge', token);
fs.unlink(tokenfile, function (err) {
if (err) {
console.error("Could not unlink '" + keyfile + "':", err.code);
console.error("Could not unlink '" + tokenfile + "':", err.code);
cb(err);
return;
}