v0.6.1: bugfixes for greenlock express v3

This commit is contained in:
AJ ONeal 2019-10-29 05:08:41 +00:00
parent bfb7019a8f
commit 51f0838539
4 changed files with 129 additions and 122 deletions

8
.prettierrc Normal file
View File

@ -0,0 +1,8 @@
{
"bracketSpacing": true,
"printWidth": 80,
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "none",
"useTabs": true
}

View File

@ -23,13 +23,9 @@ Manage.create = function(opts) {
var manage = {}; var manage = {};
manage.ping = function() {
return Manage._ping(manage, opts);
};
manage._txPromise = Promise.resolve(); manage._txPromise = Promise.resolve();
manage.config = function(conf) { manage.defaults = manage.config = function(conf) {
// get / set default site settings such as // get / set default site settings such as
// subscriberEmail, store, challenges, renewOffset, renewStagger // subscriberEmail, store, challenges, renewOffset, renewStagger
return Manage._getLatest(manage, opts).then(function(config) { 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.add = function(args) {
manage._txPromise = manage._txPromise.then(function() { manage._txPromise = manage._txPromise.then(function() {
// if the fs has changed since we last wrote, get the lastest from disk // 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 subscriberEmail = args.subscriberEmail;
var subject = args.subject || args.domain; var subject = args.subject || args.domain;
var primary = subject; var primary = subject;
var altnames = args.altnames || args.domains; var altnames =
args.servernames || args.altnames || args.domains;
if ('string' !== typeof primary) { if ('string' !== typeof primary) {
if (!Array.isArray(altnames) || !altnames.length) { if (!Array.isArray(altnames) || !altnames.length) {
throw new Error('there needs to be a subject'); throw new Error('there needs to be a subject');
@ -203,6 +167,14 @@ Manage.create = function(opts) {
}; };
manage.find = function(args) { 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) { return Manage._getLatest(manage, opts).then(function(config) {
// i.e. find certs more than 30 days old // i.e. find certs more than 30 days old
//args.issuedBefore = Date.now() - 30 * 24 * 60 * 60 * 1000; //args.issuedBefore = Date.now() - 30 * 24 * 60 * 60 * 1000;
@ -252,6 +224,69 @@ Manage.create = function(opts) {
return sites; 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) { manage.remove = function(args) {
@ -272,76 +307,37 @@ Manage.create = function(opts) {
return manage._txPromise; return manage._txPromise;
}; };
manage.notify = manage.notifications = function(ev, args) { manage._lastStat = {
if (!args) { size: 0,
args = ev; mtimeMs: 0
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._config = {};
manage.errors = function(err) { manage._save = function(config) {
// err.subject return mkdirp(path.dirname(opts.configFile)).then(function() {
// err.altnames return sfs
// err.challenge .writeFileAsync(
// err.challengeOptions opts.configFile,
// err.store // pretty-print the config file
// err.storeOptions JSON.stringify(config, null, 2),
console.error('Failure with ', err.subject); 'utf8'
}; )
.then(function() {
manage.update = function(args) { // this file may contain secrets, so keep it safe
manage._txPromise = manage.txPromise.then(function() { return chmodFile(opts.configFile, parseInt('0600', 8))
return Manage._getLatest(manage, opts).then(function(config) { .catch(function() {
var site = config.sites[args.subject]; /*ignore for Windows */
site.issuedAt = args.issuedAt; })
site.expiresAt = args.expiresAt; .then(function() {
site.renewAt = args.renewAt; return statFile(opts.configFile).then(function(
// foo stat
) {
manage._lastStat.size = stat.size;
manage._lastStat.mtimeMs = stat.mtimeMs;
});
});
}); });
}); });
return manage._txPromise;
}; };
return manage; 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;
};

18
package-lock.json generated Normal file
View File

@ -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=="
}
}
}

View File

@ -1,6 +1,6 @@
{ {
"name": "greenlock-manager-fs", "name": "greenlock-manager-fs",
"version": "0.6.0", "version": "0.6.1",
"description": "A simple file-based management strategy for Greenlock", "description": "A simple file-based management strategy for Greenlock",
"main": "manager.js", "main": "manager.js",
"scripts": { "scripts": {