@itentialopensource/adapter-adtran_mosaic_devicemanager 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 (52) hide show
  1. package/AUTH.md +39 -0
  2. package/BROKER.md +199 -0
  3. package/CALLS.md +733 -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 +14 -14
  8. package/PROPERTIES.md +483 -89
  9. package/README.md +156 -67
  10. package/SUMMARY.md +2 -2
  11. package/SYSTEMINFO.md +11 -0
  12. package/TROUBLESHOOT.md +4 -3
  13. package/adapter.js +236 -626
  14. package/adapterBase.js +647 -494
  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/metadata.json +47 -0
  19. package/package.json +24 -24
  20. package/pronghorn.json +508 -90
  21. package/propertiesSchema.json +496 -39
  22. package/refs?service=git-upload-pack +0 -0
  23. package/report/adapter-openapi.json +7211 -0
  24. package/report/adapter-openapi.yaml +6459 -0
  25. package/report/adapterInfo.json +10 -0
  26. package/report/updateReport1653138377421.json +120 -0
  27. package/report/updateReport1691507605063.json +120 -0
  28. package/report/updateReport1692202606613.json +120 -0
  29. package/report/updateReport1694462023649.json +120 -0
  30. package/report/updateReport1698421007213.json +120 -0
  31. package/sampleProperties.json +153 -3
  32. package/test/integration/adapterTestBasicGet.js +3 -5
  33. package/test/integration/adapterTestConnectivity.js +91 -42
  34. package/test/integration/adapterTestIntegration.js +1965 -2493
  35. package/test/unit/adapterBaseTestUnit.js +388 -306
  36. package/test/unit/adapterTestUnit.js +364 -231
  37. package/utils/adapterInfo.js +206 -0
  38. package/utils/addAuth.js +1 -1
  39. package/utils/artifactize.js +1 -1
  40. package/utils/checkMigrate.js +1 -1
  41. package/utils/entitiesToDB.js +12 -57
  42. package/utils/findPath.js +1 -1
  43. package/utils/methodDocumentor.js +273 -0
  44. package/utils/modify.js +13 -15
  45. package/utils/packModificationScript.js +1 -1
  46. package/utils/pre-commit.sh +5 -0
  47. package/utils/taskMover.js +309 -0
  48. package/utils/tbScript.js +123 -53
  49. package/utils/tbUtils.js +84 -59
  50. package/utils/testRunner.js +17 -17
  51. package/utils/troubleshootingAdapter.js +9 -6
  52. package/workflows/README.md +0 -3
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, iapDir, discovery) => {
104
- const propertyEncryptionClassPath = path.join(iapDir, 'node_modules/@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
 
@@ -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, iapDir, 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 = this.getIAPHome();
356
- const pronghornProps = this.getPronghornProps(iapDir);
357
- console.log('Connecting to Database...');
358
- const database = await this.connect(iapDir, 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,52 +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
443
  return stdout.trim();
429
444
  },
430
445
 
431
446
  /**
432
- * @summary Obtain the IAP installation directory depending on how adapter is used:
433
- * by IAP, or by npm run CLI interface
434
- * @returns IAP installation directory
435
- * @function getIAPHome
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
436
450
  */
437
- getIAPHome: function getIAPHome() {
438
- // if adapter started via IAP, use path injected by core
439
- if (process.env.iap_home) return process.env.iap_home;
440
- // adapter started via CLI `npm run <command>` so we have to be located under
441
- // <IAP_HOME>/node_modules/@itentialopensource/<adapter>/ directory,
442
- // use `pwd` command wihout option -P(resolving symlinks) https://linux.die.net/man/1/pwd
443
- const { stdout } = this.systemSync('pwd', true);
444
- if (stdout.indexOf('/node_modules') >= 0) {
445
- return stdout.trim().split('/node_modules')[0];
446
- }
447
- return path.join(stdout.trim(), '../../../');
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;
448
459
  },
449
460
 
450
461
  /**
@@ -453,10 +464,24 @@ module.exports = {
453
464
  * @function connect
454
465
  * @param {Object} properties - pronghornProps
455
466
  */
456
- connect: async function connect(iapDir, properties) {
457
- // Connect to Mongo
467
+ connect: async function connect(properties) {
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();
458
483
  const { MongoDBConnection } = require(path.join(iapDir, 'node_modules/@itential/database'));
459
- const connection = new MongoDBConnection(properties.mongoProps);
484
+ const connection = new MongoDBConnection(dbConnectionProperties);
460
485
  const database = await connection.connect(true);
461
486
  return database;
462
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.