Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
rpc.__get__('initServer')(function serverStarted() {
// meddle with base port to get a loopback client in worker process
require('nconf').overrides({net: {rpc: {basePort: 17001}}});
rpc.__get__('initClient')(GSCONF_LOOPBACK, function clientStarted() {
// make fake client RPC connection available under our own GSID
rpc.__get__('clients')['gs01-02'] =
rpc.__get__('clients')['gs01-loopback'];
done();
});
require('nconf').overrides({}); // reset
});
});
function completeConfigSetup(config, next) {
// Add CI object
if (install.ciVals) {
config.test_database = {};
for (var prop in install.ciVals) {
if (install.ciVals.hasOwnProperty(prop)) {
config.test_database[prop] = install.ciVals[prop];
}
}
}
// Add package_manager object if set
if (nconf.get('package_manager')) {
config.package_manager = nconf.get('package_manager');
}
nconf.overrides(config);
async.waterfall([
function (next) {
require('./database').init(next);
},
function (next) {
require('./database').createIndices(next);
},
function (next) {
// Sanity-check/fix url/port
if (!/^http(?:s)?:\/\//.test(config.url)) {
config.url = 'http://' + config.url;
}
var urlObj = url.parse(config.url);
if (urlObj.port) {
config.port = urlObj.port;
}
function create (overrides) {
nconf
.overrides(overrides || {})
.env()
.file({ file: path.join(__dirname, localEnv) })
.defaults(configs(nconf));
var config = nconf.get();
// Remove all the items that pass the filter
Object.keys(config).filter(function (key) {
return /^(?:npm)?_/.test(key);
}).forEach(function (key) {
delete config[key];
});
return config;
}
function init(isMaster, baseConfig, localConfig) {
reset();
baseConfig = baseConfig || require(CFG_BASE);
localConfig = localConfig || require(CFG_LOCAL);
// environment variables take precedence:
nconf.env();
// ...then cmdline arguments:
nconf.argv();
// ...then anything in local config file:
nconf.overrides(localConfig);
// ...default values for anything not specified otherwise:
nconf.defaults(baseConfig);
initClusterConfig(isMaster);
if (gsid === null) {
throw new ConfigError('invalid network configuration for this host ' +
'(unable to initialize GSID)');
}
}
module.exports = function (env) {
'use strict';
// Configuration object.
var config = {};
config.path = __dirname + '/config';
config.baseFile = config.path + '/base.json';
config.overrideFile = config.path + '/config.json';
// overrides should be the very first thing
if (fs.existsSync(config.overrideFile)) {
nconf.overrides(JSON.parse(fs.readFileSync(config.overrideFile)));
console.log('Loading overrides from ' + config.overrideFile);
}
// THEN use env & args
nconf.env().argv();
var NODE_ENV = nconf.get('NODE_ENV') || 'development';
if (env && (NODE_ENV !== env)) {
nconf.set('NODE_ENV', env);
NODE_ENV = env;
}
config.environmentFile = config.path + '/' + NODE_ENV + '.json';
// finally the config file and defaults
return new Promise((resolve, reject) => {
nconf.overrides(configs[env]);
// do some async stuff if needed
resolve();
});
},
* through the environement variables or through the command line parameter
*/
var nconf = require('nconf');
var path = require('path');
var envConfig = process.env.EZPAARSE_CONFIG;
if (typeof envConfig === 'string' && envConfig.length > 0) {
try {
envConfig = JSON.parse(envConfig);
} catch (e) {
throw new Error('EZPAARSE_CONFIG is not a valid JSON');
}
nconf.overrides(envConfig);
}
nconf.argv() // try to get parameter from the command line
// then from the environment
.env()
// then from the local config
.file('local', path.join(__dirname, '../config.local.json'))
// then (default value) from the standard config.json file
.file('default', path.join(__dirname, '../config.json'));
nconf.defaults({
'EZPAARSE_HTTP_PROXY': process.env.HTTP_PROXY || process.env.http_proxy
});
// ezpaarse ezmasterification
// see https://github.com/Inist-CNRS/ezmaster
function loadConfig(config) {
if (config) {
nconf.overrides(config);
}
mapCustomEnvVariables();
loadConfigFromProject();
loadConfigFromModules();
}
module.exports = function readConfiguration(argv) {
nconf.defaults(require(config));
nconf.overrides(require(defaults));
let library = nconf.get('library');
let parseFunc;
switch (library) {
case 'hawk':
parseFunc = parseHawk;
break;
default:
break;
}
return parseFunc(nconf.get(library), argv);
}