@itentialopensource/adapter-bluecat_ipam 0.1.1

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.
Files changed (108) hide show
  1. package/.eslintignore +5 -0
  2. package/.eslintrc.js +19 -0
  3. package/.jshintrc +3 -0
  4. package/AUTH.md +39 -0
  5. package/BROKER.md +211 -0
  6. package/CALLS.md +3069 -0
  7. package/CHANGELOG.md +9 -0
  8. package/CODE_OF_CONDUCT.md +43 -0
  9. package/CONTRIBUTING.md +13 -0
  10. package/ENHANCE.md +69 -0
  11. package/LICENSE +201 -0
  12. package/PROPERTIES.md +681 -0
  13. package/README.md +344 -0
  14. package/SUMMARY.md +9 -0
  15. package/SYSTEMINFO.md +25 -0
  16. package/TAB1.md +15 -0
  17. package/TAB2.md +318 -0
  18. package/TROUBLESHOOT.md +56 -0
  19. package/UTILITIES.md +473 -0
  20. package/adapter.js +47832 -0
  21. package/adapterBase.js +1526 -0
  22. package/entities/.generic/action.json +214 -0
  23. package/entities/.generic/schema.json +28 -0
  24. package/entities/.system/action.json +50 -0
  25. package/entities/.system/mockdatafiles/getToken-default.json +3 -0
  26. package/entities/.system/mockdatafiles/healthcheck-default.json +3 -0
  27. package/entities/.system/schema.json +19 -0
  28. package/entities/.system/schemaTokenReq.json +53 -0
  29. package/entities/.system/schemaTokenResp.json +53 -0
  30. package/entities/ACLResources/action.json +127 -0
  31. package/entities/ACLResources/schema.json +24 -0
  32. package/entities/AdminResources/action.json +1954 -0
  33. package/entities/AdminResources/schema.json +113 -0
  34. package/entities/ConfigurationResources/action.json +106 -0
  35. package/entities/ConfigurationResources/schema.json +23 -0
  36. package/entities/DHCPClientClassResources/action.json +250 -0
  37. package/entities/DHCPClientClassResources/schema.json +30 -0
  38. package/entities/DHCPZoneResources/action.json +250 -0
  39. package/entities/DHCPZoneResources/schema.json +30 -0
  40. package/entities/DNSSECResources/action.json +147 -0
  41. package/entities/DNSSECResources/schema.json +25 -0
  42. package/entities/DeploymentOptionResources/action.json +250 -0
  43. package/entities/DeploymentOptionResources/schema.json +30 -0
  44. package/entities/DeploymentRoleResources/action.json +169 -0
  45. package/entities/DeploymentRoleResources/schema.json +26 -0
  46. package/entities/DeviceResources/action.json +352 -0
  47. package/entities/DeviceResources/schema.json +35 -0
  48. package/entities/FavoriteResources/action.json +65 -0
  49. package/entities/FavoriteResources/schema.json +21 -0
  50. package/entities/IPv4AndIPv6Resources/action.json +1964 -0
  51. package/entities/IPv4AndIPv6Resources/schema.json +113 -0
  52. package/entities/KerberosResources/action.json +393 -0
  53. package/entities/KerberosResources/schema.json +37 -0
  54. package/entities/LocationResources/action.json +209 -0
  55. package/entities/LocationResources/schema.json +28 -0
  56. package/entities/MACAddressAndClientIdentifierResources/action.json +395 -0
  57. package/entities/MACAddressAndClientIdentifierResources/schema.json +37 -0
  58. package/entities/NamingPolicyResources/action.json +476 -0
  59. package/entities/NamingPolicyResources/schema.json +41 -0
  60. package/entities/ResourceRecordResources/action.json +377 -0
  61. package/entities/ResourceRecordResources/schema.json +36 -0
  62. package/entities/ServerResources/action.json +784 -0
  63. package/entities/ServerResources/schema.json +56 -0
  64. package/entities/TFTPResources/action.json +250 -0
  65. package/entities/TFTPResources/schema.json +30 -0
  66. package/entities/TagResources/action.json +495 -0
  67. package/entities/TagResources/schema.json +42 -0
  68. package/entities/TaskResources/action.json +106 -0
  69. package/entities/TaskResources/schema.json +23 -0
  70. package/entities/VendorProfileResources/action.json +106 -0
  71. package/entities/VendorProfileResources/schema.json +23 -0
  72. package/entities/ViewAndZoneResources/action.json +660 -0
  73. package/entities/ViewAndZoneResources/schema.json +50 -0
  74. package/error.json +190 -0
  75. package/metadata.json +84 -0
  76. package/package.json +75 -0
  77. package/pronghorn.json +34480 -0
  78. package/propertiesDecorators.json +18 -0
  79. package/propertiesSchema.json +1777 -0
  80. package/report/Bluecat IPAM 9.5 v2 API.yml-OpenApi3Json.json +114720 -0
  81. package/report/adapterInfo.json +10 -0
  82. package/report/auto-adapter-openapi.json +28663 -0
  83. package/report/creationReport.json +2910 -0
  84. package/sampleProperties.json +264 -0
  85. package/test/integration/adapterTestBasicGet.js +117 -0
  86. package/test/integration/adapterTestConnectivity.js +117 -0
  87. package/test/integration/adapterTestIntegration.js +12568 -0
  88. package/test/unit/adapterBaseTestUnit.js +1628 -0
  89. package/test/unit/adapterTestUnit.js +16058 -0
  90. package/utils/adapterInfo.js +156 -0
  91. package/utils/argParser.js +44 -0
  92. package/utils/checkMigrate.js +102 -0
  93. package/utils/entitiesToDB.js +190 -0
  94. package/utils/findPath.js +74 -0
  95. package/utils/logger.js +26 -0
  96. package/utils/methodDocumentor.js +298 -0
  97. package/utils/modify.js +153 -0
  98. package/utils/mongoDbConnection.js +79 -0
  99. package/utils/mongoUtils.js +162 -0
  100. package/utils/pre-commit.sh +32 -0
  101. package/utils/removeHooks.js +20 -0
  102. package/utils/setup.js +33 -0
  103. package/utils/taskMover.js +308 -0
  104. package/utils/tbScript.js +103 -0
  105. package/utils/tbUtils.js +347 -0
  106. package/utils/testRunner.js +298 -0
  107. package/utils/troubleshootingAdapter.js +177 -0
  108. package/utils/updateAdapterConfig.js +158 -0
@@ -0,0 +1,32 @@
1
+ #!/bin/sh
2
+ # @copyright Itential, LLC 2019
3
+
4
+ #exit on any failure in the pipeline
5
+ set -e
6
+
7
+ # --------------------------------------------------
8
+ # pre-commit
9
+ # --------------------------------------------------
10
+ # Contains the standard set of tasks to runbefore
11
+ # committing changes to the repo. If any tasks fail
12
+ # then the commit will be aborted.
13
+ # --------------------------------------------------
14
+
15
+ printf "%b" "Running pre-commit hooks...\\n"
16
+
17
+ # verify testing script is stubbed and no credentials
18
+ node utils/testRunner.js -r
19
+
20
+ # update the adapter information file
21
+ node utils/adapterInfo.js
22
+ node utils/methodDocumentor.js
23
+ git add CALLS.md report/adapterInfo.json
24
+
25
+ # security audit on the code
26
+ npm audit --registry=https://registry.npmjs.org --audit-level=moderate
27
+
28
+ # lint the code
29
+ npm run lint
30
+
31
+ # test the code
32
+ npm run test
@@ -0,0 +1,20 @@
1
+ const fs = require('fs');
2
+
3
+ /**
4
+ * This script will uninstall pre-commit or pre-push hooks in case there's ever a need to
5
+ * commit/push something that has issues
6
+ */
7
+
8
+ const precommitPath = '.git/hooks/pre-commit';
9
+ const prepushPath = '.git/hooks/pre-push';
10
+ fs.unlink(precommitPath, (err) => {
11
+ if (err && err.code !== 'ENOENT') {
12
+ console.log(`${err.message}`);
13
+ }
14
+ });
15
+
16
+ fs.unlink(prepushPath, (err) => {
17
+ if (err && err.code !== 'ENOENT') {
18
+ console.log(`${err.message}`);
19
+ }
20
+ });
package/utils/setup.js ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env node
2
+ /* @copyright Itential, LLC 2019 */
3
+
4
+ const fs = require('fs');
5
+
6
+ /**
7
+ * This script will execute before an npm install command. The purpose is to
8
+ * write out some standard git hooks that will enable folks working on this
9
+ * project to benefit from the protections that the hooks provide.
10
+ */
11
+
12
+ const precommit = fs.readFileSync('utils/pre-commit.sh', 'utf8');
13
+
14
+ fs.stat('.git', (err) => {
15
+ if (err == null) {
16
+ // git repo, not an npm repo.
17
+ // add pre-commit hook if it doesn't exist
18
+ fs.stat('.git/hooks/pre-commit', (statErr) => {
19
+ if (statErr == null || statErr.code === 'ENOENT') {
20
+ fs.writeFile('.git/hooks/pre-commit', precommit, {
21
+ mode: 0o755
22
+ }, (writeErr) => {
23
+ if (writeErr) {
24
+ return console.log(writeErr.message);
25
+ }
26
+ return null;
27
+ });
28
+ } else {
29
+ console.log(statErr.message);
30
+ }
31
+ });
32
+ }
33
+ });
@@ -0,0 +1,308 @@
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
+ let shouldExitWithFailure = false;
37
+
38
+ function updatePronghorn(tasks, original, updated) {
39
+ const originalFile = require(original);
40
+ const unusedMethods = [];
41
+ const usedMethods = originalFile.methods.filter((method) => {
42
+ if (tasks.includes(method.name)) {
43
+ unusedMethods.push(method);
44
+ return false;
45
+ }
46
+ return true;
47
+ });
48
+ //write used and unused to new files
49
+ let updatedFile;
50
+ if (!fs.existsSync(updated)) {
51
+ updatedFile = { ...originalFile, methods: [], src: 'adapter-inactive.js' };
52
+ } else {
53
+ updatedFile = require(updated);
54
+ }
55
+ updatedFile.methods = updatedFile.methods.concat(unusedMethods);
56
+ originalFile.methods = usedMethods;
57
+ fs.writeFileSync(updated, JSON.stringify(updatedFile, null, 2));
58
+ fs.writeFileSync(original, JSON.stringify(originalFile, null, 2));
59
+ return 'Done';
60
+ }
61
+
62
+ function flipTaskFlag(task, pronghornPath, value) {
63
+ const pronghorn = require(pronghornPath);
64
+ const index = pronghorn.methods.findIndex((method) => method.name === task);
65
+ pronghorn.methods[index] = { ...pronghorn.methods[index], task: value };
66
+ fs.writeFileSync(pronghornPath, JSON.stringify(pronghorn, null, 2));
67
+ }
68
+
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
+ function updateAdapterJs(tasks, original, updated, adapterDir) {
90
+ if (!fs.existsSync(original)) {
91
+ throw new Error(`Original file ${original} does not exist.`);
92
+ }
93
+ let originalFile = fs.readFileSync(original, 'utf8');
94
+ let updatedFile;
95
+ if (!fs.existsSync(updated)) {
96
+ const adapterExport = require(`${adapterDir}/pronghorn.json`).export;
97
+ 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`;
98
+ } else {
99
+ updatedFile = fs.readFileSync(updated, 'utf8');
100
+ }
101
+
102
+ tasks.forEach((method) => {
103
+ //accounting for different js docs format
104
+ const comment = originalFile.indexOf(`* @function ${method}`);
105
+ const start = originalFile.slice(0, comment).lastIndexOf('/**');
106
+ if (start !== -1) {
107
+ //next comment block
108
+ const end = originalFile.indexOf('/**\n', start + 1);
109
+ let func = end === -1
110
+ ? originalFile.substring(start - 3, originalFile.lastIndexOf('}'))
111
+ : originalFile.substring(start, end);
112
+ originalFile = originalFile.replace(func, '');
113
+ func = '\n ' + func.trim() + '\n';
114
+ updatedFile = insert(updatedFile, updatedFile.lastIndexOf('}'), func);
115
+ } else {
116
+ console.log(`Task ${method} wasn't found in original file. Skipping.`);
117
+ }
118
+ });
119
+ fs.writeFileSync(original, originalFile, 'utf8');
120
+ fs.writeFileSync(updated, updatedFile, 'utf8');
121
+ return 'done';
122
+ }
123
+
124
+ //Update test file for when we deactivate a task
125
+ function deactivateTest(adapterPath, testPath, tasks) {
126
+ let unitTest = fs.readFileSync(`${adapterPath}/${testPath}`, 'utf8');
127
+ tasks.forEach((task) => {
128
+ const searchStr = `describe('#${task}`;
129
+ unitTest = unitTest.replace(searchStr, `describe.skip('#${task}`);
130
+ });
131
+ fs.writeFileSync(`${adapterPath}/${testPath}`, unitTest, 'utf8');
132
+ }
133
+
134
+ //Update test file when we activate tasks
135
+ function activateTest(adapterPath, testPath, tasks) {
136
+ let unitTest = fs.readFileSync(`${adapterPath}/${testPath}`, 'utf8');
137
+ //tasks ==> toMove
138
+ tasks.forEach((task) => {
139
+ const searchStr = `describe.skip('#${task}`;
140
+ unitTest = unitTest.replace(searchStr, `describe('#${task}`);
141
+ });
142
+ fs.writeFileSync(`${adapterPath}/${testPath}`, unitTest, 'utf8');
143
+ }
144
+
145
+ //backups are not actually being written back
146
+ function rollbackChanges(adapterPath) {
147
+ const backups = fs.readdirSync(`${adapterPath}/temp`); //this is an array of file names not the full path
148
+ const filePaths = createPaths(adapterPath);
149
+ for (let i = 0; i < backups.length; i++) {
150
+ const file = fs.readFileSync(`${adapterPath}/temp/${backups[i]}`, 'utf8'); //make sure this is getting the file
151
+ const currentFile = filePaths.find((path) => {
152
+ const index = path.split('/').length - 1;
153
+ const fileName = path.split('/')[index];
154
+ return fileName === backups[i].replace('temp-', '');
155
+ }); //returns undefined if no match
156
+
157
+ if (currentFile) {
158
+ fs.writeFileSync(currentFile, file, 'utf8');
159
+ }
160
+ }
161
+ //inactive didn't exist before script
162
+ if (!backups.includes('temp-adapter-inactive.js')) {
163
+ fs.unlinkSync(`${adapterPath}/pronghorn-inactive.json`);
164
+ fs.unlinkSync(`${adapterPath}/adapter-inactive.js`);
165
+ }
166
+ deleteBackups(adapterPath);
167
+ }
168
+
169
+ function deleteBackups(adapterPath) {
170
+ fs.rmSync(`${adapterPath}/temp`, { recursive: true });
171
+ }
172
+
173
+ function activateTasks(adapterDir, tasks) {
174
+ const toDelete = [];
175
+ const backupFiles = [];
176
+ const filePaths = createPaths(adapterDir);
177
+ try {
178
+ //take backup of each file here
179
+ if (!fs.existsSync(`${adapterDir}/temp`)) {
180
+ fs.mkdirSync(`${adapterDir}/temp`);
181
+ }
182
+ filePaths.forEach((filePath) => {
183
+ if (fs.existsSync(filePath)) {
184
+ const index = filePath.split('/').length - 1;
185
+ const backupName = `temp-${filePath.split('/')[index]}`;
186
+ backupFiles.push(`${adapterDir}/temp/${backupName}`);
187
+ fs.copyFileSync(filePath, `${adapterDir}/temp/${backupName}`);
188
+ } else {
189
+ //File doesn't exist before script
190
+ toDelete.push(filePath);
191
+ }
192
+ });
193
+ tasks = tasks.filter((task) => {
194
+ if (adapterBaseTasks.includes(task)) {
195
+ flipTaskFlag(task, `${adapterDir}/pronghorn.json`, true);
196
+ return false;
197
+ } else {
198
+ return true;
199
+ }
200
+ });
201
+ updateAdapterJs(
202
+ tasks,
203
+ `${adapterDir}/adapter-inactive.js`,
204
+ `${adapterDir}/adapter.js`,
205
+ adapterDir
206
+ );
207
+ updatePronghorn(
208
+ tasks,
209
+ `${adapterDir}/pronghorn-inactive.json`,
210
+ `${adapterDir}/pronghorn.json`
211
+ );
212
+ activateTest(
213
+ adapterDir,
214
+ '/test/integration/adapterTestIntegration.js',
215
+ tasks
216
+ );
217
+ activateTest(adapterDir, '/test/unit/adapterTestUnit.js', tasks);
218
+ return 'success';
219
+ } catch (e) {
220
+ console.log(`Error: ${e} ocurred during execution. Rolling back changes.`);
221
+ shouldExitWithFailure = true;
222
+ for (let i = 0; i < backupFiles.length; i++) {
223
+ const file = fs.readFileSync(backupFiles[i], 'utf8');
224
+ fs.writeFileSync(filePaths[i], file, 'utf8');
225
+ }
226
+ toDelete.forEach((filePath) => {
227
+ if (fs.existsSync(filePath)) {
228
+ fs.unlinkSync(filePath);
229
+ }
230
+ });
231
+ deleteBackups(adapterDir);
232
+ }
233
+ }
234
+
235
+ //moving from adapter.js to adapter-inactive.js
236
+ function deactivateTasks(adapterDir, tasks) {
237
+ const toDelete = [];
238
+ const backupFiles = [];
239
+ const filePaths = createPaths(adapterDir);
240
+ try {
241
+ //take backup of each file here
242
+ if (!fs.existsSync(`${adapterDir}/temp`)) {
243
+ fs.mkdirSync(`${adapterDir}/temp`);
244
+ }
245
+ filePaths.forEach((filePath) => {
246
+ if (fs.existsSync(filePath)) {
247
+ const index = filePath.split('/').length - 1;
248
+ const backupName = `temp-${filePath.split('/')[index]}`;
249
+ backupFiles.push(`${adapterDir}/temp/${backupName}`);
250
+ fs.copyFileSync(filePath, `${adapterDir}/temp/${backupName}`);
251
+ } else {
252
+ //File doesn't exist before script
253
+ toDelete.push(filePath);
254
+ }
255
+ });
256
+ //filter tasks for blacklisted tasks or IAP tasks
257
+ tasks = tasks.filter((task) => {
258
+ if (blacklistTasks.includes(task)) {
259
+ console.log(`${task} cannot be deactivated.`);
260
+ return false;
261
+ } else if (adapterBaseTasks.includes(task)) {
262
+ flipTaskFlag(task, `${adapterDir}/pronghorn.json`, false);
263
+ return false;
264
+ } else {
265
+ return true;
266
+ }
267
+ });
268
+ updateAdapterJs(
269
+ tasks,
270
+ `${adapterDir}/adapter.js`,
271
+ `${adapterDir}/adapter-inactive.js`,
272
+ adapterDir
273
+ );
274
+ updatePronghorn(
275
+ tasks,
276
+ `${adapterDir}/pronghorn.json`,
277
+ `${adapterDir}/pronghorn-inactive.json`
278
+ );
279
+ deactivateTest(
280
+ adapterDir,
281
+ '/test/integration/adapterTestIntegration.js',
282
+ tasks
283
+ );
284
+ deactivateTest(adapterDir, '/test/unit/adapterTestUnit.js', tasks);
285
+ return 'success';
286
+ } catch (e) {
287
+ console.log(`Error: ${e} ocurred during execution. Rolling back changes.`);
288
+ shouldExitWithFailure = true;
289
+ for (let i = 0; i < backupFiles.length; i++) {
290
+ const file = fs.readFileSync(backupFiles[i], 'utf8');
291
+ fs.writeFileSync(filePaths[i], file, 'utf8');
292
+ }
293
+ toDelete.forEach((filePath) => {
294
+ if (fs.existsSync(filePath)) {
295
+ fs.unlinkSync(filePath);
296
+ }
297
+ });
298
+ deleteBackups(adapterDir);
299
+ }
300
+ }
301
+
302
+ if (shouldExitWithFailure) {
303
+ process.exit(1);
304
+ }
305
+
306
+ module.exports = {
307
+ activateTasks, deactivateTasks, rollbackChanges, deleteBackups
308
+ };
@@ -0,0 +1,103 @@
1
+ /* @copyright Itential, LLC 2025 */
2
+
3
+ /**
4
+ * This script will determine which troubleshooting script the user is trying to run and then start the
5
+ * process to run it.
6
+ *
7
+ * This utility is executed from a script in the package.json by `node utils/tbScript.js <script>`. As a result,
8
+ * this utility is exposed and available to customers but exclusively through the CLI.
9
+ */
10
+
11
+ const program = require('commander');
12
+ const rls = require('readline-sync');
13
+ const utils = require('./tbUtils');
14
+ const sampleProperties = require('../sampleProperties.json');
15
+ const { troubleshoot } = require('./troubleshootingAdapter');
16
+
17
+ /**
18
+ * @summary tbScript is how many of the troubleshooting scripts are called from the command line (scripts in package.json)
19
+ *
20
+ * execution: node utils/tbScript.js healthcheck (or one of the other supported scripts)
21
+ */
22
+ const main = async (command, maxCalls) => {
23
+ console.info('> Using sampleProperties.json configuration');
24
+ const samProps = sampleProperties.properties;
25
+
26
+ // perform the desired action
27
+ switch (command) {
28
+ case 'connectivity': {
29
+ const { host } = samProps;
30
+ console.log(`perform networking diagnositics to ${host}`);
31
+ utils.runConnectivity(host, true);
32
+ break;
33
+ }
34
+ case 'healthcheck': {
35
+ const a = utils.getAdapterInstance({ properties: sampleProperties });
36
+ console.log(`perform healthcheck on instantiated adapter with properties: ${sampleProperties.properties}`);
37
+ await utils.healthCheck(a);
38
+ break;
39
+ }
40
+ case 'basicget': {
41
+ console.log(`perform basic get to ${samProps.host}`);
42
+ utils.runBasicGet(samProps, true, maxCalls);
43
+ break;
44
+ }
45
+ default: {
46
+ if (rls.keyInYN('Troubleshooting without IAP?')) {
47
+ await troubleshoot(samProps, true, null);
48
+ }
49
+ }
50
+ }
51
+ process.exit(0);
52
+ };
53
+
54
+ program
55
+ .command('connectivity')
56
+ .alias('c')
57
+ .description('networking diagnostics')
58
+ .action(() => {
59
+ main('connectivity');
60
+ });
61
+
62
+ program
63
+ .command('healthcheck')
64
+ .alias('hc')
65
+ .description('perfom none interative healthcheck with current setting')
66
+ .action(() => {
67
+ main('healthcheck');
68
+ });
69
+
70
+ program
71
+ .command('basicget')
72
+ .alias('bg')
73
+ .description('perfom basicget')
74
+ .option(
75
+ '--maxcalls <n>',
76
+ 'maximum number of GET calls (overrides default)',
77
+ parseInt
78
+ )
79
+ .action((cmd) => {
80
+ main('basicget', cmd.maxcalls);
81
+ });
82
+
83
+ program
84
+ .command('troubleshoot')
85
+ .alias('tb')
86
+ .description('perfom troubleshooting')
87
+ .action(() => {
88
+ main('troubleshoot');
89
+ });
90
+
91
+ // Allow commander to parse process.argv
92
+ // tbScript is called with an argument of the desired script
93
+ program.parse(process.argv);
94
+
95
+ if (process.argv.length < 3) {
96
+ main();
97
+ }
98
+ const allowedParams = ['healthcheck', 'basicget', 'connectivity', 'troubleshoot'];
99
+ if (process.argv.length === 3 && !allowedParams.includes(process.argv[2])) {
100
+ console.log(`unknown parameter ${process.argv[2]}`);
101
+ console.log('try `node troubleshootingAdapter.js -h` to see allowed parameters. Exiting...');
102
+ process.exit(0);
103
+ }