From 51f0838539b32e9590972e5072f8ae919ca06926 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 29 Oct 2019 05:08:41 +0000 Subject: [PATCH] v0.6.1: bugfixes for greenlock express v3 --- .prettierrc | 8 ++ manager.js | 223 +++++++++++++++++++++------------------------- package-lock.json | 18 ++++ package.json | 2 +- 4 files changed, 129 insertions(+), 122 deletions(-) create mode 100644 .prettierrc create mode 100644 package-lock.json diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..2bc4861 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,8 @@ +{ + "bracketSpacing": true, + "printWidth": 80, + "singleQuote": true, + "tabWidth": 4, + "trailingComma": "none", + "useTabs": true +} diff --git a/manager.js b/manager.js index f01065f..40a849b 100644 --- a/manager.js +++ b/manager.js @@ -23,13 +23,9 @@ Manage.create = function(opts) { var manage = {}; - manage.ping = function() { - return Manage._ping(manage, opts); - }; - manage._txPromise = Promise.resolve(); - manage.config = function(conf) { + manage.defaults = manage.config = function(conf) { // get / set default site settings such as // subscriberEmail, store, challenges, renewOffset, renewStagger return Manage._getLatest(manage, opts).then(function(config) { @@ -87,39 +83,6 @@ Manage.create = function(opts) { }); }; - manage._lastStat = { - size: 0, - mtimeMs: 0 - }; - manage._config = {}; - - manage._save = function(config) { - return mkdirp(path.dirname(opts.configFile)).then(function() { - return sfs - .writeFileAsync( - opts.configFile, - // pretty-print the config file - JSON.stringify(config, null, 2), - 'utf8' - ) - .then(function() { - // this file may contain secrets, so keep it safe - return chmodFile(opts.configFile, parseInt('0600', 8)) - .catch(function() { - /*ignore for Windows */ - }) - .then(function() { - return statFile(opts.configFile).then(function( - stat - ) { - manage._lastStat.size = stat.size; - manage._lastStat.mtimeMs = stat.mtimeMs; - }); - }); - }); - }); - }; - manage.add = function(args) { manage._txPromise = manage._txPromise.then(function() { // if the fs has changed since we last wrote, get the lastest from disk @@ -128,7 +91,8 @@ Manage.create = function(opts) { var subscriberEmail = args.subscriberEmail; var subject = args.subject || args.domain; var primary = subject; - var altnames = args.altnames || args.domains; + var altnames = + args.servernames || args.altnames || args.domains; if ('string' !== typeof primary) { if (!Array.isArray(altnames) || !altnames.length) { throw new Error('there needs to be a subject'); @@ -203,6 +167,14 @@ Manage.create = function(opts) { }; manage.find = function(args) { + var some = _find(args); + if (!opts.find) { + return some; + } + // TODO function to always add + throw new Error('TODO: use the given find'); + }; + function _find(args) { return Manage._getLatest(manage, opts).then(function(config) { // i.e. find certs more than 30 days old //args.issuedBefore = Date.now() - 30 * 24 * 60 * 60 * 1000; @@ -252,6 +224,69 @@ Manage.create = function(opts) { return sites; }); + } + + manage.notify = opts.notify || _notify; + function _notify(ev, args) { + if (!args) { + args = ev; + ev = args.event; + delete args.event; + } + + // TODO define message types + if (!manage._notify_notice) { + console.info( + 'set greenlockOptions.notify to override the default logger' + ); + manage._notify_notice = true; + } + switch (ev) { + case 'error': + /* falls through */ + case 'warning': + console.error( + 'Error%s:', + (' ' + (args.context || '')).trimRight() + ); + console.error(args.message); + if (args.description) { + console.error(args.description); + } + if (args.code) { + console.error('code:', args.code); + } + break; + default: + if (/status/.test(ev)) { + console.info( + ev, + args.altname || args.subject || '', + args.status || '' + ); + if (!args.status) { + console.info(args); + } + break; + } + console.info( + ev, + '(more info available: ' + Object.keys(args).join(' ') + ')' + ); + } + } + + manage.update = function(args) { + manage._txPromise = manage.txPromise.then(function() { + return Manage._getLatest(manage, opts).then(function(config) { + var site = config.sites[args.subject]; + site.issuedAt = args.issuedAt; + site.expiresAt = args.expiresAt; + site.renewAt = args.renewAt; + // foo + }); + }); + return manage._txPromise; }; manage.remove = function(args) { @@ -272,76 +307,37 @@ Manage.create = function(opts) { return manage._txPromise; }; - manage.notify = manage.notifications = function(ev, args) { - if (!args) { - args = ev; - ev = args.event; - delete args.event; - } - - // TODO define message types - if (!manage._notify_notice) { - console.info( - 'set greenlockOptions.notify to override the default logger' - ); - manage._notify_notice = true; - } - switch (ev) { - case 'error': - /* falls through */ - case 'warning': - console.error( - 'Error%s:', - args.context ? ' ' + args.context : '' - ); - console.error(args.message); - if (args.description) { - console.error(args.description); - } - if (args.code) { - console.error('code:', args.code); - } - break; - default: - if (/status/.test(ev)) { - console.info( - ev, - args.altname || args.subject || '', - args.status || '' - ); - if (!args.status) { - console.log(args); - } - break; - } - console.info( - ev, - '(more info available: ' + Object.keys(args).join(' ') + ')' - ); - } + manage._lastStat = { + size: 0, + mtimeMs: 0 }; + manage._config = {}; - manage.errors = function(err) { - // err.subject - // err.altnames - // err.challenge - // err.challengeOptions - // err.store - // err.storeOptions - console.error('Failure with ', err.subject); - }; - - manage.update = function(args) { - manage._txPromise = manage.txPromise.then(function() { - return Manage._getLatest(manage, opts).then(function(config) { - var site = config.sites[args.subject]; - site.issuedAt = args.issuedAt; - site.expiresAt = args.expiresAt; - site.renewAt = args.renewAt; - // foo - }); + manage._save = function(config) { + return mkdirp(path.dirname(opts.configFile)).then(function() { + return sfs + .writeFileAsync( + opts.configFile, + // pretty-print the config file + JSON.stringify(config, null, 2), + 'utf8' + ) + .then(function() { + // this file may contain secrets, so keep it safe + return chmodFile(opts.configFile, parseInt('0600', 8)) + .catch(function() { + /*ignore for Windows */ + }) + .then(function() { + return statFile(opts.configFile).then(function( + stat + ) { + manage._lastStat.size = stat.size; + manage._lastStat.mtimeMs = stat.mtimeMs; + }); + }); + }); }); - return manage._txPromise; }; return manage; @@ -373,18 +369,3 @@ Manage._getLatest = function(mng, opts) { }); }); }; - -Manage._ping = function(mng, opts) { - if (mng._pingPromise) { - return mng._pingPromise; - } - - mng._pringPromise = Promise.resolve().then(function() { - // TODO file permissions - if (!opts.configFile) { - throw new Error('no config file location provided'); - } - JSON.parse(fs.readFileSync(opts.configFile, 'utf8')); - }); - return mng._pingPromise; -}; diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..71f4a0d --- /dev/null +++ b/package-lock.json @@ -0,0 +1,18 @@ +{ + "name": "greenlock-manager-fs", + "version": "0.6.1", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@root/mkdirp": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@root/mkdirp/-/mkdirp-1.0.0.tgz", + "integrity": "sha512-hxGAYUx5029VggfG+U9naAhQkoMSXtOeXtbql97m3Hi6/sQSRL/4khKZPyOF6w11glyCOU38WCNLu9nUcSjOfA==" + }, + "safe-replace": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/safe-replace/-/safe-replace-1.1.0.tgz", + "integrity": "sha512-9/V2E0CDsKs9DWOOwJH7jYpSl9S3N05uyevNjvsnDauBqRowBPOyot1fIvV5N2IuZAbYyvrTXrYFVG0RZInfFw==" + } + } +} diff --git a/package.json b/package.json index 3b057bf..c3c20d6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "greenlock-manager-fs", - "version": "0.6.0", + "version": "0.6.1", "description": "A simple file-based management strategy for Greenlock", "main": "manager.js", "scripts": {