@itentialopensource/adapter-meraki 0.7.3 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AUTH.md +40 -0
- package/CALLS.md +100 -0
- package/CHANGELOG.md +24 -0
- package/ENHANCE.md +69 -0
- package/PROPERTIES.md +247 -0
- package/README.md +113 -470
- package/SUMMARY.md +9 -0
- package/SYSTEMINFO.md +11 -0
- package/TROUBLESHOOT.md +46 -0
- package/adapter.js +566 -59
- package/adapterBase.js +571 -278
- package/entities/.generic/action.json +5 -5
- package/error.json +12 -0
- package/package.json +18 -13
- package/pronghorn.json +273 -88
- package/propertiesDecorators.json +14 -0
- package/propertiesSchema.json +382 -0
- package/refs?service=git-upload-pack +0 -0
- package/report/updateReport1642739939352.json +95 -0
- package/report/updateReport1651511176919.json +115 -0
- package/sampleProperties.json +4 -1
- package/test/integration/adapterTestIntegration.js +10 -1
- package/test/unit/adapterBaseTestUnit.js +26 -25
- package/test/unit/adapterTestUnit.js +631 -10
- package/utils/addAuth.js +94 -0
- package/utils/basicGet.js +1 -14
- package/utils/entitiesToDB.js +224 -0
- package/utils/modify.js +1 -1
- package/utils/patches2bundledDeps.js +90 -0
- package/utils/removeHooks.js +20 -0
- package/utils/tbScript.js +14 -8
- package/utils/tbUtils.js +111 -19
- package/utils/troubleshootingAdapter.js +2 -26
package/adapterBase.js
CHANGED
@@ -8,6 +8,7 @@
|
|
8
8
|
/* eslint no-cond-assign: warn */
|
9
9
|
/* eslint global-require: warn */
|
10
10
|
/* eslint no-unused-vars: warn */
|
11
|
+
/* eslint prefer-destructuring: warn */
|
11
12
|
|
12
13
|
/* Required libraries. */
|
13
14
|
const fs = require('fs-extra');
|
@@ -22,6 +23,7 @@ const AjvCl = require('ajv');
|
|
22
23
|
const PropUtilCl = require('@itentialopensource/adapter-utils').PropertyUtility;
|
23
24
|
const RequestHandlerCl = require('@itentialopensource/adapter-utils').RequestHandler;
|
24
25
|
|
26
|
+
const entitiesToDB = require(path.join(__dirname, 'utils/entitiesToDB'));
|
25
27
|
const troubleshootingAdapter = require(path.join(__dirname, 'utils/troubleshootingAdapter'));
|
26
28
|
const tbUtils = require(path.join(__dirname, 'utils/tbUtils'));
|
27
29
|
|
@@ -153,6 +155,9 @@ class AdapterBase extends EventEmitterCl {
|
|
153
155
|
// Instantiate the EventEmitter super class
|
154
156
|
super();
|
155
157
|
|
158
|
+
// IAP home directory injected by core when running the adapter within IAP
|
159
|
+
process.env.iap_home = process.argv[3];
|
160
|
+
|
156
161
|
try {
|
157
162
|
// Capture the adapter id
|
158
163
|
this.id = prongid;
|
@@ -276,129 +281,6 @@ class AdapterBase extends EventEmitterCl {
|
|
276
281
|
}
|
277
282
|
}
|
278
283
|
|
279
|
-
/**
|
280
|
-
* updateAdapterConfiguration is used to update any of the adapter configuration files. This
|
281
|
-
* allows customers to make changes to adapter configuration without having to be on the
|
282
|
-
* file system.
|
283
|
-
*
|
284
|
-
* @function updateAdapterConfiguration
|
285
|
-
* @param {string} configFile - the name of the file being updated (required)
|
286
|
-
* @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
|
287
|
-
* @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
|
288
|
-
* @param {string} type - the type of entity file to change, (action, schema, mock) (optional)
|
289
|
-
* @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
|
290
|
-
* @param {Callback} callback - The results of the call
|
291
|
-
*/
|
292
|
-
updateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
|
293
|
-
const meth = 'adapterBase-updateAdapterConfiguration';
|
294
|
-
const origin = `${this.id}-${meth}`;
|
295
|
-
log.trace(origin);
|
296
|
-
|
297
|
-
// verify the parameters are valid
|
298
|
-
if (changes === undefined || changes === null || typeof changes !== 'object'
|
299
|
-
|| Object.keys(changes).length === 0) {
|
300
|
-
const result = {
|
301
|
-
response: 'No configuration updates to make'
|
302
|
-
};
|
303
|
-
log.info(result.response);
|
304
|
-
return callback(result, null);
|
305
|
-
}
|
306
|
-
if (configFile === undefined || configFile === null || configFile === '') {
|
307
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['configFile'], null, null, null);
|
308
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
309
|
-
return callback(null, errorObj);
|
310
|
-
}
|
311
|
-
|
312
|
-
// take action based on configFile being changed
|
313
|
-
if (configFile === 'package.json') {
|
314
|
-
const pres = updatePackage(changes);
|
315
|
-
if (pres) {
|
316
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${pres}`, [], null, null, null);
|
317
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
318
|
-
return callback(null, errorObj);
|
319
|
-
}
|
320
|
-
const result = {
|
321
|
-
response: 'Package updates completed - restarting adapter'
|
322
|
-
};
|
323
|
-
log.info(result.response);
|
324
|
-
forceFail(true);
|
325
|
-
return callback(result, null);
|
326
|
-
}
|
327
|
-
if (entity === undefined || entity === null || entity === '') {
|
328
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Unsupported Configuration Change or Missing Entity', [], null, null, null);
|
329
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
330
|
-
return callback(null, errorObj);
|
331
|
-
}
|
332
|
-
|
333
|
-
// this means we are changing an entity file so type is required
|
334
|
-
if (type === undefined || type === null || type === '') {
|
335
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['type'], null, null, null);
|
336
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
337
|
-
return callback(null, errorObj);
|
338
|
-
}
|
339
|
-
|
340
|
-
// if the entity does not exist - error
|
341
|
-
const epath = `${__dirname}/entities/${entity}`;
|
342
|
-
if (!fs.existsSync(epath)) {
|
343
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: Invalid Entity - ${entity}`, [], null, null, null);
|
344
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
345
|
-
return callback(null, errorObj);
|
346
|
-
}
|
347
|
-
|
348
|
-
// take action based on type of file being changed
|
349
|
-
if (type === 'action') {
|
350
|
-
// BACKUP???
|
351
|
-
const ares = updateAction(epath, action, changes);
|
352
|
-
if (ares) {
|
353
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${ares}`, [], null, null, null);
|
354
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
355
|
-
return callback(null, errorObj);
|
356
|
-
}
|
357
|
-
// AJV CHECK???
|
358
|
-
// RESTORE IF NEEDED???
|
359
|
-
const result = {
|
360
|
-
response: `Action updates completed to entity: ${entity} - ${action}`
|
361
|
-
};
|
362
|
-
log.info(result.response);
|
363
|
-
return callback(result, null);
|
364
|
-
}
|
365
|
-
if (type === 'schema') {
|
366
|
-
const sres = updateSchema(epath, configFile, changes);
|
367
|
-
if (sres) {
|
368
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${sres}`, [], null, null, null);
|
369
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
370
|
-
return callback(null, errorObj);
|
371
|
-
}
|
372
|
-
const result = {
|
373
|
-
response: `Schema updates completed to entity: ${entity} - ${configFile}`
|
374
|
-
};
|
375
|
-
log.info(result.response);
|
376
|
-
return callback(result, null);
|
377
|
-
}
|
378
|
-
if (type === 'mock') {
|
379
|
-
// if the mock directory does not exist - error
|
380
|
-
const mpath = `${__dirname}/entities/${entity}/mockdatafiles`;
|
381
|
-
if (!fs.existsSync(mpath)) {
|
382
|
-
fs.mkdirSync(mpath);
|
383
|
-
}
|
384
|
-
|
385
|
-
const mres = updateMock(mpath, configFile, changes);
|
386
|
-
if (mres) {
|
387
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${mres}`, [], null, null, null);
|
388
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
389
|
-
return callback(null, errorObj);
|
390
|
-
}
|
391
|
-
const result = {
|
392
|
-
response: `Mock data updates completed to entity: ${entity} - ${configFile}`
|
393
|
-
};
|
394
|
-
log.info(result.response);
|
395
|
-
return callback(result, null);
|
396
|
-
}
|
397
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: Unsupported Type - ${type}`, [], null, null, null);
|
398
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
399
|
-
return callback(null, errorObj);
|
400
|
-
}
|
401
|
-
|
402
284
|
/**
|
403
285
|
* @summary Connect function is used during Pronghorn startup to provide instantiation feedback.
|
404
286
|
*
|
@@ -467,7 +349,7 @@ class AdapterBase extends EventEmitterCl {
|
|
467
349
|
}
|
468
350
|
|
469
351
|
// call to the healthcheck in connector
|
470
|
-
return this.requestHandlerInst.identifyHealthcheck(
|
352
|
+
return this.requestHandlerInst.identifyHealthcheck(myRequest, (res, error) => {
|
471
353
|
// unhealthy
|
472
354
|
if (error) {
|
473
355
|
// if we were healthy, toggle health
|
@@ -500,98 +382,12 @@ class AdapterBase extends EventEmitterCl {
|
|
500
382
|
}
|
501
383
|
|
502
384
|
/**
|
503
|
-
*
|
504
|
-
* @param {Callback} callback - The adapater suspension status
|
505
|
-
* @function suspend
|
506
|
-
*/
|
507
|
-
suspend(mode, callback) {
|
508
|
-
const origin = `${this.id}-adapterBase-suspend`;
|
509
|
-
if (this.suspended) {
|
510
|
-
throw new Error(`${origin}: Adapter is already suspended`);
|
511
|
-
}
|
512
|
-
try {
|
513
|
-
this.suspended = true;
|
514
|
-
this.suspendMode = mode;
|
515
|
-
if (this.suspendMode === 'pause') {
|
516
|
-
const props = JSON.parse(JSON.stringify(this.initProps));
|
517
|
-
// To suspend adapter, enable throttling and set concurrent max to 0
|
518
|
-
props.throttle.throttle_enabled = true;
|
519
|
-
props.throttle.concurrent_max = 0;
|
520
|
-
this.refreshProperties(props);
|
521
|
-
}
|
522
|
-
return callback({ suspended: true });
|
523
|
-
} catch (error) {
|
524
|
-
return callback(null, error);
|
525
|
-
}
|
526
|
-
}
|
527
|
-
|
528
|
-
/**
|
529
|
-
* @summary Unsuspends the adapter
|
530
|
-
* @param {Callback} callback - The adapater suspension status
|
531
|
-
*
|
532
|
-
* @function unsuspend
|
533
|
-
*/
|
534
|
-
unsuspend(callback) {
|
535
|
-
const origin = `${this.id}-adapterBase-unsuspend`;
|
536
|
-
if (!this.suspended) {
|
537
|
-
throw new Error(`${origin}: Adapter is not suspended`);
|
538
|
-
}
|
539
|
-
if (this.suspendMode === 'pause') {
|
540
|
-
const props = JSON.parse(JSON.stringify(this.initProps));
|
541
|
-
// To unsuspend adapter, keep throttling enabled and begin processing queued requests in order
|
542
|
-
props.throttle.throttle_enabled = true;
|
543
|
-
props.throttle.concurrent_max = 1;
|
544
|
-
this.refreshProperties(props);
|
545
|
-
setTimeout(() => {
|
546
|
-
this.getQueue((q, error) => {
|
547
|
-
// console.log("Items in queue: " + String(q.length))
|
548
|
-
if (q.length === 0) {
|
549
|
-
// if queue is empty, return to initial properties state
|
550
|
-
this.refreshProperties(this.initProps);
|
551
|
-
this.suspended = false;
|
552
|
-
return callback({ suspended: false });
|
553
|
-
}
|
554
|
-
// recursive call to check queue again every second
|
555
|
-
return this.unsuspend(callback);
|
556
|
-
});
|
557
|
-
}, 1000);
|
558
|
-
} else {
|
559
|
-
this.suspended = false;
|
560
|
-
callback({ suspend: false });
|
561
|
-
}
|
562
|
-
}
|
563
|
-
|
564
|
-
/**
|
565
|
-
* getAllFunctions is used to get all of the exposed function in the adapter
|
566
|
-
*
|
567
|
-
* @function getAllFunctions
|
568
|
-
*/
|
569
|
-
getAllFunctions() {
|
570
|
-
let myfunctions = [];
|
571
|
-
let obj = this;
|
572
|
-
|
573
|
-
// find the functions in this class
|
574
|
-
do {
|
575
|
-
const l = Object.getOwnPropertyNames(obj)
|
576
|
-
.concat(Object.getOwnPropertySymbols(obj).map((s) => s.toString()))
|
577
|
-
.sort()
|
578
|
-
.filter((p, i, arr) => typeof obj[p] === 'function' && p !== 'constructor' && (i === 0 || p !== arr[i - 1]) && myfunctions.indexOf(p) === -1);
|
579
|
-
myfunctions = myfunctions.concat(l);
|
580
|
-
}
|
581
|
-
while (
|
582
|
-
(obj = Object.getPrototypeOf(obj)) && Object.getPrototypeOf(obj)
|
583
|
-
);
|
584
|
-
|
585
|
-
return myfunctions;
|
586
|
-
}
|
587
|
-
|
588
|
-
/**
|
589
|
-
* getWorkflowFunctions is used to get all of the workflow function in the adapter
|
385
|
+
* iapGetAdapterWorkflowFunctions is used to get all of the workflow function in the adapter
|
590
386
|
* @param {array} ignoreThese - additional methods to ignore (optional)
|
591
387
|
*
|
592
|
-
* @function
|
388
|
+
* @function iapGetAdapterWorkflowFunctions
|
593
389
|
*/
|
594
|
-
|
390
|
+
iapGetAdapterWorkflowFunctions(ignoreThese) {
|
595
391
|
const myfunctions = this.getAllFunctions();
|
596
392
|
const wffunctions = [];
|
597
393
|
|
@@ -601,8 +397,9 @@ class AdapterBase extends EventEmitterCl {
|
|
601
397
|
// got to the second tier (adapterBase)
|
602
398
|
break;
|
603
399
|
}
|
604
|
-
if (myfunctions[m] !== '
|
605
|
-
&& myfunctions[m] !== '
|
400
|
+
if (myfunctions[m] !== 'iapHasAdapterEntity' && myfunctions[m] !== 'iapVerifyAdapterCapability'
|
401
|
+
&& myfunctions[m] !== 'iapUpdateAdapterEntityCache' && myfunctions[m] !== 'healthCheck'
|
402
|
+
&& myfunctions[m] !== 'iapGetAdapterWorkflowFunctions'
|
606
403
|
&& !(myfunctions[m].endsWith('Emit') || myfunctions[m].match(/Emit__v[0-9]+/))) {
|
607
404
|
let found = false;
|
608
405
|
if (ignoreThese && Array.isArray(ignoreThese)) {
|
@@ -616,36 +413,142 @@ class AdapterBase extends EventEmitterCl {
|
|
616
413
|
wffunctions.push(myfunctions[m]);
|
617
414
|
}
|
618
415
|
}
|
619
|
-
}
|
620
|
-
|
621
|
-
return wffunctions;
|
622
|
-
}
|
623
|
-
|
624
|
-
/**
|
625
|
-
*
|
626
|
-
*
|
627
|
-
*
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
416
|
+
}
|
417
|
+
|
418
|
+
return wffunctions;
|
419
|
+
}
|
420
|
+
|
421
|
+
/**
|
422
|
+
* iapUpdateAdapterConfiguration is used to update any of the adapter configuration files. This
|
423
|
+
* allows customers to make changes to adapter configuration without having to be on the
|
424
|
+
* file system.
|
425
|
+
*
|
426
|
+
* @function iapUpdateAdapterConfiguration
|
427
|
+
* @param {string} configFile - the name of the file being updated (required)
|
428
|
+
* @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
|
429
|
+
* @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
|
430
|
+
* @param {string} type - the type of entity file to change, (action, schema, mock) (optional)
|
431
|
+
* @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
|
432
|
+
* @param {Callback} callback - The results of the call
|
433
|
+
*/
|
434
|
+
iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
|
435
|
+
const meth = 'adapterBase-iapUpdateAdapterConfiguration';
|
436
|
+
const origin = `${this.id}-${meth}`;
|
437
|
+
log.trace(origin);
|
438
|
+
|
439
|
+
// verify the parameters are valid
|
440
|
+
if (changes === undefined || changes === null || typeof changes !== 'object'
|
441
|
+
|| Object.keys(changes).length === 0) {
|
442
|
+
const result = {
|
443
|
+
response: 'No configuration updates to make'
|
444
|
+
};
|
445
|
+
log.info(result.response);
|
446
|
+
return callback(result, null);
|
447
|
+
}
|
448
|
+
if (configFile === undefined || configFile === null || configFile === '') {
|
449
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['configFile'], null, null, null);
|
450
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
451
|
+
return callback(null, errorObj);
|
452
|
+
}
|
453
|
+
|
454
|
+
// take action based on configFile being changed
|
455
|
+
if (configFile === 'package.json') {
|
456
|
+
const pres = updatePackage(changes);
|
457
|
+
if (pres) {
|
458
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${pres}`, [], null, null, null);
|
459
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
460
|
+
return callback(null, errorObj);
|
461
|
+
}
|
462
|
+
const result = {
|
463
|
+
response: 'Package updates completed - restarting adapter'
|
464
|
+
};
|
465
|
+
log.info(result.response);
|
466
|
+
forceFail(true);
|
467
|
+
return callback(result, null);
|
468
|
+
}
|
469
|
+
if (entity === undefined || entity === null || entity === '') {
|
470
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Unsupported Configuration Change or Missing Entity', [], null, null, null);
|
471
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
472
|
+
return callback(null, errorObj);
|
473
|
+
}
|
474
|
+
|
475
|
+
// this means we are changing an entity file so type is required
|
476
|
+
if (type === undefined || type === null || type === '') {
|
477
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['type'], null, null, null);
|
478
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
479
|
+
return callback(null, errorObj);
|
480
|
+
}
|
481
|
+
|
482
|
+
// if the entity does not exist - error
|
483
|
+
const epath = `${__dirname}/entities/${entity}`;
|
484
|
+
if (!fs.existsSync(epath)) {
|
485
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: Invalid Entity - ${entity}`, [], null, null, null);
|
486
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
487
|
+
return callback(null, errorObj);
|
488
|
+
}
|
489
|
+
|
490
|
+
// take action based on type of file being changed
|
491
|
+
if (type === 'action') {
|
492
|
+
// BACKUP???
|
493
|
+
const ares = updateAction(epath, action, changes);
|
494
|
+
if (ares) {
|
495
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${ares}`, [], null, null, null);
|
496
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
497
|
+
return callback(null, errorObj);
|
498
|
+
}
|
499
|
+
// AJV CHECK???
|
500
|
+
// RESTORE IF NEEDED???
|
501
|
+
const result = {
|
502
|
+
response: `Action updates completed to entity: ${entity} - ${action}`
|
503
|
+
};
|
504
|
+
log.info(result.response);
|
505
|
+
return callback(result, null);
|
506
|
+
}
|
507
|
+
if (type === 'schema') {
|
508
|
+
const sres = updateSchema(epath, configFile, changes);
|
509
|
+
if (sres) {
|
510
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${sres}`, [], null, null, null);
|
511
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
512
|
+
return callback(null, errorObj);
|
513
|
+
}
|
514
|
+
const result = {
|
515
|
+
response: `Schema updates completed to entity: ${entity} - ${configFile}`
|
516
|
+
};
|
517
|
+
log.info(result.response);
|
518
|
+
return callback(result, null);
|
519
|
+
}
|
520
|
+
if (type === 'mock') {
|
521
|
+
// if the mock directory does not exist - error
|
522
|
+
const mpath = `${__dirname}/entities/${entity}/mockdatafiles`;
|
523
|
+
if (!fs.existsSync(mpath)) {
|
524
|
+
fs.mkdirSync(mpath);
|
525
|
+
}
|
632
526
|
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
527
|
+
const mres = updateMock(mpath, configFile, changes);
|
528
|
+
if (mres) {
|
529
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${mres}`, [], null, null, null);
|
530
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
531
|
+
return callback(null, errorObj);
|
532
|
+
}
|
533
|
+
const result = {
|
534
|
+
response: `Mock data updates completed to entity: ${entity} - ${configFile}`
|
535
|
+
};
|
536
|
+
log.info(result.response);
|
537
|
+
return callback(result, null);
|
638
538
|
}
|
539
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: Unsupported Type - ${type}`, [], null, null, null);
|
540
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
541
|
+
return callback(null, errorObj);
|
639
542
|
}
|
640
543
|
|
641
544
|
/**
|
642
545
|
* See if the API path provided is found in this adapter
|
643
546
|
*
|
644
|
-
* @function
|
547
|
+
* @function iapFindAdapterPath
|
645
548
|
* @param {string} apiPath - the api path to check on
|
646
549
|
* @param {Callback} callback - The results of the call
|
647
550
|
*/
|
648
|
-
|
551
|
+
iapFindAdapterPath(apiPath, callback) {
|
649
552
|
const result = {
|
650
553
|
apiPath
|
651
554
|
};
|
@@ -687,7 +590,7 @@ class AdapterBase extends EventEmitterCl {
|
|
687
590
|
log.info(` method: ${actions.actions[a].method} path: ${actions.actions[a].entitypath}`);
|
688
591
|
const fitem = {
|
689
592
|
entity: entities[e],
|
690
|
-
action: actions[a].name,
|
593
|
+
action: actions.actions[a].name,
|
691
594
|
method: actions.actions[a].method,
|
692
595
|
path: actions.actions[a].entitypath
|
693
596
|
};
|
@@ -722,66 +625,90 @@ class AdapterBase extends EventEmitterCl {
|
|
722
625
|
}
|
723
626
|
|
724
627
|
/**
|
725
|
-
*
|
726
|
-
*
|
727
|
-
* @function
|
728
|
-
* @param {Object} properties - an object containing all of the properties
|
628
|
+
* @summary Suspends the adapter
|
629
|
+
* @param {Callback} callback - The adapater suspension status
|
630
|
+
* @function iapSuspendAdapter
|
729
631
|
*/
|
730
|
-
|
731
|
-
const origin = `${this.
|
732
|
-
|
733
|
-
|
734
|
-
|
632
|
+
iapSuspendAdapter(mode, callback) {
|
633
|
+
const origin = `${this.id}-adapterBase-iapSuspendAdapter`;
|
634
|
+
if (this.suspended) {
|
635
|
+
throw new Error(`${origin}: Adapter is already suspended`);
|
636
|
+
}
|
735
637
|
try {
|
736
|
-
|
737
|
-
|
738
|
-
|
638
|
+
this.suspended = true;
|
639
|
+
this.suspendMode = mode;
|
640
|
+
if (this.suspendMode === 'pause') {
|
641
|
+
const props = JSON.parse(JSON.stringify(this.initProps));
|
642
|
+
// To suspend adapter, enable throttling and set concurrent max to 0
|
643
|
+
props.throttle.throttle_enabled = true;
|
644
|
+
props.throttle.concurrent_max = 0;
|
645
|
+
this.refreshProperties(props);
|
646
|
+
}
|
647
|
+
return callback({ suspended: true });
|
648
|
+
} catch (error) {
|
649
|
+
return callback(null, error);
|
739
650
|
}
|
740
651
|
}
|
741
652
|
|
742
653
|
/**
|
743
|
-
*
|
654
|
+
* @summary Unsuspends the adapter
|
655
|
+
* @param {Callback} callback - The adapater suspension status
|
744
656
|
*
|
745
|
-
* @function
|
746
|
-
* @param {Callback} callback - a callback function to return the result (Queue) or the error
|
657
|
+
* @function iapUnsuspendAdapter
|
747
658
|
*/
|
748
|
-
|
749
|
-
const origin = `${this.id}-adapterBase-
|
750
|
-
|
751
|
-
|
752
|
-
|
659
|
+
iapUnsuspendAdapter(callback) {
|
660
|
+
const origin = `${this.id}-adapterBase-iapUnsuspendAdapter`;
|
661
|
+
if (!this.suspended) {
|
662
|
+
throw new Error(`${origin}: Adapter is not suspended`);
|
663
|
+
}
|
664
|
+
if (this.suspendMode === 'pause') {
|
665
|
+
const props = JSON.parse(JSON.stringify(this.initProps));
|
666
|
+
// To unsuspend adapter, keep throttling enabled and begin processing queued requests in order
|
667
|
+
props.throttle.throttle_enabled = true;
|
668
|
+
props.throttle.concurrent_max = 1;
|
669
|
+
this.refreshProperties(props);
|
670
|
+
setTimeout(() => {
|
671
|
+
this.getQueue((q, error) => {
|
672
|
+
// console.log("Items in queue: " + String(q.length))
|
673
|
+
if (q.length === 0) {
|
674
|
+
// if queue is empty, return to initial properties state
|
675
|
+
this.refreshProperties(this.initProps);
|
676
|
+
this.suspended = false;
|
677
|
+
return callback({ suspended: false });
|
678
|
+
}
|
679
|
+
// recursive call to check queue again every second
|
680
|
+
return this.iapUnsuspendAdapter(callback);
|
681
|
+
});
|
682
|
+
}, 1000);
|
683
|
+
} else {
|
684
|
+
this.suspended = false;
|
685
|
+
callback({ suspend: false });
|
686
|
+
}
|
753
687
|
}
|
754
688
|
|
755
689
|
/**
|
756
|
-
*
|
757
|
-
* encoded/encrypted string
|
758
|
-
*
|
759
|
-
* @function encryptProperty
|
760
|
-
* @param {String} property - the property to encrypt
|
761
|
-
* @param {String} technique - the technique to use to encrypt
|
690
|
+
* iapGetAdapterQueue is used to get information for all of the requests currently in the queue.
|
762
691
|
*
|
763
|
-
* @
|
764
|
-
*
|
692
|
+
* @function iapGetAdapterQueue
|
693
|
+
* @param {Callback} callback - a callback function to return the result (Queue) or the error
|
765
694
|
*/
|
766
|
-
|
767
|
-
const origin = `${this.id}-adapterBase-
|
695
|
+
iapGetAdapterQueue(callback) {
|
696
|
+
const origin = `${this.id}-adapterBase-iapGetAdapterQueue`;
|
768
697
|
log.trace(origin);
|
769
698
|
|
770
|
-
|
771
|
-
// encryptProperty(property, technique, callback)
|
772
|
-
return this.requestHandlerInst.encryptProperty(property, technique, callback);
|
699
|
+
return this.requestHandlerInst.getQueue(callback);
|
773
700
|
}
|
774
701
|
|
775
702
|
/**
|
776
703
|
* @summary runs troubleshoot scripts for adapter
|
777
704
|
*
|
778
|
-
* @function
|
705
|
+
* @function iapTroubleshootAdapter
|
779
706
|
* @param {Object} props - the connection, healthcheck and authentication properties
|
780
707
|
* @param {boolean} persistFlag - whether the adapter properties should be updated
|
781
708
|
* @param {Adapter} adapter - adapter instance to troubleshoot
|
782
709
|
* @param {Callback} callback - callback function to return troubleshoot results
|
783
710
|
*/
|
784
|
-
async
|
711
|
+
async iapTroubleshootAdapter(props, persistFlag, adapter, callback) {
|
785
712
|
try {
|
786
713
|
const result = await troubleshootingAdapter.troubleshoot(props, false, persistFlag, adapter);
|
787
714
|
if (result.healthCheck && result.connectivity.failCount === 0 && result.basicGet.failCount === 0) {
|
@@ -796,11 +723,11 @@ class AdapterBase extends EventEmitterCl {
|
|
796
723
|
/**
|
797
724
|
* @summary runs healthcheck script for adapter
|
798
725
|
*
|
799
|
-
* @function
|
726
|
+
* @function iapRunAdapterHealthcheck
|
800
727
|
* @param {Adapter} adapter - adapter instance to troubleshoot
|
801
728
|
* @param {Callback} callback - callback function to return healthcheck status
|
802
729
|
*/
|
803
|
-
async
|
730
|
+
async iapRunAdapterHealthcheck(adapter, callback) {
|
804
731
|
try {
|
805
732
|
const result = await tbUtils.healthCheck(adapter);
|
806
733
|
if (result) {
|
@@ -815,13 +742,13 @@ class AdapterBase extends EventEmitterCl {
|
|
815
742
|
/**
|
816
743
|
* @summary runs connectivity check script for adapter
|
817
744
|
*
|
818
|
-
* @function
|
745
|
+
* @function iapRunAdapterConnectivity
|
819
746
|
* @param {Adapter} adapter - adapter instance to troubleshoot
|
820
747
|
* @param {Callback} callback - callback function to return connectivity status
|
821
748
|
*/
|
822
|
-
async
|
749
|
+
async iapRunAdapterConnectivity(callback) {
|
823
750
|
try {
|
824
|
-
const { serviceItem } = await
|
751
|
+
const { serviceItem } = await tbUtils.getAdapterConfig();
|
825
752
|
const { host } = serviceItem.properties.properties;
|
826
753
|
const result = tbUtils.runConnectivity(host, false);
|
827
754
|
if (result.failCount > 0) {
|
@@ -836,10 +763,10 @@ class AdapterBase extends EventEmitterCl {
|
|
836
763
|
/**
|
837
764
|
* @summary runs basicGet script for adapter
|
838
765
|
*
|
839
|
-
* @function
|
766
|
+
* @function iapRunAdapterBasicGet
|
840
767
|
* @param {Callback} callback - callback function to return basicGet result
|
841
768
|
*/
|
842
|
-
|
769
|
+
iapRunAdapterBasicGet(callback) {
|
843
770
|
try {
|
844
771
|
const result = tbUtils.runBasicGet(false);
|
845
772
|
if (result.failCount > 0) {
|
@@ -851,6 +778,106 @@ class AdapterBase extends EventEmitterCl {
|
|
851
778
|
}
|
852
779
|
}
|
853
780
|
|
781
|
+
/**
|
782
|
+
* @summary moves entities to mongo database
|
783
|
+
*
|
784
|
+
* @function iapMoveAdapterEntitiesToDB
|
785
|
+
*
|
786
|
+
* @return {Callback} - containing the response from the mongo transaction
|
787
|
+
*/
|
788
|
+
iapMoveAdapterEntitiesToDB(callback) {
|
789
|
+
const meth = 'adapterBase-iapMoveAdapterEntitiesToDB';
|
790
|
+
const origin = `${this.id}-${meth}`;
|
791
|
+
log.trace(origin);
|
792
|
+
|
793
|
+
try {
|
794
|
+
return callback(entitiesToDB.iapMoveAdapterEntitiesToDB(__dirname, { pronghornProps: this.allProps, id: this.id }), null);
|
795
|
+
} catch (err) {
|
796
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, err);
|
797
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
798
|
+
return callback(null, errorObj);
|
799
|
+
}
|
800
|
+
}
|
801
|
+
|
802
|
+
/**
|
803
|
+
* getAllFunctions is used to get all of the exposed function in the adapter
|
804
|
+
*
|
805
|
+
* @function getAllFunctions
|
806
|
+
*/
|
807
|
+
getAllFunctions() {
|
808
|
+
let myfunctions = [];
|
809
|
+
let obj = this;
|
810
|
+
|
811
|
+
// find the functions in this class
|
812
|
+
do {
|
813
|
+
const l = Object.getOwnPropertyNames(obj)
|
814
|
+
.concat(Object.getOwnPropertySymbols(obj).map((s) => s.toString()))
|
815
|
+
.sort()
|
816
|
+
.filter((p, i, arr) => typeof obj[p] === 'function' && p !== 'constructor' && (i === 0 || p !== arr[i - 1]) && myfunctions.indexOf(p) === -1);
|
817
|
+
myfunctions = myfunctions.concat(l);
|
818
|
+
}
|
819
|
+
while (
|
820
|
+
(obj = Object.getPrototypeOf(obj)) && Object.getPrototypeOf(obj)
|
821
|
+
);
|
822
|
+
|
823
|
+
return myfunctions;
|
824
|
+
}
|
825
|
+
|
826
|
+
/**
|
827
|
+
* checkActionFiles is used to update the validation of the action files.
|
828
|
+
*
|
829
|
+
* @function checkActionFiles
|
830
|
+
*/
|
831
|
+
checkActionFiles() {
|
832
|
+
const origin = `${this.id}-adapterBase-checkActionFiles`;
|
833
|
+
log.trace(origin);
|
834
|
+
|
835
|
+
// validate the action files for the adapter
|
836
|
+
try {
|
837
|
+
return this.requestHandlerInst.checkActionFiles();
|
838
|
+
} catch (e) {
|
839
|
+
return ['Exception increase log level'];
|
840
|
+
}
|
841
|
+
}
|
842
|
+
|
843
|
+
/**
|
844
|
+
* checkProperties is used to validate the adapter properties.
|
845
|
+
*
|
846
|
+
* @function checkProperties
|
847
|
+
* @param {Object} properties - an object containing all of the properties
|
848
|
+
*/
|
849
|
+
checkProperties(properties) {
|
850
|
+
const origin = `${this.myid}-adapterBase-checkProperties`;
|
851
|
+
log.trace(origin);
|
852
|
+
|
853
|
+
// validate the properties for the adapter
|
854
|
+
try {
|
855
|
+
return this.requestHandlerInst.checkProperties(properties);
|
856
|
+
} catch (e) {
|
857
|
+
return { exception: 'Exception increase log level' };
|
858
|
+
}
|
859
|
+
}
|
860
|
+
|
861
|
+
/**
|
862
|
+
* @summary Takes in property text and an encoding/encryption and returns the resulting
|
863
|
+
* encoded/encrypted string
|
864
|
+
*
|
865
|
+
* @function encryptProperty
|
866
|
+
* @param {String} property - the property to encrypt
|
867
|
+
* @param {String} technique - the technique to use to encrypt
|
868
|
+
*
|
869
|
+
* @param {Callback} callback - a callback function to return the result
|
870
|
+
* Encrypted String or the Error
|
871
|
+
*/
|
872
|
+
encryptProperty(property, technique, callback) {
|
873
|
+
const origin = `${this.id}-adapterBase-encryptProperty`;
|
874
|
+
log.trace(origin);
|
875
|
+
|
876
|
+
// Make the call -
|
877
|
+
// encryptProperty(property, technique, callback)
|
878
|
+
return this.requestHandlerInst.encryptProperty(property, technique, callback);
|
879
|
+
}
|
880
|
+
|
854
881
|
/**
|
855
882
|
* @summary take the entities and add them to the cache
|
856
883
|
*
|
@@ -1001,6 +1028,272 @@ class AdapterBase extends EventEmitterCl {
|
|
1001
1028
|
return [];
|
1002
1029
|
}
|
1003
1030
|
}
|
1031
|
+
|
1032
|
+
/**
|
1033
|
+
* @summary Make one of the needed Broker calls - could be one of many
|
1034
|
+
*
|
1035
|
+
* @function iapMakeBrokerCall
|
1036
|
+
* @param {string} brokCall - the name of the broker call (required)
|
1037
|
+
* @param {object} callProps - the proeprties for the broker call (required)
|
1038
|
+
* @param {object} devResp - the device details to extract needed inputs (required)
|
1039
|
+
* @param {string} filterName - any filter to search on (required)
|
1040
|
+
*
|
1041
|
+
* @param {getCallback} callback - a callback function to return the result of the call
|
1042
|
+
*/
|
1043
|
+
iapMakeBrokerCall(brokCall, callProps, devResp, filterName, callback) {
|
1044
|
+
const meth = 'adapter-iapMakeBrokerCall';
|
1045
|
+
const origin = `${this.id}-${meth}`;
|
1046
|
+
log.trace(origin);
|
1047
|
+
|
1048
|
+
try {
|
1049
|
+
let uriPath = '';
|
1050
|
+
let uriMethod = 'GET';
|
1051
|
+
let callQuery = {};
|
1052
|
+
let callBody = {};
|
1053
|
+
let callHeaders = {};
|
1054
|
+
let handleFail = 'fail';
|
1055
|
+
let ostypePrefix = '';
|
1056
|
+
let statusValue = 'true';
|
1057
|
+
if (callProps.path) {
|
1058
|
+
uriPath = `${callProps.path}`;
|
1059
|
+
|
1060
|
+
// make any necessary changes to the path
|
1061
|
+
if (devResp !== null && callProps.requestFields && Object.keys(callProps.requestFields).length > 0) {
|
1062
|
+
const rqKeys = Object.keys(callProps.requestFields);
|
1063
|
+
|
1064
|
+
// get the field from the provided device
|
1065
|
+
for (let rq = 0; rq < rqKeys.length; rq += 1) {
|
1066
|
+
// get the request field we are retrieving
|
1067
|
+
const loopField = callProps.requestFields[rqKeys[rq]];
|
1068
|
+
const loopArray = loopField.split('.');
|
1069
|
+
let nestedValue = devResp;
|
1070
|
+
|
1071
|
+
// loops through incase the field is nested
|
1072
|
+
for (let i = 0; i < loopArray.length; i += 1) {
|
1073
|
+
if (Object.hasOwnProperty.call(nestedValue, loopArray[i])) {
|
1074
|
+
nestedValue = nestedValue[loopArray[i]];
|
1075
|
+
} else {
|
1076
|
+
// failed to traverse
|
1077
|
+
nestedValue = loopField;
|
1078
|
+
break;
|
1079
|
+
}
|
1080
|
+
}
|
1081
|
+
|
1082
|
+
// put the value into the path - if it has been specified in the path
|
1083
|
+
uriPath = uriPath.replace(`{${rqKeys[rq]}}`, nestedValue);
|
1084
|
+
}
|
1085
|
+
}
|
1086
|
+
}
|
1087
|
+
if (callProps.method) {
|
1088
|
+
uriMethod = callProps.method;
|
1089
|
+
}
|
1090
|
+
if (callProps.query) {
|
1091
|
+
callQuery = callProps.query;
|
1092
|
+
|
1093
|
+
// go through the query params to check for variable values
|
1094
|
+
const cpKeys = Object.keys(callQuery);
|
1095
|
+
for (let cp = 0; cp < cpKeys.length; cp += 1) {
|
1096
|
+
if (callQuery[cpKeys[cp]].startsWith('{') && callQuery[cpKeys[cp]].endsWith('}')) {
|
1097
|
+
// make any necessary changes to the query params
|
1098
|
+
if (devResp !== null && callProps.requestFields && Object.keys(callProps.requestFields).length > 0) {
|
1099
|
+
const rqKeys = Object.keys(callProps.requestFields);
|
1100
|
+
|
1101
|
+
// get the uuid from the device
|
1102
|
+
for (let rq = 0; rq < rqKeys.length; rq += 1) {
|
1103
|
+
if (cpKeys[cp] === rqKeys[rq]) {
|
1104
|
+
// get the request field we are retrieving
|
1105
|
+
const loopField = callProps.requestFields[rqKeys[rq]];
|
1106
|
+
const loopArray = loopField.split('.');
|
1107
|
+
let nestedValue = devResp;
|
1108
|
+
|
1109
|
+
// loops through incase the field is nested
|
1110
|
+
for (let i = 0; i < loopArray.length; i += 1) {
|
1111
|
+
if (Object.hasOwnProperty.call(nestedValue, loopArray[i])) {
|
1112
|
+
nestedValue = nestedValue[loopArray[i]];
|
1113
|
+
} else {
|
1114
|
+
// failed to traverse
|
1115
|
+
nestedValue = loopField;
|
1116
|
+
break;
|
1117
|
+
}
|
1118
|
+
}
|
1119
|
+
|
1120
|
+
// put the value into the query - if it has been specified in the query
|
1121
|
+
callQuery[cpKeys[cp]] = nestedValue;
|
1122
|
+
}
|
1123
|
+
}
|
1124
|
+
}
|
1125
|
+
}
|
1126
|
+
}
|
1127
|
+
}
|
1128
|
+
if (callProps.body) {
|
1129
|
+
callBody = callProps.body;
|
1130
|
+
}
|
1131
|
+
if (callProps.headers) {
|
1132
|
+
callHeaders = callProps.headers;
|
1133
|
+
}
|
1134
|
+
if (callProps.handleFailure) {
|
1135
|
+
handleFail = callProps.handleFailure;
|
1136
|
+
}
|
1137
|
+
if (callProps.responseFields && callProps.responseFields.ostypePrefix) {
|
1138
|
+
ostypePrefix = callProps.responseFields.ostypePrefix;
|
1139
|
+
}
|
1140
|
+
if (callProps.responseFields && callProps.responseFields.statusValue) {
|
1141
|
+
statusValue = callProps.responseFields.statusValue;
|
1142
|
+
}
|
1143
|
+
|
1144
|
+
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
1145
|
+
// !! you can also replace with a specific call if that is easier
|
1146
|
+
return this.genericAdapterRequest(uriPath, uriMethod, callQuery, callBody, callHeaders, (result, error) => {
|
1147
|
+
// if we received an error or their is no response on the results return an error
|
1148
|
+
if (error) {
|
1149
|
+
if (handleFail === 'fail') {
|
1150
|
+
return callback(null, error);
|
1151
|
+
}
|
1152
|
+
return callback({}, null);
|
1153
|
+
}
|
1154
|
+
if (!result.response) {
|
1155
|
+
if (handleFail === 'fail') {
|
1156
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', [brokCall], null, null, null);
|
1157
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
1158
|
+
return callback(null, errorObj);
|
1159
|
+
}
|
1160
|
+
return callback({}, null);
|
1161
|
+
}
|
1162
|
+
|
1163
|
+
// get the keys for the response fields
|
1164
|
+
let rfKeys = [];
|
1165
|
+
if (callProps.responseFields && Object.keys(callProps.responseFields).length > 0) {
|
1166
|
+
rfKeys = Object.keys(callProps.responseFields);
|
1167
|
+
}
|
1168
|
+
|
1169
|
+
// if we got an array returned (e.g. getDevicesFitered)
|
1170
|
+
if (Array.isArray(result.response)) {
|
1171
|
+
const listDevices = [];
|
1172
|
+
for (let a = 0; a < result.response.length; a += 1) {
|
1173
|
+
const thisDevice = result.response[a];
|
1174
|
+
for (let rf = 0; rf < rfKeys.length; rf += 1) {
|
1175
|
+
if (rfKeys[rf] !== 'ostypePrefix') {
|
1176
|
+
// get the response field we are retrieving
|
1177
|
+
const loopField = callProps.responseFields[rfKeys[rf]];
|
1178
|
+
const loopArray = loopField.split('.');
|
1179
|
+
let nestedValue = thisDevice;
|
1180
|
+
|
1181
|
+
// loops through incase the field is nested
|
1182
|
+
for (let i = 0; i < loopArray.length; i += 1) {
|
1183
|
+
if (Object.hasOwnProperty.call(nestedValue, loopArray[i])) {
|
1184
|
+
nestedValue = nestedValue[loopArray[i]];
|
1185
|
+
} else {
|
1186
|
+
// failed to traverse
|
1187
|
+
nestedValue = '';
|
1188
|
+
break;
|
1189
|
+
}
|
1190
|
+
}
|
1191
|
+
// if the field is ostype - need to add prefix
|
1192
|
+
if (rfKeys[rf] === 'ostype' && typeof nestedValue === 'string') {
|
1193
|
+
nestedValue = ostypePrefix + nestedValue;
|
1194
|
+
}
|
1195
|
+
// if there is a status to set, set it
|
1196
|
+
if (rfKeys[rf] === 'status') {
|
1197
|
+
// if really looking for just a good response
|
1198
|
+
if (loopField === 'return2xx' && result.icode === statusValue.toString()) {
|
1199
|
+
thisDevice.isAlive = true;
|
1200
|
+
} else if (nestedValue.toString() === statusValue.toString()) {
|
1201
|
+
thisDevice.isAlive = true;
|
1202
|
+
} else {
|
1203
|
+
thisDevice.isAlive = false;
|
1204
|
+
}
|
1205
|
+
}
|
1206
|
+
// if we found a good value
|
1207
|
+
thisDevice[rfKeys[rf]] = nestedValue;
|
1208
|
+
}
|
1209
|
+
}
|
1210
|
+
|
1211
|
+
// if there is no filter - add the device to the list
|
1212
|
+
if (!filterName || filterName.length === 0) {
|
1213
|
+
listDevices.push(thisDevice);
|
1214
|
+
} else {
|
1215
|
+
// if we have to match a filter
|
1216
|
+
let found = false;
|
1217
|
+
for (let f = 0; f < filterName.length; f += 1) {
|
1218
|
+
if (thisDevice.name.indexOf(filterName[f]) >= 0) {
|
1219
|
+
found = true;
|
1220
|
+
break;
|
1221
|
+
}
|
1222
|
+
}
|
1223
|
+
// matching device
|
1224
|
+
if (found) {
|
1225
|
+
listDevices.push(thisDevice);
|
1226
|
+
}
|
1227
|
+
}
|
1228
|
+
}
|
1229
|
+
|
1230
|
+
// return the array of devices
|
1231
|
+
return callback(listDevices, null);
|
1232
|
+
}
|
1233
|
+
|
1234
|
+
// if this is not an array - just about everything else, just handle as a single object
|
1235
|
+
let thisDevice = result.response;
|
1236
|
+
for (let rf = 0; rf < rfKeys.length; rf += 1) {
|
1237
|
+
// skip ostypePrefix since it is not a field
|
1238
|
+
if (rfKeys[rf] !== 'ostypePrefix') {
|
1239
|
+
// get the response field we are retrieving
|
1240
|
+
const loopField = callProps.responseFields[rfKeys[rf]];
|
1241
|
+
const loopArray = loopField.split('.');
|
1242
|
+
let nestedValue = thisDevice;
|
1243
|
+
|
1244
|
+
// loops through incase the field is nested
|
1245
|
+
for (let i = 0; i < loopArray.length; i += 1) {
|
1246
|
+
if (Object.hasOwnProperty.call(nestedValue, loopArray[i])) {
|
1247
|
+
nestedValue = nestedValue[loopArray[i]];
|
1248
|
+
} else {
|
1249
|
+
// failed to traverse
|
1250
|
+
nestedValue = '';
|
1251
|
+
break;
|
1252
|
+
}
|
1253
|
+
}
|
1254
|
+
// if the field is ostype - need to add prefix
|
1255
|
+
if (rfKeys[rf] === 'ostype' && typeof nestedValue === 'string') {
|
1256
|
+
nestedValue = ostypePrefix + nestedValue;
|
1257
|
+
}
|
1258
|
+
// if there is a status to set, set it
|
1259
|
+
if (rfKeys[rf] === 'status') {
|
1260
|
+
// if really looking for just a good response
|
1261
|
+
if (loopField === 'return2xx' && result.icode === statusValue.toString()) {
|
1262
|
+
thisDevice.isAlive = true;
|
1263
|
+
} else if (nestedValue.toString() === statusValue.toString()) {
|
1264
|
+
thisDevice.isAlive = true;
|
1265
|
+
} else {
|
1266
|
+
thisDevice.isAlive = false;
|
1267
|
+
}
|
1268
|
+
}
|
1269
|
+
// if we found a good value
|
1270
|
+
thisDevice[rfKeys[rf]] = nestedValue;
|
1271
|
+
}
|
1272
|
+
}
|
1273
|
+
|
1274
|
+
// if there is a filter - check the device is in the list
|
1275
|
+
if (filterName && filterName.length > 0) {
|
1276
|
+
let found = false;
|
1277
|
+
for (let f = 0; f < filterName.length; f += 1) {
|
1278
|
+
if (thisDevice.name.indexOf(filterName[f]) >= 0) {
|
1279
|
+
found = true;
|
1280
|
+
break;
|
1281
|
+
}
|
1282
|
+
}
|
1283
|
+
// no matching device - clear the device
|
1284
|
+
if (!found) {
|
1285
|
+
thisDevice = {};
|
1286
|
+
}
|
1287
|
+
}
|
1288
|
+
|
1289
|
+
return callback(thisDevice, null);
|
1290
|
+
});
|
1291
|
+
} catch (e) {
|
1292
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, e);
|
1293
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
1294
|
+
return callback(null, errorObj);
|
1295
|
+
}
|
1296
|
+
}
|
1004
1297
|
}
|
1005
1298
|
|
1006
1299
|
module.exports = AdapterBase;
|