@itentialopensource/adapter-microsoft_graph 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. package/.eslintignore +6 -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 +0 -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 +18798 -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/Applications/action.json +127 -0
  33. package/entities/Applications/schema.json +35 -0
  34. package/entities/AzureADDevice/action.json +106 -0
  35. package/entities/AzureADDevice/schema.json +45 -0
  36. package/entities/Batch/action.json +24 -0
  37. package/entities/Batch/schema.json +19 -0
  38. package/entities/CaseCreation/action.json +249 -0
  39. package/entities/CaseCreation/schema.json +30 -0
  40. package/entities/Catalog/action.json +25 -0
  41. package/entities/Catalog/schema.json +19 -0
  42. package/entities/ConnectionSetup/action.json +148 -0
  43. package/entities/ConnectionSetup/schema.json +25 -0
  44. package/entities/ContentSync/action.json +65 -0
  45. package/entities/ContentSync/schema.json +21 -0
  46. package/entities/CreateDSR/action.json +45 -0
  47. package/entities/CreateDSR/schema.json +20 -0
  48. package/entities/Deployment/action.json +106 -0
  49. package/entities/Deployment/schema.json +34 -0
  50. package/entities/DeploymentAudience/action.json +66 -0
  51. package/entities/DeploymentAudience/schema.json +32 -0
  52. package/entities/Events/action.json +108 -0
  53. package/entities/Events/schema.json +34 -0
  54. package/entities/Files/action.json +108 -0
  55. package/entities/Files/schema.json +23 -0
  56. package/entities/Groups/action.json +25 -0
  57. package/entities/Groups/schema.json +19 -0
  58. package/entities/IdentitySync/action.json +105 -0
  59. package/entities/IdentitySync/schema.json +23 -0
  60. package/entities/Insights/action.json +46 -0
  61. package/entities/Insights/schema.json +20 -0
  62. package/entities/LabelManagement/action.json +106 -0
  63. package/entities/LabelManagement/schema.json +23 -0
  64. package/entities/Mail/action.json +212 -0
  65. package/entities/Mail/schema.json +72 -0
  66. package/entities/Memberships/action.json +167 -0
  67. package/entities/Memberships/schema.json +70 -0
  68. package/entities/Misc/action.json +66 -0
  69. package/entities/Misc/schema.json +21 -0
  70. package/entities/Notebooks/action.json +107 -0
  71. package/entities/Notebooks/schema.json +34 -0
  72. package/entities/OpenExtensions/action.json +65 -0
  73. package/entities/OpenExtensions/schema.json +54 -0
  74. package/entities/People/action.json +46 -0
  75. package/entities/People/schema.json +31 -0
  76. package/entities/SchemaExtensions/action.json +65 -0
  77. package/entities/SchemaExtensions/schema.json +32 -0
  78. package/entities/Search/action.json +24 -0
  79. package/entities/Search/schema.json +19 -0
  80. package/entities/Security/action.json +151 -0
  81. package/entities/Security/schema.json +58 -0
  82. package/entities/SharePoint/action.json +214 -0
  83. package/entities/SharePoint/schema.json +39 -0
  84. package/entities/Subscriptions/action.json +65 -0
  85. package/entities/Subscriptions/schema.json +32 -0
  86. package/entities/TasksPlanner/action.json +272 -0
  87. package/entities/TasksPlanner/schema.json +86 -0
  88. package/entities/TasksTodo/action.json +187 -0
  89. package/entities/TasksTodo/schema.json +49 -0
  90. package/entities/Teams/action.json +519 -0
  91. package/entities/Teams/schema.json +120 -0
  92. package/entities/TrackDSRStatus/action.json +108 -0
  93. package/entities/TrackDSRStatus/schema.json +23 -0
  94. package/entities/TriggerEventForExistingLabel/action.json +108 -0
  95. package/entities/TriggerEventForExistingLabel/schema.json +23 -0
  96. package/entities/Users/action.json +213 -0
  97. package/entities/Users/schema.json +50 -0
  98. package/entities/WorkflowAutomation/action.json +249 -0
  99. package/entities/WorkflowAutomation/schema.json +30 -0
  100. package/error.json +190 -0
  101. package/package.json +87 -0
  102. package/pronghorn.json +8654 -0
  103. package/propertiesDecorators.json +14 -0
  104. package/propertiesSchema.json +1248 -0
  105. package/refs?service=git-upload-pack +0 -0
  106. package/report/creationReport.json +1715 -0
  107. package/report/graph.json +14709 -0
  108. package/sampleProperties.json +195 -0
  109. package/test/integration/adapterTestBasicGet.js +83 -0
  110. package/test/integration/adapterTestConnectivity.js +93 -0
  111. package/test/integration/adapterTestIntegration.js +6059 -0
  112. package/test/unit/adapterBaseTestUnit.js +949 -0
  113. package/test/unit/adapterTestUnit.js +7492 -0
  114. package/utils/adapterInfo.js +206 -0
  115. package/utils/addAuth.js +94 -0
  116. package/utils/artifactize.js +146 -0
  117. package/utils/basicGet.js +50 -0
  118. package/utils/checkMigrate.js +63 -0
  119. package/utils/entitiesToDB.js +178 -0
  120. package/utils/findPath.js +74 -0
  121. package/utils/methodDocumentor.js +225 -0
  122. package/utils/modify.js +154 -0
  123. package/utils/packModificationScript.js +35 -0
  124. package/utils/patches2bundledDeps.js +90 -0
  125. package/utils/pre-commit.sh +32 -0
  126. package/utils/removeHooks.js +20 -0
  127. package/utils/setup.js +33 -0
  128. package/utils/tbScript.js +246 -0
  129. package/utils/tbUtils.js +490 -0
  130. package/utils/testRunner.js +298 -0
  131. package/utils/troubleshootingAdapter.js +195 -0
  132. 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.