From 050ec1f1f300f06923a1bb0bc8fc18c1f66229d8 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 14 Dec 2015 21:21:59 -0800 Subject: [PATCH] making way for forge and ursa backends --- backends-python.js => backends/python.js | 3 ++- examples/commandline.js | 15 ++++++++------- examples/config-minimal.js | 5 +++-- examples/express.js | 13 +++++++------ index.js | 18 +++++++++++++++++- pyconf.js => lib/pyconf.js | 0 package.json | 11 +++++++++-- 7 files changed, 46 insertions(+), 19 deletions(-) rename backends-python.js => backends/python.js (92%) rename pyconf.js => lib/pyconf.js (100%) diff --git a/backends-python.js b/backends/python.js similarity index 92% rename from backends-python.js rename to backends/python.js index 70498b0..4fc1bc9 100644 --- a/backends-python.js +++ b/backends/python.js @@ -3,11 +3,12 @@ var PromiseA = require('bluebird'); var fs = PromiseA.promisifyAll(require('fs')); -module.exports.create = function (leBinPath, defaults, opts) { +module.exports.create = function (defaults, opts) { defaults.webroot = true; defaults.renewByDefault = true; defaults.text = true; + var leBinPath = defaults.pythonClientPath; var LEP = require('letsencrypt-python'); var lep = PromiseA.promisifyAll(LEP.create(leBinPath, opts)); var wrapped = { diff --git a/examples/commandline.js b/examples/commandline.js index deb0c1a..3ee6925 100644 --- a/examples/commandline.js +++ b/examples/commandline.js @@ -23,27 +23,28 @@ var bkDefaults = { , fullchainTpl: '/live/:hostname/fullchain.pem' , privkeyTpl: '/live/:hostname/privkey.pem' , configDir: path.join(__dirname, '..', 'tests', 'letsencrypt.config') +, server: LE.stagingServer + +// backend-specific , logsDir: path.join(__dirname, '..', 'tests', 'letsencrypt.logs') , workDir: path.join(__dirname, '..', 'tests', 'letsencrypt.work') -, server: LE.stagingServer , text: true +, pythonClientPath: require('os').homedir() + '/.local/share/letsencrypt/bin/letsencrypt' }; -var leBinPath = require('os').homedir() + '/.local/share/letsencrypt/bin/letsencrypt'; -var LEB = require('../backends-python'); -var backend = LEB.create(leBinPath, bkDefaults, { debug: true }); +var LEP = require('../backends/python'); -var le = LE.create(backend, bkDefaults, { +var le = LE.create(LEP, bkDefaults, { /* setChallenge: function (hostnames, key, value, cb) { // the python backend needs fs.watch implemented // before this would work (and even then it would be difficult) } , getChallenge: function (hostnames, key, cb) { - // + // } , sniRegisterCallback: function (args, certInfo, cb) { - + } , registrationFailureCallback: function (args, certInfo, cb) { what do to when a backgrounded registration fails diff --git a/examples/config-minimal.js b/examples/config-minimal.js index 5caa94b..2a88cb9 100644 --- a/examples/config-minimal.js +++ b/examples/config-minimal.js @@ -21,11 +21,12 @@ var config = { // these are specific to the python client and won't be needed with the purejs library , logsDir: path.join(__dirname, '..', 'tests', 'letsencrypt.logs') , workDir: path.join(__dirname, '..', 'tests', 'letsencrypt.work') + , pythonClientPath: binpath } }; -//config.backend = require('letsencrypt/backends-python').create(binpath, config.le); -config.backend = require('../backends-python').create(binpath, config.le); +//config.backend = require('letsencrypt/backends/python').create(binpath, config.le); +config.backend = require('../backends/python'); module.exports = config; diff --git a/examples/express.js b/examples/express.js index bf79abb..81ade0e 100644 --- a/examples/express.js +++ b/examples/express.js @@ -23,16 +23,17 @@ var bkDefaults = { , fullchainTpl: '/live/:hostname/fullchain.pem' , privkeyTpl: '/live/:hostname/privkey.pem' , configDir: path.join(__dirname, '..', 'tests', 'letsencrypt.config') +, server: LE.stagingServer + +// python-specific , logsDir: path.join(__dirname, '..', 'tests', 'letsencrypt.logs') , workDir: path.join(__dirname, '..', 'tests', 'letsencrypt.work') -, server: LE.stagingServer +, pythonClientPath: require('os').homedir() + '/.local/share/letsencrypt/bin/letsencrypt' }; -var leBinPath = require('os').homedir() + '/.local/share/letsencrypt/bin/letsencrypt'; -var LEB = require('../backends-python'); -var backend = LEB.create(leBinPath, bkDefaults, { debug: true }); +var LEP = require('../backends/python'); -var le = LE.create(backend, bkDefaults, { +var le = LE.create(LEP, bkDefaults, { sniRegisterCallback: function (args, certInfo, cb) { var allowedDomains = conf.domains; // require('../tests/config').allowedDomains; @@ -62,7 +63,7 @@ var le = LE.create(backend, bkDefaults, { // before this would work (and even then it would be difficult) } , getChallenge: function (hostnames, key, cb) { - // + // } , registrationFailureCallback: function (args, certInfo, cb) { what do to when a backgrounded registration fails diff --git a/index.js b/index.js index 96c6c8e..5c6d3c1 100644 --- a/index.js +++ b/index.js @@ -5,11 +5,15 @@ var PromiseA = require('bluebird'); var crypto = require('crypto'); var tls = require('tls'); +var path = require('path'); var LE = module.exports; LE.liveServer = "https://acme-v01.api.letsencrypt.org/directory"; LE.stagingServer = "https://acme-staging.api.letsencrypt.org/directory"; +LE.configDir = "/etc/letsencrypt/"; +LE.logsDir = "/var/log/letsencrypt/"; +LE.workDir = "/var/lib/letsencrypt/"; LE.merge = function merge(defaults, args) { var copy = {}; @@ -25,6 +29,18 @@ LE.merge = function merge(defaults, args) { }; LE.create = function (backend, defaults, handlers) { + if ('function' === typeof backend.create) { + backend.create(defaults, handlers); + } + else if ('string' === typeof backend) { + // TODO I'll probably regret this + // I don't like dynamic requires because they cause build / minification issues. + backend = require(path.join('backends', backend)).create(defaults, handlers); + } + else { + // ignore + // this backend was created the v1.0.0 way + } if (!handlers) { handlers = {}; } if (!handlers.lifetime) { handlers.lifetime = 90 * 24 * 60 * 60 * 1000; } if (!handlers.renewWithin) { handlers.renewWithin = 3 * 24 * 60 * 60 * 1000; } @@ -73,7 +89,7 @@ LE.create = function (backend, defaults, handlers) { //, ciphers // node's defaults are great }); } - + cb(null, cache.context); } diff --git a/pyconf.js b/lib/pyconf.js similarity index 100% rename from pyconf.js rename to lib/pyconf.js diff --git a/package.json b/package.json index 6c38b64..11d0f9b 100644 --- a/package.json +++ b/package.json @@ -33,9 +33,16 @@ "express": "^4.13.3", "localhost.daplie.com-certificates": "^1.1.2" }, + "optionalDependencies": { + "letsencrypt-python": "^1.0.3", + "letsencrypt-forge": "file:letsencrypt-forge", + "letsencrypt-ursa": "file:letsencrypt-ursa", + "node-forge": "^0.6.38", + "ursa": "^0.9.1" + "letiny": "0.0.4-beta", + }, "dependencies": { "bluebird": "^3.0.6", - "letsencrypt-python": "^1.0.3", - "serve-static": "^1.10.0" + "serve-static": "^1.10.0", } }