@itentialopensource/adapter-etsi_sol003 0.1.2 → 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 (54) hide show
  1. package/AUTH.md +39 -0
  2. package/BROKER.md +199 -0
  3. package/CALLS.md +707 -0
  4. package/CHANGELOG.md +13 -5
  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 +291 -640
  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 +527 -116
  22. package/propertiesDecorators.json +14 -0
  23. package/propertiesSchema.json +827 -6
  24. package/refs?service=git-upload-pack +0 -0
  25. package/report/adapter-openapi.json +7598 -0
  26. package/report/adapter-openapi.yaml +5267 -0
  27. package/report/adapterInfo.json +10 -0
  28. package/report/updateReport1653138357676.json +120 -0
  29. package/report/updateReport1691507408979.json +120 -0
  30. package/report/updateReport1692202442500.json +120 -0
  31. package/report/updateReport1694460725963.json +120 -0
  32. package/report/updateReport1698420524874.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 +1784 -2174
  37. package/test/unit/adapterBaseTestUnit.js +388 -308
  38. package/test/unit/adapterTestUnit.js +399 -260
  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/pre-commit.sh +5 -0
  49. package/utils/taskMover.js +309 -0
  50. package/utils/tbScript.js +123 -53
  51. package/utils/tbUtils.js +87 -49
  52. package/utils/testRunner.js +17 -17
  53. package/utils/troubleshootingAdapter.js +9 -6
  54. 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,34 +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 newDirname = this.getDirname();
356
- let iapDir;
357
- if (this.withinIAP(newDirname)) { // when this script is called from IAP
358
- iapDir = newDirname;
366
+ getAdapterConfig: async function getAdapterConfig(adapterId) {
367
+ const database = await this.getIAPDatabaseConnection();
368
+ const { name } = require(path.join(__dirname, '..', 'package.json'));
369
+ let query = {};
370
+ if (!adapterId) {
371
+ query = { model: name };
359
372
  } else {
360
- iapDir = path.join(this.getDirname(), 'utils', '../../../../');
373
+ query = { _id: adapterId };
361
374
  }
362
- const pronghornProps = this.getPronghornProps(iapDir);
363
- console.log('Connecting to Database...');
364
- const database = await this.connect(iapDir, pronghornProps);
365
- console.log('Connection established.');
366
- const { name } = require(path.join(__dirname, '..', 'package.json'));
367
375
  const serviceItem = await database.collection(this.SERVICE_CONFIGS_COLLECTION).findOne(
368
- { model: name }
376
+ query
369
377
  );
378
+ const pronghornProps = await this.getPronghornProps();
370
379
  return { database, serviceItem, pronghornProps };
371
380
  },
372
381
 
@@ -405,45 +414,74 @@ module.exports = {
405
414
  },
406
415
 
407
416
  /**
408
- * @summary Check whether adapter is located within IAP node_modules
409
- * by loading properties.json. If not, return false.
410
- * @function withinIAP
411
- * @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
412
421
  */
413
- withinIAP: (iapDir) => {
414
- try {
415
- const rawProps = require(path.join(iapDir, 'properties.json'));
416
- return rawProps;
417
- } catch (error) {
418
- 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');
419
431
  }
432
+ return IAPHomePath;
420
433
  },
421
434
 
422
435
  /**
423
- * @summary Used to determine the proper dirname to return in case adapter reference is
424
- * symlinked withink IAP
425
- * @returns the symlinked path (using pwd command) of the adapter in case properties.json
426
- * is not found in the original path
427
- * @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
428
440
  */
429
- getDirname: function getDirname() {
430
- if (this.withinIAP(path.join(__dirname, '../../../../'))) {
431
- return __dirname;
432
- }
441
+ getCurrentExecutionPath: function getCurrentExecutionPAth() {
433
442
  const { stdout } = this.systemSync('pwd', true);
434
443
  return stdout.trim();
435
444
  },
436
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;
459
+ },
460
+
437
461
  /**
438
462
  * @summary connect to mongodb
439
463
  *
440
464
  * @function connect
441
465
  * @param {Object} properties - pronghornProps
442
466
  */
443
- connect: async function connect(iapDir, properties) {
444
- // 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();
445
483
  const { MongoDBConnection } = require(path.join(iapDir, 'node_modules/@itential/database'));
446
- const connection = new MongoDBConnection(properties.mongoProps);
484
+ const connection = new MongoDBConnection(dbConnectionProperties);
447
485
  const database = await connection.connect(true);
448
486
  return database;
449
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.