diff --git a/.gitignore b/.gitignore index 144585f..c161e1a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +*delete-me* + # ---> Node # Logs logs diff --git a/README.md b/README.md index 21e942b..11895f6 100644 --- a/README.md +++ b/README.md @@ -10,22 +10,28 @@ A simple file-based management strategy for Greenlock v3 npm install --save greenlock-manager-fs@v3 ``` -## Use with Greenlock +## Usage ```js -var greenlock = require('greenlock').create({ - // ... +npx greenlock init --manager greenlock-manager-fs --config-dir './greenlock.d' +``` - manager: 'greenlock-manager-fs', - configFile: '~/.config/greenlock/manager.json' -}); +Or, place this file in the root of your project: + +`.greenlockrc`: + +```json +{ + "manager": "greenlock-manager-fs", + "configDir": "./greenlock.d" +} ``` ## Example config file You might start your config file like this: -`~/.config/greenlock/manager.json`: +`./greenlock.d/config.json`: ```json { diff --git a/manager.js b/manager.js index 49ef5c6..6bfe05c 100644 --- a/manager.js +++ b/manager.js @@ -19,8 +19,13 @@ var mkdirp = promisify(require('@root/mkdirp')); // and wanting to be fairly sure it works and produces // meaningful errors +// IMPORTANT // For your use case you'll probably find a better example -// in greenlock-manager-test +// in greenlock-manager-test: +// +// npm install --save greenlock-manager-test +// npx greenlock-manager-init +// Manage.create = function(CONF) { if (!CONF) { @@ -75,6 +80,31 @@ Manage.create = function(CONF) { return manage._txPromise; }; + manage.get = async function(args) { + manage._txPromise = manage._txPromise.then(async function() { + var config = await Manage._getLatest(manage, CONF); + var site; + Object.keys(config.sites).some(function(k) { + // if subject is specified, don't return anything else + var _site = config.sites[k]; + + // altnames, servername, and wildname all get rolled into one + return _site.altnames.some(function(altname) { + if ([args.servername, args.wildname].includes(altname)) { + site = _site; + } + }); + }); + + if (site && !site.deletedAt) { + return doctor.site(config.sites, site.subject); + } + return null; + }); + + return manage._txPromise; + }; + manage._merge = function(config, current, args) { if (!current || current.deletedAt) { current = config.sites[args.subject] = { @@ -250,8 +280,16 @@ Manage.create = function(CONF) { manage._save = async function(config) { await mkdirp(path.dirname(CONF.configFile)); // pretty-print the config file - var data = JSON.stringify(config, null, 2); - await sfs.writeFileAsync(CONF.configFile, data, 'utf8'); + var data = JSON.parse(JSON.stringify(config)); + var sites = data.sites || {}; + data.sites = Object.keys(sites).map(function(k) { + return sites[k]; + }); + await sfs.writeFileAsync( + CONF.configFile, + JSON.stringify(data, null, 2), + 'utf8' + ); // this file may contain secrets, so keep it safe return chmodFile(CONF.configFile, parseInt('0600', 8)) @@ -266,8 +304,9 @@ Manage.create = function(CONF) { }; manage.init = async function(deps) { - var request = deps.request; - // how nice... + // even though we don't need it + manage.request = deps.request; + return null; }; return manage; @@ -310,7 +349,10 @@ doctor.config = function(config) { doctor.sites(config); Object.keys(config).forEach(function(key) { - if (['defaults', 'routes', 'sites'].includes(key)) { + // .greenlockrc and greenlock.json shall merge as one + // and be called greenlock.json because calling it + // .greenlockrc seems to rub people the wrong way + if (['manager', 'defaults', 'routes', 'sites'].includes(key)) { return; } config.defaults[key] = config[key]; diff --git a/package-lock.json b/package-lock.json index f5ca7b5..c62074a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "greenlock-manager-fs", - "version": "3.0.5", + "version": "3.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -16,9 +16,9 @@ "dev": true }, "greenlock-manager-fs": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/greenlock-manager-fs/-/greenlock-manager-fs-3.0.1.tgz", - "integrity": "sha512-vZfGFq1TTKxaAqdGDUwNservrNzXx0xCwT/ovG/N378GrhS+U5S8B8LUlNtQU7Fdw6RToMiBcm22OOxSrvZ2zw==", + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/greenlock-manager-fs/-/greenlock-manager-fs-3.0.5.tgz", + "integrity": "sha512-r/q+tEFuDwklfzPfiGhcIrHuJxMrppC+EseESpu5f0DMokh+1iZVm9nGC/VE7/7GETdOYfEYhhQkmspsi8Gr/A==", "dev": true, "requires": { "@root/mkdirp": "^1.0.0", @@ -26,9 +26,9 @@ } }, "greenlock-manager-test": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/greenlock-manager-test/-/greenlock-manager-test-3.0.0.tgz", - "integrity": "sha512-grqpUcxT7v5KzJ04r8wJWXjSVm7us1z/2QluCJRl9BZUM4CXzQuP1C0d2wdsV4NHwziEGJpA+4mFsntuh3f1YA==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/greenlock-manager-test/-/greenlock-manager-test-3.1.1.tgz", + "integrity": "sha512-wZ+Oxn5qTEoN+VDd3Y+kBYZ8MlaLlhm40KwIwfyR90bj08IZpfzE7zGY8SwBEbIx0wNSo6ztDku4Y0gVgxxwCA==", "dev": true, "requires": { "@root/request": "^1.4.1", diff --git a/package.json b/package.json index 7b3b264..8c81b5e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "greenlock-manager-fs", - "version": "3.0.5", + "version": "3.1.0", "description": "A simple file-based management strategy for Greenlock", "main": "manager.js", "scripts": { @@ -27,6 +27,6 @@ "safe-replace": "^1.1.0" }, "devDependencies": { - "greenlock-manager-test": "^3.0.0" + "greenlock-manager-test": "^3.1.1" } }