Exemplo n.º 1
0
 runs(function() {
   nconf.add('awsec2tag', { whitelist: [ 'Another' ] });
   nconf.load(function(err) {
     expect(err).toBeFalsy();
     loaded = true;
   });
 });
Exemplo n.º 2
0
 runs(function() {
   nconf.add('awsinstance', { whitelist: [ 'imageId', 'devpayProductCodes' ], prefix: 'aws_' });
   nconf.load(function(err) {
     expect(err).toBeFalsy();
     loaded = true;
   });
 });
Exemplo n.º 3
0
 runs(function() {
   nconf.add('awsec2tag', [ 'Name', 'Test', 'Test2' ]);
   nconf.load(function(err) {
     expect(err).toBeFalsy();
     loaded = true;
   });
 });
Exemplo n.º 4
0
var configure = function(){
    //order of hiearchy: 1. command line args, 2. environment vars, 3. file 
    nconf.argv()
        .env();

    nconf.file('secrets', __dirname + '/secrets.json');

    // app: { port: xxxx } and other server confi live in this file. Uses
    // default if cannot find file
    var configFile = __dirname + '/server.json';
    nconf.file({file: configFile});

    // Make sure secrets exists / has data
    if(_.keys(nconf.stores.secrets.store).length < 1){
        console.log('conf/secrets.json NOT found! Copy conf/secrets.example.json to conf/secrets.json and modify secrets');
        throw new Error('secrets.json not found! Copy conf/secrets.example.json to conf/secrets.json. View README for setup instructions');
    }

    if(_.keys(nconf.stores.file.store).length < 1){
        console.log('conf/server.json NOT found! Copy conf/server.example.json to conf/server.json, otherwise default server settings will be used');
    }

    // configure DB (also pulls from server.json)
    nconf.add('db', {
        'type': 'literal',
        'db': { 
            'port': 27017,
            'host': 'localhost',
            'db': 'checkin',
            'type': 'Mongo'
        }
    });

};
Exemplo n.º 5
0
 runs(function() {
   nconf.add('awsec2tag', { prefix: 'ec2_' });
   nconf.load(function(err) {
     expect(err).toBeFalsy();
     loaded = true;
   });
 });
Exemplo n.º 6
0
 runs(function() {
   nconf.add('awsinstance');
   nconf.load(function(err) {
     expect(err).toBeFalsy();
     loaded = true;
   });
 });
Exemplo n.º 7
0
 runs(function() {
   nconf.add('awsinstance', { whitelist: [ 'privateIp', 'version' ] });
   nconf.load(function(err) {
     expect(err).toBeFalsy();
     loaded = true;
   });
 });
Exemplo n.º 8
0
 runs(function() {
   nconf.add('awss3', { bucket: 'config.goonies3.com', key: 'development/config_invalid.json' });
   nconf.load(function(err) {
     expect(err).toBeTruthy();
     loaded = true;
   });
 });
Exemplo n.º 9
0
_([allFile, environmentFile]).each(function(file) {
    if (!fs.existsSync(file)) {
        return;
    }
    if (fileRead) {
        nconf.merge(JSON.parse(fs.readFileSync(file, 'utf8')));
    } else {
        nconf.add('file', {file: file});
        fileRead = true;
    }
});
Exemplo n.º 10
0
module.exports = function configureRedis(){
    nconf.add('amqp', {
        'type': 'literal',
        //amqp
        'amqp': nconf.get('amqp') || { 
            'host': 'localhost',
            'port': 15672,
            'chatRoomTopic': 'someapptopic',
            'unsubscribeHmac': 'thisissomertestporcupineandhootbreakfastdeeply',
            'username': '******',
            'password': '******'
        }
    });
};
Exemplo n.º 11
0
var loadSettings = function(baseProjPath) {
  try {
    nconf.argv()
    nconf.env() 
  }
  catch(e) {
    console.log(e)
  }
    
  nconf.add('notifications', { type: 'file', file: baseProjPath +'/notifications/notificationConfig.json' });
  
  // stores everything in in-app memory
  // nconf.use('memory');
}
Exemplo n.º 12
0
function createConfiguration(type, configDir) {
  
  var paths = Object.create(null);
    // 'eg config/settings.defaults.json'
    paths.defaults = path.join(configDir, type + '.defaults.json');
    // 'eg' ./settings.json
    paths.overrides = path.join(process.cwd(), type + '.json');
  
  nconf.add('production', {
    type: 'memory',
    loadFrom: [paths.defaults]
  });
  
  nconf.add('development', {
    type: 'memory',
    loadFrom: [paths.overrides]
  });
  
  if (!process.env.NODE_ENV) {
    process.env.NODE_ENV = detectEnvironment();
  }
  return getConfiguration(type, process.env.NODE_ENV);
}
module.exports = function configureRedis(){
    nconf.add('amqp', {
        'type': 'literal',
        //amqp
        'amqp': {
            'host': 'localhost',
            'channel': 'userRated',
            'channel-analytics': 'analytics',
            'unsubscribeHmac': 'thisissomerandompasswordfinestshootbreakfastdeeply',
            // NOTE: must match python queue name
            'queueName': 'prediction-rpc-queue'
        }
    });
};
Exemplo n.º 14
0
function init(config_dir) {
  let statSync = fs.lstatSync(config_dir);

  Config.argv();
  if (statSync.isDirectory()) {
    const env = (Config.get('environment') || process.env.NODE_ENV || 'development').toLowerCase();
    Config
      .add('env_js', {
        type: 'file',
        readOnly: true,
        file: path.resolve(config_dir, `${env}.js`)
      }).add('env_json', {
        type: 'file',
        readOnly: true,
        file: path.resolve(config_dir, `${env}.json`)
      }).add('shared_js', {
        type: 'file',
        readOnly: true,
        file: path.resolve(config_dir, 'shared.js')
      }).add('shared_json', {
        type: 'file',
        readOnly: true,
        file: path.resolve(config_dir, 'shared.json')
      }).add('home_js', {
        type: 'file',
        readOnly: true,
        file: path.resolve(user_home, `.telegrammer.js`)
      }).add('home_json', {
        type: 'file',
        readOnly: true,
        file: path.resolve(user_home, `.telegrammer.json`)
      });
  } else if (statSync.isFile()) {
    Config.file({
      file: config_dir
    });
  }
  Config.env('__');

  for (let key in Config.stores) {
    let store = Config.stores[key];
    if (store.type === 'file') {
      store.loadSync();
    }
  }
  Config.load_from = init;
  initialized = true;
  return Config;
}
Exemplo n.º 15
0
nconf.init = function(appRoot, files, callback) {
	var env = 'development',
		name = null,
		paths = null;

	if (!callback && typeof files === 'function') {
		callback = files;
		files = [];
	}
	files = files || [];

	// Read in base configuration
	nconf.argv().env();

	// Get environment and build base list of files
	env = nconf.get('NODE_ENV') || env;
	files.unshift('app-' + env);
	files.unshift('app');

	// Iterate backward through the list of files. nconf resolves properties
	// in order of definition, so specific properties should be added first,
	// and more more generic, last.
	while(files.length) {
		name = files.pop();
		nconf.add(name, { type: 'file', file: path.join(appRoot, 'config', name + '.json') });
	}

	// Process relative paths in the configuration and rewrite them as absolute paths
	paths = nconf.get('paths');
	Object.keys(paths).forEach(function(key) {
		nconf.set('paths:' + key, path.join(appRoot, paths[key]));
	});


	// Cloud Foundry Support - not a fan of deployment-specific code, but at least it's hidden here.
	var altPort = nconf.get('VCAP_APP_PORT');
	if (altPort) {
		nconf.set('port', altPort);
	} else {
		altPort = nconf.get('PORT');
		if (altPort) {
			nconf.set('port', altPort);
		}
	}

	// Callback is merely reserved for future use
	callback && callback();
};
Exemplo n.º 16
0
 it("Should setup fixtures", function(done) {
     nconf.add("readonly", {
             type: "literal",
             store: {
                 "app" : { "readonly" : true }
             }
         });
     ApiServer.start(function(err, sd) {
         if (err) { return done(err); }
         app = sd.app;
         var options = { user : sd.superUser, version : "v1.1" };
         sd.schemaManager.delete(schema.name, options).nodeify(function() {
             sd.schemaManager.add(schema, options).nodeify(done);
         });
     });
 });
Exemplo n.º 17
0
function reloadConfig() {
    var newconfig;
    nconf.remove('conf');
    nconf.add('conf', {type:'file', file: './worker-config.json'});
    newconfig = nconf.get('vxsync');
    var refreshTime = config.configRefresh;
    var vistaSitesChanged = false;
    // console.log('refreshing config');
    //if file refresh changed, redo the file polling
    if(newconfig.configRefresh !== config.configRefresh) {
        console.log('updating refresh timer');
        clearInterval(reloadTimer);
        reloadTimer = setInterval(reloadConfig, newconfig.configRefresh);
    }
    if( JSON.stringify(newconfig.vistaSites) !== JSON.stringify(config.vistaSites) ) {
        console.log('vista site change found');
        vistaSitesChanged = true;
    }
    //update configuration with new settings
    var newConfigString = JSON.stringify(newconfig);
    if(cachedConfig !== newConfigString) {
        console.log('updating config');
        var keys = _.keys(newconfig);
        _.each(keys, function(key){
            config[key] = newconfig[key];
        });
        config.beanstak = queueConfig.createFullBeanstalkConfig(config.beanstalk);
        cachedConfig = newConfigString;
    }
    //run any registered callbacks
    if(configChangeCallback !== null) {
        if(vistaSitesChanged) {
            console.log('running callbacks');
            _.each(configChangeCallback, function(callbackConfig){
                    var delay = refreshTime; //use the old refresh time to ensure cross process coordination
                    if(!callbackConfig.useDelay) {
                        delay = 0;
                    }
                    setTimeout(callbackConfig.function, delay);
                }
            );
        }
    }
}
Exemplo n.º 18
0
  before(function(done){


    //setup a spy logger
    spyLogger = {
      info : function(obj) {
        console.info(obj);
      },
      error : sinon.spy()
    };

    //setup the configuration for the tests
    configObj = {
      "ago": {
        "rest": "http://fakeago.com/rest"
      }
    }
    config.add('test', { type: 'literal', store: configObj });

    //all done!
    done();
  });
Exemplo n.º 19
0
nconf.file('resources', __dirname + '/resources.json');
nconf.file('secrets', __dirname + '/secrets.json');
if(!nconf.get('github')){
    throw new Error('secrets.json file NOT found. be sure to `cp secrets.json-example secrets.json`');
}

// if running blockbuilder-search-index
var esIndexer = nconf.get('elasticsearch-indexer') || {}

nconf.add('app', {
  'type': 'literal',
  'app': {
    'port': 8889,
    'allowedDomains': '*',
    'cookie': {
        'maxAge': 86400000 * 365, //one year, in milliseconds
        httpOnly: true,
        'key': '_c',
        'secret': 'd0f03jiioj>?re4l12kj"f23jiioj>?re4l12kj"l;l'
    }
  }
});

app.use(cookieParser());
var redisClient = redis.createClient(
    nconf.get('app:redis:port'),
    nconf.get('app:redis:host')
);
redisClient.on('error', function(err) {
    //catch redis errors so server doesn't blow up
    console.error('Redis client error:' + err);
Exemplo n.º 20
0
// if config files exist but are blank we write blank files for nconf
if (fs.existsSync(app_config, "utf8")) {
    if(fs.readFileSync(app_config, "utf8") == ""){
        fs.writeFileSync(app_config, "{}", 'utf8');
    }
}
if (fs.existsSync(connection_config, "utf8")) {
    if(fs.readFileSync(connection_config, "utf8") == ""){
        fs.writeFileSync(connection_config, "{}", 'utf8');
    }
}

// setup the two conf. 'app' holds application config, and connections
// holds the mongoDB connections
nconf.add('connections', { type: 'file', file: connection_config });
nconf.add('app', { type: 'file', file: app_config });

// set app defaults
var app_host = '0.0.0.0';
var app_port = process.env.PORT || 1234;

// get the app configs and override if present
if(nconf.stores.app.get('app:host') != undefined){
    app_host = nconf.stores.app.get('app:host');
}
if(nconf.stores.app.get('app:port') != undefined){
    app_port = nconf.stores.app.get('app:port');
}

// Make stuff accessible to our router
var vows = require('vows');
var queueSuite = vows.describe('notif_queue_test');

var util = require('util')
var assert = require('assert')

var nock = require('nock')
  // , fs = require('fs')
  // , xml2js = require('xml2js')
  // , parser = new xml2js.Parser();

// Mock Notificaton Config
var fs    = require('fs'),
    nconf = require('nconf');   

nconf.add('notifications', { type: 'file', file: __dirname +'/mocks/mockNotificationConfig.json' });
var creatives = nconf.get('creative');
var notifQueueConfig = nconf.get('notifQueueConfig');

var  options = {
  creatives :creatives,
  notifQueueConfig : notifQueueConfig
};


var mockQueueModel = require('./mocks/mockQueueModel');
var SandboxedModule = require('sandboxed-module');

// delay loading so config is set
var notifPostController = require('../notificationPostController');
Exemplo n.º 22
0
var nconf = require('nconf');

var ENV = process.env.AMQP2SOLR_ENVIRONMENT || 'DEV';
var lowerEnv = ENV.toLowerCase();

nconf.add('local', {
  type: 'file',
  file: './config/local.json'
});

nconf.add(lowerEnv, {
  type: 'file',
  file: './config/' + lowerEnv + '.json'
});

nconf.add('global', {
  type: 'file',
  file: './config/global.json'
});

nconf.set('ENVIRONMENT', ENV.toUpperCase());

module.exports = nconf;

Exemplo n.º 23
0
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

"use strict";

let path = require('path');
let spawn = require('child_process').spawn;

let colors = require('colors/safe');
let fs = require('fs-extra');
let program = require('commander');
let request = require('request');
let jszip = require('jszip');
let nconf = require('nconf');

nconf.add('configuration', {type: 'file', file: path.join(__dirname, 'config.json')});
let config = {};
config.docfx = nconf.get('docfx');
config.myget = nconf.get('myget');
config.msbuild = nconf.get('msbuild');
config.git = nconf.get('git');

if (config.myget) {
  config.myget.apiKey = process.env.MGAPIKEY;
} else {
  throw new Error("Cannot find myget.org apikey");
}

let globalOptions = {
  query_url: config.docfx.releaseUrl + '/latest'
};
Exemplo n.º 24
0
var nconf = require('nconf')

// Args are top priority, followed by environment variables
nconf.argv().env()

// Figure out what environment we're running in
var env = nconf.get("NODE_ENV")
if (!env) {
	env = "development"
	nconf.set("NODE_ENV", env)
}

// Add environment specific config
nconf.add('user', {type: 'file', file: __dirname + "/" + env + "-config.json"})

// Add common config
nconf.add('global', { type: 'file', file: __dirname + "/common-config.json" })

module.exports = nconf
Exemplo n.º 25
0
// if config files exist but are blank we write blank files for nconf
if (fs.existsSync(config_app, 'utf8')) {
    if (fs.readFileSync(config_app, 'utf8') == '') {
        fs.writeFileSync(config_app, '{}', 'utf8');
    }
}
if (fs.existsSync(config_connections, 'utf8')) {
    if (fs.readFileSync(config_connections, 'utf8') == '') {
        fs.writeFileSync(config_connections, '{}', 'utf8');
    }
}

// setup the two conf. 'app' holds application config, and connections
// holds the mongoDB connections
nconf.add('connections', { type: 'file', file: config_connections });
nconf.add('app', { type: 'file', file: config_app });

// set app defaults
var app_host = '0.0.0.0';
var app_port = process.env.PORT || 1234;

// get the app configs and override if present
if (nconf.stores.app.get('app:host') != undefined) {
    app_host = nconf.stores.app.get('app:host');
}
if (nconf.stores.app.get('app:port') != undefined) {
    app_port = nconf.stores.app.get('app:port');
}
if (nconf.stores.app.get('app:locale') != undefined) {
    i18n.setLocale(nconf.stores.app.get('app:locale'));
Exemplo n.º 26
0
  // Note that the database schema is hardcoded to allow 16 characters which is
  // enough for a 12-byte token. (Base64 has a 33% overhead.)
  'token_size': 12
});

if (nconf.get('NODE_ENV') === 'fig') {
  // nconf doesn't support multiple layers of defaults
  // https://github.com/flatiron/nconf/issues/81
  nconf.add('db_defaults', {'type': 'literal',
    'db': {
      client: 'pg',
      connection: {
        host:     process.env.CODIUSHOST_DB_1_PORT_5432_TCP_ADDR,
        port:     process.env.CODIUSHOST_DB_1_PORT_5432_TCP_PORT,
        database: 'docker',
        user:     '******',
        password: '******'
      },
      pool: {
        min: 2,
        max: 10
      }
    }
  });
} else {
  nconf.add('db_defaults', {'type': 'literal',
    'db': {
      client: 'sqlite3',
      connection: {
        filename: './dev.sqlite3'
      }
    }
Exemplo n.º 27
0
Arquivo: DB.js Projeto: Jiang-To/tdd
 _massageConfig(err,obj,function manipulateModuleConfig(obj,cb){
     logger.info('module config: ' + JSON.stringify(obj.values));
     //nconf.set('mConfig', obj.values);
     nconf.add('module', { type: 'literal', store: obj.values});
     cb(null, 1);
 },ap_callback);
Exemplo n.º 28
0
var packdb = function packdb() {
    //defining a var instead of this (works for variable & function) will create a private definition
    var dirty = require("./dirty/dirty"),
        query = require("dirty-query").query,
        nconf = require("nconf"),
        log4js = require('log4js'),
        logger = log4js.getLogger('packdb');

    var homePath = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;
    var appHome = homePath+'/.slingxdcc/';

    nconf.add('settings', {type: 'file', file: appHome+'config/settings.json'});

    nconf.defaults({
        "logger": {
            "packdb": appHome+"packets.db",
            "autocleandb" : true,
            "cleandb_Xminutes": 60,
            "redundantPercentage": 25,
            "removePacketsOlder_Xhours": false
        }
    });
    nconf.set('logger',nconf.get('logger'));

    nconf.save();

    var packDb = dirty.Dirty(nconf.get('logger:packdb'));


    packDb.on('load', function () {
        this.setCompactingFilter(nconf.get('logger:removePacketsOlder_Xhours'));
        packDb.compact();
    })

    this.onServerKeys = [];

    var nextCompacting = nconf.get('logger:autocleandb') ? new Date().getTime() + nconf.get('logger:cleandb_Xminutes') * 60 * 1000 : 0;

    if (nconf.get('logger:autocleandb')) {
        var minutes = nconf.get('logger:cleandb_Xminutes');
        var redPercentage = nconf.get('logger:redundantPercentage');
        cronID = setInterval(function () {
            if (packDb.redundantLength / (packDb.redundantLength + packDb.length) * 100 > redPercentage) {
                packDb.compact();
            }
            nextCompacting = new Date().getTime() + minutes * 60 * 1000;
        }, minutes * 1000 * 60);
    }

    var self = this;

    var cronID;

    this.getNextCompacting = function(){
        return nextCompacting;
    }

    this.numberOfRedundantPackets = function () {
        return packDb.redundantLength;
    }

    this.compactDb = function () {
        packDb.compact();
    }

    this.stopCompactCronjob = function () {
        if (cronID) {
            clearInterval(cronID);
        }
        nconf.set('logger:autocleandb', false);
        nconf.save();
        nextCompacting = 0;
    }

    this.startCompactCronjob = function (minutes, redPercentage) {
        if (cronID) {
            clearInterval(cronID);
        }
        nextCompacting = new Date().getTime() + minutes * 60 * 1000;
        cronID = setInterval(function () {
            if (packDb.redundantLength / (packDb.redundantLength + packDb.length) * 100 > redPercentage) {
                packDb.compact();
            }
            nextCompacting = new Date().getTime() + minutes * 60 * 1000;
        }, minutes * 1000 * 60);
        nconf.set('logger:autocleandb', true);
        nconf.set('logger:cleandb_Xminutes',minutes);
        nconf.set('logger:redundantPercentage',redPercentage);
        nconf.save();
    }

    this.addPack = function (packObj) {
        if (packObj !== null) {
            packDb.set(packObj.server + '#' + packObj.nick + '#' + packObj.nr, packObj);
        }
    }

    this.numberOfPackets = function () {
        return packDb.size();
    };

    this.getPacket = function (key) {
        return packDb.get(key);
    };

    this.searchPackets = function (string, sortBy, sortOrder, filterDiscon) {
        var q = queryBuilder(null, null, sortBy, sortOrder, string, filterDiscon, null);
        logger.debug('Search packages:', string, sortBy, sortOrder, filterDiscon, JSON.stringify(q));
        return query(packDb, q.query, q.options);
    };

    this.searchPacketsPaged = function (string, limit, page, sortBy, sortOrder, filterDiscon, cb) {
        if (parseInt(page) == 1) query(packDb, "reset_cache");

        var q = queryBuilder(limit, page, sortBy, sortOrder, string, filterDiscon, cb);

        return query(packDb, q.query, q.options);
    };

    this.setCompactingFilter = function(hours){
        if(hours != false){
            nconf.set('logger:removePacketsOlder_Xhours',hours);
            packDb.setCompactingFilter(function(key,value){
                return (value.lastseen < (parseInt(new Date().getTime()) - hours * 1000 * 60 * 60));
            });
        }else{
            nconf.set('logger:removePacketsOlder_Xhours',false);
            packDb.setCompactingFilter(function(key,value){
                return false;
            })
        }
        nconf.save();
    }

    this.getCompactingFilter = function(){
        return nconf.get('logger:removePacketsOlder_Xhours');
    }

    function queryBuilder(limit, page, sortBy, sortOrder, search, filterDiscon, cb) {
        var buildquery = {
            query: {},
            options: {}
        };

        if (limit !== null) {
            buildquery.options = {
                sortBy: sortBy,
                order: sortOrder,
                limit: limit,
                page: page,
                cache: true,
                pager: cb
            };
        } else {
            buildquery.options = {
                sortBy: sortBy,
                order: sortOrder
            };
        }

        if (typeof search !== 'string') {
            buildquery.query = {nr: {$has: true}};
        } else {
            var words = search.toLowerCase().split(" ");
            buildquery.query.filename = {
                $cb: function (attr) {
                    attr = attr.toLowerCase();
                    for (var i in words) {
                        if (attr.indexOf(words[i]) < 0) {
                            return false;
                        }
                    }
                    return true;
                }
            };
        }

        if (filterDiscon === true) {
            buildquery.query.server = {
                $in: self.onServerKeys
            };
        }
        return buildquery;
    }


    if (packdb.caller != packdb.getInstance) {
        throw new Error("This object cannot be instantiated");
    }
};
Exemplo n.º 29
0
var nconf = require('nconf');

var commentedJson = {
    stringify: function (obj, replacer, spacing) {
        return JSON.stringify(obj, replacer || null, spacing || 2);
    },
    parse: function (obj) {
        return JSON.parse(removeComments(obj));
    }
};

nconf.add('main', {
    type: 'file',
    format: commentedJson,
    file: 'config/config.json'
});

module.exports = nconf.get();

/**
 * Thank you for this work by James padolsey who provide 'removeComments' function on the following web site.
 *
 * http://james.padolsey.com/javascript/javascript-comment-removal-revisted/
 */

function removeComments(str) {

    var uid = '_' + +new Date(),
        primatives = [],
        primIndex = 0;
Exemplo n.º 30
0
  return path;
};

// NOTE: use this script to create an nconf compatible settings file.  It will create (or overwrite/update) a file called nconf.json in the same folder as this script.
var fs        = require('fs'),
    nconf     = require('nconf'),
    path      = require('path'),
    pkg       = JSON.parse(fs.readFileSync('package.json', 'utf8'));

nconf.env().argv(); //load environment settings and args

//load user settings first, if file exists
var userFile = path.join(__dirname, 'settings-user.json');
if (fs.existsSync(userFile)) {
  console.log('user settings:', userFile);
  nconf.add('user', { type: 'file', file: userFile });  
}

//determine which settings file to apply
var key = "development"; // "development" is the default if an environment is not determined to have been supplied

//priority 1: was an argument passed while starting up node?  e.g. node server.js staging
if (process.argv[2]) {
  key = process.argv[2].toLowerCase();
}
//priority 2: match on "env" in user-settings.js
else if (nconf.get('env')) {
  key = nconf.get('env');
}
//priority 3: match on "env" in package.json
else if (pkg.env) {