@itentialopensource/adapter-meraki 0.8.3 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BROKER.md +6 -2
- package/CHANGELOG.md +69 -43
- package/adapter.js +2 -1
- package/adapterBase.js +63 -30
- package/package.json +3 -2
- package/pronghorn.json +642 -642
- package/propertiesSchema.json +50 -9
- package/refs?service=git-upload-pack +0 -0
- package/report/adapterInfo.json +10 -0
- package/report/updateReport1652488414759.json +120 -0
- package/sampleProperties.json +73 -26
- package/test/integration/adapterTestBasicGet.js +1 -1
- package/test/integration/adapterTestIntegration.js +24 -107
- package/test/unit/adapterTestUnit.js +29 -112
- package/utils/entitiesToDB.js +12 -57
- package/utils/tbScript.js +35 -20
- package/utils/tbUtils.js +44 -39
- package/utils/testRunner.js +16 -16
@@ -4,6 +4,7 @@
|
|
4
4
|
/* global describe it log pronghornProps */
|
5
5
|
/* eslint global-require: warn */
|
6
6
|
/* eslint no-unused-vars: warn */
|
7
|
+
/* eslint import/no-dynamic-require:warn */
|
7
8
|
|
8
9
|
// include required items for testing & logging
|
9
10
|
const assert = require('assert');
|
@@ -18,22 +19,31 @@ const { use } = require('chai');
|
|
18
19
|
const td = require('testdouble');
|
19
20
|
|
20
21
|
const anything = td.matchers.anything();
|
21
|
-
|
22
|
-
// stub and attemptTimeout are used throughout the code so set them here
|
23
22
|
let logLevel = 'none';
|
24
|
-
const stub = true;
|
25
23
|
const isRapidFail = false;
|
26
|
-
|
24
|
+
|
25
|
+
// read in the properties from the sampleProperties files
|
26
|
+
let adaptdir = __dirname;
|
27
|
+
if (adaptdir.endsWith('/test/integration')) {
|
28
|
+
adaptdir = adaptdir.substring(0, adaptdir.length - 17);
|
29
|
+
} else if (adaptdir.endsWith('/test/unit')) {
|
30
|
+
adaptdir = adaptdir.substring(0, adaptdir.length - 10);
|
31
|
+
}
|
32
|
+
const samProps = require(`${adaptdir}/sampleProperties.json`).properties;
|
27
33
|
|
28
34
|
// these variables can be changed to run in integrated mode so easier to set them here
|
29
35
|
// always check these in with bogus data!!!
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
36
|
+
samProps.stub = true;
|
37
|
+
samProps.host = 'replace.hostorip.here';
|
38
|
+
samProps.authentication.username = 'username';
|
39
|
+
samProps.authentication.password = 'password';
|
40
|
+
samProps.protocol = 'http';
|
41
|
+
samProps.port = 80;
|
42
|
+
samProps.ssl.enabled = false;
|
43
|
+
samProps.ssl.accept_invalid_cert = false;
|
44
|
+
samProps.request.attempt_timeout = 60000;
|
45
|
+
const attemptTimeout = samProps.request.attempt_timeout;
|
46
|
+
const { stub } = samProps;
|
37
47
|
|
38
48
|
// these are the adapter properties. You generally should not need to alter
|
39
49
|
// any of these after they are initially set up
|
@@ -45,102 +55,7 @@ global.pronghornProps = {
|
|
45
55
|
adapters: [{
|
46
56
|
id: 'Test-meraki',
|
47
57
|
type: 'Meraki',
|
48
|
-
properties:
|
49
|
-
host,
|
50
|
-
port,
|
51
|
-
base_path: '//api',
|
52
|
-
version: 'v0',
|
53
|
-
cache_location: 'none',
|
54
|
-
encode_pathvars: true,
|
55
|
-
save_metric: false,
|
56
|
-
protocol,
|
57
|
-
stub,
|
58
|
-
authentication: {
|
59
|
-
auth_method: 'basic user_password',
|
60
|
-
username,
|
61
|
-
password,
|
62
|
-
token: '',
|
63
|
-
token_timeout: -1,
|
64
|
-
token_cache: 'local',
|
65
|
-
invalid_token_error: 401,
|
66
|
-
auth_field: 'header.headers.Authorization',
|
67
|
-
auth_field_format: 'Basic {b64}{username}:{password}{/b64}',
|
68
|
-
auth_logging: false,
|
69
|
-
client_id: '',
|
70
|
-
client_secret: '',
|
71
|
-
grant_type: ''
|
72
|
-
},
|
73
|
-
healthcheck: {
|
74
|
-
type: 'none',
|
75
|
-
frequency: 60000,
|
76
|
-
query_object: {}
|
77
|
-
},
|
78
|
-
throttle: {
|
79
|
-
throttle_enabled: false,
|
80
|
-
number_pronghorns: 1,
|
81
|
-
sync_async: 'sync',
|
82
|
-
max_in_queue: 1000,
|
83
|
-
concurrent_max: 1,
|
84
|
-
expire_timeout: 0,
|
85
|
-
avg_runtime: 200,
|
86
|
-
priorities: [
|
87
|
-
{
|
88
|
-
value: 0,
|
89
|
-
percent: 100
|
90
|
-
}
|
91
|
-
]
|
92
|
-
},
|
93
|
-
request: {
|
94
|
-
number_redirects: 0,
|
95
|
-
number_retries: 3,
|
96
|
-
limit_retry_error: 0,
|
97
|
-
failover_codes: [],
|
98
|
-
attempt_timeout: attemptTimeout,
|
99
|
-
global_request: {
|
100
|
-
payload: {},
|
101
|
-
uriOptions: {},
|
102
|
-
addlHeaders: {},
|
103
|
-
authData: {}
|
104
|
-
},
|
105
|
-
healthcheck_on_timeout: true,
|
106
|
-
return_raw: true,
|
107
|
-
archiving: false,
|
108
|
-
return_request: false
|
109
|
-
},
|
110
|
-
proxy: {
|
111
|
-
enabled: false,
|
112
|
-
host: '',
|
113
|
-
port: 1,
|
114
|
-
protocol: 'http',
|
115
|
-
username: '',
|
116
|
-
password: ''
|
117
|
-
},
|
118
|
-
ssl: {
|
119
|
-
ecdhCurve: '',
|
120
|
-
enabled: sslenable,
|
121
|
-
accept_invalid_cert: sslinvalid,
|
122
|
-
ca_file: '',
|
123
|
-
key_file: '',
|
124
|
-
cert_file: '',
|
125
|
-
secure_protocol: '',
|
126
|
-
ciphers: ''
|
127
|
-
},
|
128
|
-
mongo: {
|
129
|
-
host: '',
|
130
|
-
port: 0,
|
131
|
-
database: '',
|
132
|
-
username,
|
133
|
-
password: '',
|
134
|
-
replSet: '',
|
135
|
-
db_ssl: {
|
136
|
-
enabled: false,
|
137
|
-
accept_invalid_cert: false,
|
138
|
-
ca_file: '',
|
139
|
-
key_file: '',
|
140
|
-
cert_file: ''
|
141
|
-
}
|
142
|
-
}
|
143
|
-
}
|
58
|
+
properties: samProps
|
144
59
|
}]
|
145
60
|
}
|
146
61
|
};
|
@@ -848,17 +763,13 @@ describe('[unit] Meraki Adapter Test', () => {
|
|
848
763
|
assert.notEqual(undefined, sampleDotJson.properties.ssl.cert_file);
|
849
764
|
assert.notEqual(undefined, sampleDotJson.properties.ssl.secure_protocol);
|
850
765
|
assert.notEqual(undefined, sampleDotJson.properties.ssl.ciphers);
|
851
|
-
|
852
766
|
assert.notEqual(undefined, sampleDotJson.properties.base_path);
|
853
767
|
assert.notEqual(undefined, sampleDotJson.properties.version);
|
854
768
|
assert.notEqual(undefined, sampleDotJson.properties.cache_location);
|
855
769
|
assert.notEqual(undefined, sampleDotJson.properties.encode_pathvars);
|
770
|
+
assert.notEqual(undefined, sampleDotJson.properties.encode_queryvars);
|
856
771
|
assert.notEqual(undefined, sampleDotJson.properties.save_metric);
|
857
772
|
assert.notEqual(undefined, sampleDotJson.properties.protocol);
|
858
|
-
assert.notEqual(undefined, sampleDotJson.properties.stub);
|
859
|
-
assert.notEqual(undefined, sampleDotJson.properties.stub);
|
860
|
-
assert.notEqual(undefined, sampleDotJson.properties.stub);
|
861
|
-
assert.notEqual(undefined, sampleDotJson.properties.stub);
|
862
773
|
assert.notEqual(undefined, sampleDotJson.properties.healthcheck);
|
863
774
|
assert.notEqual(null, sampleDotJson.properties.healthcheck);
|
864
775
|
assert.notEqual('', sampleDotJson.properties.healthcheck);
|
@@ -917,6 +828,12 @@ describe('[unit] Meraki Adapter Test', () => {
|
|
917
828
|
assert.notEqual(undefined, sampleDotJson.properties.mongo.db_ssl.ca_file);
|
918
829
|
assert.notEqual(undefined, sampleDotJson.properties.mongo.db_ssl.key_file);
|
919
830
|
assert.notEqual(undefined, sampleDotJson.properties.mongo.db_ssl.cert_file);
|
831
|
+
assert.notEqual(undefined, sampleDotJson.properties.devicebroker);
|
832
|
+
assert.notEqual(undefined, sampleDotJson.properties.devicebroker.getDevice);
|
833
|
+
assert.notEqual(undefined, sampleDotJson.properties.devicebroker.getDevicesFiltered);
|
834
|
+
assert.notEqual(undefined, sampleDotJson.properties.devicebroker.isAlive);
|
835
|
+
assert.notEqual(undefined, sampleDotJson.properties.devicebroker.getConfig);
|
836
|
+
assert.notEqual(undefined, sampleDotJson.properties.devicebroker.getCount);
|
920
837
|
done();
|
921
838
|
} catch (error) {
|
922
839
|
log.error(`Test Failure: ${error}`);
|
package/utils/entitiesToDB.js
CHANGED
@@ -14,10 +14,8 @@
|
|
14
14
|
*/
|
15
15
|
|
16
16
|
const fs = require('fs');
|
17
|
-
const { MongoClient } = require('mongodb');
|
18
17
|
const path = require('path');
|
19
|
-
|
20
|
-
// const { string } = require('yargs');
|
18
|
+
const utils = require('./tbUtils');
|
21
19
|
|
22
20
|
// get the pronghorn database information
|
23
21
|
const getPronghornProps = async (iapDir) => {
|
@@ -99,7 +97,7 @@ const optionsHandler = (options) => {
|
|
99
97
|
/**
|
100
98
|
* Function used to put the adapter configuration into the provided database
|
101
99
|
*/
|
102
|
-
const moveEntitiesToDB = (targetPath, options) => {
|
100
|
+
const moveEntitiesToDB = async (targetPath, options) => {
|
103
101
|
// set local variables
|
104
102
|
let myOpts = options;
|
105
103
|
let myPath = targetPath;
|
@@ -120,25 +118,7 @@ const moveEntitiesToDB = (targetPath, options) => {
|
|
120
118
|
}
|
121
119
|
|
122
120
|
// get the pronghorn database properties
|
123
|
-
optionsHandler(options).then((currentProps) => {
|
124
|
-
let mongoUrl;
|
125
|
-
let dbName;
|
126
|
-
|
127
|
-
// find the mongo properties so we can connect
|
128
|
-
if (currentProps.mongoProps) {
|
129
|
-
mongoUrl = currentProps.mongoProps.url;
|
130
|
-
dbName = currentProps.mongoProps.db;
|
131
|
-
} else if (currentProps.mongo) {
|
132
|
-
if (currentProps.mongo.url) {
|
133
|
-
mongoUrl = currentProps.mongo.url;
|
134
|
-
} else {
|
135
|
-
mongoUrl = `mongodb://${currentProps.mongo.host}:${currentProps.mongo.port}`;
|
136
|
-
}
|
137
|
-
dbName = currentProps.mongo.database;
|
138
|
-
} else {
|
139
|
-
throw new Error('Mongo properties are not specified in adapter preferences!');
|
140
|
-
}
|
141
|
-
|
121
|
+
return optionsHandler(options).then(async (currentProps) => {
|
142
122
|
// Check valid filepath provided
|
143
123
|
if (!myPath) {
|
144
124
|
// if no path use the current directory without the utils
|
@@ -184,41 +164,16 @@ const moveEntitiesToDB = (targetPath, options) => {
|
|
184
164
|
});
|
185
165
|
|
186
166
|
// Upload documents to db collection
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
collection.insertMany(docs, { checkKeys: false }, (error, res) => {
|
197
|
-
if (error) {
|
198
|
-
log.error(JSON.stringify(error));
|
199
|
-
throw error;
|
200
|
-
}
|
201
|
-
// log the insertion, close the database and return
|
202
|
-
log.debug(`Inserted ${docs.length} documents to ${dbName}.${myOpts.targetCollection} with response ${JSON.stringify(res)}`);
|
203
|
-
db.close();
|
204
|
-
return res;
|
205
|
-
});
|
206
|
-
});
|
167
|
+
const iapDir = utils.getIAPHome();
|
168
|
+
const db = await utils.connect(iapDir, currentProps).catch((err) => { console.error(err); throw err; });
|
169
|
+
if (!db) {
|
170
|
+
console.error('Error occured when connectiong to database', currentProps);
|
171
|
+
throw new Error('Database not found');
|
172
|
+
}
|
173
|
+
const collection = db.collection(myOpts.targetCollection);
|
174
|
+
const res = await collection.insertMany(docs, { checkKeys: false }).catch((err) => { console.error(err); throw err; });
|
175
|
+
return res;
|
207
176
|
});
|
208
177
|
};
|
209
178
|
|
210
|
-
// const args = process.argv.slice(2);
|
211
|
-
|
212
|
-
// throw new SyntaxError(args[0]);
|
213
|
-
|
214
|
-
// if (args.length === 0) {
|
215
|
-
// console.error('ERROR: target path not specified!');
|
216
|
-
// } else if (args[0] === 'help') {
|
217
|
-
// log.trace('node ./entitiesToDB <target path> <options object: {iapDir: string, pronghornProps: string, targetCollection: string}>');
|
218
|
-
// } else if (args.length === 1) {
|
219
|
-
// console.error('ERROR: IAP directory not specified');
|
220
|
-
// } else {
|
221
|
-
// moveEntitiesToDB(args[0], args[1]);
|
222
|
-
// }
|
223
|
-
|
224
179
|
module.exports = { moveEntitiesToDB };
|
package/utils/tbScript.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/* eslint no-console
|
1
|
+
/* eslint-disable no-console */
|
2
2
|
/* eslint import/no-unresolved: warn */
|
3
3
|
/* eslint global-require: warn */
|
4
4
|
|
@@ -7,7 +7,6 @@
|
|
7
7
|
/* eslint import/no-extraneous-dependencies: warn */
|
8
8
|
/* eslint import/no-dynamic-require: warn */
|
9
9
|
|
10
|
-
const path = require('path');
|
11
10
|
const program = require('commander');
|
12
11
|
const rls = require('readline-sync');
|
13
12
|
const utils = require('./tbUtils');
|
@@ -19,32 +18,39 @@ const { addAuthInfo } = require('./addAuth');
|
|
19
18
|
|
20
19
|
const { troubleshoot, offline } = require('./troubleshootingAdapter');
|
21
20
|
|
22
|
-
const
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
console.
|
28
|
-
|
29
|
-
}
|
21
|
+
const executeInStandaloneMode = async (command) => {
|
22
|
+
console.info('\n> Executing the script outside of IAP installation directory');
|
23
|
+
console.info('> Using sampleProperties.json configuration');
|
24
|
+
switch (command) {
|
25
|
+
case 'install': {
|
26
|
+
console.error('Not currently in IAP directory - installation not possible');
|
27
|
+
break;
|
28
|
+
}
|
29
|
+
case 'connectivity': {
|
30
30
|
const { host } = sampleProperties.properties;
|
31
31
|
console.log(`perform networking diagnositics to ${host}`);
|
32
|
-
|
33
|
-
|
34
|
-
}
|
32
|
+
utils.runConnectivity(host);
|
33
|
+
break;
|
34
|
+
}
|
35
|
+
case 'healthcheck': {
|
35
36
|
const a = basicGet.getAdapterInstance({ properties: sampleProperties });
|
36
37
|
await utils.healthCheck(a);
|
37
|
-
|
38
|
-
} else if (command === 'basicget') {
|
39
|
-
await utils.runBasicGet();
|
40
|
-
process.exit(0);
|
38
|
+
break;
|
41
39
|
}
|
42
|
-
|
43
|
-
|
40
|
+
case 'basicget': {
|
41
|
+
utils.runBasicGet();
|
42
|
+
break;
|
43
|
+
}
|
44
|
+
default: {
|
45
|
+
if (rls.keyInYN('Troubleshooting without IAP?')) {
|
46
|
+
await offline();
|
47
|
+
}
|
44
48
|
}
|
45
|
-
process.exit(0);
|
46
49
|
}
|
50
|
+
process.exit(0);
|
51
|
+
};
|
47
52
|
|
53
|
+
const executeUnderIAPInstallationDirectory = async (command) => {
|
48
54
|
if (command === undefined) {
|
49
55
|
await troubleshoot({}, true, true);
|
50
56
|
} else if (command === 'install') {
|
@@ -79,6 +85,7 @@ const main = async (command) => {
|
|
79
85
|
process.exit(0);
|
80
86
|
}
|
81
87
|
} else {
|
88
|
+
const dirname = utils.getCurrentExecutionPath();
|
82
89
|
utils.verifyInstallationDir(dirname, name);
|
83
90
|
utils.runTest();
|
84
91
|
if (rls.keyInYN(`Do you want to install ${name} to IAP?`)) {
|
@@ -123,6 +130,14 @@ const main = async (command) => {
|
|
123
130
|
}
|
124
131
|
};
|
125
132
|
|
133
|
+
const main = async (command) => {
|
134
|
+
if (!utils.areWeUnderIAPinstallationDirectory()) {
|
135
|
+
executeInStandaloneMode(command); // configuration from sampleproperties.json
|
136
|
+
} else {
|
137
|
+
executeUnderIAPInstallationDirectory(command); // configuration from $IAP_HOME/properties.json
|
138
|
+
}
|
139
|
+
};
|
140
|
+
|
126
141
|
program
|
127
142
|
.command('connectivity')
|
128
143
|
.alias('c')
|
package/utils/tbUtils.js
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
/* eslint import/no-extraneous-dependencies: warn */
|
4
4
|
/* eslint global-require: warn */
|
5
5
|
/* eslint import/no-dynamic-require: warn */
|
6
|
+
/* eslint-disable no-console */
|
6
7
|
|
7
8
|
const path = require('path');
|
8
9
|
const fs = require('fs-extra');
|
@@ -305,9 +306,9 @@ module.exports = {
|
|
305
306
|
* @param {Object} sampleProperties - './sampleProperties.json' in adapter dir
|
306
307
|
*/
|
307
308
|
createAdapter: function createAdapter(pronghornProps, profileItem, sampleProperties, adapterPronghorn) {
|
308
|
-
const
|
309
|
-
const
|
310
|
-
const info = JSON.parse(fs.readFileSync(
|
309
|
+
const iapDir = this.getIAPHome();
|
310
|
+
const packageFile = path.join(iapDir, 'package.json');
|
311
|
+
const info = JSON.parse(fs.readFileSync(packageFile));
|
311
312
|
const version = parseInt(info.version.split('.')[0], 10);
|
312
313
|
|
313
314
|
let adapter = {};
|
@@ -399,52 +400,42 @@ module.exports = {
|
|
399
400
|
},
|
400
401
|
|
401
402
|
/**
|
402
|
-
* @summary
|
403
|
-
*
|
404
|
-
* @
|
405
|
-
* @
|
403
|
+
* @summary Obtain the IAP installation directory depending on how adapter is used:
|
404
|
+
* by IAP, or by npm run CLI interface
|
405
|
+
* @returns IAP installation directory or null if adapter running without IAP
|
406
|
+
* @function getIAPHome
|
406
407
|
*/
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
408
|
+
getIAPHome: function getIAPHome() {
|
409
|
+
let IAPHomePath = null;
|
410
|
+
// check if adapter started via IAP, use path injected by core
|
411
|
+
if (process.env.iap_home) IAPHomePath = process.env.iap_home;
|
412
|
+
// check if adapter started via CLI `npm run <command>` so we have to be located under
|
413
|
+
// <IAP_HOME>/node_modules/@itentialopensource/<adapter_name>/ directory
|
414
|
+
const currentExecutionPath = this.getCurrentExecutionPath();
|
415
|
+
if (currentExecutionPath.indexOf('/node_modules') >= 0) {
|
416
|
+
[IAPHomePath] = currentExecutionPath.split('/node_modules');
|
413
417
|
}
|
418
|
+
return IAPHomePath;
|
414
419
|
},
|
415
420
|
|
416
421
|
/**
|
417
|
-
* @summary
|
418
|
-
*
|
419
|
-
* @returns
|
420
|
-
*
|
421
|
-
* @function getDirname
|
422
|
+
* @summary get current execution path without resolving symbolic links,
|
423
|
+
* use `pwd` command wihout '-P' option (resolving symlinks) https://linux.die.net/man/1/pwd
|
424
|
+
* @returns
|
425
|
+
* @function getCurrentExecutionPAth
|
422
426
|
*/
|
423
|
-
|
424
|
-
if (this.withinIAP(path.join(__dirname, '../../../../'))) {
|
425
|
-
return __dirname;
|
426
|
-
}
|
427
|
+
getCurrentExecutionPath: function getCurrentExecutionPAth() {
|
427
428
|
const { stdout } = this.systemSync('pwd', true);
|
428
429
|
return stdout.trim();
|
429
430
|
},
|
430
431
|
|
431
432
|
/**
|
432
|
-
* @summary
|
433
|
-
*
|
434
|
-
* @
|
435
|
-
* @function getIAPHome
|
433
|
+
* @summary checks if command executed from <IAP_HOME>/node_modules/@itentialopensource/<adapter_name>/ location
|
434
|
+
* @returns true if command executed under <IAP_HOME>/node_modules/@itentialopensource/<adapter_name>/ path
|
435
|
+
* @function areWeUnderIAPinstallationDirectory
|
436
436
|
*/
|
437
|
-
|
438
|
-
|
439
|
-
if (process.env.iap_home) return process.env.iap_home;
|
440
|
-
// adapter started via CLI `npm run <command>` so we have to be located under
|
441
|
-
// <IAP_HOME>/node_modules/@itentialopensource/<adapter>/ directory,
|
442
|
-
// use `pwd` command wihout option -P(resolving symlinks) https://linux.die.net/man/1/pwd
|
443
|
-
const { stdout } = this.systemSync('pwd', true);
|
444
|
-
if (stdout.indexOf('/node_modules') >= 0) {
|
445
|
-
return stdout.trim().split('/node_modules')[0];
|
446
|
-
}
|
447
|
-
return path.join(stdout.trim(), '../../../');
|
437
|
+
areWeUnderIAPinstallationDirectory: function areWeUnderIAPinstallationDirectory() {
|
438
|
+
return path.join(this.getCurrentExecutionPath(), '../../..') === this.getIAPHome();
|
448
439
|
},
|
449
440
|
|
450
441
|
/**
|
@@ -454,9 +445,23 @@ module.exports = {
|
|
454
445
|
* @param {Object} properties - pronghornProps
|
455
446
|
*/
|
456
447
|
connect: async function connect(iapDir, properties) {
|
457
|
-
|
448
|
+
let dbConnectionProperties = {};
|
449
|
+
if (properties.mongoProps) {
|
450
|
+
dbConnectionProperties = properties.mongoProps;
|
451
|
+
} else if (properties.mongo) {
|
452
|
+
if (properties.mongo.url) {
|
453
|
+
dbConnectionProperties.url = properties.mongo.url;
|
454
|
+
} else {
|
455
|
+
dbConnectionProperties.url = `mongodb://${properties.mongo.host}:${properties.mongo.port}`;
|
456
|
+
}
|
457
|
+
dbConnectionProperties.db = properties.mongo.database;
|
458
|
+
}
|
459
|
+
if (!dbConnectionProperties.url || !dbConnectionProperties.db) {
|
460
|
+
throw new Error('Mongo properties are not specified in IAP configuration!');
|
461
|
+
}
|
462
|
+
|
458
463
|
const { MongoDBConnection } = require(path.join(iapDir, 'node_modules/@itential/database'));
|
459
|
-
const connection = new MongoDBConnection(
|
464
|
+
const connection = new MongoDBConnection(dbConnectionProperties);
|
460
465
|
const database = await connection.connect(true);
|
461
466
|
return database;
|
462
467
|
}
|
package/utils/testRunner.js
CHANGED
@@ -47,11 +47,11 @@ function replaceTestVars(test) {
|
|
47
47
|
let intTest = fs.readFileSync(test, 'utf8');
|
48
48
|
|
49
49
|
// replace stub variable but check if it exists first
|
50
|
-
let sindex = intTest.indexOf('
|
50
|
+
let sindex = intTest.indexOf('samProps.stub');
|
51
51
|
let eindex = intTest.indexOf(';', sindex);
|
52
52
|
let replStr = intTest.substring(sindex, eindex + 1);
|
53
53
|
if (sindex > -1) {
|
54
|
-
intTest = intTest.replace(replStr, `
|
54
|
+
intTest = intTest.replace(replStr, `samProps.stub = ${stub};`);
|
55
55
|
}
|
56
56
|
|
57
57
|
// replace isRapidFail variable but check if it exists first
|
@@ -71,46 +71,46 @@ function replaceTestVars(test) {
|
|
71
71
|
}
|
72
72
|
|
73
73
|
// replace host variable
|
74
|
-
sindex = intTest.indexOf('
|
74
|
+
sindex = intTest.indexOf('samProps.host');
|
75
75
|
eindex = intTest.indexOf(';', sindex);
|
76
76
|
replStr = intTest.substring(sindex, eindex + 1);
|
77
|
-
intTest = intTest.replace(replStr, `
|
77
|
+
intTest = intTest.replace(replStr, `samProps.host = '${host}';`);
|
78
78
|
|
79
79
|
// replace username variable
|
80
|
-
sindex = intTest.indexOf('
|
80
|
+
sindex = intTest.indexOf('samProps.authentication.username');
|
81
81
|
eindex = intTest.indexOf(';', sindex);
|
82
82
|
replStr = intTest.substring(sindex, eindex + 1);
|
83
|
-
intTest = intTest.replace(replStr, `
|
83
|
+
intTest = intTest.replace(replStr, `samProps.authentication.username = '${username}';`);
|
84
84
|
|
85
85
|
// replace password variable
|
86
|
-
sindex = intTest.indexOf('
|
86
|
+
sindex = intTest.indexOf('samProps.authentication.password');
|
87
87
|
eindex = intTest.indexOf(';', sindex);
|
88
88
|
replStr = intTest.substring(sindex, eindex + 1);
|
89
|
-
intTest = intTest.replace(replStr, `
|
89
|
+
intTest = intTest.replace(replStr, `samProps.authentication.password = '${password}';`);
|
90
90
|
|
91
91
|
// replace protocol variable
|
92
|
-
sindex = intTest.indexOf('
|
92
|
+
sindex = intTest.indexOf('samProps.protocol');
|
93
93
|
eindex = intTest.indexOf(';', sindex);
|
94
94
|
replStr = intTest.substring(sindex, eindex + 1);
|
95
|
-
intTest = intTest.replace(replStr, `
|
95
|
+
intTest = intTest.replace(replStr, `samProps.protocol = '${protocol}';`);
|
96
96
|
|
97
97
|
// replace port variable
|
98
|
-
sindex = intTest.indexOf('
|
98
|
+
sindex = intTest.indexOf('samProps.port');
|
99
99
|
eindex = intTest.indexOf(';', sindex);
|
100
100
|
replStr = intTest.substring(sindex, eindex + 1);
|
101
|
-
intTest = intTest.replace(replStr, `
|
101
|
+
intTest = intTest.replace(replStr, `samProps.port = ${port};`);
|
102
102
|
|
103
103
|
// replace sslenable variable
|
104
|
-
sindex = intTest.indexOf('
|
104
|
+
sindex = intTest.indexOf('samProps.ssl.enabled');
|
105
105
|
eindex = intTest.indexOf(';', sindex);
|
106
106
|
replStr = intTest.substring(sindex, eindex + 1);
|
107
|
-
intTest = intTest.replace(replStr, `
|
107
|
+
intTest = intTest.replace(replStr, `samProps.ssl.enabled = ${sslenable};`);
|
108
108
|
|
109
109
|
// replace sslinvalid variable
|
110
|
-
sindex = intTest.indexOf('
|
110
|
+
sindex = intTest.indexOf('samProps.ssl.accept_invalid_cert');
|
111
111
|
eindex = intTest.indexOf(';', sindex);
|
112
112
|
replStr = intTest.substring(sindex, eindex + 1);
|
113
|
-
intTest = intTest.replace(replStr, `
|
113
|
+
intTest = intTest.replace(replStr, `samProps.ssl.accept_invalid_cert = ${sslinvalid};`);
|
114
114
|
|
115
115
|
console.log(`Updates to ${test} complete`);
|
116
116
|
fs.writeFileSync(test, intTest);
|