@itentialopensource/adapter-datadog 0.5.2 → 0.6.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/.eslintignore +1 -0
- package/.eslintrc.js +12 -12
- package/AUTH.md +39 -0
- package/BROKER.md +199 -0
- package/CALLS.md +169 -0
- package/CHANGELOG.md +50 -16
- package/CODE_OF_CONDUCT.md +12 -17
- package/CONTRIBUTING.md +88 -74
- package/ENHANCE.md +69 -0
- package/PROPERTIES.md +641 -0
- package/README.md +244 -392
- package/SUMMARY.md +9 -0
- package/SYSTEMINFO.md +11 -0
- package/TROUBLESHOOT.md +47 -0
- package/adapter.js +1415 -86
- package/adapterBase.js +1331 -50
- package/entities/.generic/action.json +214 -0
- package/entities/.generic/schema.json +28 -0
- package/entities/.system/action.json +1 -1
- package/error.json +12 -0
- package/package.json +47 -23
- package/pronghorn.json +642 -0
- package/propertiesDecorators.json +14 -0
- package/propertiesSchema.json +505 -11
- package/refs?service=git-upload-pack +0 -0
- package/report/adapterInfo.json +10 -0
- package/report/updateReport1594143341130.json +95 -0
- package/report/updateReport1614879713647.json +95 -0
- package/report/updateReport1653677151204.json +120 -0
- package/sampleProperties.json +110 -6
- package/test/integration/adapterTestBasicGet.js +85 -0
- package/test/integration/adapterTestConnectivity.js +93 -0
- package/test/integration/adapterTestIntegration.js +33 -96
- package/test/unit/adapterBaseTestUnit.js +949 -0
- package/test/unit/adapterTestUnit.js +643 -104
- package/utils/adapterInfo.js +206 -0
- package/utils/addAuth.js +94 -0
- package/utils/artifactize.js +9 -14
- package/utils/basicGet.js +50 -0
- package/utils/checkMigrate.js +63 -0
- package/utils/entitiesToDB.js +179 -0
- package/utils/findPath.js +74 -0
- package/utils/modify.js +154 -0
- package/utils/packModificationScript.js +1 -1
- package/utils/patches2bundledDeps.js +90 -0
- package/utils/pre-commit.sh +4 -1
- package/utils/removeHooks.js +20 -0
- package/utils/tbScript.js +184 -0
- package/utils/tbUtils.js +469 -0
- package/utils/testRunner.js +16 -16
- package/utils/troubleshootingAdapter.js +190 -0
- package/gl-code-quality-report.json +0 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* @copyright Itential, LLC 2019 */
|
|
3
|
+
/* eslint global-require:warn */
|
|
4
|
+
/* eslint import/no-dynamic-require:warn */
|
|
5
|
+
/* eslint prefer-destructuring:warn */
|
|
6
|
+
|
|
7
|
+
const fs = require('fs-extra');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const rls = require('readline-sync');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* This script will determine the type of integration test to run
|
|
13
|
+
* based on input. If other information is needed, it will solicit
|
|
14
|
+
* that input and then edit the integration test accordingly.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Updates the action files
|
|
19
|
+
*/
|
|
20
|
+
function checkActionFiles(apath) {
|
|
21
|
+
// verify the path
|
|
22
|
+
if (!apath) {
|
|
23
|
+
console.log(' NO PATH PROVIDED!');
|
|
24
|
+
return 'Done';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// make sure the entities directory exists
|
|
28
|
+
const entitydir = path.join(__dirname, '../entities');
|
|
29
|
+
if (!fs.statSync(entitydir).isDirectory()) {
|
|
30
|
+
console.log('Could not find the entities directory');
|
|
31
|
+
return 'error';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const entities = fs.readdirSync(entitydir);
|
|
35
|
+
let found = false;
|
|
36
|
+
|
|
37
|
+
// need to go through each entity in the entities directory
|
|
38
|
+
for (let e = 0; e < entities.length; e += 1) {
|
|
39
|
+
// make sure the entity is a directory - do not care about extra files
|
|
40
|
+
// only entities (dir)
|
|
41
|
+
if (fs.statSync(`${entitydir}/${entities[e]}`).isDirectory()) {
|
|
42
|
+
// see if the action file exists in the entity
|
|
43
|
+
if (fs.existsSync(`${entitydir}/${entities[e]}/action.json`)) {
|
|
44
|
+
// Read the entity actions from the file system
|
|
45
|
+
const actions = require(`${entitydir}/${entities[e]}/action.json`);
|
|
46
|
+
|
|
47
|
+
// go through all of the actions set the appropriate info in the newActions
|
|
48
|
+
for (let a = 0; a < actions.actions.length; a += 1) {
|
|
49
|
+
if (actions.actions[a].entitypath.indexOf(apath) >= 0) {
|
|
50
|
+
found = true;
|
|
51
|
+
console.log(` Found - entity: ${entities[e]} action: ${actions.actions[a].name}`);
|
|
52
|
+
console.log(` method: ${actions.actions[a].method} path: ${actions.actions[a].entitypath}`);
|
|
53
|
+
console.log(' ');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
console.log(`Could not find entities ${entities[e]} action.json file`);
|
|
58
|
+
return 'error';
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
console.log(`Could not find entities ${entities[e]} directory`);
|
|
62
|
+
return 'error';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (!found) {
|
|
67
|
+
console.log(' PATH NOT FOUND!');
|
|
68
|
+
}
|
|
69
|
+
return 'Done';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const findPath = rls.question('Enter the path/partial path you are looking for: ');
|
|
73
|
+
console.log(`PATH: ${findPath}`);
|
|
74
|
+
checkActionFiles(findPath);
|
package/utils/modify.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
const fs = require('fs-extra');
|
|
2
|
+
const Ajv = require('ajv');
|
|
3
|
+
const rls = require('readline-sync');
|
|
4
|
+
const { execSync } = require('child_process');
|
|
5
|
+
const { existsSync } = require('fs-extra');
|
|
6
|
+
const { getAdapterConfig } = require('./tbUtils');
|
|
7
|
+
const { name } = require('../package.json');
|
|
8
|
+
const propertiesSchema = require('../propertiesSchema.json');
|
|
9
|
+
|
|
10
|
+
const flags = process.argv[2];
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @summary Updates database instance with new adapter properties
|
|
14
|
+
*
|
|
15
|
+
* @function updateServiceItem
|
|
16
|
+
*/
|
|
17
|
+
async function updateServiceItem() {
|
|
18
|
+
const { database, serviceItem } = await getAdapterConfig();
|
|
19
|
+
const currentProps = serviceItem.properties.properties;
|
|
20
|
+
const ajv = new Ajv({ allErrors: true, useDefaults: true });
|
|
21
|
+
const validate = ajv.compile(propertiesSchema);
|
|
22
|
+
validate(currentProps);
|
|
23
|
+
console.log('Updating Properties...');
|
|
24
|
+
await database.collection('service_configs').updateOne(
|
|
25
|
+
{ model: name }, { $set: serviceItem }
|
|
26
|
+
);
|
|
27
|
+
console.log('Properties Updated');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @summary Creates a backup zip file of current adapter
|
|
32
|
+
*
|
|
33
|
+
* @function backup
|
|
34
|
+
*/
|
|
35
|
+
function backup() {
|
|
36
|
+
// zip all files except node_modules and package-lock
|
|
37
|
+
const backupCmd = 'zip -r previousVersion.zip .';
|
|
38
|
+
execSync(backupCmd, { encoding: 'utf-8' });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @summary Archives previous modifications and removes the modification package
|
|
43
|
+
*
|
|
44
|
+
* @function archiveMod
|
|
45
|
+
* @param {String} modType - update(UPD) or migrate(MIG)
|
|
46
|
+
*/
|
|
47
|
+
function archiveMod(modType) {
|
|
48
|
+
if (!existsSync('./adapter_modifications/archive')) {
|
|
49
|
+
execSync('mkdir ./adapter_modifications/archive');
|
|
50
|
+
}
|
|
51
|
+
const zipFile = modType === 'UPD' ? 'updatePackage.zip' : 'migrationPackage.zip';
|
|
52
|
+
const now = new Date();
|
|
53
|
+
const archiveName = `${modType}-${now.toISOString()}`;
|
|
54
|
+
execSync(`mkdir adapter_modifications/archive/${archiveName}`);
|
|
55
|
+
const archiveCmd = 'mv adapter_modifications/archive .'
|
|
56
|
+
+ ` && mv adapter_modifications/* archive/${archiveName}`
|
|
57
|
+
+ ' && mv archive adapter_modifications'
|
|
58
|
+
+ ` && rm ${zipFile}`;
|
|
59
|
+
execSync(archiveCmd, { encoding: 'utf-8' });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @summary Reverts modifications using backup zip file
|
|
64
|
+
*
|
|
65
|
+
* @function revertMod
|
|
66
|
+
*/
|
|
67
|
+
function revertMod() {
|
|
68
|
+
const files = fs.readdirSync('./');
|
|
69
|
+
// remove all files except previousVersion
|
|
70
|
+
files.forEach((file) => {
|
|
71
|
+
if (file !== 'previousVersion.zip') {
|
|
72
|
+
fs.removeSync(file);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
// // unzip previousVersion, reinstall dependencies and delete zipfile
|
|
76
|
+
execSync('unzip -o previousVersion.zip && rm -rf node_modules && rm package-lock.json && npm install');
|
|
77
|
+
execSync('rm previousVersion.zip');
|
|
78
|
+
console.log('Changes have been reverted');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Main Script
|
|
82
|
+
|
|
83
|
+
// Migrate
|
|
84
|
+
if (flags === '-m') {
|
|
85
|
+
if (!fs.existsSync('migrationPackage.zip')) {
|
|
86
|
+
console.log('Migration Package not found. Download and place migrationPackage in the adapter root directory');
|
|
87
|
+
process.exit();
|
|
88
|
+
}
|
|
89
|
+
// Backup current adapter
|
|
90
|
+
backup();
|
|
91
|
+
console.log('Migrating adapter and running tests...');
|
|
92
|
+
const migrateCmd = 'unzip -o migrationPackage.zip'
|
|
93
|
+
+ ' && cd adapter_modifications'
|
|
94
|
+
+ ' && node migrate';
|
|
95
|
+
const migrateOutput = execSync(migrateCmd, { encoding: 'utf-8' });
|
|
96
|
+
console.log(migrateOutput);
|
|
97
|
+
if (migrateOutput.indexOf('Lint exited with code 1') >= 0
|
|
98
|
+
|| migrateOutput.indexOf('Tests exited with code 1') >= 0) {
|
|
99
|
+
if (rls.keyInYN('Adapter failed tests or lint after migrating. Would you like to revert the changes?')) {
|
|
100
|
+
console.log('Reverting changes...');
|
|
101
|
+
revertMod();
|
|
102
|
+
process.exit();
|
|
103
|
+
}
|
|
104
|
+
console.log('Adapter Migration will continue. If you want to revert the changes, run the command npm run adapter:revert');
|
|
105
|
+
}
|
|
106
|
+
console.log('Installing new dependencies..');
|
|
107
|
+
const updatePackageCmd = 'rm -rf node_modules && rm package-lock.json && npm install';
|
|
108
|
+
const updatePackageOutput = execSync(updatePackageCmd, { encoding: 'utf-8' });
|
|
109
|
+
console.log(updatePackageOutput);
|
|
110
|
+
console.log('New dependencies installed');
|
|
111
|
+
console.log('Updating adapter properties..');
|
|
112
|
+
updateServiceItem().then(() => {
|
|
113
|
+
console.log('Adapter Successfully Migrated. Restart adapter in IAP to apply the changes');
|
|
114
|
+
archiveMod('MIG');
|
|
115
|
+
process.exit();
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Update
|
|
120
|
+
if (flags === '-u') {
|
|
121
|
+
if (!fs.existsSync('updatePackage.zip')) {
|
|
122
|
+
console.log('Update Package not found. Download and place updateAdapter.zip in the adapter root directory');
|
|
123
|
+
process.exit();
|
|
124
|
+
}
|
|
125
|
+
// Backup current adapter
|
|
126
|
+
backup();
|
|
127
|
+
const updateCmd = 'unzip -o updatePackage.zip'
|
|
128
|
+
+ ' && cd adapter_modifications'
|
|
129
|
+
+ ' && node update.js updateFiles';
|
|
130
|
+
execSync(updateCmd, { encoding: 'utf-8' });
|
|
131
|
+
const updateOutput = execSync(updateCmd, { encoding: 'utf-8' });
|
|
132
|
+
if (updateOutput.indexOf('Lint exited with code 1') >= 0
|
|
133
|
+
|| updateOutput.indexOf('Tests exited with code 1') >= 0) {
|
|
134
|
+
if (rls.keyInYN('Adapter failed tests or lint after updating. Would you like to revert the changes?')) {
|
|
135
|
+
console.log('Reverting changes...');
|
|
136
|
+
revertMod();
|
|
137
|
+
process.exit();
|
|
138
|
+
}
|
|
139
|
+
console.log('Adapter Update will continue. If you want to revert the changes, run the command npm run adapter:revert');
|
|
140
|
+
}
|
|
141
|
+
console.log(updateOutput);
|
|
142
|
+
console.log('Adapter Successfully Updated. Restart adapter in IAP to apply the changes');
|
|
143
|
+
archiveMod('UPD');
|
|
144
|
+
process.exit();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Revert
|
|
148
|
+
if (flags === '-r') {
|
|
149
|
+
if (!fs.existsSync('previousVersion.zip')) {
|
|
150
|
+
console.log('Previous adapter version not found. There are no changes to revert');
|
|
151
|
+
process.exit();
|
|
152
|
+
}
|
|
153
|
+
revertMod();
|
|
154
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
const fs = require('fs-extra');
|
|
5
5
|
const path = require('path');
|
|
6
6
|
const { spawnSync } = require('child_process');
|
|
7
|
-
const { createBundle } = require('./artifactize
|
|
7
|
+
const { createBundle } = require('./artifactize');
|
|
8
8
|
|
|
9
9
|
const nodeEntryPath = path.resolve('.');
|
|
10
10
|
createBundle(nodeEntryPath).then((pathObj) => {
|
|
@@ -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/pre-commit.sh
CHANGED
|
@@ -17,8 +17,11 @@ printf "%b" "Running pre-commit hooks...\\n"
|
|
|
17
17
|
# verify testing script is stubbed and no credentials
|
|
18
18
|
node utils/testRunner.js -r
|
|
19
19
|
|
|
20
|
+
# update the adapter information file
|
|
21
|
+
node utils/adapterInfo.js
|
|
22
|
+
|
|
20
23
|
# security audit on the code
|
|
21
|
-
npm audit --registry=https://registry.npmjs.org
|
|
24
|
+
npm audit --registry=https://registry.npmjs.org --audit-level=moderate
|
|
22
25
|
|
|
23
26
|
# lint the code
|
|
24
27
|
npm run lint
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This script will uninstall pre-commit or pre-push hooks in case there's ever a need to
|
|
5
|
+
* commit/push something that has issues
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const precommitPath = '.git/hooks/pre-commit';
|
|
9
|
+
const prepushPath = '.git/hooks/pre-push';
|
|
10
|
+
fs.unlink(precommitPath, (err) => {
|
|
11
|
+
if (err && err.code !== 'ENOENT') {
|
|
12
|
+
console.log(`${err.message}`);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
fs.unlink(prepushPath, (err) => {
|
|
17
|
+
if (err && err.code !== 'ENOENT') {
|
|
18
|
+
console.log(`${err.message}`);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
/* eslint import/no-unresolved: warn */
|
|
3
|
+
/* eslint global-require: warn */
|
|
4
|
+
|
|
5
|
+
// suppress eslint rule in adapter
|
|
6
|
+
/* eslint arrow-parens: warn */
|
|
7
|
+
/* eslint import/no-extraneous-dependencies: warn */
|
|
8
|
+
/* eslint import/no-dynamic-require: warn */
|
|
9
|
+
|
|
10
|
+
const program = require('commander');
|
|
11
|
+
const rls = require('readline-sync');
|
|
12
|
+
const utils = require('./tbUtils');
|
|
13
|
+
const basicGet = require('./basicGet');
|
|
14
|
+
const { name } = require('../package.json');
|
|
15
|
+
const sampleProperties = require('../sampleProperties.json');
|
|
16
|
+
const adapterPronghorn = require('../pronghorn.json');
|
|
17
|
+
const { addAuthInfo } = require('./addAuth');
|
|
18
|
+
|
|
19
|
+
const { troubleshoot, offline } = require('./troubleshootingAdapter');
|
|
20
|
+
|
|
21
|
+
const executeInStandaloneMode = async (command) => {
|
|
22
|
+
console.info('\n> Executing the script outside of IAP installation directory');
|
|
23
|
+
console.info('> Using sampleProperties.json configuration');
|
|
24
|
+
switch (command) {
|
|
25
|
+
case 'install': {
|
|
26
|
+
console.error('Not currently in IAP directory - installation not possible');
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
case 'connectivity': {
|
|
30
|
+
const { host } = sampleProperties.properties;
|
|
31
|
+
console.log(`perform networking diagnositics to ${host}`);
|
|
32
|
+
utils.runConnectivity(host);
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
case 'healthcheck': {
|
|
36
|
+
const a = basicGet.getAdapterInstance({ properties: sampleProperties });
|
|
37
|
+
await utils.healthCheck(a);
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
case 'basicget': {
|
|
41
|
+
utils.runBasicGet();
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
default: {
|
|
45
|
+
if (rls.keyInYN('Troubleshooting without IAP?')) {
|
|
46
|
+
await offline();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
process.exit(0);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const executeUnderIAPInstallationDirectory = async (command) => {
|
|
54
|
+
if (command === undefined) {
|
|
55
|
+
await troubleshoot({}, true, true);
|
|
56
|
+
} else if (command === 'install') {
|
|
57
|
+
const { database, serviceItem, pronghornProps } = await utils.getAdapterConfig();
|
|
58
|
+
const filter = { id: pronghornProps.id };
|
|
59
|
+
const profileItem = await database.collection(utils.IAP_PROFILES_COLLECTION).findOne(filter);
|
|
60
|
+
if (!profileItem) {
|
|
61
|
+
console.log(`Could not find IAP profile for id ${pronghornProps.id}`);
|
|
62
|
+
process.exit(0);
|
|
63
|
+
}
|
|
64
|
+
if (serviceItem) {
|
|
65
|
+
console.log(`A service by the name ${name} already exits!`);
|
|
66
|
+
if (rls.keyInYN(`Do you want to completely remove ${name}?`)) {
|
|
67
|
+
console.log(`Removing ${name} from db...`);
|
|
68
|
+
await database.collection(utils.SERVICE_CONFIGS_COLLECTION).deleteOne({ model: name });
|
|
69
|
+
console.log(`${name} removed from db.`);
|
|
70
|
+
if (profileItem.services.includes(serviceItem.name)) {
|
|
71
|
+
const serviceIndex = profileItem.services.indexOf(serviceItem.name);
|
|
72
|
+
profileItem.services.splice(serviceIndex, 1);
|
|
73
|
+
const update = { $set: { services: profileItem.services } };
|
|
74
|
+
await database.collection(utils.IAP_PROFILES_COLLECTION).updateOne(
|
|
75
|
+
{ id: pronghornProps.id }, update
|
|
76
|
+
);
|
|
77
|
+
console.log(`${serviceItem.name} removed from profileItem.services.`);
|
|
78
|
+
console.log(`Rerun the script to reinstall ${serviceItem.name}.`);
|
|
79
|
+
process.exit(0);
|
|
80
|
+
} else {
|
|
81
|
+
process.exit(0);
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
console.log('Exiting...');
|
|
85
|
+
process.exit(0);
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
const dirname = utils.getCurrentExecutionPath();
|
|
89
|
+
utils.verifyInstallationDir(dirname, name);
|
|
90
|
+
utils.runTest();
|
|
91
|
+
if (rls.keyInYN(`Do you want to install ${name} to IAP?`)) {
|
|
92
|
+
console.log('Creating database entries...');
|
|
93
|
+
const adapter = utils.createAdapter(
|
|
94
|
+
pronghornProps, profileItem, sampleProperties, adapterPronghorn
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
adapter.properties.properties = await addAuthInfo(adapter.properties.properties);
|
|
98
|
+
|
|
99
|
+
await database.collection(utils.SERVICE_CONFIGS_COLLECTION).insertOne(adapter);
|
|
100
|
+
profileItem.services.push(adapter.name);
|
|
101
|
+
const update = { $set: { services: profileItem.services } };
|
|
102
|
+
await database.collection(utils.IAP_PROFILES_COLLECTION).updateOne(
|
|
103
|
+
{ id: pronghornProps.id }, update
|
|
104
|
+
);
|
|
105
|
+
console.log('Database entry creation complete.');
|
|
106
|
+
}
|
|
107
|
+
console.log('Exiting...');
|
|
108
|
+
process.exit(0);
|
|
109
|
+
}
|
|
110
|
+
} else if (['healthcheck', 'basicget', 'connectivity'].includes(command)) {
|
|
111
|
+
const { serviceItem } = await utils.getAdapterConfig();
|
|
112
|
+
if (serviceItem) {
|
|
113
|
+
const adapter = serviceItem;
|
|
114
|
+
const a = basicGet.getAdapterInstance(adapter);
|
|
115
|
+
if (command === 'healthcheck') {
|
|
116
|
+
await utils.healthCheck(a);
|
|
117
|
+
process.exit(0);
|
|
118
|
+
} else if (command === 'basicget') {
|
|
119
|
+
await utils.runBasicGet(true);
|
|
120
|
+
} else if (command === 'connectivity') {
|
|
121
|
+
const { host } = adapter.properties.properties;
|
|
122
|
+
console.log(`perform networking diagnositics to ${host}`);
|
|
123
|
+
await utils.runConnectivity(host, true);
|
|
124
|
+
process.exit(0);
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
console.log(`${name} not installed. Run npm \`run install:adapter\` to install.`);
|
|
128
|
+
process.exit(0);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const main = async (command) => {
|
|
134
|
+
if (!utils.areWeUnderIAPinstallationDirectory()) {
|
|
135
|
+
executeInStandaloneMode(command); // configuration from sampleproperties.json
|
|
136
|
+
} else {
|
|
137
|
+
executeUnderIAPInstallationDirectory(command); // configuration from $IAP_HOME/properties.json
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
program
|
|
142
|
+
.command('connectivity')
|
|
143
|
+
.alias('c')
|
|
144
|
+
.description('networking diagnostics')
|
|
145
|
+
.action(() => {
|
|
146
|
+
main('connectivity');
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
program
|
|
150
|
+
.command('install')
|
|
151
|
+
.alias('i')
|
|
152
|
+
.description('install current adapter')
|
|
153
|
+
.action(() => {
|
|
154
|
+
main('install');
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
program
|
|
158
|
+
.command('healthcheck')
|
|
159
|
+
.alias('hc')
|
|
160
|
+
.description('perfom none interative healthcheck with current setting')
|
|
161
|
+
.action(() => {
|
|
162
|
+
main('healthcheck');
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
program
|
|
166
|
+
.command('basicget')
|
|
167
|
+
.alias('bg')
|
|
168
|
+
.description('perfom basicget')
|
|
169
|
+
.action(() => {
|
|
170
|
+
main('basicget');
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// Allow commander to parse `process.argv`
|
|
174
|
+
program.parse(process.argv);
|
|
175
|
+
|
|
176
|
+
if (process.argv.length < 3) {
|
|
177
|
+
main();
|
|
178
|
+
}
|
|
179
|
+
const allowedParams = ['install', 'healthcheck', 'basicget', 'connectivity'];
|
|
180
|
+
if (process.argv.length === 3 && !allowedParams.includes(process.argv[2])) {
|
|
181
|
+
console.log(`unknown parameter ${process.argv[2]}`);
|
|
182
|
+
console.log('try `node troubleshootingAdapter.js -h` to see allowed parameters. Exiting...');
|
|
183
|
+
process.exit(0);
|
|
184
|
+
}
|