hardened configuration

- moved env rewrite + dotenv code to single location
- fixed bug with system flag on user
This commit is contained in:
Wyatt Johnson
2018-01-05 16:06:36 -07:00
parent 6260339508
commit c07ec23a20
18 changed files with 70 additions and 52 deletions
+25 -27
View File
@@ -4,6 +4,7 @@
* Module dependencies.
*/
require('./util');
const program = require('commander');
const {head, map} = require('lodash');
const Matcher = require('did-you-mean');
@@ -18,40 +19,37 @@ program
.command('users', 'work with the application auth')
.command('migration', 'provides utilities for migrating the database')
.command('verify', 'provides utilities for performing data verification')
.command(
'plugins',
'provides utilities for interacting with the plugin system'
)
.command('plugins', 'provides utilities for interacting with the plugin system')
.parse(process.argv);
// If the command wasn't found, output help.
const cmds = map(program.commands, '_name');
const cmd = head(program.args);
if (!cmds.includes(cmd)) {
const m = new Matcher(cmds);
const similarCMDs = m.list(cmd);
const commands = map(program.commands, '_name');
const command = head(program.args);
if (!commands.includes(command)) {
const m = new Matcher(commands);
const similarCommands = m.list(command);
console.error(`cli '${cmd}' is not a talk cli command. See 'cli --help'.`);
if (similarCMDs.length > 0) {
const sc = similarCMDs.map(({value}) => `\t${value}\n`).join('');
console.error(`cli '${command}' is not a talk cli command. See 'cli --help'.`);
if (similarCommands.length > 0) {
const sc = similarCommands.map(({value}) => `\t${value}\n`).join('');
console.error(`\nThe most similar commands are\n${sc}`);
}
process.exit(1);
}
/**
* When this provess exists, check to see if we have a running command, if we do
* check to see if it is still running. If it is, then kill it with a SIGINT
* signal. This is for the use case where we want to kill the process that is
* labled with the PID written out by the parent process.
*/
process.once('exit', () => {
if (
// /**
// * When this process exists, check to see if we have a running command, if we do
// * check to see if it is still running. If it is, then kill it with a SIGINT
// * signal. This is for the use case where we want to kill the process that is
// * labeled with the PID written out by the parent process.
// */
// process.once('exit', () => {
// if (
// program.runningCommand &&
program.runningCommand.killed === false &&
program.runningCommand.exitCode === null
) {
program.runningCommand.kill('SIGINT');
}
});
// // program.runningCommand &&
// program.runningCommand.killed === false &&
// program.runningCommand.exitCode === null
// ) {
// program.runningCommand.kill('SIGINT');
// }
// });
+1 -1
View File
@@ -4,6 +4,7 @@
* Module dependencies.
*/
const util = require('./util');
const program = require('commander');
const parseDuration = require('ms');
const Table = require('cli-table');
@@ -12,7 +13,6 @@ const CommentModel = require('../models/comment');
const AssetsService = require('../services/assets');
const mongoose = require('../services/mongoose');
const scraper = require('../services/scraper');
const util = require('./util');
const inquirer = require('inquirer');
// Register the shutdown criteria.
+1 -1
View File
@@ -4,10 +4,10 @@
* Module dependencies.
*/
const util = require('./util');
const program = require('commander');
const scraper = require('../services/scraper');
const mailer = require('../services/mailer');
const util = require('./util');
const mongoose = require('../services/mongoose');
const kue = require('../services/kue');
+1 -1
View File
@@ -4,8 +4,8 @@
* Module dependencies.
*/
const program = require('commander');
const util = require('./util');
const program = require('commander');
const inquirer = require('inquirer');
const mongoose = require('../services/mongoose');
const MigrationService = require('../services/migration');
+1
View File
@@ -7,6 +7,7 @@
// Interface heavily inspired by the yarn package manager:
// https://yarnpkg.com/
require('./util');
const program = require('commander');
const inquirer = require('inquirer');
+1 -1
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env node
const program = require('commander');
const util = require('./util');
const program = require('commander');
const serve = require('../serve');
//==============================================================================
+1 -1
View File
@@ -1,10 +1,10 @@
#!/usr/bin/env node
const util = require('./util');
const program = require('commander');
const inquirer = require('inquirer');
const mongoose = require('../services/mongoose');
const SettingsService = require('../services/settings');
const util = require('./util');
// Register the shutdown criteria.
util.onshutdown([() => mongoose.disconnect()]);
+1 -1
View File
@@ -4,6 +4,7 @@
* Module dependencies.
*/
const util = require('./util');
const program = require('commander');
const inquirer = require('inquirer');
const mongoose = require('../services/mongoose');
@@ -12,7 +13,6 @@ const MODERATION_OPTIONS = require('../models/enum/moderation_options');
const SettingsService = require('../services/settings');
const SetupService = require('../services/setup');
const UsersService = require('../services/users');
const util = require('./util');
const errors = require('../errors');
// Register the shutdown criteria.
+1 -1
View File
@@ -4,10 +4,10 @@
* Module dependencies.
*/
const util = require('./util');
const program = require('commander');
const mongoose = require('../services/mongoose');
const TokensService = require('../services/tokens');
const util = require('./util');
const Table = require('cli-table');
// Register the shutdown criteria.
+4
View File
@@ -156,6 +156,10 @@ async function searchUsers() {
throw errors[0];
}
if (data.users === null) {
return [];
}
return data.users.nodes.map((user) => {
const emails = user.profiles
.filter(({provider}) => provider === 'local')
+1 -1
View File
@@ -4,9 +4,9 @@
* Module dependencies.
*/
const util = require('./util');
const program = require('commander');
const mongoose = require('../services/mongoose');
const util = require('./util');
const databaseVerifications = require('./verifications/database');
// Register the shutdown criteria.
+4
View File
@@ -1,3 +1,7 @@
// Setup the environment.
require('../services/env');
const debug = require('debug')('talk:util');
const util = module.exports = {};
+2 -11
View File
@@ -2,17 +2,8 @@
// application. All defaults are assumed here, validation should also be
// completed here.
// Perform rewrites to the runtime environment variables based on the contents
// of the process.env.REWRITE_ENV if it exists. This is done here as it is the
// entrypoint for the entire applications configuration.
require('env-rewrite').rewrite();
if (process.env.NODE_ENV !== 'test') {
// Apply all the configuration provided in the .env file if it isn't already
// in the environment.
require('dotenv').config();
}
// Setup the environment.
require('./services/env');
const uniq = require('lodash/uniq');
const ms = require('ms');
+8
View File
@@ -295,6 +295,14 @@ UserSchema.virtual('hasVerifiedEmail').get(function() {
});
});
UserSchema.virtual('system')
.get(function() {
return this._system;
})
.set(function(system) {
this._system = system;
});
/**
* banned returns true when the user is currently banned, and sets the banned
* status locally.
+1
View File
@@ -173,6 +173,7 @@
"snake-case": "2.1.0",
"style-loader": "^0.16.0",
"subscriptions-transport-ws": "^0.7.2",
"supports-color": "^4",
"timeago.js": "^2.0.3",
"timekeeper": "^1.0.0",
"tlds": "^1.196.0",
+11
View File
@@ -0,0 +1,11 @@
// Perform rewrites to the runtime environment variables based on the contents
// of the process.env.REWRITE_ENV if it exists. This is done here as it is the
// entrypoint for the entire applications configuration.
require('env-rewrite').rewrite();
if (process.env.NODE_ENV !== 'test') {
// Apply all the configuration provided in the .env file if it isn't already
// in the environment.
require('dotenv').config();
}
+5 -5
View File
@@ -1,14 +1,14 @@
const mongoose = require('mongoose');
const debug = require('debug')('talk:db');
const enabled = require('debug').enabled;
const queryDebugger = require('debug')('talk:db:query');
const {
MONGO_URL,
WEBPACK,
CREATE_MONGO_INDEXES,
} = require('../config');
const mongoose = require('mongoose');
const debug = require('debug')('talk:db');
const enabled = require('debug').enabled;
const queryDebugger = require('debug')('talk:db:query');
// Loading the formatter from Mongoose:
//
// https://github.com/Automattic/mongoose/blob/1a93d1f4d12e441e17ddf451e96fbc5f6e8f54b8/lib/drivers/node-mongodb-native/collection.js#L182
+1 -1
View File
@@ -8997,7 +8997,7 @@ supports-color@^3.1.0, supports-color@^3.1.2, supports-color@^3.2.3:
dependencies:
has-flag "^1.0.0"
supports-color@^4.0.0, supports-color@^4.4.0:
supports-color@^4, supports-color@^4.0.0, supports-color@^4.4.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-4.5.0.tgz#be7a0de484dec5c5cddf8b3d59125044912f635b"
dependencies: