@itentialopensource/adapter-oracle_cloud 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/AUTH.md +39 -0
  2. package/BROKER.md +199 -0
  3. package/CALLS.md +859 -0
  4. package/CHANGELOG.md +17 -2
  5. package/CODE_OF_CONDUCT.md +12 -17
  6. package/CONTRIBUTING.md +3 -148
  7. package/ENHANCE.md +69 -0
  8. package/PROPERTIES.md +641 -0
  9. package/README.md +235 -576
  10. package/SUMMARY.md +9 -0
  11. package/SYSTEMINFO.md +11 -0
  12. package/TROUBLESHOOT.md +47 -0
  13. package/adapter.js +371 -270
  14. package/adapterBase.js +843 -419
  15. package/changelogs/changelog.md +16 -0
  16. package/entities/.generic/action.json +105 -0
  17. package/entities/.generic/schema.json +6 -1
  18. package/error.json +6 -0
  19. package/metadata.json +49 -0
  20. package/package.json +24 -24
  21. package/pronghorn.json +680 -100
  22. package/propertiesDecorators.json +14 -0
  23. package/propertiesSchema.json +830 -9
  24. package/refs?service=git-upload-pack +0 -0
  25. package/report/adapter-openapi.json +11867 -0
  26. package/report/adapter-openapi.yaml +11966 -0
  27. package/report/adapterInfo.json +10 -0
  28. package/report/updateReport1653049581192.json +120 -0
  29. package/report/updateReport1691507422430.json +120 -0
  30. package/report/updateReport1692202455354.json +120 -0
  31. package/report/updateReport1694460824360.json +120 -0
  32. package/report/updateReport1698420559437.json +120 -0
  33. package/sampleProperties.json +153 -3
  34. package/test/integration/adapterTestBasicGet.js +3 -5
  35. package/test/integration/adapterTestConnectivity.js +91 -42
  36. package/test/integration/adapterTestIntegration.js +176 -127
  37. package/test/unit/adapterBaseTestUnit.js +388 -308
  38. package/test/unit/adapterTestUnit.js +643 -402
  39. package/utils/adapterInfo.js +206 -0
  40. package/utils/addAuth.js +1 -1
  41. package/utils/artifactize.js +1 -1
  42. package/utils/checkMigrate.js +1 -1
  43. package/utils/entitiesToDB.js +12 -57
  44. package/utils/findPath.js +1 -1
  45. package/utils/methodDocumentor.js +273 -0
  46. package/utils/modify.js +13 -15
  47. package/utils/packModificationScript.js +1 -1
  48. package/utils/patches2bundledDeps.js +90 -0
  49. package/utils/pre-commit.sh +5 -0
  50. package/utils/taskMover.js +309 -0
  51. package/utils/tbScript.js +123 -53
  52. package/utils/tbUtils.js +92 -48
  53. package/utils/testRunner.js +17 -17
  54. package/utils/troubleshootingAdapter.js +9 -6
  55. package/workflows/README.md +0 -3
package/utils/tbScript.js CHANGED
@@ -1,4 +1,4 @@
1
- /* eslint no-console: warn */
1
+ /* eslint-disable no-console */
2
2
  /* eslint import/no-unresolved: warn */
3
3
  /* eslint global-require: warn */
4
4
 
@@ -7,9 +7,9 @@
7
7
  /* eslint import/no-extraneous-dependencies: warn */
8
8
  /* eslint import/no-dynamic-require: warn */
9
9
 
10
- const path = require('path');
11
10
  const program = require('commander');
12
11
  const rls = require('readline-sync');
12
+ const prompts = require('prompts');
13
13
  const utils = require('./tbUtils');
14
14
  const basicGet = require('./basicGet');
15
15
  const { name } = require('../package.json');
@@ -19,35 +19,113 @@ const { addAuthInfo } = require('./addAuth');
19
19
 
20
20
  const { troubleshoot, offline } = require('./troubleshootingAdapter');
21
21
 
22
- const main = async (command) => {
23
- const dirname = utils.getDirname();
24
- const iapDir = path.join(dirname, '../../../../');
25
- if (!utils.withinIAP(iapDir)) {
26
- if (command === 'install') {
27
- console.log('Not currently in IAP directory - installation not possible');
28
- process.exit(0);
29
- } else if (command === 'connectivity') {
22
+ const executeInStandaloneMode = async (command) => {
23
+ console.info('\n> Executing the script outside of IAP installation directory');
24
+ console.info('> Using sampleProperties.json configuration');
25
+ switch (command) {
26
+ case 'install': {
27
+ console.error('Not currently in IAP directory - installation not possible');
28
+ break;
29
+ }
30
+ case 'connectivity': {
30
31
  const { host } = sampleProperties.properties;
31
32
  console.log(`perform networking diagnositics to ${host}`);
32
- await utils.runConnectivity(host);
33
- process.exit(0);
34
- } else if (command === 'healthcheck') {
33
+ utils.runConnectivity(host);
34
+ break;
35
+ }
36
+ case 'healthcheck': {
35
37
  const a = basicGet.getAdapterInstance({ properties: sampleProperties });
36
38
  await utils.healthCheck(a);
37
- process.exit(0);
38
- } else if (command === 'basicget') {
39
- await utils.runBasicGet();
40
- process.exit(0);
39
+ break;
41
40
  }
42
- if (rls.keyInYN('Troubleshooting without IAP?')) {
43
- await offline();
41
+ case 'basicget': {
42
+ utils.runBasicGet();
43
+ break;
44
44
  }
45
+ default: {
46
+ if (rls.keyInYN('Troubleshooting without IAP?')) {
47
+ await offline();
48
+ }
49
+ }
50
+ }
51
+ process.exit(0);
52
+ };
53
+
54
+ const getAdapterInstanceConfig = async (command) => {
55
+ const instances = await utils.getAllAdapterInstances();
56
+ if (!instances || instances.length === 0) {
57
+ return console.log('None adapter instances found!');
58
+ }
59
+
60
+ let instance;
61
+ if (instances.length === 1) {
62
+ [instance] = instances;
63
+ } else {
64
+ const choices = instances.map((item) => ({ title: item.name }));
65
+ const menu = {
66
+ type: 'select',
67
+ name: 'index',
68
+ message: `Pick an adapter for ${command} check`,
69
+ choices
70
+ };
71
+
72
+ console.log('\n');
73
+ const selected = await prompts(menu);
74
+ console.log('\n');
75
+ instance = instances[selected.index];
76
+ }
77
+
78
+ if (!instance) {
79
+ console.error('No adapter instance selected');
80
+ return null;
81
+ }
82
+
83
+ const { serviceItem: adapterConfig } = await utils.getAdapterConfig(instance._id); /* eslint-disable-line no-underscore-dangle */
84
+
85
+ console.log('\nAdapter instance configuration =>');
86
+ console.log('======================================');
87
+ console.log(adapterConfig);
88
+ console.log('======================================');
89
+
90
+ return adapterConfig;
91
+ };
92
+
93
+ const executeCommandOnInstance = async (command) => {
94
+ const adapterConfig = await getAdapterInstanceConfig(command);
95
+ if (!adapterConfig) {
45
96
  process.exit(0);
46
97
  }
47
98
 
48
- if (command === undefined) {
49
- await troubleshoot({}, true, true);
50
- } else if (command === 'install') {
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') {
51
129
  const { database, serviceItem, pronghornProps } = await utils.getAdapterConfig();
52
130
  const filter = { id: pronghornProps.id };
53
131
  const profileItem = await database.collection(utils.IAP_PROFILES_COLLECTION).findOne(filter);
@@ -65,9 +143,7 @@ const main = async (command) => {
65
143
  const serviceIndex = profileItem.services.indexOf(serviceItem.name);
66
144
  profileItem.services.splice(serviceIndex, 1);
67
145
  const update = { $set: { services: profileItem.services } };
68
- await database.collection(utils.IAP_PROFILES_COLLECTION).updateOne(
69
- { id: pronghornProps.id }, update
70
- );
146
+ await database.collection(utils.IAP_PROFILES_COLLECTION).updateOne({ id: pronghornProps.id }, update);
71
147
  console.log(`${serviceItem.name} removed from profileItem.services.`);
72
148
  console.log(`Rerun the script to reinstall ${serviceItem.name}.`);
73
149
  process.exit(0);
@@ -79,47 +155,33 @@ const main = async (command) => {
79
155
  process.exit(0);
80
156
  }
81
157
  } else {
158
+ const dirname = utils.getCurrentExecutionPath();
82
159
  utils.verifyInstallationDir(dirname, name);
83
160
  utils.runTest();
84
161
  if (rls.keyInYN(`Do you want to install ${name} to IAP?`)) {
85
162
  console.log('Creating database entries...');
86
- const adapter = utils.createAdapter(
87
- pronghornProps, profileItem, sampleProperties, adapterPronghorn
88
- );
89
-
163
+ const adapter = utils.createAdapter(pronghornProps, profileItem, sampleProperties, adapterPronghorn);
90
164
  adapter.properties.properties = await addAuthInfo(adapter.properties.properties);
91
165
 
92
166
  await database.collection(utils.SERVICE_CONFIGS_COLLECTION).insertOne(adapter);
93
167
  profileItem.services.push(adapter.name);
94
168
  const update = { $set: { services: profileItem.services } };
95
- await database.collection(utils.IAP_PROFILES_COLLECTION).updateOne(
96
- { id: pronghornProps.id }, update
97
- );
169
+ await database.collection(utils.IAP_PROFILES_COLLECTION).updateOne({ id: pronghornProps.id }, update);
98
170
  console.log('Database entry creation complete.');
99
171
  }
100
172
  console.log('Exiting...');
101
173
  process.exit(0);
102
174
  }
103
- } else if (['healthcheck', 'basicget', 'connectivity'].includes(command)) {
104
- const { serviceItem } = await utils.getAdapterConfig();
105
- if (serviceItem) {
106
- const adapter = serviceItem;
107
- const a = basicGet.getAdapterInstance(adapter);
108
- if (command === 'healthcheck') {
109
- await utils.healthCheck(a);
110
- process.exit(0);
111
- } else if (command === 'basicget') {
112
- await utils.runBasicGet(true);
113
- } else if (command === 'connectivity') {
114
- const { host } = adapter.properties.properties;
115
- console.log(`perform networking diagnositics to ${host}`);
116
- await utils.runConnectivity(host, true);
117
- process.exit(0);
118
- }
119
- } else {
120
- console.log(`${name} not installed. Run npm \`run install:adapter\` to install.`);
121
- process.exit(0);
122
- }
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
123
185
  }
124
186
  };
125
187
 
@@ -155,13 +217,21 @@ program
155
217
  main('basicget');
156
218
  });
157
219
 
220
+ program
221
+ .command('troubleshoot')
222
+ .alias('tb')
223
+ .description('perfom troubleshooting')
224
+ .action(() => {
225
+ main('troubleshoot');
226
+ });
227
+
158
228
  // Allow commander to parse `process.argv`
159
229
  program.parse(process.argv);
160
230
 
161
231
  if (process.argv.length < 3) {
162
232
  main();
163
233
  }
164
- const allowedParams = ['install', 'healthcheck', 'basicget', 'connectivity'];
234
+ const allowedParams = ['install', 'healthcheck', 'basicget', 'connectivity', 'troubleshoot'];
165
235
  if (process.argv.length === 3 && !allowedParams.includes(process.argv[2])) {
166
236
  console.log(`unknown parameter ${process.argv[2]}`);
167
237
  console.log('try `node troubleshootingAdapter.js -h` to see allowed parameters. Exiting...');
package/utils/tbUtils.js CHANGED
@@ -3,10 +3,11 @@
3
3
  /* eslint import/no-extraneous-dependencies: warn */
4
4
  /* eslint global-require: warn */
5
5
  /* eslint import/no-dynamic-require: warn */
6
+ /* eslint-disable no-console */
6
7
 
7
8
  const path = require('path');
8
- const fs = require('fs-extra');
9
9
  const cp = require('child_process');
10
+ const fs = require('fs-extra');
10
11
 
11
12
  module.exports = {
12
13
  SERVICE_CONFIGS_COLLECTION: 'service_configs',
@@ -100,10 +101,8 @@ module.exports = {
100
101
  *
101
102
  * @function decryptProperties
102
103
  */
103
- decryptProperties: (props, dirname, discovery) => {
104
- const propertyEncryptionClassPath = path.join(dirname, '../../../@itential/pronghorn-core/core/PropertyEncryption.js');
105
- const isEncrypted = props.pathProps.encrypted;
106
- const PropertyEncryption = discovery.require(propertyEncryptionClassPath, isEncrypted);
104
+ decryptProperties: (props, iapDir) => {
105
+ const { PropertyEncryption } = require(path.join(iapDir, 'node_modules/@itential/itential-utils'));
107
106
  const propertyEncryption = new PropertyEncryption({
108
107
  algorithm: 'aes-256-ctr',
109
108
  key: 'TG9uZ0Rpc3RhbmNlUnVubmVyUHJvbmdob3JuCg==',
@@ -159,8 +158,7 @@ module.exports = {
159
158
  * @param {Object} healthcheck - {Object} healthcheck - ./entities/.system/action.json object
160
159
  */
161
160
  getHealthCheckEndpoint: (healthcheck) => {
162
- const endpoint = healthcheck.actions[1].entitypath.slice(21,
163
- healthcheck.actions[1].entitypath.length - 8);
161
+ const endpoint = healthcheck.actions[1].entitypath.slice(21, healthcheck.actions[1].entitypath.length - 8);
164
162
  return { healthCheckEndpoint: endpoint };
165
163
  },
166
164
 
@@ -177,12 +175,12 @@ module.exports = {
177
175
  verifyInstallationDir: (dirname, name) => {
178
176
  const pathArray = dirname.split(path.sep);
179
177
  const expectedPath = `node_modules/${name}`;
180
- const currentPath = pathArray.slice(pathArray.length - 4, pathArray.length - 1).join('/');
178
+ const currentPath = pathArray.slice(pathArray.length - 3, pathArray.length).join('/');
181
179
  if (currentPath.trim() !== expectedPath.trim()) {
182
- throw new Error(`adapter should be installed under ${expectedPath}`);
180
+ throw new Error(`adapter should be installed under ${expectedPath} but is installed under ${currentPath}`);
183
181
  }
184
182
 
185
- const serverFile = path.join(dirname, '../../../..', 'server.js');
183
+ const serverFile = path.join(dirname, '../../../', 'server.js');
186
184
  if (!fs.existsSync(serverFile)) {
187
185
  throw new Error(`adapter should be installed under IAP/${expectedPath}`);
188
186
  }
@@ -202,6 +200,7 @@ module.exports = {
202
200
  try {
203
201
  stdout = cp.execSync(cmd).toString();
204
202
  } catch (error) {
203
+ console.log('execute command error', error.stdout.toString(), error.stderr.toString());
205
204
  stdout = error.stdout.toString();
206
205
  }
207
206
  const output = this.getTestCount(stdout);
@@ -289,10 +288,12 @@ module.exports = {
289
288
  */
290
289
  runConnectivity: function runConnectivity(host, scriptFlag) {
291
290
  let testPath = 'test/integration/adapterTestConnectivity.js';
291
+ let executable = 'mocha';
292
292
  if (!scriptFlag) {
293
293
  testPath = path.resolve(__dirname, '..', testPath);
294
+ executable = path.join(__dirname, '..', 'node_modules/mocha/bin/mocha');
294
295
  }
295
- return this.systemSync(`mocha ${testPath} --HOST=${host} --timeout 10000 --exit`, !scriptFlag);
296
+ return this.systemSync(`${executable} ${testPath} --HOST=${host} --timeout 10000 --exit`, !scriptFlag);
296
297
  },
297
298
 
298
299
  /**
@@ -305,9 +306,9 @@ module.exports = {
305
306
  * @param {Object} sampleProperties - './sampleProperties.json' in adapter dir
306
307
  */
307
308
  createAdapter: function createAdapter(pronghornProps, profileItem, sampleProperties, adapterPronghorn) {
308
- const dirname = this.getDirname();
309
- const packagePath = `${dirname.split('node_modules')[0]}package.json`;
310
- const info = JSON.parse(fs.readFileSync(packagePath));
309
+ const iapDir = this.getIAPHome();
310
+ const packageFile = path.join(iapDir, 'package.json');
311
+ const info = JSON.parse(fs.readFileSync(packageFile));
311
312
  const version = parseInt(info.version.split('.')[0], 10);
312
313
 
313
314
  let adapter = {};
@@ -339,28 +340,42 @@ module.exports = {
339
340
  return adapter;
340
341
  },
341
342
 
342
- getPronghornProps: function getPronghornProps(iapDir) {
343
+ getPronghornProps: function getPronghornProps() {
344
+ const iapDir = this.getIAPHome();
343
345
  console.log('Retrieving properties.json file...');
344
346
  const rawProps = require(path.join(iapDir, 'properties.json'));
345
347
  console.log('Decrypting properties...');
346
- const { Discovery } = require(path.join(iapDir, 'node_modules/@itential/itential-utils'));
347
- const discovery = new Discovery();
348
- const pronghornProps = this.decryptProperties(rawProps, this.getDirname(), discovery);
348
+ const pronghornProps = this.decryptProperties(rawProps, iapDir);
349
349
  console.log('Found properties.\n');
350
350
  return pronghornProps;
351
351
  },
352
352
 
353
+ getAllAdapterInstances: async function getAllAdapterInstances() {
354
+ const database = await this.getIAPDatabaseConnection();
355
+ const { name } = require(path.join(__dirname, '..', 'package.json'));
356
+ const query = { model: name };
357
+ const options = { projection: { name: 1 } };
358
+ const adapterInstancesNames = await database.collection(this.SERVICE_CONFIGS_COLLECTION).find(
359
+ query,
360
+ options
361
+ ).toArray();
362
+ return adapterInstancesNames;
363
+ },
364
+
353
365
  // get database connection and existing adapter config
354
- getAdapterConfig: async function getAdapterConfig() {
355
- const iapDir = path.join(this.getDirname(), '../../../../');
356
- const pronghornProps = this.getPronghornProps(iapDir);
357
- console.log('Connecting to Database...');
358
- const database = await this.connect(pronghornProps);
359
- console.log('Connection established.');
366
+ getAdapterConfig: async function getAdapterConfig(adapterId) {
367
+ const database = await this.getIAPDatabaseConnection();
360
368
  const { name } = require(path.join(__dirname, '..', 'package.json'));
369
+ let query = {};
370
+ if (!adapterId) {
371
+ query = { model: name };
372
+ } else {
373
+ query = { _id: adapterId };
374
+ }
361
375
  const serviceItem = await database.collection(this.SERVICE_CONFIGS_COLLECTION).findOne(
362
- { model: name }
376
+ query
363
377
  );
378
+ const pronghornProps = await this.getPronghornProps();
364
379
  return { database, serviceItem, pronghornProps };
365
380
  },
366
381
 
@@ -399,33 +414,48 @@ module.exports = {
399
414
  },
400
415
 
401
416
  /**
402
- * @summary Check whether adapter is located within IAP node_modules
403
- * by loading properties.json. If not, return false.
404
- * @function withinIAP
405
- * @param {String} iapDir root directory of IAP
417
+ * @summary Obtain the IAP installation directory depending on how adapter is used:
418
+ * by IAP, or by npm run CLI interface
419
+ * @returns IAP installation directory or null if adapter running without IAP
420
+ * @function getIAPHome
406
421
  */
407
- withinIAP: (iapDir) => {
408
- try {
409
- const rawProps = require(path.join(iapDir, 'properties.json'));
410
- return rawProps;
411
- } catch (error) {
412
- return false;
422
+ getIAPHome: function getIAPHome() {
423
+ let IAPHomePath = null;
424
+ // check if adapter started via IAP, use path injected by core
425
+ if (process.env.iap_home) IAPHomePath = process.env.iap_home;
426
+ // check if adapter started via CLI `npm run <command>` so we have to be located under
427
+ // <IAP_HOME>/node_modules/@itentialopensource/<adapter_name>/ directory
428
+ const currentExecutionPath = this.getCurrentExecutionPath();
429
+ if (currentExecutionPath.indexOf('/node_modules') >= 0) {
430
+ [IAPHomePath] = currentExecutionPath.split('/node_modules');
413
431
  }
432
+ return IAPHomePath;
414
433
  },
415
434
 
416
435
  /**
417
- * @summary Used to determine the proper dirname to return in case adapter reference is
418
- * symlinked withink IAP
419
- * @returns the symlinked path (using pwd command) of the adapter in case properties.json
420
- * is not found in the original path
421
- * @function getDirname
436
+ * @summary get current execution path without resolving symbolic links,
437
+ * use `pwd` command wihout '-P' option (resolving symlinks) https://linux.die.net/man/1/pwd
438
+ * @returns
439
+ * @function getCurrentExecutionPAth
422
440
  */
423
- getDirname: function getDirname() {
424
- if (this.withinIAP(path.join(__dirname, '../../../../'))) {
425
- return __dirname;
426
- }
441
+ getCurrentExecutionPath: function getCurrentExecutionPAth() {
427
442
  const { stdout } = this.systemSync('pwd', true);
428
- return path.join(stdout, 'utils');
443
+ return stdout.trim();
444
+ },
445
+
446
+ /**
447
+ * @summary checks if command executed from <IAP_HOME>/node_modules/@itentialopensource/<adapter_name>/ location
448
+ * @returns true if command executed under <IAP_HOME>/node_modules/@itentialopensource/<adapter_name>/ path
449
+ * @function areWeUnderIAPinstallationDirectory
450
+ */
451
+ areWeUnderIAPinstallationDirectory: function areWeUnderIAPinstallationDirectory() {
452
+ return path.join(this.getCurrentExecutionPath(), '../../..') === this.getIAPHome();
453
+ },
454
+
455
+ getIAPDatabaseConnection: async function getIAPDatabaseConnection() {
456
+ const pronghornProps = await this.getPronghornProps();
457
+ const database = await this.connect(pronghornProps);
458
+ return database;
429
459
  },
430
460
 
431
461
  /**
@@ -435,9 +465,23 @@ module.exports = {
435
465
  * @param {Object} properties - pronghornProps
436
466
  */
437
467
  connect: async function connect(properties) {
438
- // Connect to Mongo
439
- const { MongoDBConnection } = require(path.join(this.getDirname(), '../../../', '@itential/database'));
440
- const connection = new MongoDBConnection(properties.mongoProps);
468
+ let dbConnectionProperties = {};
469
+ if (properties.mongoProps) {
470
+ dbConnectionProperties = properties.mongoProps;
471
+ } else if (properties.mongo) {
472
+ if (properties.mongo.url) {
473
+ dbConnectionProperties.url = properties.mongo.url;
474
+ } else {
475
+ dbConnectionProperties.url = `mongodb://${properties.mongo.host}:${properties.mongo.port}`;
476
+ }
477
+ dbConnectionProperties.db = properties.mongo.database;
478
+ }
479
+ if (!dbConnectionProperties.url || !dbConnectionProperties.db) {
480
+ throw new Error('Mongo properties are not specified in IAP configuration!');
481
+ }
482
+ const iapDir = this.getIAPHome();
483
+ const { MongoDBConnection } = require(path.join(iapDir, 'node_modules/@itential/database'));
484
+ const connection = new MongoDBConnection(dbConnectionProperties);
441
485
  const database = await connection.connect(true);
442
486
  return database;
443
487
  }
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  /* @copyright Itential, LLC 2019 */
3
3
 
4
+ const execute = require('child_process').exec;
4
5
  const fs = require('fs-extra');
5
6
  const rl = require('readline-sync');
6
- const execute = require('child_process').exec;
7
7
 
8
8
  /**
9
9
  * This script will determine the type of integration test to run
@@ -47,11 +47,11 @@ function replaceTestVars(test) {
47
47
  let intTest = fs.readFileSync(test, 'utf8');
48
48
 
49
49
  // replace stub variable but check if it exists first
50
- let sindex = intTest.indexOf('const stub');
50
+ let sindex = intTest.indexOf('samProps.stub');
51
51
  let eindex = intTest.indexOf(';', sindex);
52
52
  let replStr = intTest.substring(sindex, eindex + 1);
53
53
  if (sindex > -1) {
54
- intTest = intTest.replace(replStr, `const stub = ${stub};`);
54
+ intTest = intTest.replace(replStr, `samProps.stub = ${stub};`);
55
55
  }
56
56
 
57
57
  // replace isRapidFail variable but check if it exists first
@@ -71,46 +71,46 @@ function replaceTestVars(test) {
71
71
  }
72
72
 
73
73
  // replace host variable
74
- sindex = intTest.indexOf('const host');
74
+ sindex = intTest.indexOf('samProps.host');
75
75
  eindex = intTest.indexOf(';', sindex);
76
76
  replStr = intTest.substring(sindex, eindex + 1);
77
- intTest = intTest.replace(replStr, `const host = '${host}';`);
77
+ intTest = intTest.replace(replStr, `samProps.host = '${host}';`);
78
78
 
79
79
  // replace username variable
80
- sindex = intTest.indexOf('const username');
80
+ sindex = intTest.indexOf('samProps.authentication.username');
81
81
  eindex = intTest.indexOf(';', sindex);
82
82
  replStr = intTest.substring(sindex, eindex + 1);
83
- intTest = intTest.replace(replStr, `const username = '${username}';`);
83
+ intTest = intTest.replace(replStr, `samProps.authentication.username = '${username}';`);
84
84
 
85
85
  // replace password variable
86
- sindex = intTest.indexOf('const password');
86
+ sindex = intTest.indexOf('samProps.authentication.password');
87
87
  eindex = intTest.indexOf(';', sindex);
88
88
  replStr = intTest.substring(sindex, eindex + 1);
89
- intTest = intTest.replace(replStr, `const password = '${password}';`);
89
+ intTest = intTest.replace(replStr, `samProps.authentication.password = '${password}';`);
90
90
 
91
91
  // replace protocol variable
92
- sindex = intTest.indexOf('const protocol');
92
+ sindex = intTest.indexOf('samProps.protocol');
93
93
  eindex = intTest.indexOf(';', sindex);
94
94
  replStr = intTest.substring(sindex, eindex + 1);
95
- intTest = intTest.replace(replStr, `const protocol = '${protocol}';`);
95
+ intTest = intTest.replace(replStr, `samProps.protocol = '${protocol}';`);
96
96
 
97
97
  // replace port variable
98
- sindex = intTest.indexOf('const port');
98
+ sindex = intTest.indexOf('samProps.port');
99
99
  eindex = intTest.indexOf(';', sindex);
100
100
  replStr = intTest.substring(sindex, eindex + 1);
101
- intTest = intTest.replace(replStr, `const port = ${port};`);
101
+ intTest = intTest.replace(replStr, `samProps.port = ${port};`);
102
102
 
103
103
  // replace sslenable variable
104
- sindex = intTest.indexOf('const sslenable');
104
+ sindex = intTest.indexOf('samProps.ssl.enabled');
105
105
  eindex = intTest.indexOf(';', sindex);
106
106
  replStr = intTest.substring(sindex, eindex + 1);
107
- intTest = intTest.replace(replStr, `const sslenable = ${sslenable};`);
107
+ intTest = intTest.replace(replStr, `samProps.ssl.enabled = ${sslenable};`);
108
108
 
109
109
  // replace sslinvalid variable
110
- sindex = intTest.indexOf('const sslinvalid');
110
+ sindex = intTest.indexOf('samProps.ssl.accept_invalid_cert');
111
111
  eindex = intTest.indexOf(';', sindex);
112
112
  replStr = intTest.substring(sindex, eindex + 1);
113
- intTest = intTest.replace(replStr, `const sslinvalid = ${sslinvalid};`);
113
+ intTest = intTest.replace(replStr, `samProps.ssl.accept_invalid_cert = ${sslinvalid};`);
114
114
 
115
115
  console.log(`Updates to ${test} complete`);
116
116
  fs.writeFileSync(test, intTest);
@@ -134,9 +134,13 @@ const offline = async () => {
134
134
  };
135
135
 
136
136
  const troubleshoot = async (props, scriptFlag, persistFlag, adapter) => {
137
- // get database connection and existing adapter config
138
- const { database, serviceItem } = await utils.getAdapterConfig();
139
- // where troubleshoot should start
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
+ }
140
144
  if (serviceItem) {
141
145
  if (!scriptFlag || rls.keyInYN(`Start verifying the connection and authentication properties for ${name}?`)) {
142
146
  const { result, updatedAdapter } = VerifyHealthCheckEndpoint(serviceItem, props, scriptFlag);
@@ -154,10 +158,9 @@ const troubleshoot = async (props, scriptFlag, persistFlag, adapter) => {
154
158
  }
155
159
 
156
160
  if (persistFlag && healthRes) {
161
+ const { database } = await utils.getIAPDatabaseConnection();
157
162
  const update = { $set: { properties: updatedAdapter.properties } };
158
- await database.collection(utils.SERVICE_CONFIGS_COLLECTION).updateOne(
159
- { model: name }, update
160
- );
163
+ await database.collection(utils.SERVICE_CONFIGS_COLLECTION).updateOne({ model: name }, update);
161
164
  if (scriptFlag) {
162
165
  console.log(`${name} updated.`);
163
166
  }
@@ -1,3 +0,0 @@
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.