normalize approveDomains

This commit is contained in:
AJ ONeal 2016-08-10 22:33:12 -04:00
parent c55765fd74
commit f36966a0d3
3 changed files with 14 additions and 13 deletions

View File

@ -3,7 +3,7 @@
module.exports.create = function (opts) { module.exports.create = function (opts) {
if (!opts.letsencrypt) { opts.letsencrypt = require('letsencrypt').create({ server: opts.server }); } if (!opts.letsencrypt) { opts.letsencrypt = require('letsencrypt').create({ server: opts.server }); }
if ('function' !== typeof opts.approveDomains) { if ('function' !== typeof opts.approveDomains) {
throw new Error("You must provide opts.approveDomains(options, certs, callback) to approve certificates"); throw new Error("You must provide opts.approveDomains(domain, certs, callback) to approve certificates");
} }
function log(debug) { function log(debug) {
@ -30,7 +30,7 @@ module.exports.create = function (opts) {
return; return;
} }
opts.approveDomains(msg.options, msg.certs, function (err, results) { opts.approveDomains(msg.domain, msg.certs, function (err, results) {
if (err) { if (err) {
log(opts.debug, 'Approval got ERROR', err.stack || err); log(opts.debug, 'Approval got ERROR', err.stack || err);
worker.send({ type: 'LE_RESPONSE', error: err }); worker.send({ type: 'LE_RESPONSE', error: err });

View File

@ -5,7 +5,7 @@ module.exports.create = function (opts) {
opts.workerSniCallback = require('le-sni-auto').create({ opts.workerSniCallback = require('le-sni-auto').create({
getCertificates: function (domain, certs, cb) { getCertificates: function (domain, certs, cb) {
opts.approveDomains(domain, certs, function (err, certs) { opts.approveDomains(domain, certs, function (err, certs) {
process.send({ type: 'LE_REQUEST', domain: domain, certs: certs }); process.send({ type: 'LE_REQUEST', domain: domain, options: { domains: [domain] } certs: certs });
process.on('message', function (msg) { process.on('message', function (msg) {
if (msg.domain === domain) { if (msg.domain === domain) {

View File

@ -5,7 +5,7 @@ var cluster = require('cluster');
function runMaster() { function runMaster() {
var numCores = 2; // // Math.max(2, require('os').cpus().length) var numCores = 2; // // Math.max(2, require('os').cpus().length)
var i; var i;
var master = require('./master').create({ var master = require('./lib/master').create({
debug: true debug: true
@ -14,14 +14,15 @@ function runMaster() {
, approveDomains: function (options, certs, cb) { , approveDomains: function (domain, certs, cb) {
// Depending on your setup it may be more efficient // Depending on your setup it may be more efficient
// for you to implement the approveDomains function // for you to implement the approveDomains function
// in your master or in your workers. // in your master or in your workers.
// //
// Since we implement it in the worker (below) in this example // Since we implement it in the worker (below) in this example
// we'll give it an immediate approval here in the master // we'll give it an immediate approval here in the master
cb(null, { options: options, certs: certs }); var results = { options: { domains: [domain] }, certs: certs };
cb(null, results);
} }
}); });
@ -33,7 +34,7 @@ function runMaster() {
} }
function runWorker() { function runWorker() {
var worker = require('./worker').create({ var worker = require('./lib/worker').create({
debug: true debug: true
// We want both to renew well before the expiration date // We want both to renew well before the expiration date
@ -49,9 +50,10 @@ function runWorker() {
cb(null, ); cb(null, );
} }
*/ */
, approveDomains: function (opts, certs, cb) { , approveDomains: function (domain, certs, cb) {
// opts = { domains, email, agreeTos, tosUrl } // opts = { domains, email, agreeTos, tosUrl }
// certs = { subject, altnames, expiresAt, issuedAt } // certs = { subject, altnames, expiresAt, issuedAt }
var results = { options: { domains: [domain] }, certs: certs };
@ -61,7 +63,7 @@ function runWorker() {
// for renewals to be automatic // for renewals to be automatic
if (certs) { if (certs) {
// modify opts.domains to overwrite certs.altnames in renewal // modify opts.domains to overwrite certs.altnames in renewal
cb(null, { options: opts, certs: certs }); cb(null, results);
return; return;
} }
@ -71,8 +73,7 @@ function runWorker() {
// This is where we would check our database to make sure that // This is where we would check our database to make sure that
// this user (specified by email address) has agreed to the terms // this user (specified by email address) has agreed to the terms
// and do some check that they have access to this domain // and do some check that they have access to this domain
opts.agreeTos = true; cb(null, results);
cb(null, { options: opts });
} }
}); });
@ -80,8 +81,8 @@ function runWorker() {
res.end("Hello, World!"); res.end("Hello, World!");
} }
var plainServer = require('http').createServer(worker.handleAcmeAndRedirectToHttps); var plainServer = require('http').createServer(worker.handleAcmeOrRedirectToHttps());
var server = require('https').createServer(worker.httpsOptions, worker.handleAcmeAndUse(app)); var server = require('https').createServer(worker.httpsOptions, worker.handleAcmeOrUse(app));
plainServer.listen(80); plainServer.listen(80);
server.listen(443); server.listen(443);
} }