node-ebics-client/examples/config.js
Herrie c3d3decd6a examples: Externalize configuration values and allow for multiple environments
In order to more easily manage testing of various order types as well as production, development etc. environments, externalize this config values.

Signed-off-by: Herman van Hazendonk <github.com@herrie.org>
2019-11-29 13:12:15 +01:00

26 lines
1.2 KiB
JavaScript

const _ = require('lodash');
const ebics = require('../index');
const config = require('./config.json');
var myArgs = process.argv.slice(2);
//We can run this script with an argument. I.e. "testing" or "production" and it will load the corresponding configuration values for the corresponding environment from config.json
const whichEnvironment = myArgs[0].trim().toLowerCase();
const defaultConfig = config.testing;
//We default back to test in case whichEnvironment argument is not passed while running the script, so we don't accidentally end up making changes in production.
const environment = whichEnvironment || 'testing';
const environmentConfig = config[environment];
if (!environmentConfig) {
console.log("ERROR! Could not find configuration for \""+whichEnvironment+"\" using configuration for \"testing\" instead");
}
global.gFinalConfig = _.merge(defaultConfig, environmentConfig);
global.gClient = new ebics.Client({
url: gFinalConfig.serverAddress,
partnerId: gFinalConfig.partnerId,
userId: gFinalConfig.userId,
hostId: gFinalConfig.hostId,
passphrase: gFinalConfig.passphrase, // keys-test will be encrypted with this passphrase
keyStorage: ebics.fsKeysStorage(gFinalConfig.keyStorage),
});