@itentialopensource/adapter-dna_center 0.5.7 → 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.
@@ -4,6 +4,7 @@
4
4
  /* global describe it log pronghornProps */
5
5
  /* eslint global-require: warn */
6
6
  /* eslint no-unused-vars: warn */
7
+ /* eslint import/no-dynamic-require:warn */
7
8
 
8
9
  // include required items for testing & logging
9
10
  const assert = require('assert');
@@ -18,22 +19,31 @@ const { use } = require('chai');
18
19
  const td = require('testdouble');
19
20
 
20
21
  const anything = td.matchers.anything();
21
-
22
- // stub and attemptTimeout are used throughout the code so set them here
23
22
  let logLevel = 'none';
24
- const stub = true;
25
23
  const isRapidFail = false;
26
- const attemptTimeout = 600000;
24
+
25
+ // read in the properties from the sampleProperties files
26
+ let adaptdir = __dirname;
27
+ if (adaptdir.endsWith('/test/integration')) {
28
+ adaptdir = adaptdir.substring(0, adaptdir.length - 17);
29
+ } else if (adaptdir.endsWith('/test/unit')) {
30
+ adaptdir = adaptdir.substring(0, adaptdir.length - 10);
31
+ }
32
+ const samProps = require(`${adaptdir}/sampleProperties.json`).properties;
27
33
 
28
34
  // these variables can be changed to run in integrated mode so easier to set them here
29
35
  // always check these in with bogus data!!!
30
- const host = 'replace.hostorip.here';
31
- const username = 'username';
32
- const password = 'password';
33
- const protocol = 'http';
34
- const port = 80;
35
- const sslenable = false;
36
- const sslinvalid = false;
36
+ samProps.stub = true;
37
+ samProps.host = 'replace.hostorip.here';
38
+ samProps.authentication.username = 'username';
39
+ samProps.authentication.password = 'password';
40
+ samProps.protocol = 'http';
41
+ samProps.port = 80;
42
+ samProps.ssl.enabled = false;
43
+ samProps.ssl.accept_invalid_cert = false;
44
+ samProps.request.attempt_timeout = 60000;
45
+ const attemptTimeout = samProps.request.attempt_timeout;
46
+ const { stub } = samProps;
37
47
 
38
48
  // these are the adapter properties. You generally should not need to alter
39
49
  // any of these after they are initially set up
@@ -45,102 +55,7 @@ global.pronghornProps = {
45
55
  adapters: [{
46
56
  id: 'Test-dna_center',
47
57
  type: 'DnaCenter',
48
- properties: {
49
- host,
50
- port,
51
- base_path: '',
52
- version: '',
53
- cache_location: '',
54
- encode_pathvars: true,
55
- save_metric: false,
56
- protocol,
57
- stub,
58
- authentication: {
59
- auth_method: 'no_authentication',
60
- username,
61
- password,
62
- token: '',
63
- token_timeout: -1,
64
- token_cache: 'local',
65
- invalid_token_error: 401,
66
- auth_field: 'header.headers.Authorization',
67
- auth_field_format: 'Basic {b64}{username}:{password}{/b64}',
68
- auth_logging: false,
69
- client_id: '',
70
- client_secret: '',
71
- grant_type: ''
72
- },
73
- healthcheck: {
74
- type: 'startup',
75
- frequency: 60000,
76
- query_object: {}
77
- },
78
- throttle: {
79
- throttle_enabled: false,
80
- number_pronghorns: 1,
81
- sync_async: 'sync',
82
- max_in_queue: 1000,
83
- concurrent_max: 1,
84
- expire_timeout: 0,
85
- avg_runtime: 200,
86
- priorities: [
87
- {
88
- value: 0,
89
- percent: 100
90
- }
91
- ]
92
- },
93
- request: {
94
- number_redirects: 0,
95
- number_retries: 3,
96
- limit_retry_error: 0,
97
- failover_codes: [],
98
- attempt_timeout: attemptTimeout,
99
- global_request: {
100
- payload: {},
101
- uriOptions: {},
102
- addlHeaders: {},
103
- authData: {}
104
- },
105
- healthcheck_on_timeout: false,
106
- return_raw: true,
107
- archiving: false,
108
- return_request: false
109
- },
110
- proxy: {
111
- enabled: false,
112
- host: '',
113
- port: 1,
114
- protocol: 'http',
115
- username: '',
116
- password: ''
117
- },
118
- ssl: {
119
- ecdhCurve: '',
120
- enabled: sslenable,
121
- accept_invalid_cert: sslinvalid,
122
- ca_file: '',
123
- key_file: '',
124
- cert_file: '',
125
- secure_protocol: '',
126
- ciphers: ''
127
- },
128
- mongo: {
129
- host: '',
130
- port: 0,
131
- database: '',
132
- username: '',
133
- password: '',
134
- replSet: '',
135
- db_ssl: {
136
- enabled: false,
137
- accept_invalid_cert: false,
138
- ca_file: '',
139
- key_file: '',
140
- cert_file: ''
141
- }
142
- }
143
- }
58
+ properties: samProps
144
59
  }]
145
60
  }
146
61
  };
@@ -647,6 +562,8 @@ describe('[unit] Dna_center Adapter Test', () => {
647
562
  assert.equal('string', propertiesDotJson.definitions.authentication.properties.client_id.type);
648
563
  assert.equal('string', propertiesDotJson.definitions.authentication.properties.client_secret.type);
649
564
  assert.equal('string', propertiesDotJson.definitions.authentication.properties.grant_type.type);
565
+ assert.notEqual(undefined, propertiesDotJson.definitions.ssl);
566
+ assert.notEqual(null, propertiesDotJson.definitions.ssl);
650
567
  assert.notEqual('', propertiesDotJson.definitions.ssl);
651
568
  assert.equal('string', propertiesDotJson.definitions.ssl.properties.ecdhCurve.type);
652
569
  assert.equal('boolean', propertiesDotJson.definitions.ssl.properties.enabled.type);
@@ -660,6 +577,7 @@ describe('[unit] Dna_center Adapter Test', () => {
660
577
  assert.equal('string', propertiesDotJson.properties.version.type);
661
578
  assert.equal('string', propertiesDotJson.properties.cache_location.type);
662
579
  assert.equal('boolean', propertiesDotJson.properties.encode_pathvars.type);
580
+ assert.equal('boolean', propertiesDotJson.properties.encode_queryvars.type);
663
581
  assert.equal(true, Array.isArray(propertiesDotJson.properties.save_metric.type));
664
582
  assert.equal('string', propertiesDotJson.properties.protocol.type);
665
583
  assert.notEqual(undefined, propertiesDotJson.definitions);
@@ -708,8 +626,6 @@ describe('[unit] Dna_center Adapter Test', () => {
708
626
  assert.equal('string', propertiesDotJson.definitions.proxy.properties.protocol.type);
709
627
  assert.equal('string', propertiesDotJson.definitions.proxy.properties.username.type);
710
628
  assert.equal('string', propertiesDotJson.definitions.proxy.properties.password.type);
711
- assert.notEqual(undefined, propertiesDotJson.definitions.ssl);
712
- assert.notEqual(null, propertiesDotJson.definitions.ssl);
713
629
  assert.notEqual(undefined, propertiesDotJson.definitions.mongo);
714
630
  assert.notEqual(null, propertiesDotJson.definitions.mongo);
715
631
  assert.notEqual('', propertiesDotJson.definitions.mongo);
@@ -847,17 +763,13 @@ describe('[unit] Dna_center Adapter Test', () => {
847
763
  assert.notEqual(undefined, sampleDotJson.properties.ssl.cert_file);
848
764
  assert.notEqual(undefined, sampleDotJson.properties.ssl.secure_protocol);
849
765
  assert.notEqual(undefined, sampleDotJson.properties.ssl.ciphers);
850
-
851
766
  assert.notEqual(undefined, sampleDotJson.properties.base_path);
852
767
  assert.notEqual(undefined, sampleDotJson.properties.version);
853
768
  assert.notEqual(undefined, sampleDotJson.properties.cache_location);
854
769
  assert.notEqual(undefined, sampleDotJson.properties.encode_pathvars);
770
+ assert.notEqual(undefined, sampleDotJson.properties.encode_queryvars);
855
771
  assert.notEqual(undefined, sampleDotJson.properties.save_metric);
856
772
  assert.notEqual(undefined, sampleDotJson.properties.protocol);
857
- assert.notEqual(undefined, sampleDotJson.properties.stub);
858
- assert.notEqual(undefined, sampleDotJson.properties.stub);
859
- assert.notEqual(undefined, sampleDotJson.properties.stub);
860
- assert.notEqual(undefined, sampleDotJson.properties.stub);
861
773
  assert.notEqual(undefined, sampleDotJson.properties.healthcheck);
862
774
  assert.notEqual(null, sampleDotJson.properties.healthcheck);
863
775
  assert.notEqual('', sampleDotJson.properties.healthcheck);
@@ -916,6 +828,12 @@ describe('[unit] Dna_center Adapter Test', () => {
916
828
  assert.notEqual(undefined, sampleDotJson.properties.mongo.db_ssl.ca_file);
917
829
  assert.notEqual(undefined, sampleDotJson.properties.mongo.db_ssl.key_file);
918
830
  assert.notEqual(undefined, sampleDotJson.properties.mongo.db_ssl.cert_file);
831
+ assert.notEqual(undefined, sampleDotJson.properties.devicebroker);
832
+ assert.notEqual(undefined, sampleDotJson.properties.devicebroker.getDevice);
833
+ assert.notEqual(undefined, sampleDotJson.properties.devicebroker.getDevicesFiltered);
834
+ assert.notEqual(undefined, sampleDotJson.properties.devicebroker.isAlive);
835
+ assert.notEqual(undefined, sampleDotJson.properties.devicebroker.getConfig);
836
+ assert.notEqual(undefined, sampleDotJson.properties.devicebroker.getCount);
919
837
  done();
920
838
  } catch (error) {
921
839
  log.error(`Test Failure: ${error}`);
@@ -1292,18 +1210,6 @@ describe('[unit] Dna_center Adapter Test', () => {
1292
1210
  });
1293
1211
  });
1294
1212
 
1295
- describe('#hasDevices', () => {
1296
- it('should have a hasDevices function', (done) => {
1297
- try {
1298
- assert.equal(true, typeof a.hasDevices === 'function');
1299
- done();
1300
- } catch (error) {
1301
- log.error(`Test Failure: ${error}`);
1302
- done(error);
1303
- }
1304
- });
1305
- });
1306
-
1307
1213
  describe('#getDevice', () => {
1308
1214
  it('should have a getDevice function', (done) => {
1309
1215
  try {
@@ -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();
@@ -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 };
@@ -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');
@@ -19,32 +18,39 @@ const { addAuthInfo } = require('./addAuth');
19
18
 
20
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') {
@@ -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?`)) {
@@ -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')