Compare commits

..

2 Commits

6 changed files with 91 additions and 35 deletions

2
.gitignore vendored
View File

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

View File

@ -10,22 +10,28 @@ A simple file-based management strategy for Greenlock v3
npm install --save greenlock-manager-fs@v3 npm install --save greenlock-manager-fs@v3
``` ```
## Use with Greenlock ## Usage
```js ```js
var greenlock = require('greenlock').create({ npx greenlock init --manager greenlock-manager-fs --config-dir './greenlock.d'
// ... ```
manager: 'greenlock-manager-fs', Or, place this file in the root of your project:
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:
`~/.config/greenlock/manager.json`: `./greenlock.d/config.json`:
```json ```json
{ {

View File

@ -19,8 +19,13 @@ 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) {
@ -75,6 +80,31 @@ 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] = {
@ -250,8 +280,16 @@ 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.stringify(config, null, 2); var data = JSON.parse(JSON.stringify(config));
await sfs.writeFileAsync(CONF.configFile, data, 'utf8'); 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 // this file may contain secrets, so keep it safe
return chmodFile(CONF.configFile, parseInt('0600', 8)) return chmodFile(CONF.configFile, parseInt('0600', 8))
@ -266,8 +304,9 @@ Manage.create = function(CONF) {
}; };
manage.init = async function(deps) { manage.init = async function(deps) {
var request = deps.request; // even though we don't need it
// how nice... manage.request = deps.request;
return null;
}; };
return manage; return manage;
@ -310,7 +349,10 @@ doctor.config = function(config) {
doctor.sites(config); doctor.sites(config);
Object.keys(config).forEach(function(key) { 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; 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.0.5", "version": "3.1.0",
"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.1", "version": "3.0.5",
"resolved": "https://registry.npmjs.org/greenlock-manager-fs/-/greenlock-manager-fs-3.0.1.tgz", "resolved": "https://registry.npmjs.org/greenlock-manager-fs/-/greenlock-manager-fs-3.0.5.tgz",
"integrity": "sha512-vZfGFq1TTKxaAqdGDUwNservrNzXx0xCwT/ovG/N378GrhS+U5S8B8LUlNtQU7Fdw6RToMiBcm22OOxSrvZ2zw==", "integrity": "sha512-r/q+tEFuDwklfzPfiGhcIrHuJxMrppC+EseESpu5f0DMokh+1iZVm9nGC/VE7/7GETdOYfEYhhQkmspsi8Gr/A==",
"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.0.0", "version": "3.1.1",
"resolved": "https://registry.npmjs.org/greenlock-manager-test/-/greenlock-manager-test-3.0.0.tgz", "resolved": "https://registry.npmjs.org/greenlock-manager-test/-/greenlock-manager-test-3.1.1.tgz",
"integrity": "sha512-grqpUcxT7v5KzJ04r8wJWXjSVm7us1z/2QluCJRl9BZUM4CXzQuP1C0d2wdsV4NHwziEGJpA+4mFsntuh3f1YA==", "integrity": "sha512-wZ+Oxn5qTEoN+VDd3Y+kBYZ8MlaLlhm40KwIwfyR90bj08IZpfzE7zGY8SwBEbIx0wNSo6ztDku4Y0gVgxxwCA==",
"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.0.5", "version": "3.1.0",
"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.0.0" "greenlock-manager-test": "^3.1.1"
} }
} }

View File

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