Compare commits

..

No commits in common. "0ebb53f5633de7de76b809942a908b3a71dc9a10" and "4b47fb4eb679594a6f2978484f0b40788e7047b6" have entirely different histories.

6 changed files with 35 additions and 91 deletions

2
.gitignore vendored
View File

@ -1,5 +1,3 @@
*delete-me*
# ---> Node # ---> Node
# Logs # Logs
logs logs

View File

@ -10,28 +10,22 @@ A simple file-based management strategy for Greenlock v3
npm install --save greenlock-manager-fs@v3 npm install --save greenlock-manager-fs@v3
``` ```
## Usage ## Use with Greenlock
```js ```js
npx greenlock init --manager greenlock-manager-fs --config-dir './greenlock.d' var greenlock = require('greenlock').create({
``` // ...
Or, place this file in the root of your project: manager: 'greenlock-manager-fs',
configFile: '~/.config/greenlock/manager.json'
`.greenlockrc`: });
```json
{
"manager": "greenlock-manager-fs",
"configDir": "./greenlock.d"
}
``` ```
## Example config file ## Example config file
You might start your config file like this: You might start your config file like this:
`./greenlock.d/config.json`: `~/.config/greenlock/manager.json`:
```json ```json
{ {

View File

@ -19,13 +19,8 @@ var mkdirp = promisify(require('@root/mkdirp'));
// and wanting to be fairly sure it works and produces // and wanting to be fairly sure it works and produces
// meaningful errors // meaningful errors
// IMPORTANT
// For your use case you'll probably find a better example // 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) { Manage.create = function(CONF) {
if (!CONF) { if (!CONF) {
@ -80,31 +75,6 @@ Manage.create = function(CONF) {
return manage._txPromise; 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) { manage._merge = function(config, current, args) {
if (!current || current.deletedAt) { if (!current || current.deletedAt) {
current = config.sites[args.subject] = { current = config.sites[args.subject] = {
@ -280,16 +250,8 @@ Manage.create = function(CONF) {
manage._save = async function(config) { manage._save = async function(config) {
await mkdirp(path.dirname(CONF.configFile)); await mkdirp(path.dirname(CONF.configFile));
// pretty-print the config file // pretty-print the config file
var data = JSON.parse(JSON.stringify(config)); var data = JSON.stringify(config, null, 2);
var sites = data.sites || {}; await sfs.writeFileAsync(CONF.configFile, data, 'utf8');
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 // this file may contain secrets, so keep it safe
return chmodFile(CONF.configFile, parseInt('0600', 8)) return chmodFile(CONF.configFile, parseInt('0600', 8))
@ -304,9 +266,8 @@ Manage.create = function(CONF) {
}; };
manage.init = async function(deps) { manage.init = async function(deps) {
// even though we don't need it var request = deps.request;
manage.request = deps.request; // how nice...
return null;
}; };
return manage; return manage;
@ -349,10 +310,7 @@ doctor.config = function(config) {
doctor.sites(config); doctor.sites(config);
Object.keys(config).forEach(function(key) { Object.keys(config).forEach(function(key) {
// .greenlockrc and greenlock.json shall merge as one if (['defaults', 'routes', 'sites'].includes(key)) {
// and be called greenlock.json because calling it
// .greenlockrc seems to rub people the wrong way
if (['manager', 'defaults', 'routes', 'sites'].includes(key)) {
return; return;
} }
config.defaults[key] = config[key]; config.defaults[key] = config[key];

14
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "greenlock-manager-fs", "name": "greenlock-manager-fs",
"version": "3.1.0", "version": "3.0.5",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -16,9 +16,9 @@
"dev": true "dev": true
}, },
"greenlock-manager-fs": { "greenlock-manager-fs": {
"version": "3.0.5", "version": "3.0.1",
"resolved": "https://registry.npmjs.org/greenlock-manager-fs/-/greenlock-manager-fs-3.0.5.tgz", "resolved": "https://registry.npmjs.org/greenlock-manager-fs/-/greenlock-manager-fs-3.0.1.tgz",
"integrity": "sha512-r/q+tEFuDwklfzPfiGhcIrHuJxMrppC+EseESpu5f0DMokh+1iZVm9nGC/VE7/7GETdOYfEYhhQkmspsi8Gr/A==", "integrity": "sha512-vZfGFq1TTKxaAqdGDUwNservrNzXx0xCwT/ovG/N378GrhS+U5S8B8LUlNtQU7Fdw6RToMiBcm22OOxSrvZ2zw==",
"dev": true, "dev": true,
"requires": { "requires": {
"@root/mkdirp": "^1.0.0", "@root/mkdirp": "^1.0.0",
@ -26,9 +26,9 @@
} }
}, },
"greenlock-manager-test": { "greenlock-manager-test": {
"version": "3.1.1", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/greenlock-manager-test/-/greenlock-manager-test-3.1.1.tgz", "resolved": "https://registry.npmjs.org/greenlock-manager-test/-/greenlock-manager-test-3.0.0.tgz",
"integrity": "sha512-wZ+Oxn5qTEoN+VDd3Y+kBYZ8MlaLlhm40KwIwfyR90bj08IZpfzE7zGY8SwBEbIx0wNSo6ztDku4Y0gVgxxwCA==", "integrity": "sha512-grqpUcxT7v5KzJ04r8wJWXjSVm7us1z/2QluCJRl9BZUM4CXzQuP1C0d2wdsV4NHwziEGJpA+4mFsntuh3f1YA==",
"dev": true, "dev": true,
"requires": { "requires": {
"@root/request": "^1.4.1", "@root/request": "^1.4.1",

View File

@ -1,6 +1,6 @@
{ {
"name": "greenlock-manager-fs", "name": "greenlock-manager-fs",
"version": "3.1.0", "version": "3.0.5",
"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": {
@ -27,6 +27,6 @@
"safe-replace": "^1.1.0" "safe-replace": "^1.1.0"
}, },
"devDependencies": { "devDependencies": {
"greenlock-manager-test": "^3.1.1" "greenlock-manager-test": "^3.0.0"
} }
} }

View File

@ -1,25 +1,19 @@
"use strict"; 'use strict';
var Tester = require("greenlock-manager-test"); var Tester = require('greenlock-manager-test');
var Manager = require("../manager.js"); var Manager = require('../');
var config = { var config = {
configFile: "greenlock-manager-test.delete-me.json" configFile: 'greenlock-manager-test.delete-me.json'
}; };
Tester.test(Manager, config) Tester.test(Manager, config)
.then(function(features) { .then(function() {
console.info("PASS"); console.log('PASS: Known-good test module passes');
console.info(); })
console.info("Optional Feature Support:"); .catch(function(err) {
features.forEach(function(feature) { console.error('Oops, you broke it. Here are the details:');
console.info(feature.supported ? "✓ (YES)" : "✘ (NO) ", feature.description); console.error(err.stack);
}); console.error();
console.info(); console.error("That's all I know.");
}) });
.catch(function(err) {
console.error("Oops, you broke it. Here are the details:");
console.error(err.stack);
console.error();
console.error("That's all I know.");
});