From 0a607ade91c38d50fc71beb4c62e2b89983001c9 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sun, 3 Nov 2019 10:01:32 -0700 Subject: [PATCH] allow for all configs with --all --- .gitignore | 4 ++++ bin/config.js | 17 ++++++++++----- bin/lib/flags.js | 5 +++++ greenlock.js | 51 +++++++++++++++++++++++---------------------- manager-underlay.js | 26 ++++++++++++++++------- package.json | 2 +- 6 files changed, 67 insertions(+), 38 deletions(-) diff --git a/.gitignore b/.gitignore index ae7cff1..bbff6d2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,10 @@ TODO.txt link.sh .env .greenlockrc +# generated by init +app.js +server.js +example.js # ---> Node # Logs diff --git a/bin/config.js b/bin/config.js index b54888f..cc40322 100644 --- a/bin/config.js +++ b/bin/config.js @@ -32,16 +32,23 @@ async function main(_, flags, rc, greenlock) { delete flags.subject; delete flags.altnames; flags.servernames = servernames; - if (flags.servernames.length > 1) { - console.error('Error: should only have one servername'); + if (!flags.all && flags.servernames.length > 1) { + console.error('Error: should specify either --subject OR --servername'); process.exit(1); return; - } else if (flags.servernames.length !== 1) { - console.error('Error: need a servername to check'); + } else if (!flags.all && flags.servernames.length !== 1) { + console.error('error: missing --servername '); process.exit(1); return; } - flags.servername = flags.servernames[0]; + if (!flags.all) { + flags.servername = flags.servernames[0]; + } else if (flags.servername) { + console.error( + 'error: missing cannot have --all and --servername / --subject' + ); + process.exit(1); + } delete flags.servernames; greenlock diff --git a/bin/lib/flags.js b/bin/lib/flags.js index c2e8907..dd482e1 100644 --- a/bin/lib/flags.js +++ b/bin/lib/flags.js @@ -21,6 +21,11 @@ Flags.flags = function(mconf, myOpts) { } return { + all: [ + false, + 'search all site configs rather than by --subject or --servernames', + 'boolean' + ], subject: [ false, 'the "subject" (primary domain) of the certificate', diff --git a/greenlock.js b/greenlock.js index b07682e..fdf3dd8 100644 --- a/greenlock.js +++ b/greenlock.js @@ -277,34 +277,35 @@ G.create = function(gconf) { }; greenlock._config = function(args) { - return greenlock - ._single(args) - .then(function() { - return greenlock._find(args); - }) - .then(function(sites) { - if (!sites || !sites.length) { - return null; + return greenlock._single(args).then(function() { + return greenlock._configAll(args); + }); + }; + greenlock._configAll = function(args) { + return greenlock._find(args).then(function(sites) { + if (!sites || !sites.length) { + return null; + } + var site = sites[0]; + site = JSON.parse(JSON.stringify(site)); + if (site.store && site.challenges) { + return site; + } + var dconf = site; + // TODO make cli and api mode the same + if (gconf._bin_mode) { + dconf = site.defaults = {}; + } + return manager.defaults().then(function(mconf) { + if (!site.store) { + dconf.store = mconf.store; } - var site = sites[0]; - site = JSON.parse(JSON.stringify(site)); - if (site.store && site.challenges) { - return site; + if (!site.challenges) { + dconf.challenges = mconf.challenges; } - var dconf = site; - if (gconf._bin_mode) { - dconf = site.defaults = {}; - } - return manager.defaults().then(function(mconf) { - if (!site.store) { - dconf.store = mconf.store; - } - if (!site.challenges) { - dconf.challenges = mconf.challenges; - } - return site; - }); + return site; }); + }); }; // needs to get info about the renewal, such as which store and challenge(s) to use diff --git a/manager-underlay.js b/manager-underlay.js index d7e4907..07270ec 100644 --- a/manager-underlay.js +++ b/manager-underlay.js @@ -192,22 +192,34 @@ module.exports.wrap = function(greenlock, manager, gconf) { */ greenlock._find = function(args) { - var altnames = args.altnames || []; + var servernames = (args.servernames || []) + .concat(args.altnames || []) + .filter(Boolean) + .slice(0); + var modified = servernames.slice(0); // servername, wildname, and altnames are all the same ['wildname', 'servername'].forEach(function(k) { var altname = args[k] || ''; - if (altname && !altnames.includes(altname)) { - altnames.push(altname); + if (altname && !modified.includes(altname)) { + modified.push(altname); } }); - if (altnames.length) { - args.altnames = altnames; - args.altnames = args.altnames.map(U._encodeName); - args.altnames = checkAltnames(false, args); + if (modified.length) { + servernames = modified; + servernames = servernames.altnames.map(U._encodeName); + args.altnames = servernames; + args.servernames = args.altnames = checkAltnames(false, args); } + // documented as args.servernames + // preserved as args.altnames for v3 beta backwards compat + // my only hesitancy in this choice is that a "servername" + // may NOT contain '*.', in which case `altnames` is a better choice. + // However, `altnames` is ambiguous - as if it means to find a + // certificate by that specific collection of altnames. + // ... perhaps `domains` could work? return manager.find(args); }; }; diff --git a/package.json b/package.json index 7b19d2d..7920aef 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@root/greenlock", - "version": "3.1.0", + "version": "3.1.0-wip", "description": "The easiest Let's Encrypt client for Node.js and Browsers", "homepage": "https://rootprojects.org/greenlock/", "main": "greenlock.js",