From fb8b33b2eb40c1db25d87402c36197a0556a2762 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 6 Apr 2017 11:43:18 -0600 Subject: [PATCH 1/5] Added plugins.default.json --- .gitignore | 1 + plugins.json => plugins.default.json | 0 plugins.js | 13 +++++++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) rename plugins.json => plugins.default.json (100%) diff --git a/.gitignore b/.gitignore index 4ad15747d..6b7b187d9 100644 --- a/.gitignore +++ b/.gitignore @@ -14,5 +14,6 @@ dump.rdb test/e2e/reports coverage/ +plugins.json plugins/* !plugins/coral-plugin-facebook-auth \ No newline at end of file diff --git a/plugins.json b/plugins.default.json similarity index 100% rename from plugins.json rename to plugins.default.json diff --git a/plugins.js b/plugins.js index d7c9f9426..4483f0595 100644 --- a/plugins.js +++ b/plugins.js @@ -12,10 +12,19 @@ let plugins = {}; // file isn't loaded, but continuing. Else, like a parsing error, throw it and // crash the program. try { - plugins = JSON.parse(fs.readFileSync(path.join(__dirname, 'plugins.json'), 'utf8')); + let defaultPlugins = path.join(__dirname, 'plugins.default.json'); + let customPlugins = path.join(__dirname, 'plugins.json'); + + if (fs.existsSync(customPlugins)) { + debug(`Now using ${customPlugins} for plugins`); + plugins = JSON.parse(fs.readFileSync(customPlugins, 'utf8')); + } else { + debug(`Now using ${defaultPlugins} for plugins`); + plugins = JSON.parse(fs.readFileSync(defaultPlugins, 'utf8')); + } } catch (err) { if (err.code === 'ENOENT') { - console.error('plugins.json not found, plugins will not be active'); + console.error('plugins.json and plguins.default.json not found, plugins will not be active'); } else { throw err; } From a9c88f52cec4f796adcb3c135f688ac00385e389 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 6 Apr 2017 11:58:18 -0600 Subject: [PATCH 2/5] Optionally load plugins config from environment --- PLUGINS.md | 15 +++++++++++---- README.md | 1 + plugins.js | 6 +++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index e5cf8d760..e0e99cccd 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -3,11 +3,18 @@ Plugins for Talk can take various forms, currently we are only supporting server side plugins. -## Plugin Registration: `plugins.json` +## Plugin Registration -All plugins must be registered in the root file `plugins.json`. +The parsing order for the plugin regsitration is as follows: -The format for this file is thus: +- `process.env.TALK_PLUGINS_JSON` +- `plugins.json` +- `plugins.default.json` + +If you need to "disable all plugins", you can simply provide `{}` as the +contents of `process.env.TALK_PLUGINS_JSON` or the `plugins.json`. + +The format for this is thus: ```json { @@ -18,7 +25,7 @@ The format for this file is thus: ``` Where we have a `server` key with an array of plugins that match the folder -name in the `plugins/` folder. For example, the above `plugins.json` would +name in the `plugins/` folder. For example, the above config would require a plugin from `plugins/people`, which must provide a `index.js` file that returns an object that matches the Plugin Specification. diff --git a/README.md b/README.md index b88138425..ef621b59c 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ available in the format: `://` without the path. - `TALK_INSTALL_LOCK` (_optional for dynamic setup_) - Defaults to `FALSE`. When `TRUE`, disables the dynamic setup endpoint. - `TALK_RECAPTCHA_SECRET` (*required for reCAPTCHA support*) - server secret used for enabling reCAPTCHA powered logins. If not provided it will instead default to providing only a time based lockout. - `TALK_RECAPTCHA_PUBLIC` (*required for reCAPTCHA support*) - client secret used for enabling reCAPTCHA powered logins. If not provided it will instead default to providing only a time based lockout. +- `TALK_PLUGINS_JSON` (_optional_) - used to specify the plugin config via the environment Refer to the wiki page on [Configuration Loading](https://github.com/coralproject/talk/wiki/Configuration-Loading) for alternative methods of loading configuration during development. diff --git a/plugins.js b/plugins.js index 4483f0595..f9d93bdce 100644 --- a/plugins.js +++ b/plugins.js @@ -14,8 +14,12 @@ let plugins = {}; try { let defaultPlugins = path.join(__dirname, 'plugins.default.json'); let customPlugins = path.join(__dirname, 'plugins.json'); + let envPluginJSON = process.env.TALK_PLUGINS_JSON; - if (fs.existsSync(customPlugins)) { + if (envPluginJSON && envPluginJSON.length > 0) { + debug('Now using TALK_PLUGINS_JSON environment variable for plugins'); + plugins = JSON.parse(envPluginJSON); + } else if (fs.existsSync(customPlugins)) { debug(`Now using ${customPlugins} for plugins`); plugins = JSON.parse(fs.readFileSync(customPlugins, 'utf8')); } else { From 943d4cf98a1c348f4d78d7eb5aac870dfcd54cd0 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 6 Apr 2017 12:00:00 -0600 Subject: [PATCH 3/5] Spelling --- PLUGINS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PLUGINS.md b/PLUGINS.md index e0e99cccd..c34cfa5eb 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -5,7 +5,7 @@ side plugins. ## Plugin Registration -The parsing order for the plugin regsitration is as follows: +The parsing order for the plugin registration is as follows: - `process.env.TALK_PLUGINS_JSON` - `plugins.json` From 4bc7848e24cdfc572531f8cb9d8355ae40ca6bdb Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 6 Apr 2017 12:00:36 -0600 Subject: [PATCH 4/5] comment updates --- PLUGINS.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index c34cfa5eb..8bf00229d 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -7,9 +7,9 @@ side plugins. The parsing order for the plugin registration is as follows: -- `process.env.TALK_PLUGINS_JSON` -- `plugins.json` -- `plugins.default.json` +- `TALK_PLUGINS_JSON` environment variable +- `plugins.json` file +- `plugins.default.json` file If you need to "disable all plugins", you can simply provide `{}` as the contents of `process.env.TALK_PLUGINS_JSON` or the `plugins.json`. From 770a4e6fe2a1b96631187e4a17417165df767068 Mon Sep 17 00:00:00 2001 From: Kim Gardner Date: Thu, 6 Apr 2017 14:38:16 -0400 Subject: [PATCH 5/5] Fix typo --- plugins.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins.js b/plugins.js index f9d93bdce..43ac04478 100644 --- a/plugins.js +++ b/plugins.js @@ -28,7 +28,7 @@ try { } } catch (err) { if (err.code === 'ENOENT') { - console.error('plugins.json and plguins.default.json not found, plugins will not be active'); + console.error('plugins.json and plugins.default.json not found, plugins will not be active'); } else { throw err; }