@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.
- package/AUTH.md +39 -0
- package/BROKER.md +199 -0
- package/CALLS.md +707 -0
- package/CHANGELOG.md +13 -5
- package/CODE_OF_CONDUCT.md +12 -17
- package/CONTRIBUTING.md +3 -148
- package/ENHANCE.md +69 -0
- package/PROPERTIES.md +641 -0
- package/README.md +235 -576
- package/SUMMARY.md +9 -0
- package/SYSTEMINFO.md +11 -0
- package/TROUBLESHOOT.md +47 -0
- package/adapter.js +291 -640
- package/adapterBase.js +843 -419
- package/changelogs/changelog.md +16 -0
- package/entities/.generic/action.json +105 -0
- package/entities/.generic/schema.json +6 -1
- package/error.json +6 -0
- package/metadata.json +49 -0
- package/package.json +24 -24
- package/pronghorn.json +527 -116
- package/propertiesDecorators.json +14 -0
- package/propertiesSchema.json +827 -6
- package/refs?service=git-upload-pack +0 -0
- package/report/adapter-openapi.json +7598 -0
- package/report/adapter-openapi.yaml +5267 -0
- package/report/adapterInfo.json +10 -0
- package/report/updateReport1653138357676.json +120 -0
- package/report/updateReport1691507408979.json +120 -0
- package/report/updateReport1692202442500.json +120 -0
- package/report/updateReport1694460725963.json +120 -0
- package/report/updateReport1698420524874.json +120 -0
- package/sampleProperties.json +153 -3
- package/test/integration/adapterTestBasicGet.js +3 -5
- package/test/integration/adapterTestConnectivity.js +91 -42
- package/test/integration/adapterTestIntegration.js +1784 -2174
- package/test/unit/adapterBaseTestUnit.js +388 -308
- package/test/unit/adapterTestUnit.js +399 -260
- package/utils/adapterInfo.js +206 -0
- package/utils/addAuth.js +1 -1
- package/utils/artifactize.js +1 -1
- package/utils/checkMigrate.js +1 -1
- package/utils/entitiesToDB.js +12 -57
- package/utils/findPath.js +1 -1
- package/utils/methodDocumentor.js +273 -0
- package/utils/modify.js +13 -15
- package/utils/packModificationScript.js +1 -1
- package/utils/pre-commit.sh +5 -0
- package/utils/taskMover.js +309 -0
- package/utils/tbScript.js +123 -53
- package/utils/tbUtils.js +87 -49
- package/utils/testRunner.js +17 -17
- package/utils/troubleshootingAdapter.js +9 -6
- 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
|
|
104
|
-
const
|
|
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(
|
|
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
|
|
309
|
-
const
|
|
310
|
-
const info = JSON.parse(fs.readFileSync(
|
|
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(
|
|
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
|
|
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
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
409
|
-
*
|
|
410
|
-
* @
|
|
411
|
-
* @
|
|
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
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
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
|
|
424
|
-
*
|
|
425
|
-
* @returns
|
|
426
|
-
*
|
|
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
|
-
|
|
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(
|
|
444
|
-
|
|
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(
|
|
484
|
+
const connection = new MongoDBConnection(dbConnectionProperties);
|
|
447
485
|
const database = await connection.connect(true);
|
|
448
486
|
return database;
|
|
449
487
|
}
|
package/utils/testRunner.js
CHANGED
|
@@ -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('
|
|
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, `
|
|
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('
|
|
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, `
|
|
77
|
+
intTest = intTest.replace(replStr, `samProps.host = '${host}';`);
|
|
78
78
|
|
|
79
79
|
// replace username variable
|
|
80
|
-
sindex = intTest.indexOf('
|
|
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, `
|
|
83
|
+
intTest = intTest.replace(replStr, `samProps.authentication.username = '${username}';`);
|
|
84
84
|
|
|
85
85
|
// replace password variable
|
|
86
|
-
sindex = intTest.indexOf('
|
|
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, `
|
|
89
|
+
intTest = intTest.replace(replStr, `samProps.authentication.password = '${password}';`);
|
|
90
90
|
|
|
91
91
|
// replace protocol variable
|
|
92
|
-
sindex = intTest.indexOf('
|
|
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, `
|
|
95
|
+
intTest = intTest.replace(replStr, `samProps.protocol = '${protocol}';`);
|
|
96
96
|
|
|
97
97
|
// replace port variable
|
|
98
|
-
sindex = intTest.indexOf('
|
|
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, `
|
|
101
|
+
intTest = intTest.replace(replStr, `samProps.port = ${port};`);
|
|
102
102
|
|
|
103
103
|
// replace sslenable variable
|
|
104
|
-
sindex = intTest.indexOf('
|
|
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, `
|
|
107
|
+
intTest = intTest.replace(replStr, `samProps.ssl.enabled = ${sslenable};`);
|
|
108
108
|
|
|
109
109
|
// replace sslinvalid variable
|
|
110
|
-
sindex = intTest.indexOf('
|
|
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, `
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
}
|
package/workflows/README.md
DELETED