minor refac
This commit is contained in:
parent
6df0dc2f76
commit
d14163d153
|
@ -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;
|
||||
};
|
12
master.js
12
master.js
|
@ -6,8 +6,6 @@ var Master = module.exports;
|
|||
|
||||
var cluster = require("cluster");
|
||||
var os = require("os");
|
||||
var Greenlock = require("@root/greenlock");
|
||||
var pkg = require("./package.json");
|
||||
|
||||
Master.create = function(opts) {
|
||||
var workers = [];
|
||||
|
@ -15,14 +13,7 @@ Master.create = function(opts) {
|
|||
var readyCb;
|
||||
var _kicked = false;
|
||||
|
||||
var packageAgent = pkg.name + "/" + pkg.version;
|
||||
if ("string" === typeof opts.packageAgent) {
|
||||
opts.packageAgent += " ";
|
||||
} else {
|
||||
opts.packageAgent = "";
|
||||
}
|
||||
opts.packageAgent += packageAgent;
|
||||
var greenlock = Greenlock.create(opts);
|
||||
var greenlock = require("./greenlock.js").create(opts);
|
||||
|
||||
var ready = new Promise(function(resolve) {
|
||||
resolveCb = resolve;
|
||||
|
@ -69,7 +60,6 @@ GLE.create = function(opts) {
|
|||
|
||||
gl.tlsOptions = {};
|
||||
|
||||
|
||||
return master;
|
||||
};
|
||||
|
||||
|
|
32
single.js
32
single.js
|
@ -4,39 +4,9 @@ require("./main.js");
|
|||
|
||||
var Single = module.exports;
|
||||
var Servers = require("./servers.js");
|
||||
var Greenlock = require("@root/greenlock");
|
||||
|
||||
Single.create = function(opts) {
|
||||
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
|
||||
};
|
||||
});
|
||||
});
|
||||
};
|
||||
var greenlock = require("./greenlock.js").create(opts);
|
||||
|
||||
var servers = Servers.create(greenlock, opts);
|
||||
|
||||
|
|
Loading…
Reference in New Issue