@itentialopensource/adapter-nokia_altiplano 0.1.3 → 0.4.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 +37 -0
- package/CALLS.md +95 -0
- package/CHANGELOG.md +24 -0
- package/ENHANCE.md +69 -0
- package/PROPERTIES.md +241 -0
- package/SUMMARY.md +9 -0
- package/SYSTEMINFO.md +12 -0
- package/TROUBLESHOOT.md +46 -0
- package/adapter.js +1135 -148
- package/adapterBase.js +1 -1
- package/entities/Intent/action.json +116 -0
- package/entities/Intent/schema.json +6 -1
- package/package.json +3 -3
- package/pronghorn.json +591 -0
- package/refs?service=git-upload-pack +0 -0
- package/report/updateReport1647623246588.json +95 -0
- package/sampleProperties.json +2 -2
- package/test/integration/adapterTestIntegration.js +154 -0
- package/test/unit/adapterTestUnit.js +287 -0
- package/utils/basicGet.js +0 -17
- package/utils/modify.js +1 -1
- package/utils/patches2bundledDeps.js +90 -0
- package/utils/tbScript.js +4 -4
- package/utils/tbUtils.js +51 -6
- package/utils/troubleshootingAdapter.js +2 -26
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const semverSatisfies = require('semver/functions/satisfies');
|
|
3
|
+
const packageJson = require('../package.json');
|
|
4
|
+
|
|
5
|
+
try {
|
|
6
|
+
// pattern supplied by semver.org via https://regex101.com/r/vkijKf/1/ but removed gm from end to only match a single semver
|
|
7
|
+
// const semverPat = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
|
8
|
+
// pattern supplied by semver.org via https://regex101.com/r/Ly7O1x/3/ with following changes
|
|
9
|
+
// removed P's from before capturing group names and
|
|
10
|
+
// removed gm from end to only match a single semver
|
|
11
|
+
// const semverPat = /^(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
|
12
|
+
|
|
13
|
+
const patches = (fs.existsSync('./patches')) ? fs.readdirSync('./patches', { withFileTypes: true }) : [];
|
|
14
|
+
if (!patches.length) {
|
|
15
|
+
console.error('\nno patches - nothing to do\n');
|
|
16
|
+
process.exitCode = 1;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const dependencies = packageJson.dependencies || {};
|
|
20
|
+
if (!Object.keys(dependencies).length) {
|
|
21
|
+
console.error('\nno dependencies - nothing to do\n');
|
|
22
|
+
process.exitCode = 1;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let changed = false;
|
|
26
|
+
console.error('\nprocessing patches');
|
|
27
|
+
const bundledDependencies = packageJson.bundledDependencies || packageJson.bundleDependencies || [];
|
|
28
|
+
|
|
29
|
+
patches.forEach((patch) => {
|
|
30
|
+
if (!patch.isFile()) {
|
|
31
|
+
console.error(`${patch.name} skipped, is not a regular file`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (!patch.name.endsWith('.patch')) {
|
|
35
|
+
console.error(`${patch.name} skipped, does not end with .patch`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const splits = patch.name.slice(0, -6).split('+');
|
|
39
|
+
if (splits.length > 4) {
|
|
40
|
+
console.error(`${patch.name} skipped, does not follow the naming convention (cannot use '+' other than to separate scope/package/semver and at most once within semver)`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const scope = splits[0][0] === '@' ? splits.shift() : null;
|
|
44
|
+
const packageName = splits.shift();
|
|
45
|
+
const semver = splits.join('+');
|
|
46
|
+
// const { groups } = semver.match(semverPat);
|
|
47
|
+
const file = scope ? `${scope}/${packageName}` : packageName;
|
|
48
|
+
if (dependencies[file] && semverSatisfies(semver, dependencies[file])) {
|
|
49
|
+
if (!bundledDependencies.includes(file)) {
|
|
50
|
+
bundledDependencies.push(file);
|
|
51
|
+
console.error(`added ${file} to bundledDependencies`);
|
|
52
|
+
changed = true;
|
|
53
|
+
} else {
|
|
54
|
+
console.error(`bundledDependencies already has ${file}`);
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
const depmsg = dependencies[file] ? `version mismatch (${dependencies[file]}) in dependencies` : 'not found in dependencies';
|
|
58
|
+
console.error(`patch ${patch.name} ${depmsg}`);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
if (!packageJson.bundledDependencies && bundledDependencies.length) {
|
|
63
|
+
delete packageJson.bundleDependencies;
|
|
64
|
+
packageJson.bundledDependencies = bundledDependencies;
|
|
65
|
+
console.error('renaming bundleDependencies to bundledDependencies');
|
|
66
|
+
changed = true;
|
|
67
|
+
}
|
|
68
|
+
if (changed) {
|
|
69
|
+
fs.writeFileSync('./package.json.new', JSON.stringify(packageJson, null, 2));
|
|
70
|
+
console.error('wrote package.json.new');
|
|
71
|
+
fs.renameSync('./package.json', './package.json.old');
|
|
72
|
+
console.error('moved package.json to package.json.old');
|
|
73
|
+
fs.renameSync('./package.json.new', './package.json');
|
|
74
|
+
console.error('moved package.json.new to package.json');
|
|
75
|
+
} else {
|
|
76
|
+
console.error('no changes\n');
|
|
77
|
+
process.exitCode = 1;
|
|
78
|
+
}
|
|
79
|
+
} catch (e) {
|
|
80
|
+
if (e) {
|
|
81
|
+
// caught error, exit with status 2 to signify abject failure
|
|
82
|
+
console.error(`\ncaught exception - ${e}\n`);
|
|
83
|
+
process.exitCode = 2;
|
|
84
|
+
} else {
|
|
85
|
+
// caught false, exit with status 1 to signify nothing done
|
|
86
|
+
process.exitCode = 1;
|
|
87
|
+
}
|
|
88
|
+
} finally {
|
|
89
|
+
console.error('done\n');
|
|
90
|
+
}
|
package/utils/tbScript.js
CHANGED
|
@@ -17,11 +17,11 @@ const sampleProperties = require('../sampleProperties.json');
|
|
|
17
17
|
const adapterPronghorn = require('../pronghorn.json');
|
|
18
18
|
const { addAuthInfo } = require('./addAuth');
|
|
19
19
|
|
|
20
|
-
const { troubleshoot,
|
|
20
|
+
const { troubleshoot, offline } = require('./troubleshootingAdapter');
|
|
21
21
|
|
|
22
22
|
const main = async (command) => {
|
|
23
23
|
const dirname = utils.getDirname();
|
|
24
|
-
const iapDir = path.join(dirname, '
|
|
24
|
+
const iapDir = path.join(dirname, '../../../');
|
|
25
25
|
if (!utils.withinIAP(iapDir)) {
|
|
26
26
|
if (command === 'install') {
|
|
27
27
|
console.log('Not currently in IAP directory - installation not possible');
|
|
@@ -48,7 +48,7 @@ const main = async (command) => {
|
|
|
48
48
|
if (command === undefined) {
|
|
49
49
|
await troubleshoot({}, true, true);
|
|
50
50
|
} else if (command === 'install') {
|
|
51
|
-
const { database, serviceItem, pronghornProps } = await getAdapterConfig();
|
|
51
|
+
const { database, serviceItem, pronghornProps } = await utils.getAdapterConfig();
|
|
52
52
|
const filter = { id: pronghornProps.id };
|
|
53
53
|
const profileItem = await database.collection(utils.IAP_PROFILES_COLLECTION).findOne(filter);
|
|
54
54
|
if (!profileItem) {
|
|
@@ -101,7 +101,7 @@ const main = async (command) => {
|
|
|
101
101
|
process.exit(0);
|
|
102
102
|
}
|
|
103
103
|
} else if (['healthcheck', 'basicget', 'connectivity'].includes(command)) {
|
|
104
|
-
const { serviceItem } = await getAdapterConfig();
|
|
104
|
+
const { serviceItem } = await utils.getAdapterConfig();
|
|
105
105
|
if (serviceItem) {
|
|
106
106
|
const adapter = serviceItem;
|
|
107
107
|
const a = basicGet.getAdapterInstance(adapter);
|
package/utils/tbUtils.js
CHANGED
|
@@ -100,8 +100,8 @@ module.exports = {
|
|
|
100
100
|
*
|
|
101
101
|
* @function decryptProperties
|
|
102
102
|
*/
|
|
103
|
-
decryptProperties: (props,
|
|
104
|
-
const propertyEncryptionClassPath = path.join(
|
|
103
|
+
decryptProperties: (props, iapDir, discovery) => {
|
|
104
|
+
const propertyEncryptionClassPath = path.join(iapDir, 'node_modules/@itential/pronghorn-core/core/PropertyEncryption.js');
|
|
105
105
|
const isEncrypted = props.pathProps.encrypted;
|
|
106
106
|
const PropertyEncryption = discovery.require(propertyEncryptionClassPath, isEncrypted);
|
|
107
107
|
const propertyEncryption = new PropertyEncryption({
|
|
@@ -177,12 +177,12 @@ module.exports = {
|
|
|
177
177
|
verifyInstallationDir: (dirname, name) => {
|
|
178
178
|
const pathArray = dirname.split(path.sep);
|
|
179
179
|
const expectedPath = `node_modules/${name}`;
|
|
180
|
-
const currentPath = pathArray.slice(pathArray.length -
|
|
180
|
+
const currentPath = pathArray.slice(pathArray.length - 3, pathArray.length).join('/');
|
|
181
181
|
if (currentPath.trim() !== expectedPath.trim()) {
|
|
182
|
-
throw new Error(`adapter should be installed under ${expectedPath}`);
|
|
182
|
+
throw new Error(`adapter should be installed under ${expectedPath} but is installed under ${currentPath}`);
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
const serverFile = path.join(dirname, '
|
|
185
|
+
const serverFile = path.join(dirname, '../../../', 'server.js');
|
|
186
186
|
if (!fs.existsSync(serverFile)) {
|
|
187
187
|
throw new Error(`adapter should be installed under IAP/${expectedPath}`);
|
|
188
188
|
}
|
|
@@ -339,6 +339,37 @@ module.exports = {
|
|
|
339
339
|
return adapter;
|
|
340
340
|
},
|
|
341
341
|
|
|
342
|
+
getPronghornProps: function getPronghornProps(iapDir) {
|
|
343
|
+
console.log('Retrieving properties.json file...');
|
|
344
|
+
const rawProps = require(path.join(iapDir, 'properties.json'));
|
|
345
|
+
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);
|
|
349
|
+
console.log('Found properties.\n');
|
|
350
|
+
return pronghornProps;
|
|
351
|
+
},
|
|
352
|
+
|
|
353
|
+
// 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;
|
|
359
|
+
} else {
|
|
360
|
+
iapDir = path.join(this.getDirname(), 'utils', '../../../../');
|
|
361
|
+
}
|
|
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
|
+
const serviceItem = await database.collection(this.SERVICE_CONFIGS_COLLECTION).findOne(
|
|
368
|
+
{ model: name }
|
|
369
|
+
);
|
|
370
|
+
return { database, serviceItem, pronghornProps };
|
|
371
|
+
},
|
|
372
|
+
|
|
342
373
|
/**
|
|
343
374
|
* @summary return async healthcheck result as a Promise
|
|
344
375
|
*
|
|
@@ -400,7 +431,21 @@ module.exports = {
|
|
|
400
431
|
return __dirname;
|
|
401
432
|
}
|
|
402
433
|
const { stdout } = this.systemSync('pwd', true);
|
|
403
|
-
return
|
|
434
|
+
return stdout.trim();
|
|
435
|
+
},
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* @summary connect to mongodb
|
|
439
|
+
*
|
|
440
|
+
* @function connect
|
|
441
|
+
* @param {Object} properties - pronghornProps
|
|
442
|
+
*/
|
|
443
|
+
connect: async function connect(iapDir, properties) {
|
|
444
|
+
// Connect to Mongo
|
|
445
|
+
const { MongoDBConnection } = require(path.join(iapDir, 'node_modules/@itential/database'));
|
|
446
|
+
const connection = new MongoDBConnection(properties.mongoProps);
|
|
447
|
+
const database = await connection.connect(true);
|
|
448
|
+
return database;
|
|
404
449
|
}
|
|
405
450
|
|
|
406
451
|
};
|
|
@@ -117,30 +117,6 @@ const VerifyHealthCheckEndpoint = (serviceItem, props, scriptFlag) => {
|
|
|
117
117
|
return { result, updatedAdapter };
|
|
118
118
|
};
|
|
119
119
|
|
|
120
|
-
const getPronghornProps = (iapDir) => {
|
|
121
|
-
console.log('Retrieving properties.json file...');
|
|
122
|
-
const rawProps = require(path.join(iapDir, 'properties.json'));
|
|
123
|
-
console.log('Decrypting properties...');
|
|
124
|
-
const { Discovery } = require(path.join(iapDir, 'node_modules/@itential/itential-utils'));
|
|
125
|
-
const discovery = new Discovery();
|
|
126
|
-
const pronghornProps = utils.decryptProperties(rawProps, utils.getDirname(), discovery);
|
|
127
|
-
console.log('Found properties.\n');
|
|
128
|
-
return pronghornProps;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
// get database connection and existing adapter config
|
|
132
|
-
const getAdapterConfig = async () => {
|
|
133
|
-
const iapDir = path.join(utils.getDirname(), '../../../../');
|
|
134
|
-
const pronghornProps = getPronghornProps(iapDir);
|
|
135
|
-
console.log('Connecting to Database...');
|
|
136
|
-
const database = await basicGet.connect(pronghornProps);
|
|
137
|
-
console.log('Connection established.');
|
|
138
|
-
const serviceItem = await database.collection(utils.SERVICE_CONFIGS_COLLECTION).findOne(
|
|
139
|
-
{ model: name }
|
|
140
|
-
);
|
|
141
|
-
return { database, serviceItem, pronghornProps };
|
|
142
|
-
};
|
|
143
|
-
|
|
144
120
|
const offline = async () => {
|
|
145
121
|
console.log('Start offline troubleshooting');
|
|
146
122
|
const { updatedAdapter } = VerifyHealthCheckEndpoint({ properties: sampleProperties }, {}, true);
|
|
@@ -159,7 +135,7 @@ const offline = async () => {
|
|
|
159
135
|
|
|
160
136
|
const troubleshoot = async (props, scriptFlag, persistFlag, adapter) => {
|
|
161
137
|
// get database connection and existing adapter config
|
|
162
|
-
const { database, serviceItem } = await getAdapterConfig();
|
|
138
|
+
const { database, serviceItem } = await utils.getAdapterConfig();
|
|
163
139
|
// where troubleshoot should start
|
|
164
140
|
if (serviceItem) {
|
|
165
141
|
if (!scriptFlag || rls.keyInYN(`Start verifying the connection and authentication properties for ${name}?`)) {
|
|
@@ -211,4 +187,4 @@ const troubleshoot = async (props, scriptFlag, persistFlag, adapter) => {
|
|
|
211
187
|
return null;
|
|
212
188
|
};
|
|
213
189
|
|
|
214
|
-
module.exports = { troubleshoot,
|
|
190
|
+
module.exports = { troubleshoot, offline };
|