moves sensitive keys to gitignored folder

This commit is contained in:
Jessop Breth 2018-11-15 11:08:33 -05:00
parent b7d70bb19f
commit 63bf01971d
7 changed files with 43 additions and 8 deletions

View file

@ -3,6 +3,7 @@ const fs = require('fs');
const Path = require('path');
const axios = require('axios');
const ip = require('ip');
const pwGenerator = require('generate-password');
const mysqlQuestions = require(Path.resolve(__dirname, 'questions/mysqlQuestions.js'));
const siteQuestions = require(Path.resolve(__dirname, 'questions/siteQuestions.js'));
@ -12,11 +13,14 @@ let thumbnailChannelDefault = '@thumbnails';
let thumbnailChannel = '';
let thumbnailChannelId = '';
const createConfigFile = (fileName, configObject) => { // siteConfig.json , siteConfig
const fileLocation = Path.resolve(__dirname, `../site/config/${fileName}`);
const createConfigFile = (fileName, configObject, topSecret) => { // siteConfig.json , siteConfig
const fileLocation = topSecret
? Path.resolve(__dirname, `../site/private/${fileName}`)
: Path.resolve(__dirname, `../site/config/${fileName}`);
const fileContents = JSON.stringify(configObject, null, 2);
fs.writeFileSync(fileLocation, fileContents, 'utf-8');
console.log(`Successfully created ./site/config/${fileName}\n`);
console.log(`Successfully created ${fileLocation}\n`);
};
// import existing configs or import the defaults
@ -74,6 +78,27 @@ try {
chainqueryConfig = require('./defaults/chainqueryConfig.json');
}
// authConfig
let randSessionKey = pwGenerator.generate({
length : 20,
numbers: true,
});
let randMasterPass = pwGenerator.generate({
length : 20,
numbers: true,
});
let authConfig;
try {
authConfig = require('../site/private/authConfig.json');
} catch (error) {
authConfig = {
sessionKey : randSessionKey,
masterPassword: randMasterPass,
};
}
// ask user questions and create config files
inquirer
.prompt(mysqlQuestions(mysqlDatabase, mysqlUsername, mysqlPassword))
@ -204,11 +229,14 @@ inquirer
createConfigFile('loggerConfig.json', loggerConfig);
createConfigFile('slackConfig.json', slackConfig);
createConfigFile('chainqueryConfig.json', chainqueryConfig);
createConfigFile('authConfig.json', authConfig, true);
})
.then(() => {
console.log('\nYou\'re all done!');
console.log('Next step: run "npm run start" to build and start your server!');
console.log('If you want to change any settings, you can edit the files in the "/config" folder.');
console.log('\nIt\'s a good idea to BACK UP YOUR MASTER PASSWORD \nin "/site/private/authConfig.json" so that you don\'t lose \ncontrol of your channel.');
console.log('\nNext step: run "npm run start" to build and start your server!');
console.log('If you want to change any settings, you can edit the files in the "/site" folder.');
process.exit(0);
})
.catch(error => {

5
package-lock.json generated
View file

@ -5753,6 +5753,11 @@
"is-property": "^1.0.2"
}
},
"generate-password": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/generate-password/-/generate-password-1.4.1.tgz",
"integrity": "sha512-MwMSkOIKkgYBG3JrquF0m/Rky+pl5jZFNmoroE9bQU5VawFDKdJfxMx1qBthPusx8GQyNWSW0m+Jaw0mZnqApg=="
},
"generic-pool": {
"version": "3.4.2",
"resolved": "https://registry.npmjs.org/generic-pool/-/generic-pool-3.4.2.tgz",

View file

@ -54,6 +54,7 @@
"express": "^4.16.4",
"express-handlebars": "^3.0.0",
"express-http-context": "^1.2.0",
"generate-password": "^1.4.1",
"get-video-dimensions": "^1.0.0",
"helmet": "^3.15.0",
"image-size": "^0.6.3",

View file

@ -1,8 +1,7 @@
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
const logger = require('winston');
const db = require('../../../../models');
const { auth: { masterPassword } } = require('@config/siteConfig.json');
const { masterPassword } = require('@private/authConfig.json');
/*
route to update a password

View file

@ -26,13 +26,14 @@ const {
const {
details: { port: PORT },
auth: { sessionKey },
startup: {
performChecks,
performUpdates,
},
} = require('@config/siteConfig');
const { sessionKey } = require('@private/authConfig.json');
function Server () {
this.initialize = () => {
// configure logging

0
site/private/.gitkeep Normal file
View file

View file

@ -42,6 +42,7 @@ module.exports = () => {
// aliases for configs
moduleAliases['@config'] = resolve('site/config');
moduleAliases['@private'] = resolve('site/private');
// create specific aliases for locally defined components in the following folders
moduleAliases = addAliasesForCustomComponentFolder('containers', moduleAliases);