a special treat

This commit is contained in:
AJ ONeal 2015-12-20 02:41:17 -08:00
parent cefaf35d7b
commit bac1dd50af
3 changed files with 111 additions and 2 deletions

View File

@ -16,6 +16,11 @@ LE.workDir = leCore.workDir;
LE.acmeChallengPrefix = leCore.acmeChallengPrefix; LE.acmeChallengPrefix = leCore.acmeChallengPrefix;
LE.knownEndpoints = leCore.knownEndpoints; LE.knownEndpoints = leCore.knownEndpoints;
LE.privkeyPath = ':config/live/:hostname/privkey.pem';
LE.fullchainPath = ':config/live/:hostname/fullchain.pem';
LE.certPath = ':config/live/:hostname/cert.pem';
LE.chainPath = ':config/live/:hostname/chain.pem';
// backwards compat // backwards compat
LE.stagingServer = leCore.stagingServerUrl; LE.stagingServer = leCore.stagingServerUrl;
LE.liveServer = leCore.productionServerUrl; LE.liveServer = leCore.productionServerUrl;
@ -118,6 +123,20 @@ LE.create = function (defaults, handlers, backend) {
le = { le = {
backend: backend backend: backend
, pyToJson: function (pyobj) {
if (!pyobj) {
return null;
}
var jsobj = {};
Object.keys(pyobj).forEach(function (key) {
jsobj[key] = pyobj[key];
});
jsobj.__lines = undefined;
jsobj.__keys = undefined;
return jsobj;
}
, validate: function (hostnames, cb) { , validate: function (hostnames, cb) {
// TODO check dns, etc // TODO check dns, etc
if ((!hostnames.length && hostnames.every(le.isValidDomain))) { if ((!hostnames.length && hostnames.every(le.isValidDomain))) {
@ -200,6 +219,31 @@ LE.create = function (defaults, handlers, backend) {
args.duplicate = false; args.duplicate = false;
le.register(args, cb); le.register(args, cb);
} }
, getConfig: function (args, cb) {
backend.getConfigAsync(args).then(function (pyobj) {
cb(null, le.pyToJson(pyobj));
}, function (err) {
console.error(err.stack);
return cb(null, []);
});
}
, getConfigs: function (args, cb) {
backend.getConfigsAsync(args).then(function (configs) {
cb(null, configs.map(le.pyToJson));
}, function (err) {
if ('ENOENT' === err.code) {
cb(null, []);
} else {
console.error(err.stack);
cb(err);
}
});
}
, setConfig: function (args, cb) {
backend.configureAsync(args).then(function (pyobj) {
cb(null, le.pyToJson(pyobj));
});
}
, register: function (args, cb) { , register: function (args, cb) {
if (!Array.isArray(args.domains)) { if (!Array.isArray(args.domains)) {
cb(new Error('args.domains should be an array of domains')); cb(new Error('args.domains should be an array of domains'));

View File

@ -59,6 +59,10 @@ module.exports.tplCopy = function merge(copy) {
Object.keys(tpls).sort(function (a, b) { Object.keys(tpls).sort(function (a, b) {
return b.length - a.length; return b.length - a.length;
}).forEach(function (tplname) { }).forEach(function (tplname) {
if (!tpls[tplname]) {
// what can't be templated now may be templatable later
return;
}
copy[key] = copy[key].replace(':' + tplname, tpls[tplname]); copy[key] = copy[key].replace(':' + tplname, tpls[tplname]);
copy[key] = copy[key].replace(homeRe, homedir + path.sep); copy[key] = copy[key].replace(homeRe, homedir + path.sep);
}); });

View File

@ -3,6 +3,7 @@
var PromiseA = require('bluebird'); var PromiseA = require('bluebird');
var mkdirpAsync = PromiseA.promisify(require('mkdirp')); var mkdirpAsync = PromiseA.promisify(require('mkdirp'));
var path = require('path'); var path = require('path');
var fs = PromiseA.promisifyAll(require('fs'));
var sfs = require('safe-replace'); var sfs = require('safe-replace');
var LE = require('../'); var LE = require('../');
var LeCore = PromiseA.promisifyAll(require('letiny-core')); var LeCore = PromiseA.promisifyAll(require('letiny-core'));
@ -229,13 +230,21 @@ function writeCertificateAsync(args, defaults, handlers) {
function getCertificateAsync(args, defaults, handlers) { function getCertificateAsync(args, defaults, handlers) {
var account = args.account; var account = args.account;
var promise;
return leCrypto.generateRsaKeypairAsync(args.rsaKeySize, 65537).then(function (domainKey) { if (args.domainKeyPath) {
// TODO use existing pre-generated key if avaibale
promise = leCrypto.generateRsaKeypairAsync(args.rsaKeySize, 65537);
} else {
promise = leCrypto.generateRsaKeypairAsync(args.rsaKeySize, 65537);
}
promise.then(function (domainKey) {
if (args.debug) { if (args.debug) {
console.log("get certificate"); console.log("get certificate");
} }
args.domainPrivateKeyPem = domainKey.privateKeyPem; args.domainPrivateKeyPem = args.domainPrivateKeyPem || domainKey.privateKeyPem;
//args.registration = domainKey; //args.registration = domainKey;
return LeCore.getCertificateAsync({ return LeCore.getCertificateAsync({
@ -422,6 +431,58 @@ module.exports.create = function (defaults, handlers) {
} }
return fetchFromConfigLiveDir(copy, defaults); return fetchFromConfigLiveDir(copy, defaults);
} }
, configureAsync: function (hargs) {
hargs.renewalPath = hargs.renewalPath || ':config/renewal/:hostname.conf';
hargs.domains = [];
var copy = merge(hargs, defaults);
tplCopy(copy);
return getOrCreateRenewal(copy);
}
, getConfigAsync: function (hargs) {
hargs.renewalPath = hargs.renewalPath || ':config/renewal/:hostname.conf';
hargs.domains = [];
var copy = merge(hargs, defaults);
tplCopy(copy);
if (copy.debug) {
console.log('[LE DEBUG] get configs', copy);
}
return readRenewalConfig(copy).then(function (pyobj) {
var exists = pyobj.checkpoints >= 0;
if (!exists) {
return null;
}
return pyobj;
});
}
, getConfigsAsync: function (hargs) {
hargs.renewalDir = hargs.renewalDir || ':config/renewal/';
hargs.renewalPath = hargs.renewalPath || ':config/renewal/:hostname.conf';
hargs.domains = [];
var copy = merge(hargs, defaults);
tplCopy(copy);
if (copy.debug) {
console.log('[LE DEBUG] get configs', copy);
}
return fs.readdirAsync(copy.renewalDir).then(function (nodes) {
nodes = nodes.filter(function (node) {
return /^[a-z0-9]+.*\.conf$/.test(node);
});
return PromiseA.all(nodes.map(function (node) {
copy.domains = [node.replace(/\.conf$/, '')];
return wrapped.getConfigAsync(copy);
}));
});
}
}; };
return wrapped; return wrapped;