@itentialopensource/adapter-azure_devops 0.1.1
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 +5 -0
- package/.eslintrc.js +18 -0
- package/.jshintrc +3 -0
- package/CHANGELOG.md +9 -0
- package/CODE_OF_CONDUCT.md +48 -0
- package/CONTRIBUTING.md +158 -0
- package/LICENSE +201 -0
- package/README.md +687 -0
- package/adapter.js +1606 -0
- package/adapterBase.js +1028 -0
- package/entities/.generic/action.json +109 -0
- package/entities/.generic/schema.json +23 -0
- package/entities/.system/action.json +50 -0
- package/entities/.system/mockdatafiles/getToken-default.json +3 -0
- package/entities/.system/mockdatafiles/healthcheck-default.json +3 -0
- package/entities/.system/schema.json +19 -0
- package/entities/.system/schemaTokenReq.json +53 -0
- package/entities/.system/schemaTokenResp.json +53 -0
- package/entities/Artifacts/action.json +25 -0
- package/entities/Artifacts/mockdatafiles/artifactsGet-default.json +5 -0
- package/entities/Artifacts/schema.json +41 -0
- package/entities/Logs/action.json +46 -0
- package/entities/Logs/mockdatafiles/logsGet-default.json +11 -0
- package/entities/Logs/mockdatafiles/logsList-default.json +119 -0
- package/entities/Logs/schema.json +42 -0
- package/entities/Pipelines/action.json +66 -0
- package/entities/Pipelines/mockdatafiles/pipelinesCreate-default.json +6 -0
- package/entities/Pipelines/mockdatafiles/pipelinesGet-default.json +6 -0
- package/entities/Pipelines/mockdatafiles/pipelinesList-default.json +26 -0
- package/entities/Pipelines/schema.json +43 -0
- package/entities/Preview/action.json +24 -0
- package/entities/Preview/mockdatafiles/previewPreview-default.json +3 -0
- package/entities/Preview/schema.json +30 -0
- package/entities/Runs/action.json +66 -0
- package/entities/Runs/mockdatafiles/runsGet-default.json +4 -0
- package/entities/Runs/mockdatafiles/runsList-default.json +18 -0
- package/entities/Runs/mockdatafiles/runsRunPipeline-default.json +4 -0
- package/entities/Runs/schema.json +32 -0
- package/error.json +184 -0
- package/package.json +85 -0
- package/pronghorn.json +2488 -0
- package/propertiesSchema.json +840 -0
- package/refs?service=git-upload-pack +0 -0
- package/report/ado.json +1382 -0
- package/report/creationReport.json +228 -0
- package/report/updateReport1639421539710.json +95 -0
- package/sampleProperties.json +106 -0
- package/test/integration/adapterTestBasicGet.js +85 -0
- package/test/integration/adapterTestConnectivity.js +93 -0
- package/test/integration/adapterTestIntegration.js +751 -0
- package/test/unit/adapterBaseTestUnit.js +944 -0
- package/test/unit/adapterTestUnit.js +2192 -0
- package/utils/addAuth.js +94 -0
- package/utils/artifactize.js +146 -0
- package/utils/basicGet.js +50 -0
- package/utils/checkMigrate.js +63 -0
- package/utils/entitiesToDB.js +224 -0
- package/utils/findPath.js +74 -0
- package/utils/modify.js +154 -0
- package/utils/packModificationScript.js +35 -0
- package/utils/pre-commit.sh +27 -0
- package/utils/removeHooks.js +20 -0
- package/utils/setup.js +33 -0
- package/utils/tbScript.js +169 -0
- package/utils/tbUtils.js +445 -0
- package/utils/testRunner.js +298 -0
- package/utils/troubleshootingAdapter.js +190 -0
- package/workflows/README.md +3 -0
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
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* @copyright Itential, LLC 2019 */
|
|
3
|
+
|
|
4
|
+
const fs = require('fs-extra');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const { spawnSync } = require('child_process');
|
|
7
|
+
const { createBundle } = require('./artifactize');
|
|
8
|
+
|
|
9
|
+
const nodeEntryPath = path.resolve('.');
|
|
10
|
+
createBundle(nodeEntryPath).then((pathObj) => {
|
|
11
|
+
const { bundlePath, bundledAdapterPath } = pathObj;
|
|
12
|
+
const npmIgnorePath = path.join(bundledAdapterPath, '.npmignore');
|
|
13
|
+
const adapterPackagePath = path.join(bundledAdapterPath, 'package.json');
|
|
14
|
+
const artifactPackagePath = path.join(bundlePath, 'package.json');
|
|
15
|
+
|
|
16
|
+
// remove node_modules from .npmIgnore so that node_modules are included in the resulting tar from npm pack
|
|
17
|
+
let npmIgnoreString;
|
|
18
|
+
if (fs.existsSync(npmIgnorePath)) {
|
|
19
|
+
npmIgnoreString = fs.readFileSync(npmIgnorePath, 'utf8');
|
|
20
|
+
npmIgnoreString = npmIgnoreString.replace('node_modules', '');
|
|
21
|
+
npmIgnoreString = npmIgnoreString.replace('\n\n', '\n');
|
|
22
|
+
fs.writeFileSync(npmIgnorePath, npmIgnoreString);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// add files to package so that node_modules are included in the resulting tar from npm pack
|
|
26
|
+
const adapterPackage = fs.readJSONSync(adapterPackagePath);
|
|
27
|
+
adapterPackage.files = ['*'];
|
|
28
|
+
fs.writeJSONSync(artifactPackagePath, adapterPackage, { spaces: 2 });
|
|
29
|
+
const npmResult = spawnSync('npm', ['pack', '-q', bundlePath], { cwd: path.resolve(bundlePath, '..') });
|
|
30
|
+
if (npmResult.status === 0) {
|
|
31
|
+
fs.removeSync(bundlePath);
|
|
32
|
+
console.log('Bundle folder removed');
|
|
33
|
+
}
|
|
34
|
+
console.log('Script successful');
|
|
35
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# @copyright Itential, LLC 2019
|
|
3
|
+
|
|
4
|
+
#exit on any failure in the pipeline
|
|
5
|
+
set -e
|
|
6
|
+
|
|
7
|
+
# --------------------------------------------------
|
|
8
|
+
# pre-commit
|
|
9
|
+
# --------------------------------------------------
|
|
10
|
+
# Contains the standard set of tasks to runbefore
|
|
11
|
+
# committing changes to the repo. If any tasks fail
|
|
12
|
+
# then the commit will be aborted.
|
|
13
|
+
# --------------------------------------------------
|
|
14
|
+
|
|
15
|
+
printf "%b" "Running pre-commit hooks...\\n"
|
|
16
|
+
|
|
17
|
+
# verify testing script is stubbed and no credentials
|
|
18
|
+
node utils/testRunner.js -r
|
|
19
|
+
|
|
20
|
+
# security audit on the code
|
|
21
|
+
npm audit --registry=https://registry.npmjs.org --audit-level=moderate
|
|
22
|
+
|
|
23
|
+
# lint the code
|
|
24
|
+
npm run lint
|
|
25
|
+
|
|
26
|
+
# test the code
|
|
27
|
+
npm run test
|
|
@@ -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
|
+
});
|
package/utils/setup.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* @copyright Itential, LLC 2019 */
|
|
3
|
+
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This script will execute before an npm install command. The purpose is to
|
|
8
|
+
* write out some standard git hooks that will enable folks working on this
|
|
9
|
+
* project to benefit from the protections that the hooks provide.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const precommit = fs.readFileSync('utils/pre-commit.sh', 'utf8');
|
|
13
|
+
|
|
14
|
+
fs.stat('.git', (err) => {
|
|
15
|
+
if (err == null) {
|
|
16
|
+
// git repo, not an npm repo.
|
|
17
|
+
// add pre-commit hook if it doesn't exist
|
|
18
|
+
fs.stat('.git/hooks/pre-commit', (statErr) => {
|
|
19
|
+
if (statErr == null || statErr.code === 'ENOENT') {
|
|
20
|
+
fs.writeFile('.git/hooks/pre-commit', precommit, {
|
|
21
|
+
mode: 0o755
|
|
22
|
+
}, (writeErr) => {
|
|
23
|
+
if (writeErr) {
|
|
24
|
+
return console.log(writeErr.message);
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
});
|
|
28
|
+
} else {
|
|
29
|
+
console.log(statErr.message);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/* eslint no-console: warn */
|
|
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 path = require('path');
|
|
11
|
+
const program = require('commander');
|
|
12
|
+
const rls = require('readline-sync');
|
|
13
|
+
const utils = require('./tbUtils');
|
|
14
|
+
const basicGet = require('./basicGet');
|
|
15
|
+
const { name } = require('../package.json');
|
|
16
|
+
const sampleProperties = require('../sampleProperties.json');
|
|
17
|
+
const adapterPronghorn = require('../pronghorn.json');
|
|
18
|
+
const { addAuthInfo } = require('./addAuth');
|
|
19
|
+
|
|
20
|
+
const { troubleshoot, offline } = require('./troubleshootingAdapter');
|
|
21
|
+
|
|
22
|
+
const main = async (command) => {
|
|
23
|
+
const dirname = utils.getDirname();
|
|
24
|
+
const iapDir = path.join(dirname, '../../../../');
|
|
25
|
+
if (!utils.withinIAP(iapDir)) {
|
|
26
|
+
if (command === 'install') {
|
|
27
|
+
console.log('Not currently in IAP directory - installation not possible');
|
|
28
|
+
process.exit(0);
|
|
29
|
+
} else if (command === 'connectivity') {
|
|
30
|
+
const { host } = sampleProperties.properties;
|
|
31
|
+
console.log(`perform networking diagnositics to ${host}`);
|
|
32
|
+
await utils.runConnectivity(host);
|
|
33
|
+
process.exit(0);
|
|
34
|
+
} else if (command === 'healthcheck') {
|
|
35
|
+
const a = basicGet.getAdapterInstance({ properties: sampleProperties });
|
|
36
|
+
await utils.healthCheck(a);
|
|
37
|
+
process.exit(0);
|
|
38
|
+
} else if (command === 'basicget') {
|
|
39
|
+
await utils.runBasicGet();
|
|
40
|
+
process.exit(0);
|
|
41
|
+
}
|
|
42
|
+
if (rls.keyInYN('Troubleshooting without IAP?')) {
|
|
43
|
+
await offline();
|
|
44
|
+
}
|
|
45
|
+
process.exit(0);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (command === undefined) {
|
|
49
|
+
await troubleshoot({}, true, true);
|
|
50
|
+
} else if (command === 'install') {
|
|
51
|
+
const { database, serviceItem, pronghornProps } = await utils.getAdapterConfig();
|
|
52
|
+
const filter = { id: pronghornProps.id };
|
|
53
|
+
const profileItem = await database.collection(utils.IAP_PROFILES_COLLECTION).findOne(filter);
|
|
54
|
+
if (!profileItem) {
|
|
55
|
+
console.log(`Could not find IAP profile for id ${pronghornProps.id}`);
|
|
56
|
+
process.exit(0);
|
|
57
|
+
}
|
|
58
|
+
if (serviceItem) {
|
|
59
|
+
console.log(`A service by the name ${name} already exits!`);
|
|
60
|
+
if (rls.keyInYN(`Do you want to completely remove ${name}?`)) {
|
|
61
|
+
console.log(`Removing ${name} from db...`);
|
|
62
|
+
await database.collection(utils.SERVICE_CONFIGS_COLLECTION).deleteOne({ model: name });
|
|
63
|
+
console.log(`${name} removed from db.`);
|
|
64
|
+
if (profileItem.services.includes(serviceItem.name)) {
|
|
65
|
+
const serviceIndex = profileItem.services.indexOf(serviceItem.name);
|
|
66
|
+
profileItem.services.splice(serviceIndex, 1);
|
|
67
|
+
const update = { $set: { services: profileItem.services } };
|
|
68
|
+
await database.collection(utils.IAP_PROFILES_COLLECTION).updateOne(
|
|
69
|
+
{ id: pronghornProps.id }, update
|
|
70
|
+
);
|
|
71
|
+
console.log(`${serviceItem.name} removed from profileItem.services.`);
|
|
72
|
+
console.log(`Rerun the script to reinstall ${serviceItem.name}.`);
|
|
73
|
+
process.exit(0);
|
|
74
|
+
} else {
|
|
75
|
+
process.exit(0);
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
console.log('Exiting...');
|
|
79
|
+
process.exit(0);
|
|
80
|
+
}
|
|
81
|
+
} else {
|
|
82
|
+
utils.verifyInstallationDir(dirname, name);
|
|
83
|
+
utils.runTest();
|
|
84
|
+
if (rls.keyInYN(`Do you want to install ${name} to IAP?`)) {
|
|
85
|
+
console.log('Creating database entries...');
|
|
86
|
+
const adapter = utils.createAdapter(
|
|
87
|
+
pronghornProps, profileItem, sampleProperties, adapterPronghorn
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
adapter.properties.properties = await addAuthInfo(adapter.properties.properties);
|
|
91
|
+
|
|
92
|
+
await database.collection(utils.SERVICE_CONFIGS_COLLECTION).insertOne(adapter);
|
|
93
|
+
profileItem.services.push(adapter.name);
|
|
94
|
+
const update = { $set: { services: profileItem.services } };
|
|
95
|
+
await database.collection(utils.IAP_PROFILES_COLLECTION).updateOne(
|
|
96
|
+
{ id: pronghornProps.id }, update
|
|
97
|
+
);
|
|
98
|
+
console.log('Database entry creation complete.');
|
|
99
|
+
}
|
|
100
|
+
console.log('Exiting...');
|
|
101
|
+
process.exit(0);
|
|
102
|
+
}
|
|
103
|
+
} else if (['healthcheck', 'basicget', 'connectivity'].includes(command)) {
|
|
104
|
+
const { serviceItem } = await utils.getAdapterConfig();
|
|
105
|
+
if (serviceItem) {
|
|
106
|
+
const adapter = serviceItem;
|
|
107
|
+
const a = basicGet.getAdapterInstance(adapter);
|
|
108
|
+
if (command === 'healthcheck') {
|
|
109
|
+
await utils.healthCheck(a);
|
|
110
|
+
process.exit(0);
|
|
111
|
+
} else if (command === 'basicget') {
|
|
112
|
+
await utils.runBasicGet(true);
|
|
113
|
+
} else if (command === 'connectivity') {
|
|
114
|
+
const { host } = adapter.properties.properties;
|
|
115
|
+
console.log(`perform networking diagnositics to ${host}`);
|
|
116
|
+
await utils.runConnectivity(host, true);
|
|
117
|
+
process.exit(0);
|
|
118
|
+
}
|
|
119
|
+
} else {
|
|
120
|
+
console.log(`${name} not installed. Run npm \`run install:adapter\` to install.`);
|
|
121
|
+
process.exit(0);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
program
|
|
127
|
+
.command('connectivity')
|
|
128
|
+
.alias('c')
|
|
129
|
+
.description('networking diagnostics')
|
|
130
|
+
.action(() => {
|
|
131
|
+
main('connectivity');
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
program
|
|
135
|
+
.command('install')
|
|
136
|
+
.alias('i')
|
|
137
|
+
.description('install current adapter')
|
|
138
|
+
.action(() => {
|
|
139
|
+
main('install');
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
program
|
|
143
|
+
.command('healthcheck')
|
|
144
|
+
.alias('hc')
|
|
145
|
+
.description('perfom none interative healthcheck with current setting')
|
|
146
|
+
.action(() => {
|
|
147
|
+
main('healthcheck');
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
program
|
|
151
|
+
.command('basicget')
|
|
152
|
+
.alias('bg')
|
|
153
|
+
.description('perfom basicget')
|
|
154
|
+
.action(() => {
|
|
155
|
+
main('basicget');
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// Allow commander to parse `process.argv`
|
|
159
|
+
program.parse(process.argv);
|
|
160
|
+
|
|
161
|
+
if (process.argv.length < 3) {
|
|
162
|
+
main();
|
|
163
|
+
}
|
|
164
|
+
const allowedParams = ['install', 'healthcheck', 'basicget', 'connectivity'];
|
|
165
|
+
if (process.argv.length === 3 && !allowedParams.includes(process.argv[2])) {
|
|
166
|
+
console.log(`unknown parameter ${process.argv[2]}`);
|
|
167
|
+
console.log('try `node troubleshootingAdapter.js -h` to see allowed parameters. Exiting...');
|
|
168
|
+
process.exit(0);
|
|
169
|
+
}
|