@itentialopensource/adapter-efficientip_solidserver 0.1.1 → 0.3.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 +1465 -0
- package/CHANGELOG.md +17 -2
- package/CODE_OF_CONDUCT.md +12 -17
- package/CONTRIBUTING.md +3 -148
- package/ENHANCE.md +69 -0
- package/PROPERTIES.md +641 -0
- package/README.md +235 -576
- package/SUMMARY.md +9 -0
- package/SYSTEMINFO.md +11 -0
- package/TROUBLESHOOT.md +47 -0
- package/adapter.js +383 -263
- package/adapterBase.js +854 -408
- package/changelogs/changelog.md +16 -0
- package/entities/.generic/action.json +110 -5
- package/entities/.generic/schema.json +6 -1
- package/error.json +6 -0
- package/metadata.json +49 -0
- package/package.json +27 -22
- package/pronghorn.json +691 -88
- package/propertiesDecorators.json +14 -0
- package/propertiesSchema.json +828 -7
- package/refs?service=git-upload-pack +0 -0
- package/report/adapter-openapi.json +41906 -0
- package/report/adapter-openapi.yaml +23138 -0
- package/report/adapterInfo.json +10 -0
- package/report/updateReport1653233995404.json +120 -0
- package/report/updateReport1691508450223.json +120 -0
- package/report/updateReport1692202927301.json +120 -0
- package/report/updateReport1694465845842.json +120 -0
- package/report/updateReport1698421858198.json +120 -0
- package/sampleProperties.json +153 -3
- package/test/integration/adapterTestBasicGet.js +3 -5
- package/test/integration/adapterTestConnectivity.js +91 -42
- package/test/integration/adapterTestIntegration.js +155 -106
- package/test/unit/adapterBaseTestUnit.js +388 -308
- package/test/unit/adapterTestUnit.js +484 -243
- package/utils/adapterInfo.js +206 -0
- package/utils/addAuth.js +94 -0
- package/utils/artifactize.js +1 -1
- package/utils/basicGet.js +1 -14
- package/utils/checkMigrate.js +1 -1
- package/utils/entitiesToDB.js +179 -0
- package/utils/findPath.js +1 -1
- package/utils/methodDocumentor.js +273 -0
- package/utils/modify.js +14 -16
- package/utils/packModificationScript.js +1 -1
- package/utils/patches2bundledDeps.js +90 -0
- package/utils/pre-commit.sh +5 -0
- package/utils/removeHooks.js +20 -0
- package/utils/taskMover.js +309 -0
- package/utils/tbScript.js +129 -53
- package/utils/tbUtils.js +125 -25
- package/utils/testRunner.js +17 -17
- package/utils/troubleshootingAdapter.js +10 -31
- package/workflows/README.md +0 -3
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
|
|
4
|
+
const blacklistTasks = [
|
|
5
|
+
'genericAdapterRequest',
|
|
6
|
+
'genericAdapterRequestNoBasePath',
|
|
7
|
+
'hasEntities',
|
|
8
|
+
'healthcheck'
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
const adapterBaseTasks = [
|
|
12
|
+
'getDevicesFiltered',
|
|
13
|
+
'isAlive',
|
|
14
|
+
'getConfig',
|
|
15
|
+
'getDevice',
|
|
16
|
+
'iapUpdateAdapterConfiguration',
|
|
17
|
+
'iapFindAdapterPath',
|
|
18
|
+
'iapSuspendAdapter',
|
|
19
|
+
'iapUnsuspendAdapter',
|
|
20
|
+
'iapGetAdapterQueue',
|
|
21
|
+
'iapTroubleshootAdapter',
|
|
22
|
+
'iapRunAdapterHealthcheck',
|
|
23
|
+
'iapRunAdapterConnectivity',
|
|
24
|
+
'iapRunAdapterBasicGet',
|
|
25
|
+
'iapMoveAdapterEntitiesToDB',
|
|
26
|
+
'getDevice',
|
|
27
|
+
'getDevicesFiltered',
|
|
28
|
+
'isAlive',
|
|
29
|
+
'getConfig',
|
|
30
|
+
'iapGetDeviceCount',
|
|
31
|
+
'iapRunAdapterLint',
|
|
32
|
+
'iapRunAdapterTests',
|
|
33
|
+
'iapGetAdapterInventory'
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
function updatePronghorn(tasks, original, updated) {
|
|
37
|
+
const originalFile = require(original);
|
|
38
|
+
const unusedMethods = [];
|
|
39
|
+
const usedMethods = originalFile.methods.filter((method) => {
|
|
40
|
+
if (tasks.includes(method.name)) {
|
|
41
|
+
unusedMethods.push(method);
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
});
|
|
46
|
+
//write used and unused to new files
|
|
47
|
+
let updatedFile;
|
|
48
|
+
if (!fs.existsSync(updated)) {
|
|
49
|
+
updatedFile = { ...originalFile, methods: [], src: 'adapter-inactive.js' };
|
|
50
|
+
} else {
|
|
51
|
+
updatedFile = require(updated);
|
|
52
|
+
}
|
|
53
|
+
updatedFile.methods = updatedFile.methods.concat(unusedMethods);
|
|
54
|
+
originalFile.methods = usedMethods;
|
|
55
|
+
fs.writeFileSync(updated, JSON.stringify(updatedFile, null, 2));
|
|
56
|
+
fs.writeFileSync(original, JSON.stringify(originalFile, null, 2));
|
|
57
|
+
return 'Done';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function flipTaskFlag(task, pronghornPath, value)
|
|
61
|
+
{
|
|
62
|
+
const pronghorn = require(pronghornPath);
|
|
63
|
+
const index = pronghorn.methods.findIndex((method) => method.name === task);
|
|
64
|
+
pronghorn.methods[index] = { ...pronghorn.methods[index], task: value };
|
|
65
|
+
fs.writeFileSync(pronghornPath, JSON.stringify(pronghorn, null, 2));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//Return array of relevant paths given adapter directory
|
|
69
|
+
function createPaths(currentAdapter) {
|
|
70
|
+
const paths = [];
|
|
71
|
+
const filePaths = [
|
|
72
|
+
'adapter.js',
|
|
73
|
+
'pronghorn.json',
|
|
74
|
+
'test/integration/adapterTestIntegration.js',
|
|
75
|
+
'test/unit/adapterTestUnit.js',
|
|
76
|
+
'adapter-inactive.js',
|
|
77
|
+
'pronghorn-inactive.json',
|
|
78
|
+
];
|
|
79
|
+
filePaths.forEach((file) => {
|
|
80
|
+
paths.push(`${currentAdapter}/${file}`);
|
|
81
|
+
});
|
|
82
|
+
return paths;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function insert(str, index, value) {
|
|
86
|
+
return str.substr(0, index) + value + str.substr(index);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//modify adapter js
|
|
90
|
+
//original - path to file containing tasks we want to remove
|
|
91
|
+
// updated - path to file we want to move the tasks to
|
|
92
|
+
function updateAdapterJs(tasks, original, updated, adapterDir) {
|
|
93
|
+
if (!fs.existsSync(original)) {
|
|
94
|
+
//could do this or just let the error ocurr lower down and catch in warpper
|
|
95
|
+
throw new Error(`Original file ${original} does not exist.`);
|
|
96
|
+
}
|
|
97
|
+
let originalFile = fs.readFileSync(original, 'utf8');
|
|
98
|
+
let updatedFile;
|
|
99
|
+
if (!fs.existsSync(updated)) {
|
|
100
|
+
const adapterExport = require(`${adapterDir}/pronghorn.json`).export;
|
|
101
|
+
updatedFile = `/* @copyright Itential, LLC 2019 */\n\n/* eslint import/no-dynamic-require: warn */\n/* eslint no-unused-vars: warn */\n/* global log */\n\nconst path = require('path');\n\nconst AdapterBaseCl = require(path.join(__dirname, 'adapterBase.js'));\n\nclass ${adapterExport}Inactive extends AdapterBaseCl {}\n`;
|
|
102
|
+
//To do handles backup files where og doesn't exist
|
|
103
|
+
} else {
|
|
104
|
+
updatedFile = fs.readFileSync(updated, 'utf8');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
tasks.forEach((method) => {
|
|
108
|
+
//accounting for different js docs format
|
|
109
|
+
const comment = originalFile.indexOf(`* @function ${method}`);
|
|
110
|
+
const start = originalFile.slice(0, comment).lastIndexOf('/**');
|
|
111
|
+
if (start !== -1) {
|
|
112
|
+
//next comment block
|
|
113
|
+
const end = originalFile.indexOf('/**\n', start + 1);
|
|
114
|
+
let func = end === -1
|
|
115
|
+
? originalFile.substring(start - 3, originalFile.lastIndexOf('}'))
|
|
116
|
+
: originalFile.substring(start, end);
|
|
117
|
+
originalFile = originalFile.replace(func, '');
|
|
118
|
+
func = '\n ' + func.trim() + '\n';
|
|
119
|
+
updatedFile = insert(updatedFile, updatedFile.lastIndexOf('}'), func);
|
|
120
|
+
} else {
|
|
121
|
+
console.log(`Task ${method} wasn't found in original file. Skipping.`);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
fs.writeFileSync(original, originalFile, 'utf8');
|
|
125
|
+
fs.writeFileSync(updated, updatedFile, 'utf8');
|
|
126
|
+
return 'done';
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
//Update test file for when we deactivate a task
|
|
130
|
+
function deactivateTest(adapterPath, testPath, tasks) {
|
|
131
|
+
let unitTest = fs.readFileSync(`${adapterPath}/${testPath}`, 'utf8');
|
|
132
|
+
tasks.forEach((task) => {
|
|
133
|
+
const searchStr = `describe('#${task}`;
|
|
134
|
+
unitTest = unitTest.replace(searchStr, `describe.skip('#${task}`);
|
|
135
|
+
});
|
|
136
|
+
fs.writeFileSync(`${adapterPath}/${testPath}`, unitTest, 'utf8');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
//Update test file when we activate tasks
|
|
140
|
+
function activateTest(adapterPath, testPath, tasks) {
|
|
141
|
+
let unitTest = fs.readFileSync(`${adapterPath}/${testPath}`, 'utf8');
|
|
142
|
+
//tasks ==> toMove
|
|
143
|
+
tasks.forEach((task) => {
|
|
144
|
+
const searchStr = `describe.skip('#${task}`;
|
|
145
|
+
unitTest = unitTest.replace(searchStr, `describe('#${task}`);
|
|
146
|
+
});
|
|
147
|
+
fs.writeFileSync(`${adapterPath}/${testPath}`, unitTest, 'utf8');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
//backups are not actually being written back
|
|
151
|
+
function rollbackChanges(adapterPath) {
|
|
152
|
+
const backups = fs.readdirSync(`${adapterPath}/temp`); //this is an array of file names not the full path
|
|
153
|
+
const filePaths = createPaths(adapterPath);
|
|
154
|
+
for (let i = 0; i < backups.length; i++) {
|
|
155
|
+
const file = fs.readFileSync(`${adapterPath}/temp/${backups[i]}`, 'utf8'); //make sure this is getting the file
|
|
156
|
+
const currentFile = filePaths.find((path) => {
|
|
157
|
+
const index = path.split('/').length - 1;
|
|
158
|
+
const fileName = path.split('/')[index];
|
|
159
|
+
return fileName === backups[i].replace('temp-', '');
|
|
160
|
+
}); //returns undefined if no match
|
|
161
|
+
|
|
162
|
+
if (currentFile) {
|
|
163
|
+
fs.writeFileSync(currentFile, file, 'utf8');
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
//inactive didn't exist before script
|
|
167
|
+
if (!backups.includes('temp-adapter-inactive.js')) {
|
|
168
|
+
fs.unlinkSync(`${adapterPath}/pronghorn-inactive.json`);
|
|
169
|
+
fs.unlinkSync(`${adapterPath}/adapter-inactive.js`);
|
|
170
|
+
}
|
|
171
|
+
deleteBackups(adapterPath);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function deleteBackups(adapterPath) {
|
|
175
|
+
fs.rmSync(`${adapterPath}/temp`, { recursive: true });
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function activateTasks(adapterDir, tasks) {
|
|
179
|
+
const toDelete = [];
|
|
180
|
+
const backupFiles = [];
|
|
181
|
+
const filePaths = createPaths(adapterDir);
|
|
182
|
+
try {
|
|
183
|
+
//take backup of each file here
|
|
184
|
+
if (!fs.existsSync(`${adapterDir}/temp`)) {
|
|
185
|
+
fs.mkdirSync(`${adapterDir}/temp`);
|
|
186
|
+
}
|
|
187
|
+
filePaths.forEach((filePath) => {
|
|
188
|
+
if (fs.existsSync(filePath)) {
|
|
189
|
+
const index = filePath.split('/').length - 1;
|
|
190
|
+
const backupName = `temp-${filePath.split('/')[index]}`;
|
|
191
|
+
backupFiles.push(`${adapterDir}/temp/${backupName}`);
|
|
192
|
+
fs.copyFileSync(filePath, `${adapterDir}/temp/${backupName}`);
|
|
193
|
+
} else {
|
|
194
|
+
//File doesn't exist before script
|
|
195
|
+
toDelete.push(filePath);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
tasks = tasks.filter((task) => {
|
|
199
|
+
if (adapterBaseTasks.includes(task)) {
|
|
200
|
+
flipTaskFlag(task, `${adapterDir}/pronghorn.json`, true);
|
|
201
|
+
return false;
|
|
202
|
+
} else {
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
updateAdapterJs(
|
|
207
|
+
tasks,
|
|
208
|
+
`${adapterDir}/adapter-inactive.js`,
|
|
209
|
+
`${adapterDir}/adapter.js`,
|
|
210
|
+
adapterDir
|
|
211
|
+
);
|
|
212
|
+
updatePronghorn(
|
|
213
|
+
tasks,
|
|
214
|
+
`${adapterDir}/pronghorn-inactive.json`,
|
|
215
|
+
`${adapterDir}/pronghorn.json`
|
|
216
|
+
);
|
|
217
|
+
activateTest(
|
|
218
|
+
adapterDir,
|
|
219
|
+
'/test/integration/adapterTestIntegration.js',
|
|
220
|
+
tasks
|
|
221
|
+
);
|
|
222
|
+
activateTest(adapterDir, '/test/unit/adapterTestUnit.js', tasks);
|
|
223
|
+
return 'success';
|
|
224
|
+
} catch (e) {
|
|
225
|
+
console.log(`Error: ${e} ocurred during execution. Rolling back changes.`);
|
|
226
|
+
for (let i = 0; i < backupFiles.length; i++) {
|
|
227
|
+
const file = fs.readFileSync(backupFiles[i], 'utf8');
|
|
228
|
+
fs.writeFileSync(filePaths[i], file, 'utf8');
|
|
229
|
+
}
|
|
230
|
+
toDelete.forEach((filePath) => {
|
|
231
|
+
if (fs.existsSync(filePath)) {
|
|
232
|
+
fs.unlinkSync(filePath);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
deleteBackups(adapterDir);
|
|
236
|
+
process.exit(1);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
//moving from adapter.js to adapter-inactive.js
|
|
241
|
+
function deactivateTasks(adapterDir, tasks) {
|
|
242
|
+
const toDelete = [];
|
|
243
|
+
const backupFiles = [];
|
|
244
|
+
const filePaths = createPaths(adapterDir);
|
|
245
|
+
try {
|
|
246
|
+
//take backup of each file here
|
|
247
|
+
if (!fs.existsSync(`${adapterDir}/temp`)) {
|
|
248
|
+
fs.mkdirSync(`${adapterDir}/temp`);
|
|
249
|
+
}
|
|
250
|
+
filePaths.forEach((filePath) => {
|
|
251
|
+
if (fs.existsSync(filePath)) {
|
|
252
|
+
const index = filePath.split('/').length - 1;
|
|
253
|
+
const backupName = `temp-${filePath.split('/')[index]}`;
|
|
254
|
+
backupFiles.push(`${adapterDir}/temp/${backupName}`);
|
|
255
|
+
fs.copyFileSync(filePath, `${adapterDir}/temp/${backupName}`);
|
|
256
|
+
} else {
|
|
257
|
+
//File doesn't exist before script
|
|
258
|
+
toDelete.push(filePath);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
//filter tasks for blacklisted tasks or IAP tasks
|
|
262
|
+
tasks = tasks.filter((task) => {
|
|
263
|
+
if (blacklistTasks.includes(task)) {
|
|
264
|
+
console.log(`${task} cannot be deactivated.`);
|
|
265
|
+
return false;
|
|
266
|
+
} else if (adapterBaseTasks.includes(task)) {
|
|
267
|
+
flipTaskFlag(task, `${adapterDir}/pronghorn.json`, false);
|
|
268
|
+
return false;
|
|
269
|
+
} else {
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
updateAdapterJs(
|
|
274
|
+
tasks,
|
|
275
|
+
`${adapterDir}/adapter.js`,
|
|
276
|
+
`${adapterDir}/adapter-inactive.js`,
|
|
277
|
+
adapterDir
|
|
278
|
+
);
|
|
279
|
+
updatePronghorn(
|
|
280
|
+
tasks,
|
|
281
|
+
`${adapterDir}/pronghorn.json`,
|
|
282
|
+
`${adapterDir}/pronghorn-inactive.json`
|
|
283
|
+
);
|
|
284
|
+
deactivateTest(
|
|
285
|
+
adapterDir,
|
|
286
|
+
'/test/integration/adapterTestIntegration.js',
|
|
287
|
+
tasks
|
|
288
|
+
);
|
|
289
|
+
deactivateTest(adapterDir, '/test/unit/adapterTestUnit.js', tasks);
|
|
290
|
+
return 'success';
|
|
291
|
+
} catch (e) {
|
|
292
|
+
console.log(`Error: ${e} ocurred during execution. Rolling back changes.`);
|
|
293
|
+
for (let i = 0; i < backupFiles.length; i++) {
|
|
294
|
+
const file = fs.readFileSync(backupFiles[i], 'utf8');
|
|
295
|
+
fs.writeFileSync(filePaths[i], file, 'utf8');
|
|
296
|
+
}
|
|
297
|
+
toDelete.forEach((filePath) => {
|
|
298
|
+
if (fs.existsSync(filePath)) {
|
|
299
|
+
fs.unlinkSync(filePath);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
deleteBackups(adapterDir);
|
|
303
|
+
process.exit(1);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
module.exports = {
|
|
308
|
+
activateTasks, deactivateTasks, rollbackChanges, deleteBackups
|
|
309
|
+
};
|
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,43 +7,126 @@
|
|
|
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');
|
|
12
|
+
const prompts = require('prompts');
|
|
13
13
|
const utils = require('./tbUtils');
|
|
14
14
|
const basicGet = require('./basicGet');
|
|
15
15
|
const { name } = require('../package.json');
|
|
16
16
|
const sampleProperties = require('../sampleProperties.json');
|
|
17
17
|
const adapterPronghorn = require('../pronghorn.json');
|
|
18
|
+
const { addAuthInfo } = require('./addAuth');
|
|
18
19
|
|
|
19
|
-
const { troubleshoot,
|
|
20
|
+
const { troubleshoot, offline } = require('./troubleshootingAdapter');
|
|
20
21
|
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const executeInStandaloneMode = async (command) => {
|
|
23
|
+
console.info('\n> Executing the script outside of IAP installation directory');
|
|
24
|
+
console.info('> Using sampleProperties.json configuration');
|
|
25
|
+
switch (command) {
|
|
26
|
+
case 'install': {
|
|
27
|
+
console.error('Not currently in IAP directory - installation not possible');
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
case 'connectivity': {
|
|
25
31
|
const { host } = sampleProperties.properties;
|
|
26
32
|
console.log(`perform networking diagnositics to ${host}`);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
33
|
+
utils.runConnectivity(host);
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
case 'healthcheck': {
|
|
30
37
|
const a = basicGet.getAdapterInstance({ properties: sampleProperties });
|
|
31
38
|
await utils.healthCheck(a);
|
|
32
|
-
|
|
33
|
-
} else if (command === 'basicget') {
|
|
34
|
-
await utils.runBasicGet();
|
|
35
|
-
process.exit(0);
|
|
39
|
+
break;
|
|
36
40
|
}
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
case 'basicget': {
|
|
42
|
+
utils.runBasicGet();
|
|
43
|
+
break;
|
|
39
44
|
}
|
|
45
|
+
default: {
|
|
46
|
+
if (rls.keyInYN('Troubleshooting without IAP?')) {
|
|
47
|
+
await offline();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
process.exit(0);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const getAdapterInstanceConfig = async (command) => {
|
|
55
|
+
const instances = await utils.getAllAdapterInstances();
|
|
56
|
+
if (!instances || instances.length === 0) {
|
|
57
|
+
return console.log('None adapter instances found!');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let instance;
|
|
61
|
+
if (instances.length === 1) {
|
|
62
|
+
[instance] = instances;
|
|
63
|
+
} else {
|
|
64
|
+
const choices = instances.map((item) => ({ title: item.name }));
|
|
65
|
+
const menu = {
|
|
66
|
+
type: 'select',
|
|
67
|
+
name: 'index',
|
|
68
|
+
message: `Pick an adapter for ${command} check`,
|
|
69
|
+
choices
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
console.log('\n');
|
|
73
|
+
const selected = await prompts(menu);
|
|
74
|
+
console.log('\n');
|
|
75
|
+
instance = instances[selected.index];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (!instance) {
|
|
79
|
+
console.error('No adapter instance selected');
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const { serviceItem: adapterConfig } = await utils.getAdapterConfig(instance._id); /* eslint-disable-line no-underscore-dangle */
|
|
84
|
+
|
|
85
|
+
console.log('\nAdapter instance configuration =>');
|
|
86
|
+
console.log('======================================');
|
|
87
|
+
console.log(adapterConfig);
|
|
88
|
+
console.log('======================================');
|
|
89
|
+
|
|
90
|
+
return adapterConfig;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const executeCommandOnInstance = async (command) => {
|
|
94
|
+
const adapterConfig = await getAdapterInstanceConfig(command);
|
|
95
|
+
if (!adapterConfig) {
|
|
40
96
|
process.exit(0);
|
|
41
97
|
}
|
|
42
98
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
99
|
+
switch (command) {
|
|
100
|
+
case 'connectivity': {
|
|
101
|
+
const { host } = adapterConfig.properties.properties;
|
|
102
|
+
console.log(`perform networking diagnositics to ${host}`);
|
|
103
|
+
utils.runConnectivity(host, true);
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
case 'healthcheck': {
|
|
107
|
+
const adapterInstance = basicGet.getAdapterInstance(adapterConfig);
|
|
108
|
+
await utils.healthCheck(adapterInstance);
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
case 'basicget': {
|
|
112
|
+
utils.runBasicGet(true);
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
case 'troubleshoot': {
|
|
116
|
+
const adapter = { properties: adapterConfig };
|
|
117
|
+
await troubleshoot({}, true, true, adapter);
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
default: {
|
|
121
|
+
console.error(`Unknown command: ${command}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return process.exit(0);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const executeUnderIAPInstallationDirectory = async (command) => {
|
|
128
|
+
if (command === 'install') {
|
|
129
|
+
const { database, serviceItem, pronghornProps } = await utils.getAdapterConfig();
|
|
47
130
|
const filter = { id: pronghornProps.id };
|
|
48
131
|
const profileItem = await database.collection(utils.IAP_PROFILES_COLLECTION).findOne(filter);
|
|
49
132
|
if (!profileItem) {
|
|
@@ -60,9 +143,7 @@ const main = async (command) => {
|
|
|
60
143
|
const serviceIndex = profileItem.services.indexOf(serviceItem.name);
|
|
61
144
|
profileItem.services.splice(serviceIndex, 1);
|
|
62
145
|
const update = { $set: { services: profileItem.services } };
|
|
63
|
-
await database.collection(utils.IAP_PROFILES_COLLECTION).updateOne(
|
|
64
|
-
{ id: pronghornProps.id }, update
|
|
65
|
-
);
|
|
146
|
+
await database.collection(utils.IAP_PROFILES_COLLECTION).updateOne({ id: pronghornProps.id }, update);
|
|
66
147
|
console.log(`${serviceItem.name} removed from profileItem.services.`);
|
|
67
148
|
console.log(`Rerun the script to reinstall ${serviceItem.name}.`);
|
|
68
149
|
process.exit(0);
|
|
@@ -74,45 +155,33 @@ const main = async (command) => {
|
|
|
74
155
|
process.exit(0);
|
|
75
156
|
}
|
|
76
157
|
} else {
|
|
77
|
-
utils.
|
|
78
|
-
utils.
|
|
158
|
+
const dirname = utils.getCurrentExecutionPath();
|
|
159
|
+
utils.verifyInstallationDir(dirname, name);
|
|
79
160
|
utils.runTest();
|
|
80
161
|
if (rls.keyInYN(`Do you want to install ${name} to IAP?`)) {
|
|
81
162
|
console.log('Creating database entries...');
|
|
82
|
-
const adapter = utils.createAdapter(
|
|
83
|
-
|
|
84
|
-
|
|
163
|
+
const adapter = utils.createAdapter(pronghornProps, profileItem, sampleProperties, adapterPronghorn);
|
|
164
|
+
adapter.properties.properties = await addAuthInfo(adapter.properties.properties);
|
|
165
|
+
|
|
85
166
|
await database.collection(utils.SERVICE_CONFIGS_COLLECTION).insertOne(adapter);
|
|
86
167
|
profileItem.services.push(adapter.name);
|
|
87
168
|
const update = { $set: { services: profileItem.services } };
|
|
88
|
-
await database.collection(utils.IAP_PROFILES_COLLECTION).updateOne(
|
|
89
|
-
{ id: pronghornProps.id }, update
|
|
90
|
-
);
|
|
169
|
+
await database.collection(utils.IAP_PROFILES_COLLECTION).updateOne({ id: pronghornProps.id }, update);
|
|
91
170
|
console.log('Database entry creation complete.');
|
|
92
171
|
}
|
|
93
172
|
console.log('Exiting...');
|
|
94
173
|
process.exit(0);
|
|
95
174
|
}
|
|
96
|
-
} else if (['healthcheck', 'basicget', 'connectivity'].includes(command)) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
} else if (command === 'connectivity') {
|
|
107
|
-
const { host } = adapter.properties.properties;
|
|
108
|
-
console.log(`perform networking diagnositics to ${host}`);
|
|
109
|
-
await utils.runConnectivity(host, true);
|
|
110
|
-
process.exit(0);
|
|
111
|
-
}
|
|
112
|
-
} else {
|
|
113
|
-
console.log(`${name} not installed. Run npm \`run install:adapter\` to install.`);
|
|
114
|
-
process.exit(0);
|
|
115
|
-
}
|
|
175
|
+
} else if (['healthcheck', 'basicget', 'connectivity', 'troubleshoot'].includes(command)) {
|
|
176
|
+
await executeCommandOnInstance(command);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const main = async (command) => {
|
|
181
|
+
if (!utils.areWeUnderIAPinstallationDirectory()) {
|
|
182
|
+
executeInStandaloneMode(command); // configuration from sampleproperties.json
|
|
183
|
+
} else {
|
|
184
|
+
executeUnderIAPInstallationDirectory(command); // configuration from $IAP_HOME/properties.json
|
|
116
185
|
}
|
|
117
186
|
};
|
|
118
187
|
|
|
@@ -148,14 +217,21 @@ program
|
|
|
148
217
|
main('basicget');
|
|
149
218
|
});
|
|
150
219
|
|
|
220
|
+
program
|
|
221
|
+
.command('troubleshoot')
|
|
222
|
+
.alias('tb')
|
|
223
|
+
.description('perfom troubleshooting')
|
|
224
|
+
.action(() => {
|
|
225
|
+
main('troubleshoot');
|
|
226
|
+
});
|
|
227
|
+
|
|
151
228
|
// Allow commander to parse `process.argv`
|
|
152
229
|
program.parse(process.argv);
|
|
153
230
|
|
|
154
231
|
if (process.argv.length < 3) {
|
|
155
232
|
main();
|
|
156
233
|
}
|
|
157
|
-
|
|
158
|
-
const allowedParams = ['install', 'healthcheck', 'basicget', 'connectivity'];
|
|
234
|
+
const allowedParams = ['install', 'healthcheck', 'basicget', 'connectivity', 'troubleshoot'];
|
|
159
235
|
if (process.argv.length === 3 && !allowedParams.includes(process.argv[2])) {
|
|
160
236
|
console.log(`unknown parameter ${process.argv[2]}`);
|
|
161
237
|
console.log('try `node troubleshootingAdapter.js -h` to see allowed parameters. Exiting...');
|