From ba3e99f009e8f577908923501a48fa09d6bc7d05 Mon Sep 17 00:00:00 2001 From: Liran Tal Date: Tue, 12 May 2015 09:22:04 +0300 Subject: [PATCH 1/5] implemented feature to address issue 553 - provide a local.js file for local development configuration parameters that will not get committed to remote repositories and will accidentally expose API keys, passwords, and sensitive local configuration --- .gitignore | 1 + config/config.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index bca129da..c519f474 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ ehthumbs.db Icon? Thumbs.db +config/env/local.js # Node and related ecosystem # ========================== diff --git a/config/config.js b/config/config.js index ef4a4c2c..aa16f12e 100644 --- a/config/config.js +++ b/config/config.js @@ -11,7 +11,8 @@ var _ = require('lodash'), */ module.exports = _.extend( require('./env/all'), - require('./env/' + process.env.NODE_ENV) || {} + require('./env/' + process.env.NODE_ENV), + require('./env/local.js') || {} ); /** From 619e123c0d7e113b4bc3d2e887dbf8a980babedd Mon Sep 17 00:00:00 2001 From: Liran Tal Date: Tue, 12 May 2015 21:42:30 +0300 Subject: [PATCH 2/5] adding the default config/env/local.js instance --- .gitignore | 1 - config/env/local.js | 58 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 config/env/local.js diff --git a/.gitignore b/.gitignore index c519f474..bca129da 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ ehthumbs.db Icon? Thumbs.db -config/env/local.js # Node and related ecosystem # ========================== diff --git a/config/env/local.js b/config/env/local.js new file mode 100644 index 00000000..7015630f --- /dev/null +++ b/config/env/local.js @@ -0,0 +1,58 @@ +'use strict'; + +// This local.js file is for local development only, and it doesn't get committed to the repository. +// Use this file for your api keys, secrets, etc which you don't want to commit to + +module.exports = { + db: { + uri: 'mongodb://localhost/local-dev', + options: { + user: '', + pass: '' + } + }, + log: { + // Can specify one of 'combined', 'common', 'dev', 'short', 'tiny' + format: 'dev', + // Stream defaults to process.stdout + // Uncomment to enable logging to a log on the file system + options: { + //stream: 'access.log' + } + }, + facebook: { + clientID: process.env.FACEBOOK_ID || 'APP_ID', + clientSecret: process.env.FACEBOOK_SECRET || 'APP_SECRET', + callbackURL: '/auth/facebook/callback' + }, + twitter: { + clientID: process.env.TWITTER_KEY || 'CONSUMER_KEY', + clientSecret: process.env.TWITTER_SECRET || 'CONSUMER_SECRET', + callbackURL: '/auth/twitter/callback' + }, + google: { + clientID: process.env.GOOGLE_ID || 'APP_ID', + clientSecret: process.env.GOOGLE_SECRET || 'APP_SECRET', + callbackURL: '/auth/google/callback' + }, + linkedin: { + clientID: process.env.LINKEDIN_ID || 'APP_ID', + clientSecret: process.env.LINKEDIN_SECRET || 'APP_SECRET', + callbackURL: '/auth/linkedin/callback' + }, + github: { + clientID: process.env.GITHUB_ID || 'APP_ID', + clientSecret: process.env.GITHUB_SECRET || 'APP_SECRET', + callbackURL: '/auth/github/callback' + }, + mailer: { + from: process.env.MAILER_FROM || 'MAILER_FROM', + options: { + service: process.env.MAILER_SERVICE_PROVIDER || 'MAILER_SERVICE_PROVIDER', + auth: { + user: process.env.MAILER_EMAIL_ID || 'MAILER_EMAIL_ID', + pass: process.env.MAILER_PASSWORD || 'MAILER_PASSWORD' + } + } + } +}; From 0fc412d428a9e91faaabfe6557dd11bc18680f66 Mon Sep 17 00:00:00 2001 From: Liran Tal Date: Wed, 13 May 2015 10:47:00 +0300 Subject: [PATCH 3/5] restoring previous state of removing local.js, we'll generate it with grunt when the project starts-up --- .gitignore | 1 + config/env/local.js | 58 --------------------------------------------- 2 files changed, 1 insertion(+), 58 deletions(-) delete mode 100644 config/env/local.js diff --git a/.gitignore b/.gitignore index bca129da..c519f474 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ ehthumbs.db Icon? Thumbs.db +config/env/local.js # Node and related ecosystem # ========================== diff --git a/config/env/local.js b/config/env/local.js deleted file mode 100644 index 7015630f..00000000 --- a/config/env/local.js +++ /dev/null @@ -1,58 +0,0 @@ -'use strict'; - -// This local.js file is for local development only, and it doesn't get committed to the repository. -// Use this file for your api keys, secrets, etc which you don't want to commit to - -module.exports = { - db: { - uri: 'mongodb://localhost/local-dev', - options: { - user: '', - pass: '' - } - }, - log: { - // Can specify one of 'combined', 'common', 'dev', 'short', 'tiny' - format: 'dev', - // Stream defaults to process.stdout - // Uncomment to enable logging to a log on the file system - options: { - //stream: 'access.log' - } - }, - facebook: { - clientID: process.env.FACEBOOK_ID || 'APP_ID', - clientSecret: process.env.FACEBOOK_SECRET || 'APP_SECRET', - callbackURL: '/auth/facebook/callback' - }, - twitter: { - clientID: process.env.TWITTER_KEY || 'CONSUMER_KEY', - clientSecret: process.env.TWITTER_SECRET || 'CONSUMER_SECRET', - callbackURL: '/auth/twitter/callback' - }, - google: { - clientID: process.env.GOOGLE_ID || 'APP_ID', - clientSecret: process.env.GOOGLE_SECRET || 'APP_SECRET', - callbackURL: '/auth/google/callback' - }, - linkedin: { - clientID: process.env.LINKEDIN_ID || 'APP_ID', - clientSecret: process.env.LINKEDIN_SECRET || 'APP_SECRET', - callbackURL: '/auth/linkedin/callback' - }, - github: { - clientID: process.env.GITHUB_ID || 'APP_ID', - clientSecret: process.env.GITHUB_SECRET || 'APP_SECRET', - callbackURL: '/auth/github/callback' - }, - mailer: { - from: process.env.MAILER_FROM || 'MAILER_FROM', - options: { - service: process.env.MAILER_SERVICE_PROVIDER || 'MAILER_SERVICE_PROVIDER', - auth: { - user: process.env.MAILER_EMAIL_ID || 'MAILER_EMAIL_ID', - pass: process.env.MAILER_PASSWORD || 'MAILER_PASSWORD' - } - } - } -}; From aca6a793e9965dbbb4f6163333e14683116cb108 Mon Sep 17 00:00:00 2001 From: Liran Tal Date: Wed, 13 May 2015 11:29:51 +0300 Subject: [PATCH 4/5] adding a grunt-contrib-copy dev dependency to create a local copy of local.js file and then updating config.js to include it and gruntfile.js to run it in all common tasks --- config/config.js | 5 +++-- gruntfile.js | 19 +++++++++++++++---- package.json | 1 + 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/config/config.js b/config/config.js index aa16f12e..efe758dc 100644 --- a/config/config.js +++ b/config/config.js @@ -4,7 +4,8 @@ * Module dependencies. */ var _ = require('lodash'), - glob = require('glob'); + glob = require('glob'), + fs = require('fs'); /** * Load app configurations @@ -12,7 +13,7 @@ var _ = require('lodash'), module.exports = _.extend( require('./env/all'), require('./env/' + process.env.NODE_ENV), - require('./env/local.js') || {} + (fs.existsSync('./config/env/local.js') && require('./env/local.js')) || {} ); /** diff --git a/gruntfile.js b/gruntfile.js index b45a9cd7..7f995da0 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -1,5 +1,7 @@ 'use strict'; +var fs = require('fs'); + module.exports = function(grunt) { // Unified Watch Object var watchFiles = { @@ -143,6 +145,15 @@ module.exports = function(grunt) { unit: { configFile: 'karma.conf.js' } + }, + copy: { + localConfig: { + src: 'config/env/development.js', + dest: 'config/env/local.js', + filter: function() { + return !fs.existsSync('config/env/local.js'); + } + } } }); @@ -162,13 +173,13 @@ module.exports = function(grunt) { }); // Default task(s). - grunt.registerTask('default', ['lint', 'concurrent:default']); + grunt.registerTask('default', ['lint', 'copy:localConfig', 'concurrent:default']); // Debug task. - grunt.registerTask('debug', ['lint', 'concurrent:debug']); + grunt.registerTask('debug', ['lint', 'copy:localConfig', 'concurrent:debug']); // Secure task(s). - grunt.registerTask('secure', ['env:secure', 'lint', 'concurrent:default']); + grunt.registerTask('secure', ['env:secure', 'lint', 'copy:localConfig', 'concurrent:default']); // Lint task(s). grunt.registerTask('lint', ['jshint', 'csslint']); @@ -177,7 +188,7 @@ module.exports = function(grunt) { grunt.registerTask('build', ['lint', 'loadConfig', 'ngAnnotate', 'uglify', 'cssmin']); // Test task. - grunt.registerTask('test', ['test:server', 'test:client']); + grunt.registerTask('test', ['copy:localConfig', 'test:server', 'test:client']); grunt.registerTask('test:server', ['env:test', 'mochaTest']); grunt.registerTask('test:client', ['env:test', 'karma:unit']); }; diff --git a/package.json b/package.json index 8d2a05b9..091f2e12 100755 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "grunt-mocha-test": "~0.12.1", "grunt-karma": "~0.9.0", "load-grunt-tasks": "~1.0.0", + "grunt-contrib-copy": "0.8", "karma": "~0.12.0", "karma-jasmine": "~0.2.1", "karma-coverage": "~0.2.0", From dce17e9fae88f51588a12d25ce8a0e5b86f2f601 Mon Sep 17 00:00:00 2001 From: Liran Tal Date: Thu, 14 May 2015 00:16:08 +0300 Subject: [PATCH 5/5] creating a local.example.js as a sample file to extend configuration to local repository without committing these changes and also replacing .extend() with .merge() for local repository changes --- config/config.js | 22 +++++++++++++++++----- config/env/local.example.js | 23 +++++++++++++++++++++++ gruntfile.js | 2 +- 3 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 config/env/local.example.js diff --git a/config/config.js b/config/config.js index efe758dc..3a22a2cd 100644 --- a/config/config.js +++ b/config/config.js @@ -7,14 +7,26 @@ var _ = require('lodash'), glob = require('glob'), fs = require('fs'); +/** + * Resolve environment configuration by extending each env configuration file, + * and lastly merge/override that with any local repository configuration that exists + * in local.js + */ +var resolvingConfig = function() { + var conf = {}; + + conf = _.extend( + require('./env/all'), + require('./env/' + process.env.NODE_ENV) || {} + ); + + return _.merge(conf, (fs.existsSync('./config/env/local.js') && require('./env/local.js')) || {}); +}; + /** * Load app configurations */ -module.exports = _.extend( - require('./env/all'), - require('./env/' + process.env.NODE_ENV), - (fs.existsSync('./config/env/local.js') && require('./env/local.js')) || {} -); +module.exports = resolvingConfig(); /** * Get files by glob patterns diff --git a/config/env/local.example.js b/config/env/local.example.js new file mode 100644 index 00000000..824a2993 --- /dev/null +++ b/config/env/local.example.js @@ -0,0 +1,23 @@ +'use strict'; + +// Rename this file to local.js for having a local configuration variables that +// will not get commited and pushed to remote repositories. +// Use it for your API keys, passwords, etc. + +/* For example: + +module.exports = { + db: { + uri: 'mongodb://localhost/local-dev', + options: { + user: '', + pass: '' + } + }, + facebook: { + clientID: process.env.FACEBOOK_ID || 'APP_ID', + clientSecret: process.env.FACEBOOK_SECRET || 'APP_SECRET', + callbackURL: '/auth/facebook/callback' + } +}; +*/ \ No newline at end of file diff --git a/gruntfile.js b/gruntfile.js index 7f995da0..c028ff77 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -148,7 +148,7 @@ module.exports = function(grunt) { }, copy: { localConfig: { - src: 'config/env/development.js', + src: 'config/env/local.example.js', dest: 'config/env/local.js', filter: function() { return !fs.existsSync('config/env/local.js');