From 11f38bee5c1241517b6f8e5dd27a2e90cfbeda46 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 5 Aug 2016 04:10:33 -0400 Subject: [PATCH] v2.0.0 --- README.md | 4 ++-- index.js | 44 ++++++++++++++++++++++++++++++-------------- package.json | 30 ++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 16 deletions(-) create mode 100644 package.json diff --git a/README.md b/README.md index 44bfd5d..945c0f6 100644 --- a/README.md +++ b/README.md @@ -39,8 +39,8 @@ Exposed Methods For ACME Challenge: * `setChallange(opts, domain, key, val, done)` -* `getChallange(domain, key, done)` -* `removeChallange(domain, key, done)` +* `getChallange(opts, domain, key, done)` +* `removeChallange(opts, domain, key, done)` For node-letsencrypt internals: diff --git a/index.js b/index.js index 9982539..f1edfe6 100644 --- a/index.js +++ b/index.js @@ -3,17 +3,38 @@ var fs = require('fs'); var path = require('path'); -module.exports.agreeToTerms = function (args, agreeCb) { - agreeCb(null, args.agreeTos); +var defaults = { + webrootPath: '~/letsencrypt/var/lib' +, debug: false }; -module.exports.setChallenge = function (args, domain, challengePath, keyAuthorization, done) { - //var hostname = args.domains[0]; +var Challenger = module.exports; + +Challenger.create = function (options) { + var results = {}; + + Object.keys(Challenger).forEach(function (key) { + results[key] = Challenger[key]; + }); + + results._options = options; + + Object.keys(defaults).forEach(function (key) { + if (!(key in options)) { + options[key] = defaults[key]; + } + }); + + results.getOptions = function () { + return results._options; + }; + + return results; +}; + +Challenger.setChallenge = function (args, domain, challengePath, keyAuthorization, done) { var mkdirp = require('mkdirp'); - // TODO should be args.webrootPath - //console.log('args.webrootPath, challengePath'); - //console.log(args.webrootPath, challengePath); mkdirp(args.webrootPath, function (err) { if (err) { done(err); @@ -26,15 +47,10 @@ module.exports.setChallenge = function (args, domain, challengePath, keyAuthoriz }); }; -module.exports.getChallenge = function (args, domain, key, done) { - //var hostname = args.domains[0]; - - //console.log("getting the challenge", args, key); +Challenger.getChallenge = function (args, domain, key, done) { fs.readFile(path.join(args.webrootPath, key), 'utf8', done); }; -module.exports.removeChallenge = function (args, domain, key, done) { - //var hostname = args.domains[0]; - +Challenger.removeChallenge = function (args, domain, key, done) { fs.unlink(path.join(args.webrootPath, key), done); }; diff --git a/package.json b/package.json new file mode 100644 index 0000000..0f4c812 --- /dev/null +++ b/package.json @@ -0,0 +1,30 @@ +{ + "name": "le-challenge-fs", + "version": "2.0.0", + "description": "A fs-based strategy for node-letsencrypt for setting, retrieving, and clearing ACME challenges issued by the ACME server", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Daplie/le-challenge-fs.git" + }, + "keywords": [ + "le", + "letsencrypt", + "le-challenge", + "le-challenge-", + "acme", + "challenge", + "fs", + "cluster", + "ephemeral" + ], + "author": "AJ ONeal (https://coolaj86.com/)", + "license": "(MIT OR Apache-2.0)", + "bugs": { + "url": "https://github.com/Daplie/le-challenge-fs/issues" + }, + "homepage": "https://github.com/Daplie/le-challenge-fs#readme" +}