minor refac

This commit is contained in:
AJ ONeal 2019-10-27 03:59:49 -06:00
parent 6df0dc2f76
commit d14163d153
3 changed files with 49 additions and 42 deletions

47
greenlock.js Normal file
View File

@ -0,0 +1,47 @@
"use strict";
var pkg = require("./package.json");
module.exports.create = function(opts) {
var Greenlock = require("@root/greenlock");
var packageAgent = pkg.name + "/" + pkg.version;
if ("string" === typeof opts.packageAgent) {
opts.packageAgent += " ";
} else {
opts.packageAgent = "";
}
opts.packageAgent += packageAgent;
var greenlock = Greenlock.create(opts);
greenlock.getAcmeHttp01ChallengeResponse = function(opts) {
return greenlock.find({ servername: opts.servername }).then(function(sites) {
if (!sites.length) {
return null;
}
var site = sites[0];
if (!site.challenges || !site.challenges["http-01"]) {
return null;
}
var plugin;
try {
plugin = require(site.challenges["http-01"].module);
plugin = plugin.create(site.challenges["http-01"]);
} catch (e) {
console.error("error getting acme http-01 plugin");
console.error(e);
return null;
}
return plugin.get(opts).then(function(result) {
// TODO is this the right way?
var ch = (result && result.challenge) || result || {};
return {
keyAuthorization: ch.keyAuthorization
};
});
});
};
return greenlock;
};

View File

@ -6,8 +6,6 @@ var Master = module.exports;
var cluster = require("cluster"); var cluster = require("cluster");
var os = require("os"); var os = require("os");
var Greenlock = require("@root/greenlock");
var pkg = require("./package.json");
Master.create = function(opts) { Master.create = function(opts) {
var workers = []; var workers = [];
@ -15,14 +13,7 @@ Master.create = function(opts) {
var readyCb; var readyCb;
var _kicked = false; var _kicked = false;
var packageAgent = pkg.name + "/" + pkg.version; var greenlock = require("./greenlock.js").create(opts);
if ("string" === typeof opts.packageAgent) {
opts.packageAgent += " ";
} else {
opts.packageAgent = "";
}
opts.packageAgent += packageAgent;
var greenlock = Greenlock.create(opts);
var ready = new Promise(function(resolve) { var ready = new Promise(function(resolve) {
resolveCb = resolve; resolveCb = resolve;
@ -69,7 +60,6 @@ GLE.create = function(opts) {
gl.tlsOptions = {}; gl.tlsOptions = {};
return master; return master;
}; };

View File

@ -4,39 +4,9 @@ require("./main.js");
var Single = module.exports; var Single = module.exports;
var Servers = require("./servers.js"); var Servers = require("./servers.js");
var Greenlock = require("@root/greenlock");
Single.create = function(opts) { Single.create = function(opts) {
var greenlock = Greenlock.create(opts); var greenlock = require("./greenlock.js").create(opts);
greenlock.getAcmeHttp01ChallengeResponse = function(opts) {
return greenlock.find({ servername: opts.servername }).then(function(sites) {
if (!sites.length) {
return null;
}
var site = sites[0];
if (!site.challenges || !site.challenges["http-01"]) {
return null;
}
var plugin;
try {
plugin = require(site.challenges["http-01"].module);
plugin = plugin.create(site.challenges["http-01"]);
} catch (e) {
console.error("error getting acme http-01 plugin");
console.error(e);
return null;
}
return plugin.get(opts).then(function(result) {
// TODO is this the right way?
var ch = (result && result.challenge) || result || {};
return {
keyAuthorization: ch.keyAuthorization
};
});
});
};
var servers = Servers.create(greenlock, opts); var servers = Servers.create(greenlock, opts);