@itentialopensource/adapter-etsi_sol002 0.1.2 → 0.2.0
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/AUTH.md +39 -0
- package/BROKER.md +199 -0
- package/CALLS.md +169 -0
- package/CHANGELOG.md +5 -5
- package/CODE_OF_CONDUCT.md +12 -17
- package/CONTRIBUTING.md +88 -74
- package/ENHANCE.md +69 -0
- package/PROPERTIES.md +641 -0
- package/README.md +221 -571
- package/SUMMARY.md +9 -0
- package/SYSTEMINFO.md +11 -0
- package/TROUBLESHOOT.md +47 -0
- package/adapter.js +292 -469
- package/adapterBase.js +1006 -252
- package/entities/.generic/action.json +105 -0
- package/entities/.generic/schema.json +6 -1
- package/error.json +6 -0
- package/package.json +5 -3
- package/pronghorn.json +642 -570
- package/propertiesDecorators.json +14 -0
- package/propertiesSchema.json +421 -0
- package/refs?service=git-upload-pack +0 -0
- package/report/adapterInfo.json +10 -0
- package/report/updateReport1653138361361.json +120 -0
- package/sampleProperties.json +90 -1
- package/test/integration/adapterTestBasicGet.js +1 -1
- package/test/integration/adapterTestIntegration.js +1162 -1560
- package/test/unit/adapterBaseTestUnit.js +30 -25
- package/test/unit/adapterTestUnit.js +90 -177
- package/utils/adapterInfo.js +206 -0
- package/utils/entitiesToDB.js +12 -57
- package/utils/pre-commit.sh +3 -0
- package/utils/tbScript.js +35 -20
- package/utils/tbUtils.js +49 -31
- package/utils/testRunner.js +16 -16
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* @copyright Itential, LLC 2019 */
|
|
3
|
+
/* eslint global-require:warn */
|
|
4
|
+
/* eslint import/no-dynamic-require:warn */
|
|
5
|
+
/* eslint prefer-destructuring:warn */
|
|
6
|
+
|
|
7
|
+
const fs = require('fs-extra');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* This script will determine the information about the adapter and store
|
|
12
|
+
* it into a file in the adapter.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* get adapter information
|
|
17
|
+
*/
|
|
18
|
+
function adapterInfo() {
|
|
19
|
+
// set the base pase of the adapter - tool shoud be one level up in utils
|
|
20
|
+
let adaptdir = __dirname;
|
|
21
|
+
const infoRes = {};
|
|
22
|
+
|
|
23
|
+
if (adaptdir.endsWith('/utils')) {
|
|
24
|
+
adaptdir = adaptdir.substring(0, adaptdir.length - 6);
|
|
25
|
+
}
|
|
26
|
+
const pack = require(`${adaptdir}/package.json`);
|
|
27
|
+
infoRes.version = pack.version;
|
|
28
|
+
|
|
29
|
+
let configCount = 0;
|
|
30
|
+
if (fs.existsSync(`${adaptdir}/pronghorn.json`)) {
|
|
31
|
+
const cFile = fs.readFileSync(`${adaptdir}/pronghorn.json`, 'utf8');
|
|
32
|
+
configCount += cFile.split('\n').length;
|
|
33
|
+
} else {
|
|
34
|
+
console.log('Missing - pronghorn.json');
|
|
35
|
+
}
|
|
36
|
+
if (fs.existsSync(`${adaptdir}/propertiesSchema.json`)) {
|
|
37
|
+
const cFile = fs.readFileSync(`${adaptdir}/propertiesSchema.json`, 'utf8');
|
|
38
|
+
configCount += cFile.split('\n').length;
|
|
39
|
+
} else {
|
|
40
|
+
console.log('Missing - propertiesSchema.json');
|
|
41
|
+
}
|
|
42
|
+
if (fs.existsSync(`${adaptdir}/error.json`)) {
|
|
43
|
+
const cFile = fs.readFileSync(`${adaptdir}/error.json`, 'utf8');
|
|
44
|
+
configCount += cFile.split('\n').length;
|
|
45
|
+
} else {
|
|
46
|
+
console.log('Missing - error.json');
|
|
47
|
+
}
|
|
48
|
+
const entitydir = path.join(adaptdir, '/entities');
|
|
49
|
+
if (fs.existsSync(entitydir) && fs.statSync(entitydir).isDirectory()) {
|
|
50
|
+
const entities = fs.readdirSync(entitydir);
|
|
51
|
+
// need to go through each entity in the entities directory
|
|
52
|
+
for (let e = 0; e < entities.length; e += 1) {
|
|
53
|
+
if (fs.statSync(`${entitydir}/${entities[e]}`).isDirectory()) {
|
|
54
|
+
const cfiles = fs.readdirSync(entitydir);
|
|
55
|
+
for (let c = 0; c < cfiles.length; c += 1) {
|
|
56
|
+
if (cfiles[c].endsWith('.json')) {
|
|
57
|
+
const ccFile = fs.readFileSync(`${entitydir}/${entities[e]}/${cfiles[c]}`, 'utf8');
|
|
58
|
+
configCount += ccFile.split('\n').length;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
console.log('Could not find the entities directory');
|
|
65
|
+
}
|
|
66
|
+
infoRes.configLines = configCount;
|
|
67
|
+
|
|
68
|
+
let scodeCount = 0;
|
|
69
|
+
if (fs.existsSync(`${adaptdir}/utils/artifactize.js`)) {
|
|
70
|
+
const sFile = fs.readFileSync(`${adaptdir}/utils/artifactize.js`, 'utf8');
|
|
71
|
+
scodeCount += sFile.split('\n').length;
|
|
72
|
+
} else {
|
|
73
|
+
console.log('Missing - utils/artifactize.js');
|
|
74
|
+
}
|
|
75
|
+
if (fs.existsSync(`${adaptdir}/utils/basicGet.js`)) {
|
|
76
|
+
const sFile = fs.readFileSync(`${adaptdir}/utils/basicGet.js`, 'utf8');
|
|
77
|
+
scodeCount += sFile.split('\n').length;
|
|
78
|
+
} else {
|
|
79
|
+
console.log('Missing - utils/basicGet.js');
|
|
80
|
+
}
|
|
81
|
+
if (fs.existsSync(`${adaptdir}/utils/checkMigrate.js`)) {
|
|
82
|
+
const sFile = fs.readFileSync(`${adaptdir}/utils/checkMigrate.js`, 'utf8');
|
|
83
|
+
scodeCount += sFile.split('\n').length;
|
|
84
|
+
} else {
|
|
85
|
+
console.log('Missing - utils/checkMigrate.js');
|
|
86
|
+
}
|
|
87
|
+
if (fs.existsSync(`${adaptdir}/utils/findPath.js`)) {
|
|
88
|
+
const sFile = fs.readFileSync(`${adaptdir}/utils/findPath.js`, 'utf8');
|
|
89
|
+
scodeCount += sFile.split('\n').length;
|
|
90
|
+
} else {
|
|
91
|
+
console.log('Missing - utils/findPath.js');
|
|
92
|
+
}
|
|
93
|
+
if (fs.existsSync(`${adaptdir}/utils/modify.js`)) {
|
|
94
|
+
const sFile = fs.readFileSync(`${adaptdir}/utils/modify.js`, 'utf8');
|
|
95
|
+
scodeCount += sFile.split('\n').length;
|
|
96
|
+
} else {
|
|
97
|
+
console.log('Missing - utils/modify.js');
|
|
98
|
+
}
|
|
99
|
+
if (fs.existsSync(`${adaptdir}/utils/packModificationScript.js`)) {
|
|
100
|
+
const sFile = fs.readFileSync(`${adaptdir}/utils/packModificationScript.js`, 'utf8');
|
|
101
|
+
scodeCount += sFile.split('\n').length;
|
|
102
|
+
} else {
|
|
103
|
+
console.log('Missing - utils/packModificationScript.js');
|
|
104
|
+
}
|
|
105
|
+
if (fs.existsSync(`${adaptdir}/utils/setup.js`)) {
|
|
106
|
+
const sFile = fs.readFileSync(`${adaptdir}/utils/setup.js`, 'utf8');
|
|
107
|
+
scodeCount += sFile.split('\n').length;
|
|
108
|
+
} else {
|
|
109
|
+
console.log('Missing - utils/setup.js');
|
|
110
|
+
}
|
|
111
|
+
if (fs.existsSync(`${adaptdir}/utils/tbScript.js`)) {
|
|
112
|
+
const sFile = fs.readFileSync(`${adaptdir}/utils/tbScript.js`, 'utf8');
|
|
113
|
+
scodeCount += sFile.split('\n').length;
|
|
114
|
+
} else {
|
|
115
|
+
console.log('Missing - utils/tbScript.js');
|
|
116
|
+
}
|
|
117
|
+
if (fs.existsSync(`${adaptdir}/utils/tbUtils.js`)) {
|
|
118
|
+
const sFile = fs.readFileSync(`${adaptdir}/utils/tbUtils.js`, 'utf8');
|
|
119
|
+
scodeCount += sFile.split('\n').length;
|
|
120
|
+
} else {
|
|
121
|
+
console.log('Missing - utils/tbUtils.js');
|
|
122
|
+
}
|
|
123
|
+
if (fs.existsSync(`${adaptdir}/utils/testRunner.js`)) {
|
|
124
|
+
const sFile = fs.readFileSync(`${adaptdir}/utils/testRunner.js`, 'utf8');
|
|
125
|
+
scodeCount += sFile.split('\n').length;
|
|
126
|
+
} else {
|
|
127
|
+
console.log('Missing - utils/testRunner.js');
|
|
128
|
+
}
|
|
129
|
+
if (fs.existsSync(`${adaptdir}/utils/troubleshootingAdapter.js`)) {
|
|
130
|
+
const sFile = fs.readFileSync(`${adaptdir}/utils/troubleshootingAdapter.js`, 'utf8');
|
|
131
|
+
scodeCount += sFile.split('\n').length;
|
|
132
|
+
} else {
|
|
133
|
+
console.log('Missing - utils/troubleshootingAdapter.js');
|
|
134
|
+
}
|
|
135
|
+
infoRes.scriptLines = scodeCount;
|
|
136
|
+
|
|
137
|
+
let codeCount = 0;
|
|
138
|
+
if (fs.existsSync(`${adaptdir}/adapter.js`)) {
|
|
139
|
+
const aFile = fs.readFileSync(`${adaptdir}/adapter.js`, 'utf8');
|
|
140
|
+
codeCount += aFile.split('\n').length;
|
|
141
|
+
} else {
|
|
142
|
+
console.log('Missing - utils/adapter.js');
|
|
143
|
+
}
|
|
144
|
+
if (fs.existsSync(`${adaptdir}/adapterBase.js`)) {
|
|
145
|
+
const aFile = fs.readFileSync(`${adaptdir}/adapterBase.js`, 'utf8');
|
|
146
|
+
codeCount += aFile.split('\n').length;
|
|
147
|
+
} else {
|
|
148
|
+
console.log('Missing - utils/adapterBase.js');
|
|
149
|
+
}
|
|
150
|
+
infoRes.codeLines = codeCount;
|
|
151
|
+
|
|
152
|
+
let tcodeCount = 0;
|
|
153
|
+
let ttestCount = 0;
|
|
154
|
+
if (fs.existsSync(`${adaptdir}/test/integration/adapterTestBasicGet.js`)) {
|
|
155
|
+
const tFile = fs.readFileSync(`${adaptdir}/test/integration/adapterTestBasicGet.js`, 'utf8');
|
|
156
|
+
tcodeCount += tFile.split('\n').length;
|
|
157
|
+
ttestCount += tFile.split('it(\'').length;
|
|
158
|
+
} else {
|
|
159
|
+
console.log('Missing - test/integration/adapterTestBasicGet.js');
|
|
160
|
+
}
|
|
161
|
+
if (fs.existsSync(`${adaptdir}/test/integration/adapterTestConnectivity.js`)) {
|
|
162
|
+
const tFile = fs.readFileSync(`${adaptdir}/test/integration/adapterTestConnectivity.js`, 'utf8');
|
|
163
|
+
tcodeCount += tFile.split('\n').length;
|
|
164
|
+
ttestCount += tFile.split('it(\'').length;
|
|
165
|
+
} else {
|
|
166
|
+
console.log('Missing - test/integration/adapterTestConnectivity.js');
|
|
167
|
+
}
|
|
168
|
+
if (fs.existsSync(`${adaptdir}/test/integration/adapterTestIntegration.js`)) {
|
|
169
|
+
const tFile = fs.readFileSync(`${adaptdir}/test/integration/adapterTestIntegration.js`, 'utf8');
|
|
170
|
+
tcodeCount += tFile.split('\n').length;
|
|
171
|
+
ttestCount += tFile.split('it(\'').length;
|
|
172
|
+
} else {
|
|
173
|
+
console.log('Missing - test/integration/adapterTestIntegration.js');
|
|
174
|
+
}
|
|
175
|
+
if (fs.existsSync(`${adaptdir}/test/unit/adapterBaseTestUnit.js`)) {
|
|
176
|
+
const tFile = fs.readFileSync(`${adaptdir}/test/unit/adapterBaseTestUnit.js`, 'utf8');
|
|
177
|
+
tcodeCount += tFile.split('\n').length;
|
|
178
|
+
ttestCount += tFile.split('it(\'').length;
|
|
179
|
+
} else {
|
|
180
|
+
console.log('Missing - test/unit/adapterBaseTestUnit.js');
|
|
181
|
+
}
|
|
182
|
+
if (fs.existsSync(`${adaptdir}/test/unit/adapterTestUnit.js`)) {
|
|
183
|
+
const tFile = fs.readFileSync(`${adaptdir}/test/unit/adapterTestUnit.js`, 'utf8');
|
|
184
|
+
tcodeCount += tFile.split('\n').length;
|
|
185
|
+
ttestCount += tFile.split('it(\'').length;
|
|
186
|
+
} else {
|
|
187
|
+
console.log('Missing - test/unit/adapterTestUnit.js');
|
|
188
|
+
}
|
|
189
|
+
infoRes.testLines = tcodeCount;
|
|
190
|
+
infoRes.testCases = ttestCount;
|
|
191
|
+
infoRes.totalCodeLines = scodeCount + codeCount + tcodeCount;
|
|
192
|
+
|
|
193
|
+
if (fs.existsSync(`${adaptdir}/pronghorn.json`)) {
|
|
194
|
+
// Read the entity schema from the file system
|
|
195
|
+
const phFile = path.join(adaptdir, '/pronghorn.json');
|
|
196
|
+
const prong = require(phFile);
|
|
197
|
+
infoRes.wfTasks = prong.methods.length;
|
|
198
|
+
} else {
|
|
199
|
+
console.log('Missing - pronghorn.json');
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
console.log(JSON.stringify(infoRes));
|
|
203
|
+
fs.writeFileSync(`${adaptdir}/report/adapterInfo.json`, JSON.stringify(infoRes, null, 2));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
adapterInfo();
|
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/pre-commit.sh
CHANGED
|
@@ -17,6 +17,9 @@ printf "%b" "Running pre-commit hooks...\\n"
|
|
|
17
17
|
# verify testing script is stubbed and no credentials
|
|
18
18
|
node utils/testRunner.js -r
|
|
19
19
|
|
|
20
|
+
# update the adapter information file
|
|
21
|
+
node utils/adapterInfo.js
|
|
22
|
+
|
|
20
23
|
# security audit on the code
|
|
21
24
|
npm audit --registry=https://registry.npmjs.org --audit-level=moderate
|
|
22
25
|
|
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 = {};
|
|
@@ -352,13 +353,7 @@ module.exports = {
|
|
|
352
353
|
|
|
353
354
|
// get database connection and existing adapter config
|
|
354
355
|
getAdapterConfig: async function getAdapterConfig() {
|
|
355
|
-
const
|
|
356
|
-
let iapDir;
|
|
357
|
-
if (this.withinIAP(newDirname)) { // when this script is called from IAP
|
|
358
|
-
iapDir = newDirname;
|
|
359
|
-
} else {
|
|
360
|
-
iapDir = path.join(this.getDirname(), 'utils', '../../../../');
|
|
361
|
-
}
|
|
356
|
+
const iapDir = this.getIAPHome();
|
|
362
357
|
const pronghornProps = this.getPronghornProps(iapDir);
|
|
363
358
|
console.log('Connecting to Database...');
|
|
364
359
|
const database = await this.connect(iapDir, pronghornProps);
|
|
@@ -405,35 +400,44 @@ module.exports = {
|
|
|
405
400
|
},
|
|
406
401
|
|
|
407
402
|
/**
|
|
408
|
-
* @summary
|
|
409
|
-
*
|
|
410
|
-
* @
|
|
411
|
-
* @
|
|
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
|
|
412
407
|
*/
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
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');
|
|
419
417
|
}
|
|
418
|
+
return IAPHomePath;
|
|
420
419
|
},
|
|
421
420
|
|
|
422
421
|
/**
|
|
423
|
-
* @summary
|
|
424
|
-
*
|
|
425
|
-
* @returns
|
|
426
|
-
*
|
|
427
|
-
* @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
|
|
428
426
|
*/
|
|
429
|
-
|
|
430
|
-
if (this.withinIAP(path.join(__dirname, '../../../../'))) {
|
|
431
|
-
return __dirname;
|
|
432
|
-
}
|
|
427
|
+
getCurrentExecutionPath: function getCurrentExecutionPAth() {
|
|
433
428
|
const { stdout } = this.systemSync('pwd', true);
|
|
434
429
|
return stdout.trim();
|
|
435
430
|
},
|
|
436
431
|
|
|
432
|
+
/**
|
|
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
|
+
*/
|
|
437
|
+
areWeUnderIAPinstallationDirectory: function areWeUnderIAPinstallationDirectory() {
|
|
438
|
+
return path.join(this.getCurrentExecutionPath(), '../../..') === this.getIAPHome();
|
|
439
|
+
},
|
|
440
|
+
|
|
437
441
|
/**
|
|
438
442
|
* @summary connect to mongodb
|
|
439
443
|
*
|
|
@@ -441,9 +445,23 @@ module.exports = {
|
|
|
441
445
|
* @param {Object} properties - pronghornProps
|
|
442
446
|
*/
|
|
443
447
|
connect: async function connect(iapDir, properties) {
|
|
444
|
-
|
|
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
|
+
|
|
445
463
|
const { MongoDBConnection } = require(path.join(iapDir, 'node_modules/@itential/database'));
|
|
446
|
-
const connection = new MongoDBConnection(
|
|
464
|
+
const connection = new MongoDBConnection(dbConnectionProperties);
|
|
447
465
|
const database = await connection.connect(true);
|
|
448
466
|
return database;
|
|
449
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);
|