diff --git a/install/databases.js b/install/databases.js index 08907dca3b..8c5a76555b 100644 --- a/install/databases.js +++ b/install/databases.js @@ -1,104 +1,82 @@ "use strict"; -var async = require('async'), - prompt = require('prompt'), - nconf = require('nconf'), - winston = require('winston'), +var async = require('async'); +var prompt = require('prompt'); +var winston = require('winston'); - questions = {}; +var questions = { + redis: require('../src/database/redis').questions, + mongo: require('../src/database/mongo').questions +}; -function success(err, config, callback) { +module.exports = function(config, callback) { + async.waterfall([ + function (next) { + process.stdout.write('\n'); + winston.info('Now configuring ' + config.database + ' database:'); + getDatabaseConfig(config, next); + }, + function (databaseConfig, next) { + saveDatabaseConfig(config, databaseConfig, next); + } + ], callback); +}; + +function getDatabaseConfig(config, callback) { if (!config) { return callback(new Error('aborted')); } - var database = (config.redis || config.mongo) ? config.secondary_database : config.database; - - function dbQuestionsSuccess(err, databaseConfig) { - if (!databaseConfig) { - return callback(new Error('aborted')); - } - - // Translate redis properties into redis object - if(database === 'redis') { - config.redis = { - host: databaseConfig['redis:host'], - port: databaseConfig['redis:port'], - password: databaseConfig['redis:password'], - database: databaseConfig['redis:database'] - }; - - if (config.redis.host.slice(0, 1) === '/') { - delete config.redis.port; - } - } else if (database === 'mongo') { - config.mongo = { - host: databaseConfig['mongo:host'], - port: databaseConfig['mongo:port'], - username: databaseConfig['mongo:username'], - password: databaseConfig['mongo:password'], - database: databaseConfig['mongo:database'] - }; - } else { - return callback(new Error('unknown database : ' + database)); - } - - var allQuestions = questions.redis.concat(questions.mongo); - for(var x=0;x