@itentialopensource/adapter-netbox_v33 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 (182) hide show
  1. package/.eslintignore +5 -0
  2. package/.eslintrc.js +18 -0
  3. package/.gitlab/.gitkeep +0 -0
  4. package/.gitlab/issue_templates/.gitkeep +0 -0
  5. package/.gitlab/issue_templates/Default.md +17 -0
  6. package/.gitlab/issue_templates/bugReportTemplate.md +42 -0
  7. package/.gitlab/issue_templates/featureRequestTemplate.md +14 -0
  8. package/.jshintrc +3 -0
  9. package/AUTH.md +39 -0
  10. package/BROKER.md +199 -0
  11. package/CALLS.md +170 -0
  12. package/CHANGELOG.md +9 -0
  13. package/CODE_OF_CONDUCT.md +43 -0
  14. package/CONTRIBUTING.md +172 -0
  15. package/ENHANCE.md +69 -0
  16. package/LICENSE +201 -0
  17. package/PROPERTIES.md +641 -0
  18. package/README.md +337 -0
  19. package/SUMMARY.md +9 -0
  20. package/SYSTEMINFO.md +11 -0
  21. package/TROUBLESHOOT.md +47 -0
  22. package/adapter.js +74593 -0
  23. package/adapterBase.js +1787 -0
  24. package/entities/.generic/action.json +214 -0
  25. package/entities/.generic/schema.json +28 -0
  26. package/entities/.system/action.json +50 -0
  27. package/entities/.system/mockdatafiles/getToken-default.json +3 -0
  28. package/entities/.system/mockdatafiles/healthcheck-default.json +3 -0
  29. package/entities/.system/schema.json +19 -0
  30. package/entities/.system/schemaTokenReq.json +53 -0
  31. package/entities/.system/schemaTokenResp.json +53 -0
  32. package/entities/Circuits/action.json +935 -0
  33. package/entities/Circuits/mockdatafiles/getCircuitsCircuitTerminations-default.json +414 -0
  34. package/entities/Circuits/mockdatafiles/getCircuitsCircuitTypes-default.json +171 -0
  35. package/entities/Circuits/mockdatafiles/getCircuitsCircuits-default.json +475 -0
  36. package/entities/Circuits/mockdatafiles/getCircuitsProviderNetworks-default.json +349 -0
  37. package/entities/Circuits/mockdatafiles/getCircuitsProviders-default.json +960 -0
  38. package/entities/Circuits/schema.json +1780 -0
  39. package/entities/Dcim/action.json +7515 -0
  40. package/entities/Dcim/mockdatafiles/getDcimCableTerminations-default.json +77 -0
  41. package/entities/Dcim/mockdatafiles/getDcimCables-default.json +133 -0
  42. package/entities/Dcim/mockdatafiles/getDcimConsolePortTemplates-default.json +95 -0
  43. package/entities/Dcim/mockdatafiles/getDcimConsolePorts-default.json +686 -0
  44. package/entities/Dcim/mockdatafiles/getDcimConsoleServerPortTemplates-default.json +315 -0
  45. package/entities/Dcim/mockdatafiles/getDcimConsoleServerPorts-default.json +353 -0
  46. package/entities/Dcim/mockdatafiles/getDcimDeviceBayTemplates-default.json +215 -0
  47. package/entities/Dcim/mockdatafiles/getDcimDeviceBays-default.json +324 -0
  48. package/entities/Dcim/mockdatafiles/getDcimDeviceRoles-default.json +104 -0
  49. package/entities/Dcim/mockdatafiles/getDcimDeviceTypes-default.json +414 -0
  50. package/entities/Dcim/mockdatafiles/getDcimDevices-default.json +703 -0
  51. package/entities/Dcim/mockdatafiles/getDcimFrontPortTemplates-default.json +163 -0
  52. package/entities/Dcim/mockdatafiles/getDcimFrontPorts-default.json +1008 -0
  53. package/entities/Dcim/mockdatafiles/getDcimInterfaceTemplates-default.json +60 -0
  54. package/entities/Dcim/mockdatafiles/getDcimInterfaces-default.json +1224 -0
  55. package/entities/Dcim/mockdatafiles/getDcimInventoryItemRoles-default.json +480 -0
  56. package/entities/Dcim/mockdatafiles/getDcimInventoryItemTemplates-default.json +295 -0
  57. package/entities/Dcim/mockdatafiles/getDcimInventoryItems-default.json +515 -0
  58. package/entities/Dcim/mockdatafiles/getDcimLocations-default.json +248 -0
  59. package/entities/Dcim/mockdatafiles/getDcimManufacturers-default.json +407 -0
  60. package/entities/Dcim/mockdatafiles/getDcimModuleBayTemplates-default.json +115 -0
  61. package/entities/Dcim/mockdatafiles/getDcimModuleBays-default.json +641 -0
  62. package/entities/Dcim/mockdatafiles/getDcimModuleTypes-default.json +121 -0
  63. package/entities/Dcim/mockdatafiles/getDcimModules-default.json +109 -0
  64. package/entities/Dcim/mockdatafiles/getDcimPlatforms-default.json +381 -0
  65. package/entities/Dcim/mockdatafiles/getDcimPowerFeeds-default.json +567 -0
  66. package/entities/Dcim/mockdatafiles/getDcimPowerOutletTemplates-default.json +493 -0
  67. package/entities/Dcim/mockdatafiles/getDcimPowerOutlets-default.json +207 -0
  68. package/entities/Dcim/mockdatafiles/getDcimPowerPanels-default.json +111 -0
  69. package/entities/Dcim/mockdatafiles/getDcimPowerPortTemplates-default.json +283 -0
  70. package/entities/Dcim/mockdatafiles/getDcimPowerPorts-default.json +89 -0
  71. package/entities/Dcim/mockdatafiles/getDcimRackReservations-default.json +735 -0
  72. package/entities/Dcim/mockdatafiles/getDcimRackRoles-default.json +69 -0
  73. package/entities/Dcim/mockdatafiles/getDcimRacks-default.json +1019 -0
  74. package/entities/Dcim/mockdatafiles/getDcimRacksIdElevation-default.json +50 -0
  75. package/entities/Dcim/mockdatafiles/getDcimRearPortTemplates-default.json +53 -0
  76. package/entities/Dcim/mockdatafiles/getDcimRearPorts-default.json +127 -0
  77. package/entities/Dcim/mockdatafiles/getDcimRegions-default.json +79 -0
  78. package/entities/Dcim/mockdatafiles/getDcimSiteGroups-default.json +711 -0
  79. package/entities/Dcim/mockdatafiles/getDcimSites-default.json +319 -0
  80. package/entities/Dcim/mockdatafiles/getDcimVirtualChassis-default.json +248 -0
  81. package/entities/Dcim/schema.json +5339 -0
  82. package/entities/Extras/action.json +1690 -0
  83. package/entities/Extras/mockdatafiles/getExtrasConfigContexts-default.json +6348 -0
  84. package/entities/Extras/mockdatafiles/getExtrasContentTypes-default.json +21 -0
  85. package/entities/Extras/mockdatafiles/getExtrasCustomFields-default.json +466 -0
  86. package/entities/Extras/mockdatafiles/getExtrasCustomLinks-default.json +71 -0
  87. package/entities/Extras/mockdatafiles/getExtrasExportTemplates-default.json +63 -0
  88. package/entities/Extras/mockdatafiles/getExtrasImageAttachments-default.json +91 -0
  89. package/entities/Extras/mockdatafiles/getExtrasJobResults-default.json +28 -0
  90. package/entities/Extras/mockdatafiles/getExtrasJournalEntries-default.json +106 -0
  91. package/entities/Extras/mockdatafiles/getExtrasObjectChanges-default.json +99 -0
  92. package/entities/Extras/mockdatafiles/getExtrasTags-default.json +55 -0
  93. package/entities/Extras/mockdatafiles/getExtrasWebhooks-default.json +64 -0
  94. package/entities/Extras/schema.json +2939 -0
  95. package/entities/Ipam/action.json +3262 -0
  96. package/entities/Ipam/mockdatafiles/getIpamAggregates-default.json +703 -0
  97. package/entities/Ipam/mockdatafiles/getIpamAsns-default.json +465 -0
  98. package/entities/Ipam/mockdatafiles/getIpamFhrpGroupAssignments-default.json +43 -0
  99. package/entities/Ipam/mockdatafiles/getIpamFhrpGroups-default.json +148 -0
  100. package/entities/Ipam/mockdatafiles/getIpamIpAddresses-default.json +1231 -0
  101. package/entities/Ipam/mockdatafiles/getIpamIpRanges-default.json +681 -0
  102. package/entities/Ipam/mockdatafiles/getIpamIpRangesIdAvailableIps-default.json +14 -0
  103. package/entities/Ipam/mockdatafiles/getIpamL2vpnTerminations-default.json +473 -0
  104. package/entities/Ipam/mockdatafiles/getIpamL2vpns-default.json +1142 -0
  105. package/entities/Ipam/mockdatafiles/getIpamPrefixes-default.json +791 -0
  106. package/entities/Ipam/mockdatafiles/getIpamPrefixesIdAvailableIps-default.json +14 -0
  107. package/entities/Ipam/mockdatafiles/getIpamPrefixesIdAvailablePrefixes-default.json +26 -0
  108. package/entities/Ipam/mockdatafiles/getIpamRirs-default.json +211 -0
  109. package/entities/Ipam/mockdatafiles/getIpamRoles-default.json +367 -0
  110. package/entities/Ipam/mockdatafiles/getIpamRouteTargets-default.json +197 -0
  111. package/entities/Ipam/mockdatafiles/getIpamServiceTemplates-default.json +256 -0
  112. package/entities/Ipam/mockdatafiles/getIpamServices-default.json +670 -0
  113. package/entities/Ipam/mockdatafiles/getIpamVlanGroups-default.json +618 -0
  114. package/entities/Ipam/mockdatafiles/getIpamVlanGroupsIdAvailableVlans-default.json +24 -0
  115. package/entities/Ipam/mockdatafiles/getIpamVlans-default.json +324 -0
  116. package/entities/Ipam/mockdatafiles/getIpamVrfs-default.json +1122 -0
  117. package/entities/Ipam/mockdatafiles/postIpamIpRangesIdAvailableIps-default.json +176 -0
  118. package/entities/Ipam/mockdatafiles/postIpamPrefixesIdAvailableIps-default.json +645 -0
  119. package/entities/Ipam/mockdatafiles/postIpamPrefixesIdAvailablePrefixes-default.json +292 -0
  120. package/entities/Ipam/mockdatafiles/postIpamVlanGroupsIdAvailableVlans-default.json +343 -0
  121. package/entities/Ipam/schema.json +2764 -0
  122. package/entities/Status/action.json +25 -0
  123. package/entities/Status/schema.json +19 -0
  124. package/entities/Tenancy/action.json +1096 -0
  125. package/entities/Tenancy/mockdatafiles/getTenancyContactAssignments-default.json +223 -0
  126. package/entities/Tenancy/mockdatafiles/getTenancyContactGroups-default.json +87 -0
  127. package/entities/Tenancy/mockdatafiles/getTenancyContactRoles-default.json +211 -0
  128. package/entities/Tenancy/mockdatafiles/getTenancyContacts-default.json +787 -0
  129. package/entities/Tenancy/mockdatafiles/getTenancyTenantGroups-default.json +191 -0
  130. package/entities/Tenancy/mockdatafiles/getTenancyTenants-default.json +404 -0
  131. package/entities/Tenancy/schema.json +1348 -0
  132. package/entities/Users/action.json +773 -0
  133. package/entities/Users/mockdatafiles/getUsersGroups-default.json +49 -0
  134. package/entities/Users/mockdatafiles/getUsersPermissions-default.json +554 -0
  135. package/entities/Users/mockdatafiles/getUsersTokens-default.json +97 -0
  136. package/entities/Users/mockdatafiles/getUsersUsers-default.json +451 -0
  137. package/entities/Users/schema.json +1068 -0
  138. package/entities/Virtualization/action.json +914 -0
  139. package/entities/Virtualization/mockdatafiles/getVirtualizationClusterGroups-default.json +161 -0
  140. package/entities/Virtualization/mockdatafiles/getVirtualizationClusterTypes-default.json +507 -0
  141. package/entities/Virtualization/mockdatafiles/getVirtualizationClusters-default.json +255 -0
  142. package/entities/Virtualization/mockdatafiles/getVirtualizationInterfaces-default.json +1367 -0
  143. package/entities/Virtualization/mockdatafiles/getVirtualizationVirtualMachines-default.json +261 -0
  144. package/entities/Virtualization/schema.json +1559 -0
  145. package/entities/Wireless/action.json +550 -0
  146. package/entities/Wireless/mockdatafiles/getWirelessWirelessLanGroups-default.json +439 -0
  147. package/entities/Wireless/mockdatafiles/getWirelessWirelessLans-default.json +107 -0
  148. package/entities/Wireless/mockdatafiles/getWirelessWirelessLinks-default.json +739 -0
  149. package/entities/Wireless/schema.json +1090 -0
  150. package/error.json +190 -0
  151. package/package.json +86 -0
  152. package/pronghorn.json +176740 -0
  153. package/propertiesDecorators.json +14 -0
  154. package/propertiesSchema.json +1248 -0
  155. package/refs?service=git-upload-pack +0 -0
  156. package/report/Netbox_v33.json +86073 -0
  157. package/report/creationReport.json +3963 -0
  158. package/sampleProperties.json +195 -0
  159. package/test/integration/adapterTestBasicGet.js +83 -0
  160. package/test/integration/adapterTestConnectivity.js +93 -0
  161. package/test/integration/adapterTestIntegration.js +23531 -0
  162. package/test/unit/adapterBaseTestUnit.js +949 -0
  163. package/test/unit/adapterTestUnit.js +25231 -0
  164. package/utils/adapterInfo.js +206 -0
  165. package/utils/addAuth.js +94 -0
  166. package/utils/artifactize.js +146 -0
  167. package/utils/basicGet.js +50 -0
  168. package/utils/checkMigrate.js +63 -0
  169. package/utils/entitiesToDB.js +178 -0
  170. package/utils/findPath.js +74 -0
  171. package/utils/methodDocumentor.js +225 -0
  172. package/utils/modify.js +154 -0
  173. package/utils/packModificationScript.js +35 -0
  174. package/utils/patches2bundledDeps.js +90 -0
  175. package/utils/pre-commit.sh +32 -0
  176. package/utils/removeHooks.js +20 -0
  177. package/utils/setup.js +33 -0
  178. package/utils/tbScript.js +246 -0
  179. package/utils/tbUtils.js +490 -0
  180. package/utils/testRunner.js +298 -0
  181. package/utils/troubleshootingAdapter.js +195 -0
  182. package/workflows/README.md +3 -0
@@ -0,0 +1,298 @@
1
+ #!/usr/bin/env node
2
+ /* @copyright Itential, LLC 2019 */
3
+
4
+ const fs = require('fs-extra');
5
+ const rl = require('readline-sync');
6
+ const execute = require('child_process').exec;
7
+
8
+ /**
9
+ * This script will determine the type of integration test to run
10
+ * based on input. If other information is needed, it will solicit
11
+ * that input and then edit the integration test accordingly.
12
+ */
13
+
14
+ let stub = true;
15
+ let isRapidFail = false;
16
+ let isSaveMockData = false;
17
+ let host = 'replace.hostorip.here';
18
+ let username = 'username';
19
+ let password = 'password';
20
+ let protocol = 'http';
21
+ let port = 80;
22
+ let sslenable = false;
23
+ let sslinvalid = false;
24
+ const dstub = true;
25
+ const disRapidFail = false;
26
+ const disSaveMockData = false;
27
+ const dhost = 'replace.hostorip.here';
28
+ const dusername = 'username';
29
+ const dpassword = 'password';
30
+ const dprotocol = 'http';
31
+ const dport = 80;
32
+ const dsslenable = false;
33
+ const dsslinvalid = false;
34
+
35
+ let stderror = false;
36
+ let running = false;
37
+
38
+ /**
39
+ * Updates the integration test file with the proper vars
40
+ */
41
+ function replaceTestVars(test) {
42
+ if (!fs.existsSync(test)) {
43
+ console.log(`Could not find ${test}`);
44
+ return 'error';
45
+ }
46
+
47
+ let intTest = fs.readFileSync(test, 'utf8');
48
+
49
+ // replace stub variable but check if it exists first
50
+ let sindex = intTest.indexOf('samProps.stub');
51
+ let eindex = intTest.indexOf(';', sindex);
52
+ let replStr = intTest.substring(sindex, eindex + 1);
53
+ if (sindex > -1) {
54
+ intTest = intTest.replace(replStr, `samProps.stub = ${stub};`);
55
+ }
56
+
57
+ // replace isRapidFail variable but check if it exists first
58
+ sindex = intTest.indexOf('const isRapidFail');
59
+ eindex = intTest.indexOf(';', sindex);
60
+ replStr = intTest.substring(sindex, eindex + 1);
61
+ if (sindex > -1) {
62
+ intTest = intTest.replace(replStr, `const isRapidFail = ${isRapidFail};`);
63
+ }
64
+
65
+ // replace isSaveMockData variable but check if it exists first
66
+ sindex = intTest.indexOf('const isSaveMockData');
67
+ eindex = intTest.indexOf(';', sindex);
68
+ replStr = intTest.substring(sindex, eindex + 1);
69
+ if (sindex > -1) {
70
+ intTest = intTest.replace(replStr, `const isSaveMockData = ${isSaveMockData};`);
71
+ }
72
+
73
+ // replace host variable
74
+ sindex = intTest.indexOf('samProps.host');
75
+ eindex = intTest.indexOf(';', sindex);
76
+ replStr = intTest.substring(sindex, eindex + 1);
77
+ intTest = intTest.replace(replStr, `samProps.host = '${host}';`);
78
+
79
+ // replace username variable
80
+ sindex = intTest.indexOf('samProps.authentication.username');
81
+ eindex = intTest.indexOf(';', sindex);
82
+ replStr = intTest.substring(sindex, eindex + 1);
83
+ intTest = intTest.replace(replStr, `samProps.authentication.username = '${username}';`);
84
+
85
+ // replace password variable
86
+ sindex = intTest.indexOf('samProps.authentication.password');
87
+ eindex = intTest.indexOf(';', sindex);
88
+ replStr = intTest.substring(sindex, eindex + 1);
89
+ intTest = intTest.replace(replStr, `samProps.authentication.password = '${password}';`);
90
+
91
+ // replace protocol variable
92
+ sindex = intTest.indexOf('samProps.protocol');
93
+ eindex = intTest.indexOf(';', sindex);
94
+ replStr = intTest.substring(sindex, eindex + 1);
95
+ intTest = intTest.replace(replStr, `samProps.protocol = '${protocol}';`);
96
+
97
+ // replace port variable
98
+ sindex = intTest.indexOf('samProps.port');
99
+ eindex = intTest.indexOf(';', sindex);
100
+ replStr = intTest.substring(sindex, eindex + 1);
101
+ intTest = intTest.replace(replStr, `samProps.port = ${port};`);
102
+
103
+ // replace sslenable variable
104
+ sindex = intTest.indexOf('samProps.ssl.enabled');
105
+ eindex = intTest.indexOf(';', sindex);
106
+ replStr = intTest.substring(sindex, eindex + 1);
107
+ intTest = intTest.replace(replStr, `samProps.ssl.enabled = ${sslenable};`);
108
+
109
+ // replace sslinvalid variable
110
+ sindex = intTest.indexOf('samProps.ssl.accept_invalid_cert');
111
+ eindex = intTest.indexOf(';', sindex);
112
+ replStr = intTest.substring(sindex, eindex + 1);
113
+ intTest = intTest.replace(replStr, `samProps.ssl.accept_invalid_cert = ${sslinvalid};`);
114
+
115
+ console.log(`Updates to ${test} complete`);
116
+ fs.writeFileSync(test, intTest);
117
+ return 'success';
118
+ }
119
+
120
+ /**
121
+ * Updates the integration test file and runs the script
122
+ */
123
+ function runTest(callback) {
124
+ replaceTestVars('test/integration/adapterTestIntegration.js');
125
+
126
+ let cmdPath = 'npm run test:integration';
127
+ console.log('\nRUNNING INTEGRATION TESTS - THIS WILL TAKE SOME TIME AND WILL NOT PRINT UNTIL TEST IS COMPLETE!\n');
128
+ if (stderror) {
129
+ console.log('\nNOTE: standard error from tests is included - unless test failed, these may be expected errors:\n');
130
+ cmdPath += ' 2>&1';
131
+ } else {
132
+ console.log('stderr not shown');
133
+ }
134
+
135
+ return execute(cmdPath, (cerror, stdout) => {
136
+ console.log('executed tests:\n');
137
+ console.log(`${stdout}\n`);
138
+ if (cerror) {
139
+ console.log('\x1b[31m%s\x1b[0m', '\nexec error:\n');
140
+ console.log('\x1b[31m%s\x1b[0m', `${cerror}\n`);
141
+ }
142
+ // reset the defaults
143
+ stub = dstub;
144
+ isRapidFail = disRapidFail;
145
+ isSaveMockData = disSaveMockData;
146
+ host = dhost;
147
+ username = dusername;
148
+ password = dpassword;
149
+ protocol = dprotocol;
150
+ port = dport;
151
+ sslenable = dsslenable;
152
+ sslinvalid = dsslinvalid;
153
+ replaceTestVars('test/integration/adapterTestIntegration.js');
154
+ return callback('done');
155
+ });
156
+ }
157
+
158
+ /**
159
+ * Updates the unit test file and runs the script
160
+ */
161
+ function runUnitTest(callback) {
162
+ let cmdPath = 'npm run test:unit';
163
+ console.log('\nRUNNING UNIT TESTS - THIS WILL TAKE SOME TIME AND WILL NOT PRINT UNTIL TEST IS COMPLETE!\n');
164
+
165
+ if (stderror) {
166
+ console.log('\nNOTE: standard error from tests is included- unless test failed, these may be expected errors:\n');
167
+ cmdPath += ' 2>&1';
168
+ } else {
169
+ console.log('stderr not shown');
170
+ }
171
+
172
+ return execute(cmdPath, (cerror, stdout) => {
173
+ console.log('executed tests:\n');
174
+ console.log(`${stdout}\n`);
175
+
176
+ if (cerror) {
177
+ console.log('\x1b[31m%s\x1b[0m', '\nexec error:\n');
178
+ console.log('\x1b[31m%s\x1b[0m', `${cerror}\n`);
179
+ }
180
+
181
+ return callback('done');
182
+ });
183
+ }
184
+
185
+ // print process.argv
186
+ const args = process.argv.slice(2);
187
+
188
+ // go through the arguments that where provided
189
+ for (let a = 0; a < args.length; a += 1) {
190
+ if (args[a].toUpperCase() === '-H' || args[a].toUpperCase() === '--HELP') {
191
+ let message = '\nThis tool is used to make it easier to run integration tests.\n';
192
+ message += '\n';
193
+ message += 'Options:\n';
194
+ message += '-h, --help: Prints this message\n';
195
+ message += '-f, --failfast: Fail the test when the first test fails\n';
196
+ message += '-m, --mockdata: Update mock data files with the results from testing (only if running integrated)\n';
197
+ message += '-r, --reset: Resets the variables back to stub settings and removes credentials\n';
198
+ message += '-s, --stderror: Displays the standard error from the run, this can have data even if all the tests pass\n';
199
+ message += '-u, --unit: Runs just the unit tests as well\n';
200
+ console.log(message);
201
+ running = true;
202
+ }
203
+
204
+ if (args[a].toUpperCase() === '-F' || args[a].toUpperCase() === '--FAILFAST') {
205
+ isRapidFail = true;
206
+ }
207
+ if (args[a].toUpperCase() === '-M' || args[a].toUpperCase() === '--MOCKDATA') {
208
+ isSaveMockData = true;
209
+ }
210
+ if (args[a].toUpperCase() === '-R' || args[a].toUpperCase() === '--RESET') {
211
+ running = true;
212
+ replaceTestVars('test/integration/adapterTestIntegration.js');
213
+ replaceTestVars('test/unit/adapterTestUnit.js');
214
+ console.log('test reset complete');
215
+ }
216
+ if (args[a].toUpperCase() === '-S' || args[a].toUpperCase() === '--STDERROR') {
217
+ stderror = true;
218
+ }
219
+ if (args[a].toUpperCase() === '-U' || args[a].toUpperCase() === '--UNIT') {
220
+ running = true;
221
+ runUnitTest((status) => {
222
+ console.log(status);
223
+ process.exit(1);
224
+ });
225
+ }
226
+ }
227
+
228
+ if (!running) {
229
+ // how are we running the test?
230
+ let answer = rl.question('\nDo you want to run the integration test integrated with the other system? (no): ');
231
+ if (answer && (answer.toLowerCase() === 'yes' || answer.toLowerCase() === 'y')) {
232
+ stub = false;
233
+ console.log('Need more information about the integration!');
234
+ } else {
235
+ running = true;
236
+ runTest((status) => {
237
+ console.log(status);
238
+ process.exit(1);
239
+ });
240
+ }
241
+
242
+ if (!running) {
243
+ // how are we running the test?
244
+ answer = rl.question('\nWhat is the dns or ip of the system you want to test with? (localhost): ');
245
+ if (answer) {
246
+ host = answer;
247
+ } else {
248
+ host = 'localhost';
249
+ }
250
+
251
+ // need the username to authenticate with
252
+ answer = rl.question('\nWhat is the username to authenticate, if no authentication just return? (username): ');
253
+ if (answer) {
254
+ username = answer;
255
+ }
256
+
257
+ // need the password to authenticate with
258
+ answer = rl.question('\nWhat is the password to authenticate, if no authentication just return? (password): ', { hideEchoBack: true });
259
+ if (answer) {
260
+ password = answer;
261
+ }
262
+
263
+ // need the protocol used with other system
264
+ answer = rl.question('\nWhat is the protocol used to communicate with the system? (http): ');
265
+ if (answer) {
266
+ protocol = answer;
267
+ }
268
+
269
+ if (protocol === 'https') {
270
+ // if protocol is https, set default port to 443
271
+ port = 443;
272
+ // need the port used with other system
273
+ answer = rl.question('\nWhat is the port used to communicate with the system? (443): ');
274
+ port = 443; // update default answer to 443 for https
275
+ if (answer) {
276
+ port = Number(answer);
277
+ }
278
+
279
+ // turn on ssl and accept invalid certs
280
+ sslenable = true;
281
+ sslinvalid = true;
282
+ runTest((status) => {
283
+ console.log(status);
284
+ process.exit(1);
285
+ });
286
+ } else {
287
+ // need the port used with other system
288
+ answer = rl.question('\nWhat is the port used to communicate with the system? (80): ');
289
+ if (answer) {
290
+ port = Number(answer);
291
+ }
292
+ runTest((status) => {
293
+ console.log(status);
294
+ process.exit(1);
295
+ });
296
+ }
297
+ }
298
+ }
@@ -0,0 +1,195 @@
1
+ /* @copyright Itential, LLC 2020 */
2
+ /* eslint global-require: warn */
3
+ /* eslint no-console: warn */
4
+ /* eslint import/no-unresolved: warn */
5
+ /* eslint import/no-dynamic-require: warn */
6
+
7
+ const path = require('path');
8
+ const rls = require('readline-sync');
9
+ const fs = require('fs-extra');
10
+
11
+ const utils = require(path.join(__dirname, 'tbUtils'));
12
+ const basicGet = require(path.join(__dirname, 'basicGet'));
13
+ const { name } = require(path.join(__dirname, '..', 'package.json'));
14
+ const sampleProperties = require(path.join(__dirname, '..', 'sampleProperties.json'));
15
+
16
+ // send interactive questions and collection answers
17
+ // return updated connection object
18
+ const collectAnswersSync = (questions, props) => {
19
+ const answers = [];
20
+ questions.forEach((q) => {
21
+ const answer = rls.question(q);
22
+ answers.push(answer);
23
+ });
24
+ return utils.getNewProps(answers, props);
25
+ };
26
+
27
+ // change object into array of questions
28
+ const confirm = (props) => {
29
+ const questions = Object.keys(props).map((key) => `${key}: (${props[key]}) `);
30
+ return collectAnswersSync(questions, props);
31
+ };
32
+
33
+ // allow user to change auth_method
34
+ const confirmAuthOptions = (authentication) => {
35
+ const authOptions = ['basic user_password', 'request_token', 'static_token', 'no_authentication'];
36
+ const displayAuthOptions = utils.getDisplayAuthOptions(authentication.auth_method, authOptions);
37
+ const index = rls.keyInSelect(displayAuthOptions, 'Which authentication?');
38
+ if (index === -1) {
39
+ return authentication.auth_method;
40
+ }
41
+ console.log(`${authOptions[index]} is selected.`);
42
+ return authOptions[index];
43
+ };
44
+
45
+ // helper function to update auth properties
46
+ const confirmAndUpdate = (auth, config) => {
47
+ const newAuth = confirm(auth);
48
+ return utils.updateAuth(newAuth, auth, config);
49
+ };
50
+
51
+ // extract basic auth properties
52
+ const updateBasicAuth = (config, authentication) => {
53
+ const auth = {
54
+ username: authentication.username,
55
+ password: authentication.password
56
+ };
57
+ return confirmAndUpdate(auth, config);
58
+ };
59
+
60
+ // extract static auth properties
61
+ const updateStaticAuth = (config, authentication) => {
62
+ const auth = {
63
+ token: authentication.token,
64
+ auth_field: authentication.auth_field,
65
+ auth_field_format: authentication.auth_field_format
66
+ };
67
+ return confirmAndUpdate(auth, config);
68
+ };
69
+
70
+ // troubleshooting connection and healthcheck endpoint setting of adapter
71
+ const VerifyHealthCheckEndpoint = (serviceItem, props, scriptFlag) => {
72
+ // Updates connectivity params and runs connectivity
73
+ let connConfig;
74
+ const result = {};
75
+ if (scriptFlag) {
76
+ const connection = utils.getConnection(serviceItem.properties);
77
+ const newConnection = confirm(connection);
78
+ utils.runConnectivity(newConnection.host, scriptFlag);
79
+ connConfig = utils.updateNewConnection(serviceItem, newConnection);
80
+ } else {
81
+ let { properties: { properties: { host } } } = serviceItem;
82
+ if (props.connProps) {
83
+ connConfig = utils.updateNewConnection(serviceItem, props.connProps);
84
+ host = connConfig.properties.properties.host;
85
+ } else {
86
+ connConfig = serviceItem;
87
+ }
88
+ result.connectivity = utils.runConnectivity(host, scriptFlag);
89
+ }
90
+ // Updates the healthcheck endpoing
91
+ const healthcheck = require('../entities/.system/action.json');
92
+ const healthCheckEndpoint = utils.getHealthCheckEndpoint(healthcheck);
93
+ let newHealthCheckEndpoint = healthCheckEndpoint;
94
+ if (scriptFlag) {
95
+ newHealthCheckEndpoint = confirm(healthCheckEndpoint);
96
+ utils.getHealthCheckEndpointURL(newHealthCheckEndpoint, connConfig);
97
+ } else if (props.healthCheckEndpoint) {
98
+ newHealthCheckEndpoint = props.healthCheckEndpoint;
99
+ }
100
+ // Updates the authorization params
101
+ const { authentication } = connConfig.properties.properties;
102
+ let updatedAdapter = connConfig;
103
+ if (scriptFlag) {
104
+ authentication.auth_method = confirmAuthOptions(authentication);
105
+ if (authentication.auth_method === 'basic user_password') {
106
+ updatedAdapter = updateBasicAuth(connConfig, authentication);
107
+ } else if (authentication.auth_method === 'static_token') {
108
+ updatedAdapter = updateStaticAuth(connConfig, authentication);
109
+ } else if (authentication.auth_method === 'request_token') {
110
+ console.log('current troubleshooting script does not support updating request_token authentication');
111
+ }
112
+ } else if (props.auth) {
113
+ updatedAdapter = utils.updateAuth(props.auth, authentication, connConfig);
114
+ }
115
+ // Writes the new healthcheck endpoint into action.json
116
+ utils.updateHealthCheckEndpoint(newHealthCheckEndpoint, healthCheckEndpoint, healthcheck);
117
+ return { result, updatedAdapter };
118
+ };
119
+
120
+ const offline = async () => {
121
+ console.log('Start offline troubleshooting');
122
+ const { updatedAdapter } = VerifyHealthCheckEndpoint({ properties: sampleProperties }, {}, true);
123
+ const a = basicGet.getAdapterInstance(updatedAdapter);
124
+ const res = await utils.healthCheck(a);
125
+ if (!res) {
126
+ console.log('run `npm run troubleshoot` again to update settings');
127
+ process.exit(0);
128
+ }
129
+ console.log('Save changes to sampleProperties.json');
130
+ await fs.writeFile('sampleProperties.json', JSON.stringify(updatedAdapter.properties, null, 2));
131
+ if (rls.keyInYN('Test with more GET request')) {
132
+ await utils.runBasicGet(true);
133
+ }
134
+ };
135
+
136
+ const troubleshoot = async (props, scriptFlag, persistFlag, adapter) => {
137
+ let serviceItem;
138
+ if (adapter && adapter.allProps) {
139
+ serviceItem = { properties: { properties: adapter.allProps } };
140
+ }
141
+ if (adapter && adapter.properties && adapter.properties.properties) {
142
+ serviceItem = adapter.properties;
143
+ }
144
+ if (serviceItem) {
145
+ if (!scriptFlag || rls.keyInYN(`Start verifying the connection and authentication properties for ${name}?`)) {
146
+ const { result, updatedAdapter } = VerifyHealthCheckEndpoint(serviceItem, props, scriptFlag);
147
+ let a;
148
+ if (scriptFlag) {
149
+ a = basicGet.getAdapterInstance(updatedAdapter);
150
+ } else {
151
+ a = adapter;
152
+ }
153
+ const healthRes = await utils.healthCheck(a);
154
+ result.healthCheck = healthRes;
155
+ if (scriptFlag && !healthRes) {
156
+ console.log('run `npm run troubleshoot` again to update settings');
157
+ process.exit(0);
158
+ }
159
+
160
+ if (persistFlag && healthRes) {
161
+ const { database } = await utils.getIAPDatabaseConnection();
162
+ const update = { $set: { properties: updatedAdapter.properties } };
163
+ await database.collection(utils.SERVICE_CONFIGS_COLLECTION).updateOne(
164
+ { model: name }, update
165
+ );
166
+ if (scriptFlag) {
167
+ console.log(`${name} updated.`);
168
+ }
169
+ }
170
+ if (scriptFlag) {
171
+ if (rls.keyInYN('Test with more GET request')) {
172
+ await utils.runBasicGet(scriptFlag);
173
+ process.exit(0);
174
+ } else {
175
+ console.log('Exiting');
176
+ process.exit(0);
177
+ }
178
+ } else {
179
+ result.basicGet = await utils.runBasicGet(scriptFlag);
180
+ return result;
181
+ }
182
+ } else {
183
+ console.log('You can update healthCheckEndpoint in ./entities/.system/action.json');
184
+ console.log('You can update authentication credientials under Settings/Services');
185
+ console.log('Exiting');
186
+ process.exit(0);
187
+ }
188
+ } else {
189
+ console.log(`${name} not installed`);
190
+ console.log('run `npm run install:adapter` to install current adapter to IAP first. Exiting...');
191
+ }
192
+ return null;
193
+ };
194
+
195
+ module.exports = { troubleshoot, offline };
@@ -0,0 +1,3 @@
1
+ # Adapter Workflows
2
+
3
+ This directory contains workflows that support the adapter use cases. These workflows can be imported into IAP. If the adapter is installed using App-Artifact the workflows should be automatically imported.