v3.0.0: @greenlock/manager

This commit is contained in:
AJ ONeal 2019-11-04 21:28:49 -07:00
parent a1c08876fe
commit 3a0af2c2e7
7 changed files with 312 additions and 2 deletions

2
.gitignore vendored
View File

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

8
.prettierrc Normal file
View File

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

119
README.md
View File

@ -1,3 +1,118 @@
# greenlock-manager.js # [Greenlock Manager](https://git.rootprojects.org/root/greenlock-manager.js)
FileSytem-based Manager with optional encrypted Cloud backup for Greenlock SSL Manages SSL Certificate issue and renewal for [Greenlock](https://git.rootprojects.org/root/greenlock-manager.js).
Saves global and per-site config to a local File Sytem (current), with optional encrypted Cloud backup (coming soon).
```bash
npm install --save greenlock@3
npm install --save greenlock-manager@3
```
# Greenlock Manager CLI & API
All manager plugins have the **same API**.
The manager-specific implementation is overlaid by Greenlock with error handling and common utilities,
and then exposed as documented here.
**Note**: Most people do not need to (and should not) not use the JavaScript API.
Instead, use the CLI (current) or Web API (coming soon).
## Initialize the Manager
```bash
npx greenlock init --manager cloud --manager-token 'xxxx' --manager-config-file './greenlock.json'
```
Note: You **should not** initialize greenlock directly as
this may make it incompatible with the CLI and Web GUI.
Instead use the file generated by the CLI `init` (shown above).
```js
Greenlock.create({
manager: "@greenlock/manager",
cloud: true,
token: "xxxx",
configFile: "./greenlock.json",
packageRoot: __dirname
});
```
## Set Subscriber and other global Defaults
```bash
npx greenlock defaults --subscriber-email jon@example.com --agree-to-terms true
```
```js
greenlock.manager.defaults({
subscriberEmail: "jon@example.com",
agreeToTerms: true
});
```
# Site Management
By "site" we mean a primary domain and, optionally, secondary domains, to be listed on an ssl certificate,
along with any configuration that is necessary for getting and renewing those certificates.
## Add a sites - domains and SSL certificates
```bash
npx greenlock add --subject example.com --altnames 'example.com,www.example.com'
```
```js
greenlock.sites.add({
subject: "example.com",
altnames: ["example.com", "www.example.com"]
});
```
## View site config
```bash
npx greenlock config --subject example.com
```
```js
greenlock.sites.get({
servername: "www.example.com",
wildname: "*.example.com"
});
```
## Update site config
```bash
npx greenlock update --subject example.com --challenge-dns-01 acme-dns-01-ovh --challenge-dns-01-token xxxx
```
```js
greenlock.sites.update({
subject: "www.example.com",
challenges: {
"dns-01": {
module: "acme-dns-01-ovh",
token: "xxxx"
}
}
});
```
## Remove a site
To stop automatic renewal of SSL certificates for a particular site.
You to restart renewal you must use `add()`.
```bash
npx greenlock remove --subject example.com
```
```js
greenlock.sites.remove({
subject: "example.com"
});
```

87
manager.js Normal file
View File

@ -0,0 +1,87 @@
"use strict";
var MFS = require("greenlock-manager-fs");
// TODO @greenlock/manager-cloud
var Manager = module.exports;
Manager.create = function(opts) {
var mfs = MFS.create(opts);
var manager = {};
//
// REQUIRED (basic issuance)
//
if (mfs.get) {
manager.get = async function({ servername, wildname }) {
// (optional) `wildcard` may or may not exist
// if *you* support wildcard domains, *you* should handle them
return mfs.get({ servername, wildname });
};
} else {
// (optional)
// because the current version doesn't have get()
manager.get = createGetFromFind();
}
//
// REQUIRED (basic issuance)
//
manager.set = async function(opts) {
return mfs.set(opts);
};
//
// Optional (Fully Automatic Renewal)
//
manager.find = async function(opts) {
// { subject, servernames, altnames, renewBefore }
return mfs.find(opts);
};
//
// Optional (Special Remove Functionality)
// The default behavior is to set `deletedAt`
//
//manager.remove = async function(opts) {
// return mfs.remove(opts);
//};
//
// Optional (special settings save)
// Implemented here because this module IS the fallback
//
manager.defaults = async function(opts) {
return mfs.defaults(opts);
};
//
// Optional (for common deps and/or async initialization)
//
manager.init = async function(deps) {
return mfs.init(deps);
};
return manager;
//
// IGNORE
// Backwards compat for the first versions of greenlock-manager-fs
//
function createGetFromFind() {
return async function({ servername, wildname }) {
var servernames = [servername];
if (wildname) {
servernames.push(wildname);
}
return mfs
.find({
servernames: servernames,
// because the original manager used altnames here
altnames: servernames
})
.then(function(sites) {
return sites[0] || null;
});
};
}
};

43
package-lock.json generated Normal file
View File

@ -0,0 +1,43 @@
{
"name": "@greenlock/manager",
"version": "3.0.0",
"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=="
},
"@root/request": {
"version": "1.4.2",
"resolved": "https://registry.npmjs.org/@root/request/-/request-1.4.2.tgz",
"integrity": "sha512-J8FM4+SJuc7WRC+Jz17m+VT2lgI7HtatHhxN1F2ck5aIKUAxJEaR4u/gLBsgT60mVHevKCjKN0O8115UtJjwLw==",
"dev": true
},
"greenlock-manager-fs": {
"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==",
"requires": {
"@root/mkdirp": "^1.0.0",
"safe-replace": "^1.1.0"
}
},
"greenlock-manager-test": {
"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",
"greenlock-manager-fs": "^3.0.0"
}
},
"safe-replace": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/safe-replace/-/safe-replace-1.1.0.tgz",
"integrity": "sha512-9/V2E0CDsKs9DWOOwJH7jYpSl9S3N05uyevNjvsnDauBqRowBPOyot1fIvV5N2IuZAbYyvrTXrYFVG0RZInfFw=="
}
}
}

30
package.json Normal file
View File

@ -0,0 +1,30 @@
{
"name": "@greenlock/manager",
"version": "3.0.0",
"description": "FileSytem-based Manager with optional encrypted Cloud backup for Greenlock SSL",
"main": "manager.js",
"scripts": {
"test": "node tests"
},
"repository": {
"type": "git",
"url": "https://git.rootprojects.org/root/greenlock-manager.js.git"
},
"keywords": [
"greenlock",
"manager",
"cloud",
"fs",
"ssl",
"file",
"system"
],
"author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/)",
"license": "MPL-2.0",
"dependencies": {
"greenlock-manager-fs": "^3.0.5"
},
"devDependencies": {
"greenlock-manager-test": "^3.1.1"
}
}

25
tests/index.js Normal file
View File

@ -0,0 +1,25 @@
"use strict";
var Tester = require("greenlock-manager-test");
var Manager = require("./manager.js");
var config = {
configFile: "greenlock-manager-test.delete-me.json"
};
Tester.test(Manager, config)
.then(function(features) {
console.info("PASS");
console.info();
console.info("Optional Feature Support:");
features.forEach(function(feature) {
console.info(feature.supported ? "✓ (YES)" : "✘ (NO) ", feature.description);
});
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.");
});