mirror of
https://github.com/node-ebics/node-ebics-client.git
synced 2024-11-25 07:32:06 +00:00
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>
This commit is contained in:
parent
5f57a072ea
commit
c3d3decd6a
@ -6,18 +6,12 @@ const ebics = require('../index');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
|
const configjs = require('./config.js');
|
||||||
|
|
||||||
const client = new ebics.Client({
|
const client = gClient;
|
||||||
url: 'https://ebics.server',
|
|
||||||
partnerId: '',
|
|
||||||
userId: '',
|
|
||||||
hostId: '',
|
|
||||||
passphrase: 'test', // keys-test will be decrypted with this passphrase
|
|
||||||
keyStorage: ebics.fsKeysStorage('./keys-test'),
|
|
||||||
});
|
|
||||||
|
|
||||||
const bankName = 'Bank name'; // Change this to the bank name you're going to send the letter to.
|
const bankName = gConfig.bankName;
|
||||||
const languageCode = 'en'; // Currently 'de' and 'en' are valid values.
|
const languageCode = gConfig.languageCode;
|
||||||
const template = fs.readFileSync('../templates/ini_'+languageCode+'.hbs').toString();
|
const template = fs.readFileSync('../templates/ini_'+languageCode+'.hbs').toString();
|
||||||
const letter = new ebics.BankLetter({ client, bankName, template });
|
const letter = new ebics.BankLetter({ client, bankName, template });
|
||||||
const bankLetterFile = path.join(os.homedir(), 'bankLetter_'+languageCode+'.html');
|
const bankLetterFile = path.join(os.homedir(), 'bankLetter_'+languageCode+'.html');
|
||||||
|
25
examples/config.js
Normal file
25
examples/config.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
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),
|
||||||
|
});
|
42
examples/config.json
Normal file
42
examples/config.json
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
"testing": {
|
||||||
|
"serverAddress": "https://ebics-test.server",
|
||||||
|
"partnerId": "EBICS ParnerID Test",
|
||||||
|
"userId": "MyUserIdTest",
|
||||||
|
"hostId": "MyHostIdTest",
|
||||||
|
"passphrase": "MyPasswordTest",
|
||||||
|
"keyStorage": "./keys-test",
|
||||||
|
"bankName":"Test Bank",
|
||||||
|
"languageCode":"en"
|
||||||
|
},
|
||||||
|
"development": {
|
||||||
|
"serverAddress": "https://ebics-development.server",
|
||||||
|
"partnerId": "EBICS ParnerID Development",
|
||||||
|
"userId": "MyUserIdDevelopment",
|
||||||
|
"hostId": "MyHostIdDevelopment",
|
||||||
|
"passphrase": "MyPasswordDevelopment",
|
||||||
|
"keyStorage": "./keys-development",
|
||||||
|
"bankName":"Development Bank",
|
||||||
|
"languageCode":"en"
|
||||||
|
},
|
||||||
|
"staging": {
|
||||||
|
"serverAddress": "https://ebics-staging.server",
|
||||||
|
"partnerId": "EBICS ParnerID Staging",
|
||||||
|
"userId": "MyUserIdStaging",
|
||||||
|
"hostId": "MyHostIdStaging",
|
||||||
|
"passphrase": "MyPasswordStaging",
|
||||||
|
"keyStorage": "./keys-staging",
|
||||||
|
"bankName":"Staging Bank",
|
||||||
|
"languageCode":"en"
|
||||||
|
},
|
||||||
|
"production": {
|
||||||
|
"serverAddress": "https://ebics.server",
|
||||||
|
"partnerId": "EBICS ParnerID Production",
|
||||||
|
"userId": "MyUserIdProduction",
|
||||||
|
"hostId": "MyHostIdProduction",
|
||||||
|
"passphrase": "MyPasswordProduction",
|
||||||
|
"keyStorage": "./keys-prod",
|
||||||
|
"bankName":"Production Bank",
|
||||||
|
"languageCode":"en"
|
||||||
|
}
|
||||||
|
}
|
@ -3,15 +3,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const ebics = require('../index');
|
const ebics = require('../index');
|
||||||
|
const configjs = require('./config.js');
|
||||||
|
|
||||||
const client = new ebics.Client({
|
const client = gClient;
|
||||||
url: 'https://ebics.server',
|
|
||||||
partnerId: 'PARTNER',
|
|
||||||
userId: 'USER',
|
|
||||||
hostId: 'HOST',
|
|
||||||
passphrase: 'test', // keys-test will be encrypted with this passphrase
|
|
||||||
keyStorage: ebics.fsKeysStorage('./keys-test'),
|
|
||||||
});
|
|
||||||
|
|
||||||
// New keys will be generated and saved in ./keys-test
|
// New keys will be generated and saved in ./keys-test
|
||||||
client.send(ebics.Orders.INI)
|
client.send(ebics.Orders.INI)
|
||||||
|
@ -3,15 +3,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const ebics = require('../index');
|
const ebics = require('../index');
|
||||||
|
const configjs = require('./config.js');
|
||||||
|
|
||||||
const client = new ebics.Client({
|
const client = gClient;
|
||||||
url: 'https://ebics.server',
|
|
||||||
partnerId: '',
|
|
||||||
userId: '',
|
|
||||||
hostId: '',
|
|
||||||
passphrase: 'test', // keys-test will be decrypted with this passphrase
|
|
||||||
keyStorage: ebics.fsKeysStorage('./keys-test'),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Client keys must be already generated and send by letter.
|
// Client keys must be already generated and send by letter.
|
||||||
// The bank should have enabled the user
|
// The bank should have enabled the user
|
||||||
|
@ -3,15 +3,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const ebics = require('../index');
|
const ebics = require('../index');
|
||||||
|
const configjs = require('./config.js');
|
||||||
|
|
||||||
const client = new ebics.Client({
|
const client = gClient;
|
||||||
url: 'https://ebics.server',
|
|
||||||
partnerId: '',
|
|
||||||
userId: '',
|
|
||||||
hostId: '',
|
|
||||||
passphrase: 'test', // keys-test will be decrypted with this passphrase
|
|
||||||
keyStorage: ebics.fsKeysStorage('./keys-test'),
|
|
||||||
});
|
|
||||||
|
|
||||||
// The bank keys must have been already saved
|
// The bank keys must have been already saved
|
||||||
client.send(ebics.Orders.C52(null, null)) // startDate 'YYYY-MM-DD', endDate 'YYYY-MM-DD'
|
client.send(ebics.Orders.C52(null, null)) // startDate 'YYYY-MM-DD', endDate 'YYYY-MM-DD'
|
||||||
|
@ -3,15 +3,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const ebics = require('../index');
|
const ebics = require('../index');
|
||||||
|
const configjs = require('./config.js');
|
||||||
|
|
||||||
const client = new ebics.Client({
|
const client = gClient;
|
||||||
url: 'https://ebics.server',
|
|
||||||
partnerId: '',
|
|
||||||
userId: '',
|
|
||||||
hostId: '',
|
|
||||||
passphrase: 'test', // keys-test will be decrypted with this passphrase
|
|
||||||
keyStorage: ebics.fsKeysStorage('./keys-test'),
|
|
||||||
});
|
|
||||||
|
|
||||||
// The bank keys must have been already saved
|
// The bank keys must have been already saved
|
||||||
client.send(ebics.Orders.C53(null, null)) // startDate 'YYYY-MM-DD', endDate 'YYYY-MM-DD'
|
client.send(ebics.Orders.C53(null, null)) // startDate 'YYYY-MM-DD', endDate 'YYYY-MM-DD'
|
||||||
|
@ -3,15 +3,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const ebics = require('../index');
|
const ebics = require('../index');
|
||||||
|
const configjs = require('./config.js');
|
||||||
|
|
||||||
const client = new ebics.Client({
|
const client = gClient;
|
||||||
url: 'https://ebics.server',
|
|
||||||
partnerId: '',
|
|
||||||
userId: '',
|
|
||||||
hostId: '',
|
|
||||||
passphrase: 'test', // keys-test will be decrypted with this passphrase
|
|
||||||
keyStorage: ebics.fsKeysStorage('./keys-test'),
|
|
||||||
});
|
|
||||||
|
|
||||||
// The bank keys must have been already saved
|
// The bank keys must have been already saved
|
||||||
client.send(ebics.Orders.DKI(null, null)) // startDate 'YYYY-MM-DD', endDate 'YYYY-MM-DD'
|
client.send(ebics.Orders.DKI(null, null)) // startDate 'YYYY-MM-DD', endDate 'YYYY-MM-DD'
|
||||||
|
@ -3,15 +3,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const ebics = require('../index');
|
const ebics = require('../index');
|
||||||
|
const configjs = require('./config.js');
|
||||||
|
|
||||||
const client = new ebics.Client({
|
const client = gClient;
|
||||||
url: 'https://ebics.server',
|
|
||||||
partnerId: '',
|
|
||||||
userId: '',
|
|
||||||
hostId: '',
|
|
||||||
passphrase: 'test', // keys-test will be decrypted with this passphrase
|
|
||||||
keyStorage: ebics.fsKeysStorage('./keys-test'),
|
|
||||||
});
|
|
||||||
|
|
||||||
// The bank keys must have been already saved
|
// The bank keys must have been already saved
|
||||||
client.send(ebics.Orders.HKD)
|
client.send(ebics.Orders.HKD)
|
||||||
|
@ -3,15 +3,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const ebics = require('../index');
|
const ebics = require('../index');
|
||||||
|
const configjs = require('./config.js');
|
||||||
|
|
||||||
const client = new ebics.Client({
|
const client = gClient;
|
||||||
url: 'https://ebics.server',
|
|
||||||
partnerId: '',
|
|
||||||
userId: '',
|
|
||||||
hostId: '',
|
|
||||||
passphrase: 'test', // keys-test will be decrypted with this passphrase
|
|
||||||
keyStorage: ebics.fsKeysStorage('./keys-test'),
|
|
||||||
});
|
|
||||||
|
|
||||||
// The bank keys must have been already saved
|
// The bank keys must have been already saved
|
||||||
client.send(ebics.Orders.HTD)
|
client.send(ebics.Orders.HTD)
|
||||||
|
@ -3,15 +3,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const ebics = require('../index');
|
const ebics = require('../index');
|
||||||
|
const configjs = require('./config.js');
|
||||||
|
|
||||||
const client = new ebics.Client({
|
const client = gClient;
|
||||||
url: 'https://ebics.server',
|
|
||||||
partnerId: '',
|
|
||||||
userId: '',
|
|
||||||
hostId: '',
|
|
||||||
passphrase: 'test', // keys-test will be decrypted with this passphrase
|
|
||||||
keyStorage: ebics.fsKeysStorage('./keys-test'),
|
|
||||||
});
|
|
||||||
|
|
||||||
// The bank keys must have been already saved
|
// The bank keys must have been already saved
|
||||||
client.send(ebics.Orders.STA(null, null)) // startDate 'YYYY-MM-DD', endDate 'YYYY-MM-DD'
|
client.send(ebics.Orders.STA(null, null)) // startDate 'YYYY-MM-DD', endDate 'YYYY-MM-DD'
|
||||||
|
@ -3,15 +3,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const ebics = require('../index');
|
const ebics = require('../index');
|
||||||
|
const configjs = require('./config.js');
|
||||||
|
|
||||||
const client = new ebics.Client({
|
const client = gClient;
|
||||||
url: 'https://ebics.server',
|
|
||||||
partnerId: '',
|
|
||||||
userId: '',
|
|
||||||
hostId: '',
|
|
||||||
passphrase: 'test', // keys-test will be decrypted with this passphrase
|
|
||||||
keyStorage: ebics.fsKeysStorage('./keys-test'),
|
|
||||||
});
|
|
||||||
|
|
||||||
// The bank keys must have been already saved
|
// The bank keys must have been already saved
|
||||||
client.send(ebics.Orders.VMK(null, null)) // startDate 'YYYY-MM-DD', endDate 'YYYY-MM-DD'
|
client.send(ebics.Orders.VMK(null, null)) // startDate 'YYYY-MM-DD', endDate 'YYYY-MM-DD'
|
||||||
|
@ -54,6 +54,7 @@
|
|||||||
"auto-changelog": "^1.16.2",
|
"auto-changelog": "^1.16.2",
|
||||||
"handlebars": "^4.5.3",
|
"handlebars": "^4.5.3",
|
||||||
"js2xmlparser": "^4.0.0",
|
"js2xmlparser": "^4.0.0",
|
||||||
|
"lodash":"^4.17.15",
|
||||||
"node-forge": "^0.9.1",
|
"node-forge": "^0.9.1",
|
||||||
"request": "^2.88.0",
|
"request": "^2.88.0",
|
||||||
"uuid": "^3.3.3",
|
"uuid": "^3.3.3",
|
||||||
|
Loading…
Reference in New Issue
Block a user