From 1ad3e6f2f27d1d41bd1ed820b67be10af86c9514 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 15 Dec 2015 12:01:05 +0000 Subject: [PATCH] updates --- backends/ursa.js | 2 +- index.js | 4 +-- .../crypto-utils-ursa.js | 0 lib/default-handlers.js | 34 ++++++++++++++++++- lib/default-remove-challenge.js | 10 ------ lib/default-set-challenge.js | 21 ------------ package.json | 2 ++ 7 files changed, 38 insertions(+), 35 deletions(-) rename crypto-utils-ursa.js => lib/crypto-utils-ursa.js (100%) delete mode 100644 lib/default-remove-challenge.js delete mode 100644 lib/default-set-challenge.js diff --git a/backends/ursa.js b/backends/ursa.js index fdbeae1..e22989d 100644 --- a/backends/ursa.js +++ b/backends/ursa.js @@ -3,7 +3,7 @@ var PromiseA = require('bluebird'); var path = require('path'); var fs = PromiseA.promisifyAll(require('fs')); -var cutils = PromiseA.promisifyAll(require('crypto-utils-ursa')); +var cutils = PromiseA.promisifyAll(require('../lib/crypto-utils-ursa')); //var futils = require('letsencrypt-forge/lib/crypto-utils'); var requestAsync = PromiseA.promisify(require('request')); var lef = PromiseA.promisifyAll(require('letsencrypt-forge')); diff --git a/index.js b/index.js index 2d6324e..32fa3e0 100644 --- a/index.js +++ b/index.js @@ -44,14 +44,14 @@ LE.create = function (backend, defaults, handlers) { // GET /.well-known/acme-challenge/{{challengeKey}} should return {{tokenValue}} throw new Error("handlers.setChallenge or defaults.webrootPath must be set"); } - handlers.setChallenge = require('lib/default-set-challenge'); + handlers.setChallenge = require('./lib/default-handlers').setChallenge; } if (!handlers.removeChallenge) { if (!defaults.webrootPath) { // GET /.well-known/acme-challenge/{{challengeKey}} should return {{tokenValue}} throw new Error("handlers.setChallenge or defaults.webrootPath must be set"); } - handlers.removeChallenge = require('lib/default-remove-challenge'); + handlers.removeChallenge = require('./lib/default-handlers').remove-Challenge; } if (!handlers.agreeToTerms) { if (defaults.agreeTos) { diff --git a/crypto-utils-ursa.js b/lib/crypto-utils-ursa.js similarity index 100% rename from crypto-utils-ursa.js rename to lib/crypto-utils-ursa.js diff --git a/lib/default-handlers.js b/lib/default-handlers.js index 88ed6b4..4becc64 100644 --- a/lib/default-handlers.js +++ b/lib/default-handlers.js @@ -1,5 +1,37 @@ 'use strict'; +var fs = require('fs'); +var path = require('path'); + module.exports.agreeToTerms = function (args, agree) { - agree(args.agreeTos || args.agree); + agree(args.agreeTos); +}; + +module.exports.setChallenge = function (args, challengePath, keyAuthorization, done) { + //var hostname = args.domains[0]; + var mkdirp = require('mkdirp'); + + // TODO should be args.webrootPath + mkdirp(path.join(args.webrootPath, challengePath), function (err) { + if (err) { + done(err); + return; + } + + fs.writeFile(path.join(args.webrootPath, challengePath), keyAuthorization, 'utf8', function (err) { + done(err); + }); + }); +}; + +module.exports.getChallenge = function (args, key, done) { + //var hostname = args.domains[0]; + + fs.readFile(path.join(args.webroot, key), 'utf8', done); +}; + +module.exports.removeChallenge = function (args, key, done) { + //var hostname = args.domains[0]; + + fs.unlinkSync(path.join(args.webroot, key), done); }; diff --git a/lib/default-remove-challenge.js b/lib/default-remove-challenge.js deleted file mode 100644 index 1aedfdd..0000000 --- a/lib/default-remove-challenge.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict'; - -var path = require('path'); -var fs = require('fs'); - -module.exports = function (args, key, done) { - //var hostname = args.domains[0]; - - fs.unlinkSync(path.join(args.webroot, key), done); -}; diff --git a/lib/default-set-challenge.js b/lib/default-set-challenge.js deleted file mode 100644 index 4aec345..0000000 --- a/lib/default-set-challenge.js +++ /dev/null @@ -1,21 +0,0 @@ -'use strict'; - -var fs = require('fs'); -var path = require('path'); - -module.exports = function (args, challengePath, keyAuthorization, done) { - //var hostname = args.domains[0]; - var mkdirp = require('mkdirp'); - - // TODO should be args.webrootPath - mkdirp(path.join(args.webrootPath, challengePath), function (err) { - if (err) { - done(err); - return; - } - - fs.writeFile(path.join(args.webrootPath, challengePath), keyAuthorization, 'utf8', function (err) { - done(err); - }); - }); -}; diff --git a/package.json b/package.json index 4255ed2..bc441d3 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,9 @@ }, "dependencies": { "bluebird": "^3.0.6", + "mkdirp": "^0.5.1", "pyconf": "^1.0.0", + "request": "^2.67.0", "safe-replace": "^1.0.0", "serve-static": "^1.10.0" }