@itentialopensource/adapter-zscaler 0.6.5 → 0.7.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 (41) hide show
  1. package/AUTH.md +39 -0
  2. package/BROKER.md +199 -0
  3. package/CALLS.md +169 -0
  4. package/CHANGELOG.md +59 -25
  5. package/CODE_OF_CONDUCT.md +12 -17
  6. package/CONTRIBUTING.md +88 -74
  7. package/ENHANCE.md +69 -0
  8. package/PROPERTIES.md +641 -0
  9. package/README.md +221 -571
  10. package/SUMMARY.md +9 -0
  11. package/SYSTEMINFO.md +11 -0
  12. package/TROUBLESHOOT.md +47 -0
  13. package/adapter.js +433 -143
  14. package/adapterBase.js +1007 -253
  15. package/entities/.generic/action.json +105 -0
  16. package/entities/.generic/schema.json +6 -1
  17. package/entities/.system/action.json +2 -2
  18. package/error.json +6 -0
  19. package/package.json +5 -3
  20. package/pronghorn.json +762 -498
  21. package/propertiesDecorators.json +14 -0
  22. package/propertiesSchema.json +421 -0
  23. package/refs?service=git-upload-pack +0 -0
  24. package/report/adapterInfo.json +10 -0
  25. package/report/updateReport1642619799800.json +95 -0
  26. package/report/updateReport1653331963274.json +120 -0
  27. package/sampleProperties.json +90 -1
  28. package/test/integration/adapterTestBasicGet.js +1 -1
  29. package/test/integration/adapterTestIntegration.js +26 -102
  30. package/test/unit/adapterBaseTestUnit.js +30 -25
  31. package/test/unit/adapterTestUnit.js +168 -156
  32. package/utils/adapterInfo.js +206 -0
  33. package/utils/basicGet.js +0 -17
  34. package/utils/entitiesToDB.js +12 -57
  35. package/utils/modify.js +1 -1
  36. package/utils/patches2bundledDeps.js +90 -0
  37. package/utils/pre-commit.sh +3 -0
  38. package/utils/tbScript.js +38 -23
  39. package/utils/tbUtils.js +91 -28
  40. package/utils/testRunner.js +16 -16
  41. package/utils/troubleshootingAdapter.js +2 -26
@@ -0,0 +1,206 @@
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
+
10
+ /**
11
+ * This script will determine the information about the adapter and store
12
+ * it into a file in the adapter.
13
+ */
14
+
15
+ /**
16
+ * get adapter information
17
+ */
18
+ function adapterInfo() {
19
+ // set the base pase of the adapter - tool shoud be one level up in utils
20
+ let adaptdir = __dirname;
21
+ const infoRes = {};
22
+
23
+ if (adaptdir.endsWith('/utils')) {
24
+ adaptdir = adaptdir.substring(0, adaptdir.length - 6);
25
+ }
26
+ const pack = require(`${adaptdir}/package.json`);
27
+ infoRes.version = pack.version;
28
+
29
+ let configCount = 0;
30
+ if (fs.existsSync(`${adaptdir}/pronghorn.json`)) {
31
+ const cFile = fs.readFileSync(`${adaptdir}/pronghorn.json`, 'utf8');
32
+ configCount += cFile.split('\n').length;
33
+ } else {
34
+ console.log('Missing - pronghorn.json');
35
+ }
36
+ if (fs.existsSync(`${adaptdir}/propertiesSchema.json`)) {
37
+ const cFile = fs.readFileSync(`${adaptdir}/propertiesSchema.json`, 'utf8');
38
+ configCount += cFile.split('\n').length;
39
+ } else {
40
+ console.log('Missing - propertiesSchema.json');
41
+ }
42
+ if (fs.existsSync(`${adaptdir}/error.json`)) {
43
+ const cFile = fs.readFileSync(`${adaptdir}/error.json`, 'utf8');
44
+ configCount += cFile.split('\n').length;
45
+ } else {
46
+ console.log('Missing - error.json');
47
+ }
48
+ const entitydir = path.join(adaptdir, '/entities');
49
+ if (fs.existsSync(entitydir) && fs.statSync(entitydir).isDirectory()) {
50
+ const entities = fs.readdirSync(entitydir);
51
+ // need to go through each entity in the entities directory
52
+ for (let e = 0; e < entities.length; e += 1) {
53
+ if (fs.statSync(`${entitydir}/${entities[e]}`).isDirectory()) {
54
+ const cfiles = fs.readdirSync(entitydir);
55
+ for (let c = 0; c < cfiles.length; c += 1) {
56
+ if (cfiles[c].endsWith('.json')) {
57
+ const ccFile = fs.readFileSync(`${entitydir}/${entities[e]}/${cfiles[c]}`, 'utf8');
58
+ configCount += ccFile.split('\n').length;
59
+ }
60
+ }
61
+ }
62
+ }
63
+ } else {
64
+ console.log('Could not find the entities directory');
65
+ }
66
+ infoRes.configLines = configCount;
67
+
68
+ let scodeCount = 0;
69
+ if (fs.existsSync(`${adaptdir}/utils/artifactize.js`)) {
70
+ const sFile = fs.readFileSync(`${adaptdir}/utils/artifactize.js`, 'utf8');
71
+ scodeCount += sFile.split('\n').length;
72
+ } else {
73
+ console.log('Missing - utils/artifactize.js');
74
+ }
75
+ if (fs.existsSync(`${adaptdir}/utils/basicGet.js`)) {
76
+ const sFile = fs.readFileSync(`${adaptdir}/utils/basicGet.js`, 'utf8');
77
+ scodeCount += sFile.split('\n').length;
78
+ } else {
79
+ console.log('Missing - utils/basicGet.js');
80
+ }
81
+ if (fs.existsSync(`${adaptdir}/utils/checkMigrate.js`)) {
82
+ const sFile = fs.readFileSync(`${adaptdir}/utils/checkMigrate.js`, 'utf8');
83
+ scodeCount += sFile.split('\n').length;
84
+ } else {
85
+ console.log('Missing - utils/checkMigrate.js');
86
+ }
87
+ if (fs.existsSync(`${adaptdir}/utils/findPath.js`)) {
88
+ const sFile = fs.readFileSync(`${adaptdir}/utils/findPath.js`, 'utf8');
89
+ scodeCount += sFile.split('\n').length;
90
+ } else {
91
+ console.log('Missing - utils/findPath.js');
92
+ }
93
+ if (fs.existsSync(`${adaptdir}/utils/modify.js`)) {
94
+ const sFile = fs.readFileSync(`${adaptdir}/utils/modify.js`, 'utf8');
95
+ scodeCount += sFile.split('\n').length;
96
+ } else {
97
+ console.log('Missing - utils/modify.js');
98
+ }
99
+ if (fs.existsSync(`${adaptdir}/utils/packModificationScript.js`)) {
100
+ const sFile = fs.readFileSync(`${adaptdir}/utils/packModificationScript.js`, 'utf8');
101
+ scodeCount += sFile.split('\n').length;
102
+ } else {
103
+ console.log('Missing - utils/packModificationScript.js');
104
+ }
105
+ if (fs.existsSync(`${adaptdir}/utils/setup.js`)) {
106
+ const sFile = fs.readFileSync(`${adaptdir}/utils/setup.js`, 'utf8');
107
+ scodeCount += sFile.split('\n').length;
108
+ } else {
109
+ console.log('Missing - utils/setup.js');
110
+ }
111
+ if (fs.existsSync(`${adaptdir}/utils/tbScript.js`)) {
112
+ const sFile = fs.readFileSync(`${adaptdir}/utils/tbScript.js`, 'utf8');
113
+ scodeCount += sFile.split('\n').length;
114
+ } else {
115
+ console.log('Missing - utils/tbScript.js');
116
+ }
117
+ if (fs.existsSync(`${adaptdir}/utils/tbUtils.js`)) {
118
+ const sFile = fs.readFileSync(`${adaptdir}/utils/tbUtils.js`, 'utf8');
119
+ scodeCount += sFile.split('\n').length;
120
+ } else {
121
+ console.log('Missing - utils/tbUtils.js');
122
+ }
123
+ if (fs.existsSync(`${adaptdir}/utils/testRunner.js`)) {
124
+ const sFile = fs.readFileSync(`${adaptdir}/utils/testRunner.js`, 'utf8');
125
+ scodeCount += sFile.split('\n').length;
126
+ } else {
127
+ console.log('Missing - utils/testRunner.js');
128
+ }
129
+ if (fs.existsSync(`${adaptdir}/utils/troubleshootingAdapter.js`)) {
130
+ const sFile = fs.readFileSync(`${adaptdir}/utils/troubleshootingAdapter.js`, 'utf8');
131
+ scodeCount += sFile.split('\n').length;
132
+ } else {
133
+ console.log('Missing - utils/troubleshootingAdapter.js');
134
+ }
135
+ infoRes.scriptLines = scodeCount;
136
+
137
+ let codeCount = 0;
138
+ if (fs.existsSync(`${adaptdir}/adapter.js`)) {
139
+ const aFile = fs.readFileSync(`${adaptdir}/adapter.js`, 'utf8');
140
+ codeCount += aFile.split('\n').length;
141
+ } else {
142
+ console.log('Missing - utils/adapter.js');
143
+ }
144
+ if (fs.existsSync(`${adaptdir}/adapterBase.js`)) {
145
+ const aFile = fs.readFileSync(`${adaptdir}/adapterBase.js`, 'utf8');
146
+ codeCount += aFile.split('\n').length;
147
+ } else {
148
+ console.log('Missing - utils/adapterBase.js');
149
+ }
150
+ infoRes.codeLines = codeCount;
151
+
152
+ let tcodeCount = 0;
153
+ let ttestCount = 0;
154
+ if (fs.existsSync(`${adaptdir}/test/integration/adapterTestBasicGet.js`)) {
155
+ const tFile = fs.readFileSync(`${adaptdir}/test/integration/adapterTestBasicGet.js`, 'utf8');
156
+ tcodeCount += tFile.split('\n').length;
157
+ ttestCount += tFile.split('it(\'').length;
158
+ } else {
159
+ console.log('Missing - test/integration/adapterTestBasicGet.js');
160
+ }
161
+ if (fs.existsSync(`${adaptdir}/test/integration/adapterTestConnectivity.js`)) {
162
+ const tFile = fs.readFileSync(`${adaptdir}/test/integration/adapterTestConnectivity.js`, 'utf8');
163
+ tcodeCount += tFile.split('\n').length;
164
+ ttestCount += tFile.split('it(\'').length;
165
+ } else {
166
+ console.log('Missing - test/integration/adapterTestConnectivity.js');
167
+ }
168
+ if (fs.existsSync(`${adaptdir}/test/integration/adapterTestIntegration.js`)) {
169
+ const tFile = fs.readFileSync(`${adaptdir}/test/integration/adapterTestIntegration.js`, 'utf8');
170
+ tcodeCount += tFile.split('\n').length;
171
+ ttestCount += tFile.split('it(\'').length;
172
+ } else {
173
+ console.log('Missing - test/integration/adapterTestIntegration.js');
174
+ }
175
+ if (fs.existsSync(`${adaptdir}/test/unit/adapterBaseTestUnit.js`)) {
176
+ const tFile = fs.readFileSync(`${adaptdir}/test/unit/adapterBaseTestUnit.js`, 'utf8');
177
+ tcodeCount += tFile.split('\n').length;
178
+ ttestCount += tFile.split('it(\'').length;
179
+ } else {
180
+ console.log('Missing - test/unit/adapterBaseTestUnit.js');
181
+ }
182
+ if (fs.existsSync(`${adaptdir}/test/unit/adapterTestUnit.js`)) {
183
+ const tFile = fs.readFileSync(`${adaptdir}/test/unit/adapterTestUnit.js`, 'utf8');
184
+ tcodeCount += tFile.split('\n').length;
185
+ ttestCount += tFile.split('it(\'').length;
186
+ } else {
187
+ console.log('Missing - test/unit/adapterTestUnit.js');
188
+ }
189
+ infoRes.testLines = tcodeCount;
190
+ infoRes.testCases = ttestCount;
191
+ infoRes.totalCodeLines = scodeCount + codeCount + tcodeCount;
192
+
193
+ if (fs.existsSync(`${adaptdir}/pronghorn.json`)) {
194
+ // Read the entity schema from the file system
195
+ const phFile = path.join(adaptdir, '/pronghorn.json');
196
+ const prong = require(phFile);
197
+ infoRes.wfTasks = prong.methods.length;
198
+ } else {
199
+ console.log('Missing - pronghorn.json');
200
+ }
201
+
202
+ console.log(JSON.stringify(infoRes));
203
+ fs.writeFileSync(`${adaptdir}/report/adapterInfo.json`, JSON.stringify(infoRes, null, 2));
204
+ }
205
+
206
+ adapterInfo();
package/utils/basicGet.js CHANGED
@@ -6,11 +6,8 @@
6
6
  /* eslint import/no-unresolved: warn */
7
7
  /* eslint import/no-dynamic-require: warn */
8
8
 
9
- const path = require('path');
10
9
  const winston = require('winston');
11
10
 
12
- const utils = require(path.join(__dirname, 'tbUtils'));
13
-
14
11
  const logLevel = 'none';
15
12
  const myCustomLevels = {
16
13
  levels: {
@@ -47,20 +44,6 @@ const basicGet = {
47
44
  adapter.id,
48
45
  adapterProps
49
46
  );
50
- },
51
-
52
- /**
53
- * @summary connect to mongodb
54
- *
55
- * @function connect
56
- * @param {Object} properties - pronghornProps
57
- */
58
- connect: async function connect(properties) {
59
- // Connect to Mongo
60
- const { MongoDBConnection } = require(path.join(utils.getDirname(), '../../../', '@itential/database'));
61
- const connection = new MongoDBConnection(properties.mongoProps);
62
- const database = await connection.connect(true);
63
- return database;
64
47
  }
65
48
  };
66
49
 
@@ -14,10 +14,8 @@
14
14
  */
15
15
 
16
16
  const fs = require('fs');
17
- const { MongoClient } = require('mongodb');
18
17
  const path = require('path');
19
- // const { argv } = require('process');
20
- // const { string } = require('yargs');
18
+ const utils = require('./tbUtils');
21
19
 
22
20
  // get the pronghorn database information
23
21
  const getPronghornProps = async (iapDir) => {
@@ -99,7 +97,7 @@ const optionsHandler = (options) => {
99
97
  /**
100
98
  * Function used to put the adapter configuration into the provided database
101
99
  */
102
- const moveEntitiesToDB = (targetPath, options) => {
100
+ const moveEntitiesToDB = async (targetPath, options) => {
103
101
  // set local variables
104
102
  let myOpts = options;
105
103
  let myPath = targetPath;
@@ -120,25 +118,7 @@ const moveEntitiesToDB = (targetPath, options) => {
120
118
  }
121
119
 
122
120
  // get the pronghorn database properties
123
- optionsHandler(options).then((currentProps) => {
124
- let mongoUrl;
125
- let dbName;
126
-
127
- // find the mongo properties so we can connect
128
- if (currentProps.mongoProps) {
129
- mongoUrl = currentProps.mongoProps.url;
130
- dbName = currentProps.mongoProps.db;
131
- } else if (currentProps.mongo) {
132
- if (currentProps.mongo.url) {
133
- mongoUrl = currentProps.mongo.url;
134
- } else {
135
- mongoUrl = `mongodb://${currentProps.mongo.host}:${currentProps.mongo.port}`;
136
- }
137
- dbName = currentProps.mongo.database;
138
- } else {
139
- throw new Error('Mongo properties are not specified in adapter preferences!');
140
- }
141
-
121
+ return optionsHandler(options).then(async (currentProps) => {
142
122
  // Check valid filepath provided
143
123
  if (!myPath) {
144
124
  // if no path use the current directory without the utils
@@ -184,41 +164,16 @@ const moveEntitiesToDB = (targetPath, options) => {
184
164
  });
185
165
 
186
166
  // Upload documents to db collection
187
- MongoClient.connect(mongoUrl, (err, db) => {
188
- if (err) {
189
- log.error(JSON.stringify(err));
190
- throw err;
191
- }
192
-
193
- // get the proper collection
194
- const collection = db.db(dbName).collection(myOpts.targetCollection);
195
- // insert the documents into the collection
196
- collection.insertMany(docs, { checkKeys: false }, (error, res) => {
197
- if (error) {
198
- log.error(JSON.stringify(error));
199
- throw error;
200
- }
201
- // log the insertion, close the database and return
202
- log.debug(`Inserted ${docs.length} documents to ${dbName}.${myOpts.targetCollection} with response ${JSON.stringify(res)}`);
203
- db.close();
204
- return res;
205
- });
206
- });
167
+ const iapDir = utils.getIAPHome();
168
+ const db = await utils.connect(iapDir, currentProps).catch((err) => { console.error(err); throw err; });
169
+ if (!db) {
170
+ console.error('Error occured when connectiong to database', currentProps);
171
+ throw new Error('Database not found');
172
+ }
173
+ const collection = db.collection(myOpts.targetCollection);
174
+ const res = await collection.insertMany(docs, { checkKeys: false }).catch((err) => { console.error(err); throw err; });
175
+ return res;
207
176
  });
208
177
  };
209
178
 
210
- // const args = process.argv.slice(2);
211
-
212
- // throw new SyntaxError(args[0]);
213
-
214
- // if (args.length === 0) {
215
- // console.error('ERROR: target path not specified!');
216
- // } else if (args[0] === 'help') {
217
- // log.trace('node ./entitiesToDB <target path> <options object: {iapDir: string, pronghornProps: string, targetCollection: string}>');
218
- // } else if (args.length === 1) {
219
- // console.error('ERROR: IAP directory not specified');
220
- // } else {
221
- // moveEntitiesToDB(args[0], args[1]);
222
- // }
223
-
224
179
  module.exports = { moveEntitiesToDB };
package/utils/modify.js CHANGED
@@ -3,7 +3,7 @@ const Ajv = require('ajv');
3
3
  const rls = require('readline-sync');
4
4
  const { execSync } = require('child_process');
5
5
  const { existsSync } = require('fs-extra');
6
- const { getAdapterConfig } = require('./troubleshootingAdapter');
6
+ const { getAdapterConfig } = require('./tbUtils');
7
7
  const { name } = require('../package.json');
8
8
  const propertiesSchema = require('../propertiesSchema.json');
9
9
 
@@ -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
+ }
@@ -17,6 +17,9 @@ 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
24
  npm audit --registry=https://registry.npmjs.org --audit-level=moderate
22
25
 
package/utils/tbScript.js CHANGED
@@ -1,4 +1,4 @@
1
- /* eslint no-console: warn */
1
+ /* eslint-disable no-console */
2
2
  /* eslint import/no-unresolved: warn */
3
3
  /* eslint global-require: warn */
4
4
 
@@ -7,7 +7,6 @@
7
7
  /* eslint import/no-extraneous-dependencies: warn */
8
8
  /* eslint import/no-dynamic-require: warn */
9
9
 
10
- const path = require('path');
11
10
  const program = require('commander');
12
11
  const rls = require('readline-sync');
13
12
  const utils = require('./tbUtils');
@@ -17,38 +16,45 @@ const sampleProperties = require('../sampleProperties.json');
17
16
  const adapterPronghorn = require('../pronghorn.json');
18
17
  const { addAuthInfo } = require('./addAuth');
19
18
 
20
- const { troubleshoot, getAdapterConfig, offline } = require('./troubleshootingAdapter');
19
+ const { troubleshoot, offline } = require('./troubleshootingAdapter');
21
20
 
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') {
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
30
  const { host } = sampleProperties.properties;
31
31
  console.log(`perform networking diagnositics to ${host}`);
32
- await utils.runConnectivity(host);
33
- process.exit(0);
34
- } else if (command === 'healthcheck') {
32
+ utils.runConnectivity(host);
33
+ break;
34
+ }
35
+ case 'healthcheck': {
35
36
  const a = basicGet.getAdapterInstance({ properties: sampleProperties });
36
37
  await utils.healthCheck(a);
37
- process.exit(0);
38
- } else if (command === 'basicget') {
39
- await utils.runBasicGet();
40
- process.exit(0);
38
+ break;
41
39
  }
42
- if (rls.keyInYN('Troubleshooting without IAP?')) {
43
- await offline();
40
+ case 'basicget': {
41
+ utils.runBasicGet();
42
+ break;
43
+ }
44
+ default: {
45
+ if (rls.keyInYN('Troubleshooting without IAP?')) {
46
+ await offline();
47
+ }
44
48
  }
45
- process.exit(0);
46
49
  }
50
+ process.exit(0);
51
+ };
47
52
 
53
+ const executeUnderIAPInstallationDirectory = async (command) => {
48
54
  if (command === undefined) {
49
55
  await troubleshoot({}, true, true);
50
56
  } else if (command === 'install') {
51
- const { database, serviceItem, pronghornProps } = await getAdapterConfig();
57
+ const { database, serviceItem, pronghornProps } = await utils.getAdapterConfig();
52
58
  const filter = { id: pronghornProps.id };
53
59
  const profileItem = await database.collection(utils.IAP_PROFILES_COLLECTION).findOne(filter);
54
60
  if (!profileItem) {
@@ -79,6 +85,7 @@ const main = async (command) => {
79
85
  process.exit(0);
80
86
  }
81
87
  } else {
88
+ const dirname = utils.getCurrentExecutionPath();
82
89
  utils.verifyInstallationDir(dirname, name);
83
90
  utils.runTest();
84
91
  if (rls.keyInYN(`Do you want to install ${name} to IAP?`)) {
@@ -101,7 +108,7 @@ const main = async (command) => {
101
108
  process.exit(0);
102
109
  }
103
110
  } else if (['healthcheck', 'basicget', 'connectivity'].includes(command)) {
104
- const { serviceItem } = await getAdapterConfig();
111
+ const { serviceItem } = await utils.getAdapterConfig();
105
112
  if (serviceItem) {
106
113
  const adapter = serviceItem;
107
114
  const a = basicGet.getAdapterInstance(adapter);
@@ -123,6 +130,14 @@ const main = async (command) => {
123
130
  }
124
131
  };
125
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
+
126
141
  program
127
142
  .command('connectivity')
128
143
  .alias('c')