@itentialopensource/adapter-microsoft_graph 1.4.8 → 1.5.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.
Files changed (45) hide show
  1. package/.eslintrc.js +1 -0
  2. package/AUTH.md +4 -4
  3. package/BROKER.md +4 -4
  4. package/CALLS.md +9 -9
  5. package/ENHANCE.md +3 -3
  6. package/PROPERTIES.md +24 -9
  7. package/README.md +24 -23
  8. package/SUMMARY.md +2 -2
  9. package/SYSTEMINFO.md +1 -1
  10. package/TAB1.md +2 -2
  11. package/TAB2.md +17 -11
  12. package/TROUBLESHOOT.md +10 -1
  13. package/UTILITIES.md +473 -0
  14. package/adapter.js +5 -5
  15. package/adapterBase.js +52 -16
  16. package/package.json +24 -28
  17. package/pronghorn.json +15 -13
  18. package/propertiesSchema.json +68 -7
  19. package/report/adapterInfo.json +7 -7
  20. package/report/auto-adapter-openapi.json +8063 -0
  21. package/report/updateReport1748551976792.json +120 -0
  22. package/sampleProperties.json +4 -0
  23. package/test/integration/adapterTestBasicGet.js +88 -54
  24. package/test/integration/adapterTestConnectivity.js +15 -16
  25. package/test/integration/adapterTestIntegration.js +1 -38
  26. package/test/unit/adapterBaseTestUnit.js +641 -39
  27. package/test/unit/adapterTestUnit.js +17 -54
  28. package/utils/adapterInfo.js +114 -164
  29. package/utils/argParser.js +44 -0
  30. package/utils/checkMigrate.js +77 -38
  31. package/utils/entitiesToDB.js +53 -42
  32. package/utils/logger.js +26 -0
  33. package/utils/modify.js +56 -55
  34. package/utils/mongoDbConnection.js +79 -0
  35. package/utils/mongoUtils.js +162 -0
  36. package/utils/taskMover.js +31 -32
  37. package/utils/tbScript.js +36 -172
  38. package/utils/tbUtils.js +84 -226
  39. package/utils/troubleshootingAdapter.js +68 -84
  40. package/utils/updateAdapterConfig.js +158 -0
  41. package/utils/addAuth.js +0 -94
  42. package/utils/artifactize.js +0 -146
  43. package/utils/basicGet.js +0 -50
  44. package/utils/packModificationScript.js +0 -35
  45. package/utils/patches2bundledDeps.js +0 -90
@@ -9,30 +9,32 @@ const blacklistTasks = [
9
9
  ];
10
10
 
11
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'
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
34
  ];
35
35
 
36
+ let shouldExitWithFailure = false;
37
+
36
38
  function updatePronghorn(tasks, original, updated) {
37
39
  const originalFile = require(original);
38
40
  const unusedMethods = [];
@@ -57,15 +59,13 @@ function updatePronghorn(tasks, original, updated) {
57
59
  return 'Done';
58
60
  }
59
61
 
60
- function flipTaskFlag(task, pronghornPath, value)
61
- {
62
+ function flipTaskFlag(task, pronghornPath, value) {
62
63
  const pronghorn = require(pronghornPath);
63
64
  const index = pronghorn.methods.findIndex((method) => method.name === task);
64
65
  pronghorn.methods[index] = { ...pronghorn.methods[index], task: value };
65
66
  fs.writeFileSync(pronghornPath, JSON.stringify(pronghorn, null, 2));
66
67
  }
67
68
 
68
- //Return array of relevant paths given adapter directory
69
69
  function createPaths(currentAdapter) {
70
70
  const paths = [];
71
71
  const filePaths = [
@@ -86,12 +86,8 @@ function insert(str, index, value) {
86
86
  return str.substr(0, index) + value + str.substr(index);
87
87
  }
88
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
89
  function updateAdapterJs(tasks, original, updated, adapterDir) {
93
90
  if (!fs.existsSync(original)) {
94
- //could do this or just let the error ocurr lower down and catch in warpper
95
91
  throw new Error(`Original file ${original} does not exist.`);
96
92
  }
97
93
  let originalFile = fs.readFileSync(original, 'utf8');
@@ -99,7 +95,6 @@ function updateAdapterJs(tasks, original, updated, adapterDir) {
99
95
  if (!fs.existsSync(updated)) {
100
96
  const adapterExport = require(`${adapterDir}/pronghorn.json`).export;
101
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`;
102
- //To do handles backup files where og doesn't exist
103
98
  } else {
104
99
  updatedFile = fs.readFileSync(updated, 'utf8');
105
100
  }
@@ -223,6 +218,7 @@ function activateTasks(adapterDir, tasks) {
223
218
  return 'success';
224
219
  } catch (e) {
225
220
  console.log(`Error: ${e} ocurred during execution. Rolling back changes.`);
221
+ shouldExitWithFailure = true;
226
222
  for (let i = 0; i < backupFiles.length; i++) {
227
223
  const file = fs.readFileSync(backupFiles[i], 'utf8');
228
224
  fs.writeFileSync(filePaths[i], file, 'utf8');
@@ -233,7 +229,6 @@ function activateTasks(adapterDir, tasks) {
233
229
  }
234
230
  });
235
231
  deleteBackups(adapterDir);
236
- process.exit(1);
237
232
  }
238
233
  }
239
234
 
@@ -290,6 +285,7 @@ function deactivateTasks(adapterDir, tasks) {
290
285
  return 'success';
291
286
  } catch (e) {
292
287
  console.log(`Error: ${e} ocurred during execution. Rolling back changes.`);
288
+ shouldExitWithFailure = true;
293
289
  for (let i = 0; i < backupFiles.length; i++) {
294
290
  const file = fs.readFileSync(backupFiles[i], 'utf8');
295
291
  fs.writeFileSync(filePaths[i], file, 'utf8');
@@ -300,10 +296,13 @@ function deactivateTasks(adapterDir, tasks) {
300
296
  }
301
297
  });
302
298
  deleteBackups(adapterDir);
303
- process.exit(1);
304
299
  }
305
300
  }
306
301
 
302
+ if (shouldExitWithFailure) {
303
+ process.exit(1);
304
+ }
305
+
307
306
  module.exports = {
308
307
  activateTasks, deactivateTasks, rollbackChanges, deleteBackups
309
308
  };
package/utils/tbScript.js CHANGED
@@ -1,190 +1,56 @@
1
- /* eslint-disable no-console */
2
- /* eslint import/no-unresolved: warn */
3
- /* eslint global-require: warn */
1
+ /* @copyright Itential, LLC 2025 */
4
2
 
5
- // suppress eslint rule in adapter
6
- /* eslint arrow-parens: warn */
7
- /* eslint import/no-extraneous-dependencies: warn */
8
- /* eslint import/no-dynamic-require: warn */
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
+ */
9
10
 
10
11
  const program = require('commander');
11
12
  const rls = require('readline-sync');
12
- const prompts = require('prompts');
13
13
  const utils = require('./tbUtils');
14
- const basicGet = require('./basicGet');
15
- const { name } = require('../package.json');
16
14
  const sampleProperties = require('../sampleProperties.json');
17
- const adapterPronghorn = require('../pronghorn.json');
18
- const { addAuthInfo } = require('./addAuth');
19
-
20
- const { troubleshoot, offline } = require('./troubleshootingAdapter');
21
-
22
- const executeInStandaloneMode = async (command) => {
23
- console.info('\n> Executing the script outside of IAP installation directory');
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) => {
24
23
  console.info('> Using sampleProperties.json configuration');
24
+ const samProps = sampleProperties.properties;
25
+
26
+ // perform the desired action
25
27
  switch (command) {
26
- case 'install': {
27
- console.error('Not currently in IAP directory - installation not possible');
28
- break;
29
- }
30
28
  case 'connectivity': {
31
- const { host } = sampleProperties.properties;
29
+ const { host } = samProps;
32
30
  console.log(`perform networking diagnositics to ${host}`);
33
- utils.runConnectivity(host);
31
+ utils.runConnectivity(host, true);
34
32
  break;
35
33
  }
36
34
  case 'healthcheck': {
37
- const a = basicGet.getAdapterInstance({ properties: sampleProperties });
35
+ const a = utils.getAdapterInstance({ properties: sampleProperties });
36
+ console.log(`perform healthcheck on instantiated adapter with properties: ${sampleProperties.properties}`);
38
37
  await utils.healthCheck(a);
39
38
  break;
40
39
  }
41
40
  case 'basicget': {
42
- utils.runBasicGet();
41
+ console.log(`perform basic get to ${samProps.host}`);
42
+ utils.runBasicGet(samProps, true, maxCalls);
43
43
  break;
44
44
  }
45
45
  default: {
46
46
  if (rls.keyInYN('Troubleshooting without IAP?')) {
47
- await offline();
47
+ await troubleshoot(samProps, true, null);
48
48
  }
49
49
  }
50
50
  }
51
51
  process.exit(0);
52
52
  };
53
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) {
96
- process.exit(0);
97
- }
98
-
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();
130
- const filter = { id: pronghornProps.id };
131
- const profileItem = await database.collection(utils.IAP_PROFILES_COLLECTION).findOne(filter);
132
- if (!profileItem) {
133
- console.log(`Could not find IAP profile for id ${pronghornProps.id}`);
134
- process.exit(0);
135
- }
136
- if (serviceItem) {
137
- console.log(`A service by the name ${name} already exits!`);
138
- if (rls.keyInYN(`Do you want to completely remove ${name}?`)) {
139
- console.log(`Removing ${name} from db...`);
140
- await database.collection(utils.SERVICE_CONFIGS_COLLECTION).deleteOne({ model: name });
141
- console.log(`${name} removed from db.`);
142
- if (profileItem.services.includes(serviceItem.name)) {
143
- const serviceIndex = profileItem.services.indexOf(serviceItem.name);
144
- profileItem.services.splice(serviceIndex, 1);
145
- const update = { $set: { services: profileItem.services } };
146
- await database.collection(utils.IAP_PROFILES_COLLECTION).updateOne({ id: pronghornProps.id }, update);
147
- console.log(`${serviceItem.name} removed from profileItem.services.`);
148
- console.log(`Rerun the script to reinstall ${serviceItem.name}.`);
149
- process.exit(0);
150
- } else {
151
- process.exit(0);
152
- }
153
- } else {
154
- console.log('Exiting...');
155
- process.exit(0);
156
- }
157
- } else {
158
- const dirname = utils.getCurrentExecutionPath();
159
- utils.verifyInstallationDir(dirname, name);
160
- utils.runTest();
161
- if (rls.keyInYN(`Do you want to install ${name} to IAP?`)) {
162
- console.log('Creating database entries...');
163
- const adapter = utils.createAdapter(pronghornProps, profileItem, sampleProperties, adapterPronghorn);
164
- adapter.properties.properties = await addAuthInfo(adapter.properties.properties);
165
-
166
- await database.collection(utils.SERVICE_CONFIGS_COLLECTION).insertOne(adapter);
167
- profileItem.services.push(adapter.name);
168
- const update = { $set: { services: profileItem.services } };
169
- await database.collection(utils.IAP_PROFILES_COLLECTION).updateOne({ id: pronghornProps.id }, update);
170
- console.log('Database entry creation complete.');
171
- }
172
- console.log('Exiting...');
173
- process.exit(0);
174
- }
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
185
- }
186
- };
187
-
188
54
  program
189
55
  .command('connectivity')
190
56
  .alias('c')
@@ -193,14 +59,6 @@ program
193
59
  main('connectivity');
194
60
  });
195
61
 
196
- program
197
- .command('install')
198
- .alias('i')
199
- .description('install current adapter')
200
- .action(() => {
201
- main('install');
202
- });
203
-
204
62
  program
205
63
  .command('healthcheck')
206
64
  .alias('hc')
@@ -213,8 +71,13 @@ program
213
71
  .command('basicget')
214
72
  .alias('bg')
215
73
  .description('perfom basicget')
216
- .action(() => {
217
- main('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);
218
81
  });
219
82
 
220
83
  program
@@ -225,13 +88,14 @@ program
225
88
  main('troubleshoot');
226
89
  });
227
90
 
228
- // Allow commander to parse `process.argv`
91
+ // Allow commander to parse process.argv
92
+ // tbScript is called with an argument of the desired script
229
93
  program.parse(process.argv);
230
94
 
231
95
  if (process.argv.length < 3) {
232
96
  main();
233
97
  }
234
- const allowedParams = ['install', 'healthcheck', 'basicget', 'connectivity', 'troubleshoot'];
98
+ const allowedParams = ['healthcheck', 'basicget', 'connectivity', 'troubleshoot'];
235
99
  if (process.argv.length === 3 && !allowedParams.includes(process.argv[2])) {
236
100
  console.log(`unknown parameter ${process.argv[2]}`);
237
101
  console.log('try `node troubleshootingAdapter.js -h` to see allowed parameters. Exiting...');