@root/greenlock
Advanced tools
Comparing version 3.1.5 to 4.0.0
@@ -11,3 +11,3 @@ 'use strict'; | ||
Flags.init().then(function({ flagOptions, rc, greenlock, mconf }) { | ||
Flags.init().then(function({ flagOptions, greenlock, mconf }) { | ||
var myFlags = {}; | ||
@@ -38,7 +38,7 @@ [ | ||
Flags.mangleFlags(flags, mconf); | ||
main(argList, flags, rc, greenlock); | ||
main(argList, flags, greenlock); | ||
}, args); | ||
}); | ||
async function main(_, flags, rc, greenlock) { | ||
async function main(_, flags, greenlock) { | ||
if (!flags.subject || !flags.altnames) { | ||
@@ -45,0 +45,0 @@ console.error( |
@@ -11,3 +11,3 @@ 'use strict'; | ||
Flags.init().then(function({ flagOptions, rc, greenlock, mconf }) { | ||
Flags.init().then(function({ flagOptions, greenlock, mconf }) { | ||
var myFlags = {}; | ||
@@ -23,7 +23,7 @@ ['all', 'subject', 'servername' /*, 'servernames', 'altnames'*/].forEach( | ||
Flags.mangleFlags(flags, mconf); | ||
main(argList, flags, rc, greenlock); | ||
main(argList, flags, greenlock); | ||
}, args); | ||
}); | ||
async function main(_, flags, rc, greenlock) { | ||
async function main(_, flags, greenlock) { | ||
var servernames = [flags.subject] | ||
@@ -30,0 +30,0 @@ .concat([flags.servername]) |
@@ -13,3 +13,2 @@ 'use strict'; | ||
flagOptions, | ||
rc, | ||
greenlock, | ||
@@ -42,7 +41,7 @@ mconf | ||
Flags.mangleFlags(flags, mconf, null, { forceSave: true }); | ||
main(argList, flags, rc, greenlock); | ||
main(argList, flags, greenlock); | ||
}, args); | ||
}); | ||
async function main(_, flags, rc, greenlock) { | ||
async function main(_, flags, greenlock) { | ||
greenlock.manager | ||
@@ -49,0 +48,0 @@ .defaults(flags) |
@@ -6,5 +6,3 @@ 'use strict'; | ||
var cli = require('./lib/cli.js'); | ||
//var path = require('path'); | ||
//var pkgpath = path.join(__dirname, '..', 'package.json'); | ||
//var pkgpath = path.join(process.cwd(), 'package.json'); | ||
var Greenlock = require('../'); | ||
@@ -15,3 +13,9 @@ var Flags = require('./lib/flags.js'); | ||
var myFlags = {}; | ||
['maintainer-email', 'cluster', 'manager', 'manager-xxxx'].forEach(function(k) { | ||
[ | ||
'config-dir', | ||
'maintainer-email', | ||
'cluster', | ||
'manager', | ||
'manager-xxxx' | ||
].forEach(function(k) { | ||
myFlags[k] = flagOptions[k]; | ||
@@ -22,6 +26,3 @@ }); | ||
cli.main(async function(argList, flags) { | ||
var path = require('path'); | ||
var pkgpath = path.join(process.cwd(), 'package.json'); | ||
var pkgdir = path.dirname(pkgpath); | ||
//var rcpath = path.join(pkgpath, '.greenlockrc'); | ||
var pkgRoot = process.cwd(); | ||
var manager = flags.manager; | ||
@@ -38,3 +39,3 @@ | ||
delete flags.managerOpts; | ||
flags.manager.manager = manager; | ||
flags.manager.module = manager; | ||
@@ -56,9 +57,15 @@ try { | ||
var GreenlockRc = require('../greenlockrc.js'); | ||
//var rc = await GreenlockRc(pkgpath, manager, flags.manager); | ||
await GreenlockRc(pkgpath, manager, flags.manager); | ||
writeGreenlockJs(pkgdir, flags); | ||
writeServerJs(pkgdir, flags); | ||
writeAppJs(pkgdir); | ||
var greenlock = Greenlock.create({ | ||
packageRoot: pkgRoot, | ||
manager: flags.manager, | ||
configDir: flags.configDir, | ||
maintainerEmail: flags.maintainerEmail, | ||
_mustPackage: true | ||
}); | ||
await greenlock.manager.defaults(); | ||
//writeGreenlockJs(pkgdir, flags); | ||
writeServerJs(pkgRoot, flags); | ||
writeAppJs(pkgRoot); | ||
/* | ||
@@ -74,2 +81,3 @@ rc._bin_mode = true; | ||
/* | ||
function writeGreenlockJs(pkgdir, flags) { | ||
@@ -101,2 +109,3 @@ var greenlockJs = 'greenlock.js'; | ||
} | ||
*/ | ||
@@ -107,6 +116,3 @@ function writeServerJs(pkgdir, flags) { | ||
var path = require('path'); | ||
var tmpl = fs.readFileSync( | ||
path.join(__dirname, 'tmpl/server.tmpl.js'), | ||
'utf8' | ||
); | ||
var tmpl; | ||
@@ -122,5 +128,20 @@ try { | ||
if (flags.cluster) { | ||
tmpl = fs.readFileSync( | ||
path.join(__dirname, 'tmpl/cluster.tmpl.js'), | ||
'utf8' | ||
); | ||
tmpl = tmpl.replace(/cluster: false/g, 'cluster: true'); | ||
} else { | ||
tmpl = fs.readFileSync( | ||
path.join(__dirname, 'tmpl/server.tmpl.js'), | ||
'utf8' | ||
); | ||
} | ||
if (flags.maintainerEmail) { | ||
tmpl = tmpl | ||
.replace(/pkg.author/g, JSON.stringify(flags.maintainerEmail)) | ||
.replace(/\/\/maintainerEmail/g, 'maintainerEmail'); | ||
} | ||
fs.writeFileSync(path.join(pkgdir, serverJs), tmpl); | ||
@@ -127,0 +148,0 @@ console.info("created '%s'", serverJs); |
@@ -5,6 +5,5 @@ 'use strict'; | ||
var path = require('path'); | ||
//var pkgpath = path.join(__dirname, '..', 'package.json'); | ||
var pkgpath = path.join(process.cwd(), 'package.json'); | ||
var GreenlockRc = require('../../greenlockrc.js'); | ||
//var path = require('path'); | ||
var pkgRoot = process.cwd(); | ||
//var Init = require('../../lib/init.js'); | ||
@@ -72,2 +71,7 @@ // These are ALL options | ||
], | ||
'config-dir': [ | ||
false, | ||
'the directory in which config.json and other config and storage files should be written', | ||
'string' | ||
], | ||
'maintainer-email': [ | ||
@@ -105,3 +109,3 @@ false, | ||
'string', | ||
'greenlock-manager-fs' | ||
'@greenlock/manager' | ||
], | ||
@@ -180,8 +184,11 @@ 'manager-xxxx': [ | ||
Flags.init = async function(myOpts) { | ||
var rc = await GreenlockRc(pkgpath); | ||
rc._bin_mode = true; | ||
var Greenlock = require('../../'); | ||
// this is a copy, so it's safe to modify | ||
rc.packageRoot = path.dirname(pkgpath); | ||
var greenlock = Greenlock.create(rc); | ||
var greenlock = Greenlock.create({ | ||
packageRoot: pkgRoot, | ||
_mustPackage: true, | ||
_init: true, | ||
_bin_mode: true | ||
}); | ||
var mconf = await greenlock.manager.defaults(); | ||
@@ -191,3 +198,2 @@ var flagOptions = Flags.flags(mconf, myOpts); | ||
flagOptions, | ||
rc, | ||
greenlock, | ||
@@ -194,0 +200,0 @@ mconf |
@@ -11,3 +11,3 @@ 'use strict'; | ||
Flags.init().then(function({ flagOptions, rc, greenlock, mconf }) { | ||
Flags.init().then(function({ flagOptions, greenlock, mconf }) { | ||
var myFlags = {}; | ||
@@ -21,7 +21,7 @@ ['subject'].forEach(function(k) { | ||
Flags.mangleFlags(flags, mconf); | ||
main(argList, flags, rc, greenlock); | ||
main(argList, flags, greenlock); | ||
}, args); | ||
}); | ||
async function main(_, flags, rc, greenlock) { | ||
async function main(_, flags, greenlock) { | ||
if (!flags.subject) { | ||
@@ -28,0 +28,0 @@ console.error('--subject must be provided as a valid domain'); |
@@ -9,3 +9,3 @@ 'use strict'; | ||
// contact for security and critical bug notices | ||
maintainerEmail: pkg.author, | ||
//maintainerEmail: pkg.author, | ||
@@ -12,0 +12,0 @@ // where to find .greenlockrc and set default paths |
'use strict'; | ||
var app = require('./app.js'); | ||
require('greenlock-express') | ||
.init(function() { | ||
return { | ||
greenlock: require('./greenlock.js'), | ||
.init({ | ||
packageRoot: __dirname, | ||
// whether or not to run at cloudscale | ||
cluster: false | ||
}; | ||
// contact for security and critical bug notices | ||
//maintainerEmail: pkg.author, | ||
// contact for security and critical bug notices | ||
configDir: './greenlock.d', | ||
// whether or not to run at cloudscale | ||
cluster: false | ||
}) | ||
.ready(function(glx) { | ||
var app = require('./app.js'); | ||
// Serves on 80 and 443 | ||
// Get's SSL certificates magically! | ||
glx.serveApp(app); | ||
}); | ||
// Serves on 80 and 443 | ||
// Get's SSL certificates magically! | ||
.serve(app); |
@@ -7,3 +7,3 @@ 'use strict'; | ||
Flags.init().then(function({ flagOptions, rc, greenlock, mconf }) { | ||
Flags.init().then(function({ flagOptions, greenlock, mconf }) { | ||
var myFlags = {}; | ||
@@ -35,7 +35,7 @@ [ | ||
Flags.mangleFlags(flags, mconf, sconf); | ||
main(argList, flags, rc, greenlock); | ||
main(argList, flags, greenlock); | ||
}, args); | ||
}); | ||
async function main(_, flags, rc, greenlock) { | ||
async function main(_, flags, greenlock) { | ||
if (!flags.subject) { | ||
@@ -42,0 +42,0 @@ console.error('--subject must be provided as a valid domain'); |
512
greenlock.js
@@ -8,2 +8,3 @@ 'use strict'; | ||
var request = require('@root/request'); | ||
var process = require('process'); | ||
@@ -16,4 +17,9 @@ var G = Greenlock; | ||
var C = require('./certificates.js'); | ||
var DIR = require('./lib/directory-url.js'); | ||
var ChWrapper = require('./lib/challenges-wrapper.js'); | ||
var MngWrapper = require('./lib/manager-wrapper.js'); | ||
var UserEvents = require('./user-events.js'); | ||
var GreenlockRc = require('./greenlockrc.js'); | ||
var Init = require('./lib/init.js'); | ||
@@ -48,9 +54,2 @@ var caches = {}; | ||
if (!gconf.packageRoot) { | ||
gconf.packageRoot = process.cwd(); | ||
console.warn( | ||
'`packageRoot` not defined, trying ' + gconf.packageRoot | ||
); | ||
} | ||
if ('function' === typeof gconf.notify) { | ||
@@ -62,5 +61,19 @@ gdefaults.notify = gconf.notify; | ||
var rc = GreenlockRc.resolve(gconf); | ||
gconf = Object.assign(rc, gconf); | ||
gconf = Init._init(gconf); | ||
// OK: /path/to/blah | ||
// OK: npm-name-blah | ||
// NOT OK: ./rel/path/to/blah | ||
// Error: .blah | ||
if ('.' === (gconf.manager.module || '')[0]) { | ||
if (!gconf.packageRoot) { | ||
gconf.packageRoot = process.cwd(); | ||
console.warn( | ||
'`packageRoot` not defined, trying ' + gconf.packageRoot | ||
); | ||
} | ||
gconf.manager.module = | ||
gconf.packageRoot + '/' + gconf.manager.module.slice(2); | ||
} | ||
// Wraps each of the following with appropriate error checking | ||
@@ -73,3 +86,3 @@ // greenlock.manager.defaults | ||
// greenlock.sites.get | ||
require('./manager-underlay.js').wrap(greenlock, gconf); | ||
MngWrapper.wrap(greenlock, gconf); | ||
// The goal here is to reduce boilerplate, such as error checking | ||
@@ -84,23 +97,7 @@ // and duration parsing, that a manager must implement | ||
// greenlock.challenges.get | ||
require('./challenges-underlay.js').wrap(greenlock); | ||
ChWrapper.wrap(greenlock); | ||
DIR._getDefaultDirectoryUrl('', gconf.staging, ''); | ||
if (gconf.directoryUrl) { | ||
gdefaults.directoryUrl = gconf.directoryUrl; | ||
if (gconf.staging) { | ||
throw new Error( | ||
'supply `directoryUrl` or `staging`, but not both' | ||
); | ||
} | ||
} else if ( | ||
gconf.staging || | ||
process.argv.includes('--staging') || | ||
/DEV|STAG/i.test(process.env.ENV) | ||
) { | ||
greenlock.staging = true; | ||
gdefaults.directoryUrl = | ||
'https://acme-staging-v02.api.letsencrypt.org/directory'; | ||
} else { | ||
greenlock.live = true; | ||
gdefaults.directoryUrl = | ||
'https://acme-v02.api.letsencrypt.org/directory'; | ||
} | ||
@@ -136,12 +133,12 @@ | ||
}) | ||
.then(function() { | ||
return greenlock.manager._defaults().then(function(MCONF) { | ||
mergeDefaults(MCONF, gconf); | ||
if (true === MCONF.agreeToTerms) { | ||
gdefaults.agreeToTerms = function(tos) { | ||
return Promise.resolve(tos); | ||
}; | ||
} | ||
return greenlock.manager._defaults(MCONF); | ||
}); | ||
.then(async function() { | ||
var MCONF = await greenlock.manager._defaults(); | ||
mergeDefaults(MCONF, gconf); | ||
if (true === MCONF.agreeToTerms) { | ||
gdefaults.agreeToTerms = function(tos) { | ||
return Promise.resolve(tos); | ||
}; | ||
} | ||
return greenlock.manager._defaults(MCONF); | ||
}) | ||
@@ -219,47 +216,43 @@ .catch(function(err) { | ||
// certs.get | ||
greenlock.get = function(args) { | ||
return greenlock | ||
._single(args) | ||
.then(function() { | ||
args._includePems = true; | ||
return greenlock.renew(args); | ||
}) | ||
.then(function(results) { | ||
if (!results || !results.length) { | ||
// TODO throw an error here? | ||
return null; | ||
} | ||
greenlock.get = async function(args) { | ||
greenlock._single(args); | ||
args._includePems = true; | ||
var results = await greenlock.renew(args); | ||
if (!results || !results.length) { | ||
// TODO throw an error here? | ||
return null; | ||
} | ||
// just get the first one | ||
var result = results[0]; | ||
// just get the first one | ||
var result = results[0]; | ||
// (there should be only one, ideally) | ||
if (results.length > 1) { | ||
var err = new Error( | ||
"a search for '" + | ||
args.servername + | ||
"' returned multiple certificates" | ||
); | ||
err.context = 'duplicate_certs'; | ||
err.servername = args.servername; | ||
err.subjects = results.map(function(r) { | ||
return (r.site || {}).subject || 'N/A'; | ||
}); | ||
// (there should be only one, ideally) | ||
if (results.length > 1) { | ||
var err = new Error( | ||
"a search for '" + | ||
args.servername + | ||
"' returned multiple certificates" | ||
); | ||
err.context = 'duplicate_certs'; | ||
err.servername = args.servername; | ||
err.subjects = results.map(function(r) { | ||
return (r.site || {}).subject || 'N/A'; | ||
}); | ||
greenlock._notify('warning', err); | ||
} | ||
greenlock._notify('warning', err); | ||
} | ||
if (result.error) { | ||
return Promise.reject(result.error); | ||
} | ||
if (result.error) { | ||
return Promise.reject(result.error); | ||
} | ||
// site for plugin options, such as http-01 challenge | ||
// pems for the obvious reasons | ||
return result; | ||
}); | ||
// site for plugin options, such as http-01 challenge | ||
// pems for the obvious reasons | ||
return result; | ||
}; | ||
greenlock._single = function(args) { | ||
// TODO remove async here, it doesn't matter | ||
greenlock._single = async function(args) { | ||
if ('string' !== typeof args.servername) { | ||
return Promise.reject(new Error('no `servername` given')); | ||
throw new Error('no `servername` given'); | ||
} | ||
@@ -286,44 +279,39 @@ // www.example.com => *.example.com | ||
) { | ||
return Promise.reject( | ||
new Error( | ||
'bad arguments, did you mean to call greenlock.renew()?' | ||
) | ||
throw new Error( | ||
'bad arguments, did you mean to call greenlock.renew()?' | ||
); | ||
} | ||
// duplicate, force, and others still allowed | ||
return Promise.resolve(args); | ||
return args; | ||
}; | ||
greenlock._config = function(args) { | ||
return greenlock._single(args).then(function() { | ||
return greenlock._configAll(args).then(function(sites) { | ||
return sites[0]; | ||
}); | ||
}); | ||
greenlock._config = async function(args) { | ||
greenlock._single(args); | ||
var sites = await greenlock._configAll(args); | ||
return sites[0]; | ||
}; | ||
greenlock._configAll = function(args) { | ||
return greenlock._find(args).then(function(sites) { | ||
if (!sites || !sites.length) { | ||
return []; | ||
greenlock._configAll = async function(args) { | ||
var sites = await greenlock._find(args); | ||
if (!sites || !sites.length) { | ||
return []; | ||
} | ||
sites = JSON.parse(JSON.stringify(sites)); | ||
var mconf = await greenlock.manager._defaults(); | ||
return sites.map(function(site) { | ||
if (site.store && site.challenges) { | ||
return site; | ||
} | ||
sites = JSON.parse(JSON.stringify(sites)); | ||
return greenlock.manager._defaults().then(function(mconf) { | ||
return sites.map(function(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 = {}; | ||
} | ||
if (!site.store) { | ||
dconf.store = mconf.store; | ||
} | ||
if (!site.challenges) { | ||
dconf.challenges = mconf.challenges; | ||
} | ||
return site; | ||
}); | ||
}); | ||
var dconf = site; | ||
// TODO make cli and api mode the same | ||
if (gconf._bin_mode) { | ||
dconf = site.defaults = {}; | ||
} | ||
if (!site.store) { | ||
dconf.store = mconf.store; | ||
} | ||
if (!site.challenges) { | ||
dconf.challenges = mconf.challenges; | ||
} | ||
return site; | ||
}); | ||
@@ -333,10 +321,8 @@ }; | ||
// needs to get info about the renewal, such as which store and challenge(s) to use | ||
greenlock.renew = function(args) { | ||
return greenlock._init().then(function() { | ||
return greenlock.manager._defaults().then(function(mconf) { | ||
return greenlock._renew(mconf, args); | ||
}); | ||
}); | ||
greenlock.renew = async function(args) { | ||
await greenlock._init(); | ||
var mconf = await greenlock.manager._defaults(); | ||
return greenlock._renew(mconf, args); | ||
}; | ||
greenlock._renew = function(mconf, args) { | ||
greenlock._renew = async function(mconf, args) { | ||
if (!args) { | ||
@@ -348,55 +334,53 @@ args = {}; | ||
//console.log('greenlock._renew find', args); | ||
return greenlock._find(args).then(function(sites) { | ||
// Note: the manager must guaranteed that these are mutable copies | ||
//console.log('greenlock._renew found', sites);; | ||
var sites = await greenlock._find(args); | ||
// Note: the manager must guaranteed that these are mutable copies | ||
//console.log('greenlock._renew found', sites);; | ||
if (!Array.isArray(sites)) { | ||
throw new Error( | ||
'Developer Error: not an array of sites returned from find: ' + | ||
JSON.stringify(sites) | ||
); | ||
if (!Array.isArray(sites)) { | ||
throw new Error( | ||
'Developer Error: not an array of sites returned from find: ' + | ||
JSON.stringify(sites) | ||
); | ||
} | ||
await (async function next() { | ||
var site = sites.shift(); | ||
if (!site) { | ||
return null; | ||
} | ||
function next() { | ||
var site = sites.shift(); | ||
if (!site) { | ||
return Promise.resolve(null); | ||
} | ||
var order = { site: site }; | ||
renewedOrFailed.push(order); | ||
// TODO merge args + result? | ||
return greenlock | ||
._order(mconf, site) | ||
.then(function(pems) { | ||
if (args._includePems) { | ||
order.pems = pems; | ||
} | ||
}) | ||
.catch(function(err) { | ||
order.error = err; | ||
var order = { site: site }; | ||
renewedOrFailed.push(order); | ||
// TODO merge args + result? | ||
return greenlock | ||
._order(mconf, site) | ||
.then(function(pems) { | ||
if (args._includePems) { | ||
order.pems = pems; | ||
} | ||
}) | ||
.catch(function(err) { | ||
order.error = err; | ||
// For greenlock express serialization | ||
err.toJSON = errorToJSON; | ||
err.context = err.context || 'cert_order'; | ||
err.subject = site.subject; | ||
if (args.servername) { | ||
err.servername = args.servername; | ||
} | ||
// for debugging, but not to be relied on | ||
err._site = site; | ||
// TODO err.context = err.context || 'renew_certificate' | ||
greenlock._notify('error', err); | ||
}) | ||
.then(function() { | ||
return next(); | ||
}); | ||
} | ||
// For greenlock express serialization | ||
err.toJSON = errorToJSON; | ||
err.context = err.context || 'cert_order'; | ||
err.subject = site.subject; | ||
if (args.servername) { | ||
err.servername = args.servername; | ||
} | ||
// for debugging, but not to be relied on | ||
err._site = site; | ||
// TODO err.context = err.context || 'renew_certificate' | ||
greenlock._notify('error', err); | ||
}) | ||
.then(function() { | ||
return next(); | ||
}); | ||
})(); | ||
return next().then(function() { | ||
return renewedOrFailed; | ||
}); | ||
}); | ||
return renewedOrFailed; | ||
}; | ||
greenlock._acme = function(mconf, args) { | ||
greenlock._acme = async function(mconf, args, dirUrl) { | ||
var packageAgent = gconf.packageAgent || ''; | ||
@@ -414,20 +398,3 @@ // because Greenlock_Express/v3.x Greenlock/v3 is redundant | ||
// The user has explicitly set the directoryUrl, great! | ||
var dirUrl = args.directoryUrl || mconf.directoryUrl; | ||
// The directoryUrl is implicit | ||
var showDir = false; | ||
if (!dirUrl) { | ||
showDir = true; | ||
dirUrl = greenlock._defaults.directoryUrl; | ||
} | ||
// Show the directory if implicit | ||
if (showDir && !gdefaults.shownDirectory) { | ||
gdefaults.shownDirectory = true; | ||
console.info('ACME Directory URL:', dirUrl); | ||
} | ||
var dir = caches[dirUrl]; | ||
// don't cache more than an hour | ||
@@ -438,83 +405,89 @@ if (dir && Date.now() - dir.ts < 1 * 60 * 60 * 1000) { | ||
return acme | ||
.init(dirUrl) | ||
.then(function(/*meta*/) { | ||
caches[dirUrl] = { | ||
promise: Promise.resolve(acme), | ||
ts: Date.now() | ||
}; | ||
return acme; | ||
}) | ||
.catch(function(err) { | ||
// TODO | ||
// let's encrypt is possibly down for maintenaince... | ||
// this is a special kind of failure mode | ||
throw err; | ||
}); | ||
await acme.init(dirUrl).catch(function(err) { | ||
// TODO this is a special kind of failure mode. What should we do? | ||
console.error( | ||
"[debug] Let's Encrypt may be down for maintenance or `directoryUrl` may be wrong" | ||
); | ||
throw err; | ||
}); | ||
caches[dirUrl] = { | ||
promise: Promise.resolve(acme), | ||
ts: Date.now() | ||
}; | ||
return acme; | ||
}; | ||
greenlock.order = function(siteConf) { | ||
return greenlock._init().then(function() { | ||
return greenlock.manager._defaults().then(function(mconf) { | ||
return greenlock._order(mconf, siteConf); | ||
}); | ||
}); | ||
greenlock.order = async function(siteConf) { | ||
await greenlock._init(); | ||
var mconf = await greenlock.manager._defaults(); | ||
return greenlock._order(mconf, siteConf); | ||
}; | ||
greenlock._order = function(mconf, siteConf) { | ||
greenlock._order = async function(mconf, siteConf) { | ||
// packageAgent, maintainerEmail | ||
return greenlock._acme(mconf, siteConf).then(function(acme) { | ||
var storeConf = siteConf.store || mconf.store; | ||
storeConf = JSON.parse(JSON.stringify(storeConf)); | ||
storeConf.packageRoot = gconf.packageRoot; | ||
var path = require('path'); | ||
if (!storeConf.basePath) { | ||
storeConf.basePath = 'greenlock'; | ||
var dirUrl = DIR._getDirectoryUrl( | ||
siteConf.directoryUrl || mconf.directoryUrl, | ||
siteConf.subject | ||
); | ||
var acme = await greenlock._acme(mconf, siteConf, dirUrl); | ||
var storeConf = siteConf.store || mconf.store; | ||
storeConf = JSON.parse(JSON.stringify(storeConf)); | ||
storeConf.packageRoot = gconf.packageRoot; | ||
if (!storeConf.basePath) { | ||
storeConf.basePath = gconf.configDir; | ||
} | ||
if ('.' === (storeConf.basePath || '')[0]) { | ||
if (!gconf.packageRoot) { | ||
gconf.packageRoot = process.cwd(); | ||
console.warn( | ||
'`packageRoot` not defined, trying ' + gconf.packageRoot | ||
); | ||
} | ||
storeConf.basePath = path.resolve( | ||
gconf.packageRoot || process.cwd(), | ||
storeConf.basePath = require('path').resolve( | ||
gconf.packageRoot || '', | ||
storeConf.basePath | ||
); | ||
return P._loadStore(storeConf).then(function(store) { | ||
return A._getOrCreate( | ||
greenlock, | ||
mconf, | ||
store.accounts, | ||
acme, | ||
siteConf | ||
).then(function(account) { | ||
var challengeConfs = | ||
siteConf.challenges || mconf.challenges; | ||
return Promise.all( | ||
Object.keys(challengeConfs).map(function(typ01) { | ||
return P._loadChallenge(challengeConfs, typ01); | ||
}) | ||
).then(function(arr) { | ||
var challenges = {}; | ||
arr.forEach(function(el) { | ||
challenges[el._type] = el; | ||
}); | ||
return C._getOrOrder( | ||
greenlock, | ||
mconf, | ||
store.certificates, | ||
acme, | ||
challenges, | ||
account, | ||
siteConf | ||
).then(function(pems) { | ||
if (!pems) { | ||
throw new Error('no order result'); | ||
} | ||
if (!pems.privkey) { | ||
throw new Error( | ||
'missing private key, which is kinda important' | ||
); | ||
} | ||
return pems; | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
storeConf.directoryUrl = dirUrl; | ||
var store = await P._loadStore(storeConf); | ||
var account = await A._getOrCreate( | ||
greenlock, | ||
mconf, | ||
store.accounts, | ||
acme, | ||
siteConf | ||
); | ||
var challengeConfs = siteConf.challenges || mconf.challenges; | ||
var challenges = {}; | ||
var arr = await Promise.all( | ||
Object.keys(challengeConfs).map(function(typ01) { | ||
return P._loadChallenge(challengeConfs, typ01); | ||
}) | ||
); | ||
arr.forEach(function(el) { | ||
challenges[el._type] = el; | ||
}); | ||
var pems = await C._getOrOrder( | ||
greenlock, | ||
mconf, | ||
store.certificates, | ||
acme, | ||
challenges, | ||
account, | ||
siteConf | ||
); | ||
if (!pems) { | ||
throw new Error('no order result'); | ||
} | ||
if (!pems.privkey) { | ||
throw new Error('missing private key, which is kinda important'); | ||
} | ||
return pems; | ||
}; | ||
@@ -560,5 +533,7 @@ | ||
}; | ||
console.info('[default] store.module: ' + MCONF.store.module); | ||
} | ||
} | ||
/* | ||
if ('greenlock-store-fs' === MCONF.store.module && !MCONF.store.basePath) { | ||
@@ -572,2 +547,3 @@ //homedir = require('os').homedir(); | ||
} | ||
*/ | ||
@@ -584,2 +560,6 @@ // just to test that it loads | ||
challenges['http-01'] = { module: 'acme-http-01-standalone' }; | ||
console.info( | ||
'[default] challenges.http-01.module: ' + | ||
challenges['http-01'].module | ||
); | ||
} | ||
@@ -608,13 +588,37 @@ if (challenges['http-01']) { | ||
MCONF.renewOffset = gconf.renewOffset || '-45d'; | ||
console.info('[default] renewOffset: ' + MCONF.renewOffset); | ||
} | ||
if (!MCONF.renewStagger) { | ||
MCONF.renewStagger = gconf.renewStagger || '3d'; | ||
console.info('[default] renewStagger: ' + MCONF.renewStagger); | ||
} | ||
var vers = process.versions.node.split('.'); | ||
var defaultKeyType = 'EC-P256'; | ||
if (vers[0] < 10 || (vers[0] === '10' && vers[1] < '12')) { | ||
defaultKeyType = 'RSA-2048'; | ||
} | ||
if (!MCONF.accountKeyType) { | ||
MCONF.accountKeyType = gconf.accountKeyType || 'EC-P256'; | ||
MCONF.accountKeyType = gconf.accountKeyType || defaultKeyType; | ||
console.info('[default] accountKeyType: ' + MCONF.accountKeyType); | ||
} | ||
if (!MCONF.serverKeyType) { | ||
MCONF.serverKeyType = gconf.serverKeyType || 'RSA-2048'; | ||
console.info('[default] serverKeyType: ' + MCONF.serverKeyType); | ||
} | ||
if (!MCONF.subscriberEmail && false !== MCONF.subscriberEmail) { | ||
MCONF.subscriberEmail = | ||
gconf.subscriberEmail || gconf.maintainerEmail || undefined; | ||
MCONF.agreeToTerms = gconf.agreeToTerms || undefined; | ||
console.info(''); | ||
console.info('[default] subscriberEmail: ' + MCONF.subscriberEmail); | ||
console.info( | ||
'[default] agreeToTerms: ' + | ||
(MCONF.agreeToTerms || | ||
gconf.agreeToTerms || | ||
'(show notice on use)') | ||
); | ||
console.info(''); | ||
} | ||
} | ||
@@ -621,0 +625,0 @@ |
{ | ||
"name": "@root/greenlock", | ||
"version": "3.1.5", | ||
"version": "4.0.0", | ||
"description": "The easiest Let's Encrypt client for Node.js and Browsers", | ||
@@ -41,3 +41,3 @@ "homepage": "https://rootprojects.org/greenlock/", | ||
"dependencies": { | ||
"@greenlock/manager": "^3.0.0", | ||
"@greenlock/manager": "^3.1.0", | ||
"@root/acme": "^3.0.8", | ||
@@ -47,7 +47,6 @@ "@root/csr": "^0.8.1", | ||
"@root/mkdirp": "^1.0.0", | ||
"@root/request": "^1.3.10", | ||
"@root/request": "^1.4.2", | ||
"acme-http-01-standalone": "^3.0.5", | ||
"cert-info": "^1.5.1", | ||
"greenlock-manager-fs": "^3.0.5", | ||
"greenlock-store-fs": "^3.2.0", | ||
"greenlock-store-fs": "^3.2.2", | ||
"safe-replace": "^1.1.0" | ||
@@ -54,0 +53,0 @@ }, |
@@ -1,5 +0,3 @@ | ||
# New Documentation & [v2/v3 Migration Guide](https://git.rootprojects.org/root/greenlock.js/src/branch/v3/MIGRATION_GUIDE_V2_V3.md) | ||
# New Documentation & [v4 Migration Guide](https://git.rootprojects.org/root/greenlock.js/src/branch/master/MIGRATION_GUIDE.md) | ||
Greenlock v3 was just released from private beta **today** (Nov 1st, 2019). | ||
We're still working on the full documentation for this new version, | ||
@@ -9,3 +7,3 @@ so please be patient. | ||
To start, check out the | ||
[Migration Guide](https://git.rootprojects.org/root/greenlock.js/src/branch/v3/MIGRATION_GUIDE_V2_V3.md). | ||
[Migration Guide](https://git.rootprojects.org/root/greenlock.js/src/branch/master/MIGRATION_GUIDE.md). | ||
@@ -89,8 +87,6 @@ !["Greenlock Logo"](https://git.rootprojects.org/root/greenlock.js/raw/branch/master/logo/greenlock-1063x250.png 'Greenlock lock logo and work mark') | ||
var greenlock = Greenlock.create({ | ||
configDir: './greenlock.d/config.json', | ||
packageAgent: pkg.name + '/' + pkg.version, | ||
maintainerEmail: pkg.author, | ||
staging: true, | ||
manager: require('greenlock-manager-fs').create({ | ||
configFile: '~/.config/greenlock/manager.json' | ||
}), | ||
notify: function(event, details) { | ||
@@ -176,3 +172,3 @@ if ('error' === event) { | ||
<details> | ||
<summary>Greenlock.create({ packageAgent, maintainerEmail, staging })</summary> | ||
<summary>Greenlock.create({ configDir, packageAgent, maintainerEmail, staging })</summary> | ||
@@ -187,2 +183,4 @@ ## Greenlock.create() | ||
var gl = Greenlock.create({ | ||
configDir: './greenlock.d/config.json', | ||
// Staging for testing environments | ||
@@ -194,2 +192,3 @@ staging: true, | ||
maintainerEmail: 'jon@example.com', | ||
// for an RFC 8555 / RFC 7231 ACME client user agent | ||
@@ -202,2 +201,3 @@ packageAgent: pkg.name + '/' pkg.version | ||
| --------------- | ------------------------------------------------------------------------------------ | | ||
| configDir | the directory to use for file-based plugins | | ||
| maintainerEmail | the developer contact for critical bug and security notifications | | ||
@@ -204,0 +204,0 @@ | packageAgent | if you publish your package for others to use, `require('./package.json').name` here | |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
181331
10
31
4359
- Removedgreenlock-manager-fs@^3.0.5
Updated@greenlock/manager@^3.1.0
Updated@root/request@^1.4.2
Updatedgreenlock-store-fs@^3.2.2