From de92265c95f49389c161c3dc81c124210eb727d4 Mon Sep 17 00:00:00 2001 From: Herman van Hazendonk Date: Thu, 25 Mar 2021 13:52:17 +0100 Subject: [PATCH] Examples: Improve config implementation for multibank. When using the software with multiple banks, the current config file solution wasn't very flexible. We had some different local implementation at our end. In order to use upstream software directly without any changes, suggesting to merge these changes. For me locally it would mean I can get rid of a lot of local example code which are currently bank and even entity specific and can be made more generic. This will also allow multiple EBICS connections with the same bank for different entities as well, in case this is needed. In our case we have multiple EBICS connections with the same bank. Signed-off-by: Herman van Hazendonk --- ...ion.json => config.production.testbank.json} | 0 .../config.production.testbank.testentity.json | 10 ++++++++++ examples/loadConfig.js | 17 ++++++++++++++--- 3 files changed, 24 insertions(+), 3 deletions(-) rename examples/config/{config.production.json => config.production.testbank.json} (100%) create mode 100644 examples/config/config.production.testbank.testentity.json diff --git a/examples/config/config.production.json b/examples/config/config.production.testbank.json similarity index 100% rename from examples/config/config.production.json rename to examples/config/config.production.testbank.json diff --git a/examples/config/config.production.testbank.testentity.json b/examples/config/config.production.testbank.testentity.json new file mode 100644 index 0000000..1bb31fa --- /dev/null +++ b/examples/config/config.production.testbank.testentity.json @@ -0,0 +1,10 @@ +{ + "url": "https://ebics.server", + "partnerId": "EBICS ParnerID Production", + "userId": "MyUserIdProduction", + "hostId": "MyHostIdProduction", + "passphrase": "MyPasswordProduction", + "keyStoragePath": "./keys-prod", + "bankName":"Production Bank", + "languageCode":"en" +} diff --git a/examples/loadConfig.js b/examples/loadConfig.js index 7a1892c..09af4ed 100644 --- a/examples/loadConfig.js +++ b/examples/loadConfig.js @@ -20,11 +20,22 @@ const getDefaultEnv = () => { return parArg || process.env.NODE_ENV; } -const loadConfig = (configDirectory = path.join(__dirname, './config'), env = getDefaultEnv()) => { - console.log(`Loading config form ${configDirectory} with env set to ${env}.`); +const getBankIdentifier = () => { + const [,,,parArg] = process.argv; + return parArg || "testbank"; +} +const getEntityIdentifier = () => { + const [,,,,parArg] = process.argv; + return parArg || "" +} + +const loadConfig = (configDirectory = path.join(__dirname, './config'), env = getDefaultEnv(), bank = getBankIdentifier(), entity = getEntityIdentifier()) => { + entity ? console.log(`Loading config from ${configDirectory} with env set to ${env}, bank set to ${bank} and entity set to ${entity}.`) : console.log(`Loading config from ${configDirectory} with env set to ${env} and bank set to ${bank}.`); + + global.entity = entity; const baseConfigFile = path.join(configDirectory, 'config.json'); - const envConfigFile = env ? path.join(configDirectory, `config.${env}.json`) : null; + const envConfigFile = env ? entity ? path.join(configDirectory, `config.${env}.${bank}.${entity}.json`) : path.join(configDirectory, `config.${env}.${bank}.json`) : null; return { ...safeLoadJson(baseConfigFile),