@itentialopensource/adapter-viptela 0.9.0 → 0.10.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 (128) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/ENHANCE.md +69 -0
  3. package/PROPERTIES.md +247 -0
  4. package/README.md +112 -542
  5. package/SUMMARY.md +9 -0
  6. package/TROUBLESHOOT.md +46 -0
  7. package/adapter.js +34555 -1569
  8. package/adapterBase.js +548 -283
  9. package/entities/AdministrationAuditLog/action.json +252 -0
  10. package/entities/AdministrationAuditLog/schema.json +30 -0
  11. package/entities/AdministrationUserAndGroup/action.json +533 -0
  12. package/entities/AdministrationUserAndGroup/mockdatafiles/findUserGroups-default.json +4 -0
  13. package/entities/AdministrationUserAndGroup/mockdatafiles/findUserGroupsAsKeyValue-default.json +5 -0
  14. package/entities/AdministrationUserAndGroup/mockdatafiles/findUsers-default.json +3 -0
  15. package/entities/AdministrationUserAndGroup/mockdatafiles/getColoGroups-default.json +6 -0
  16. package/entities/AdministrationUserAndGroup/mockdatafiles/getVpnGroups-default.json +5 -0
  17. package/entities/AdministrationUserAndGroup/schema.json +44 -0
  18. package/entities/CertificateManagementDevice/action.json +517 -0
  19. package/entities/CertificateManagementDevice/mockdatafiles/getRootCertChains-default.json +3 -0
  20. package/entities/CertificateManagementDevice/schema.json +43 -0
  21. package/entities/ClusterManagement/action.json +477 -0
  22. package/entities/ClusterManagement/mockdatafiles/getConfiguredIPList-default.json +5 -0
  23. package/entities/ClusterManagement/mockdatafiles/getConnectedDevices-default.json +3 -0
  24. package/entities/ClusterManagement/mockdatafiles/getConnectedDevicesPerTenant-default.json +3 -0
  25. package/entities/ClusterManagement/mockdatafiles/getTenantsList-default.json +4 -0
  26. package/entities/ClusterManagement/mockdatafiles/listVmanages-default.json +4 -0
  27. package/entities/ClusterManagement/schema.json +41 -0
  28. package/entities/ColocationCluster/action.json +229 -0
  29. package/entities/ColocationCluster/schema.json +29 -0
  30. package/entities/ColocationServiceChain/action.json +86 -0
  31. package/entities/ColocationServiceChain/mockdatafiles/getEdgeDevices-default.json +5 -0
  32. package/entities/ColocationServiceChain/mockdatafiles/getpnfDevices-default.json +5 -0
  33. package/entities/ColocationServiceChain/schema.json +22 -0
  34. package/entities/ColocationServiceGroup/action.json +148 -0
  35. package/entities/ColocationServiceGroup/mockdatafiles/getAvailableChains-default.json +6 -0
  36. package/entities/ColocationServiceGroup/schema.json +25 -0
  37. package/entities/ConfigurationDisasterRecovery/action.json +696 -0
  38. package/entities/ConfigurationDisasterRecovery/mockdatafiles/downloadReplicationData-default.json +5 -0
  39. package/entities/ConfigurationDisasterRecovery/mockdatafiles/getDisasterRecoveryStatus-default.json +6 -0
  40. package/entities/ConfigurationDisasterRecovery/mockdatafiles/getLocalDataCenterState-default.json +6 -0
  41. package/entities/ConfigurationDisasterRecovery/mockdatafiles/getReachabilityInfo-default.json +5 -0
  42. package/entities/ConfigurationDisasterRecovery/mockdatafiles/getRemoteDCMembersState-default.json +3 -0
  43. package/entities/ConfigurationDisasterRecovery/mockdatafiles/getRemoteDataCenterState-default.json +6 -0
  44. package/entities/ConfigurationDisasterRecovery/schema.json +52 -0
  45. package/entities/ConfigurationFeatureList/action.json +46 -0
  46. package/entities/ConfigurationFeatureList/schema.json +20 -0
  47. package/entities/CreateABackupSnapshot/action.json +24 -0
  48. package/entities/CreateABackupSnapshot/schema.json +19 -0
  49. package/entities/DataCollectionAgent/action.json +470 -0
  50. package/entities/DataCollectionAgent/mockdatafiles/getTemplatePolicyDefinitionsDCA-default.json +5 -0
  51. package/entities/DataCollectionAgent/mockdatafiles/getVPNListsDCA-default.json +3 -0
  52. package/entities/DataCollectionAgent/mockdatafiles/getVedgeTemplateListDCA-default.json +6 -0
  53. package/entities/DataCollectionAgent/mockdatafiles/getVsmartTemplateListDCA-default.json +5 -0
  54. package/entities/DataCollectionAgent/mockdatafiles/listAllDevicesDCA-default.json +5 -0
  55. package/entities/DataCollectionAgent/schema.json +41 -0
  56. package/entities/DeviceActions/action.json +243 -0
  57. package/entities/DeviceActions/mockdatafiles/generateSecurityDevicesList-default.json +5 -0
  58. package/entities/DeviceActions/schema.json +13 -1
  59. package/entities/DeviceConfigHistory/action.json +294 -0
  60. package/entities/DeviceConfigHistory/schema.json +32 -0
  61. package/entities/MonitoringAlarmsDetails/action.json +684 -0
  62. package/entities/MonitoringAlarmsDetails/mockdatafiles/listDisabledAlarm-default.json +5 -0
  63. package/entities/MonitoringAlarmsDetails/schema.json +51 -0
  64. package/entities/MonitoringColocationCluster/action.json +360 -0
  65. package/entities/MonitoringColocationCluster/mockdatafiles/getClusterConfigByClusterId-default.json +3 -0
  66. package/entities/MonitoringColocationCluster/mockdatafiles/getClusterPortMappingByClusterId-default.json +3 -0
  67. package/entities/MonitoringColocationCluster/mockdatafiles/getPNFConfig-default.json +3 -0
  68. package/entities/MonitoringColocationCluster/mockdatafiles/getServiceGroupByClusterId-default.json +3 -0
  69. package/entities/MonitoringColocationCluster/mockdatafiles/getSystemStatusByDeviceId-default.json +6 -0
  70. package/entities/MonitoringColocationCluster/mockdatafiles/getVNFAlarmCount-default.json +6 -0
  71. package/entities/MonitoringColocationCluster/mockdatafiles/getVNFEventsCountDetail-default.json +4 -0
  72. package/entities/MonitoringColocationCluster/mockdatafiles/getVNFEventsDetail-default.json +3 -0
  73. package/entities/MonitoringColocationCluster/mockdatafiles/getVNFInterfaceDetail-default.json +3 -0
  74. package/entities/MonitoringColocationCluster/mockdatafiles/getpnfDetails-default.json +5 -0
  75. package/entities/MonitoringColocationCluster/mockdatafiles/getvnfByDeviceId-default.json +4 -0
  76. package/entities/MonitoringColocationCluster/mockdatafiles/listNetworkFunctionMap-default.json +3 -0
  77. package/entities/MonitoringColocationCluster/schema.json +35 -0
  78. package/entities/MonitoringDeviceDetails/action.json +40 -0
  79. package/entities/MonitoringDeviceDetails/schema.json +3 -1
  80. package/entities/MonitoringDeviceStatisticsDetails/action.json +109 -0
  81. package/entities/MonitoringDeviceStatisticsDetails/mockdatafiles/generateDeviceStatisticsData-default.json +3 -0
  82. package/entities/MonitoringDeviceStatisticsDetails/mockdatafiles/getActiveAlarms-default.json +5 -0
  83. package/entities/MonitoringDeviceStatisticsDetails/mockdatafiles/getStatDataFieldsByStateDataType-default.json +6 -0
  84. package/entities/MonitoringDeviceStatisticsDetails/mockdatafiles/getStatisticsType-default.json +4 -0
  85. package/entities/MonitoringDeviceStatisticsDetails/schema.json +23 -0
  86. package/entities/MonitoringEvents/action.json +378 -0
  87. package/entities/MonitoringEvents/mockdatafiles/getComponentsAsKeyValue-default.json +4 -0
  88. package/entities/MonitoringEvents/mockdatafiles/getEventTypesAsKeyValue-default.json +3 -0
  89. package/entities/MonitoringEvents/schema.json +36 -0
  90. package/entities/RealTimeMonitoringAAA/action.json +109 -0
  91. package/entities/RealTimeMonitoringAAA/mockdatafiles/getAllDeviceUsers-default.json +5 -0
  92. package/entities/RealTimeMonitoringAAA/mockdatafiles/getUsersFromDevice-default.json +6 -0
  93. package/entities/RealTimeMonitoringAAA/schema.json +23 -0
  94. package/entities/SSLProxyCertificateManagementDevice/action.json +494 -0
  95. package/entities/SSLProxyCertificateManagementDevice/mockdatafiles/getSslProxyList-default.json +4 -0
  96. package/entities/SSLProxyCertificateManagementDevice/schema.json +42 -0
  97. package/entities/ScheduledBackupRestore/action.json +189 -0
  98. package/entities/ScheduledBackupRestore/schema.json +27 -0
  99. package/entities/SystemCloudService/action.json +313 -0
  100. package/entities/SystemCloudService/schema.json +33 -0
  101. package/entities/SystemContainer/action.json +189 -0
  102. package/entities/SystemContainer/mockdatafiles/getCustomApp-default.json +3 -0
  103. package/entities/SystemContainer/schema.json +27 -0
  104. package/entities/TroubleshootingToolsDashboard/action.json +128 -0
  105. package/entities/TroubleshootingToolsDashboard/schema.json +24 -0
  106. package/entities/TroubleshootingToolsDeviceConnectivity/action.json +288 -0
  107. package/entities/TroubleshootingToolsDeviceConnectivity/schema.json +32 -0
  108. package/entities/TroubleshootingToolsDeviceSoftwarePackage/action.json +85 -0
  109. package/entities/TroubleshootingToolsDeviceSoftwarePackage/schema.json +22 -0
  110. package/entities/TroubleshootingToolsDeviceSoftwareUpdate/action.json +86 -0
  111. package/entities/TroubleshootingToolsDeviceSoftwareUpdate/schema.json +22 -0
  112. package/entities/TroubleshootingToolsDiagnostics/action.json +977 -0
  113. package/entities/TroubleshootingToolsDiagnostics/schema.json +65 -0
  114. package/entities/TroubleshootingToolsSoftwareActions/action.json +232 -0
  115. package/entities/TroubleshootingToolsSoftwareActions/mockdatafiles/findSoftwareImages-default.json +6 -0
  116. package/entities/TroubleshootingToolsSoftwareActions/mockdatafiles/findSoftwareImagesWithFilters-default.json +5 -0
  117. package/entities/TroubleshootingToolsSoftwareActions/schema.json +29 -0
  118. package/error.json +6 -0
  119. package/package.json +3 -3
  120. package/pronghorn.json +13893 -113
  121. package/propertiesDecorators.json +14 -0
  122. package/propertiesSchema.json +350 -0
  123. package/refs?service=git-upload-pack +0 -0
  124. package/report/updateReport1651360586947.json +114 -0
  125. package/test/integration/adapterTestIntegration.js +13161 -0
  126. package/test/unit/adapterBaseTestUnit.js +22 -24
  127. package/test/unit/adapterTestUnit.js +8053 -51
  128. package/utils/tbUtils.js +20 -7
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');
@@ -154,6 +155,9 @@ class AdapterBase extends EventEmitterCl {
154
155
  // Instantiate the EventEmitter super class
155
156
  super();
156
157
 
158
+ // IAP home directory injected by core when running the adapter within IAP
159
+ process.env.iap_home = process.argv[3];
160
+
157
161
  try {
158
162
  // Capture the adapter id
159
163
  this.id = prongid;
@@ -277,129 +281,6 @@ class AdapterBase extends EventEmitterCl {
277
281
  }
278
282
  }
279
283
 
280
- /**
281
- * updateAdapterConfiguration is used to update any of the adapter configuration files. This
282
- * allows customers to make changes to adapter configuration without having to be on the
283
- * file system.
284
- *
285
- * @function updateAdapterConfiguration
286
- * @param {string} configFile - the name of the file being updated (required)
287
- * @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
288
- * @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
289
- * @param {string} type - the type of entity file to change, (action, schema, mock) (optional)
290
- * @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
291
- * @param {Callback} callback - The results of the call
292
- */
293
- updateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
294
- const meth = 'adapterBase-updateAdapterConfiguration';
295
- const origin = `${this.id}-${meth}`;
296
- log.trace(origin);
297
-
298
- // verify the parameters are valid
299
- if (changes === undefined || changes === null || typeof changes !== 'object'
300
- || Object.keys(changes).length === 0) {
301
- const result = {
302
- response: 'No configuration updates to make'
303
- };
304
- log.info(result.response);
305
- return callback(result, null);
306
- }
307
- if (configFile === undefined || configFile === null || configFile === '') {
308
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['configFile'], null, null, null);
309
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
310
- return callback(null, errorObj);
311
- }
312
-
313
- // take action based on configFile being changed
314
- if (configFile === 'package.json') {
315
- const pres = updatePackage(changes);
316
- if (pres) {
317
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${pres}`, [], null, null, null);
318
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
319
- return callback(null, errorObj);
320
- }
321
- const result = {
322
- response: 'Package updates completed - restarting adapter'
323
- };
324
- log.info(result.response);
325
- forceFail(true);
326
- return callback(result, null);
327
- }
328
- if (entity === undefined || entity === null || entity === '') {
329
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Unsupported Configuration Change or Missing Entity', [], null, null, null);
330
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
331
- return callback(null, errorObj);
332
- }
333
-
334
- // this means we are changing an entity file so type is required
335
- if (type === undefined || type === null || type === '') {
336
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['type'], null, null, null);
337
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
338
- return callback(null, errorObj);
339
- }
340
-
341
- // if the entity does not exist - error
342
- const epath = `${__dirname}/entities/${entity}`;
343
- if (!fs.existsSync(epath)) {
344
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: Invalid Entity - ${entity}`, [], null, null, null);
345
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
346
- return callback(null, errorObj);
347
- }
348
-
349
- // take action based on type of file being changed
350
- if (type === 'action') {
351
- // BACKUP???
352
- const ares = updateAction(epath, action, changes);
353
- if (ares) {
354
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${ares}`, [], null, null, null);
355
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
356
- return callback(null, errorObj);
357
- }
358
- // AJV CHECK???
359
- // RESTORE IF NEEDED???
360
- const result = {
361
- response: `Action updates completed to entity: ${entity} - ${action}`
362
- };
363
- log.info(result.response);
364
- return callback(result, null);
365
- }
366
- if (type === 'schema') {
367
- const sres = updateSchema(epath, configFile, changes);
368
- if (sres) {
369
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${sres}`, [], null, null, null);
370
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
371
- return callback(null, errorObj);
372
- }
373
- const result = {
374
- response: `Schema updates completed to entity: ${entity} - ${configFile}`
375
- };
376
- log.info(result.response);
377
- return callback(result, null);
378
- }
379
- if (type === 'mock') {
380
- // if the mock directory does not exist - error
381
- const mpath = `${__dirname}/entities/${entity}/mockdatafiles`;
382
- if (!fs.existsSync(mpath)) {
383
- fs.mkdirSync(mpath);
384
- }
385
-
386
- const mres = updateMock(mpath, configFile, changes);
387
- if (mres) {
388
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${mres}`, [], null, null, null);
389
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
390
- return callback(null, errorObj);
391
- }
392
- const result = {
393
- response: `Mock data updates completed to entity: ${entity} - ${configFile}`
394
- };
395
- log.info(result.response);
396
- return callback(result, null);
397
- }
398
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: Unsupported Type - ${type}`, [], null, null, null);
399
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
400
- return callback(null, errorObj);
401
- }
402
-
403
284
  /**
404
285
  * @summary Connect function is used during Pronghorn startup to provide instantiation feedback.
405
286
  *
@@ -468,7 +349,7 @@ class AdapterBase extends EventEmitterCl {
468
349
  }
469
350
 
470
351
  // call to the healthcheck in connector
471
- return this.requestHandlerInst.identifyHealthcheck(reqObj, (res, error) => {
352
+ return this.requestHandlerInst.identifyHealthcheck(myRequest, (res, error) => {
472
353
  // unhealthy
473
354
  if (error) {
474
355
  // if we were healthy, toggle health
@@ -501,98 +382,12 @@ class AdapterBase extends EventEmitterCl {
501
382
  }
502
383
 
503
384
  /**
504
- * @summary Suspends the adapter
505
- * @param {Callback} callback - The adapater suspension status
506
- * @function suspend
507
- */
508
- suspend(mode, callback) {
509
- const origin = `${this.id}-adapterBase-suspend`;
510
- if (this.suspended) {
511
- throw new Error(`${origin}: Adapter is already suspended`);
512
- }
513
- try {
514
- this.suspended = true;
515
- this.suspendMode = mode;
516
- if (this.suspendMode === 'pause') {
517
- const props = JSON.parse(JSON.stringify(this.initProps));
518
- // To suspend adapter, enable throttling and set concurrent max to 0
519
- props.throttle.throttle_enabled = true;
520
- props.throttle.concurrent_max = 0;
521
- this.refreshProperties(props);
522
- }
523
- return callback({ suspended: true });
524
- } catch (error) {
525
- return callback(null, error);
526
- }
527
- }
528
-
529
- /**
530
- * @summary Unsuspends the adapter
531
- * @param {Callback} callback - The adapater suspension status
532
- *
533
- * @function unsuspend
534
- */
535
- unsuspend(callback) {
536
- const origin = `${this.id}-adapterBase-unsuspend`;
537
- if (!this.suspended) {
538
- throw new Error(`${origin}: Adapter is not suspended`);
539
- }
540
- if (this.suspendMode === 'pause') {
541
- const props = JSON.parse(JSON.stringify(this.initProps));
542
- // To unsuspend adapter, keep throttling enabled and begin processing queued requests in order
543
- props.throttle.throttle_enabled = true;
544
- props.throttle.concurrent_max = 1;
545
- this.refreshProperties(props);
546
- setTimeout(() => {
547
- this.getQueue((q, error) => {
548
- // console.log("Items in queue: " + String(q.length))
549
- if (q.length === 0) {
550
- // if queue is empty, return to initial properties state
551
- this.refreshProperties(this.initProps);
552
- this.suspended = false;
553
- return callback({ suspended: false });
554
- }
555
- // recursive call to check queue again every second
556
- return this.unsuspend(callback);
557
- });
558
- }, 1000);
559
- } else {
560
- this.suspended = false;
561
- callback({ suspend: false });
562
- }
563
- }
564
-
565
- /**
566
- * getAllFunctions is used to get all of the exposed function in the adapter
567
- *
568
- * @function getAllFunctions
569
- */
570
- getAllFunctions() {
571
- let myfunctions = [];
572
- let obj = this;
573
-
574
- // find the functions in this class
575
- do {
576
- const l = Object.getOwnPropertyNames(obj)
577
- .concat(Object.getOwnPropertySymbols(obj).map((s) => s.toString()))
578
- .sort()
579
- .filter((p, i, arr) => typeof obj[p] === 'function' && p !== 'constructor' && (i === 0 || p !== arr[i - 1]) && myfunctions.indexOf(p) === -1);
580
- myfunctions = myfunctions.concat(l);
581
- }
582
- while (
583
- (obj = Object.getPrototypeOf(obj)) && Object.getPrototypeOf(obj)
584
- );
585
-
586
- return myfunctions;
587
- }
588
-
589
- /**
590
- * 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
591
386
  * @param {array} ignoreThese - additional methods to ignore (optional)
592
387
  *
593
- * @function getWorkflowFunctions
388
+ * @function iapGetAdapterWorkflowFunctions
594
389
  */
595
- getWorkflowFunctions(ignoreThese) {
390
+ iapGetAdapterWorkflowFunctions(ignoreThese) {
596
391
  const myfunctions = this.getAllFunctions();
597
392
  const wffunctions = [];
598
393
 
@@ -602,8 +397,9 @@ class AdapterBase extends EventEmitterCl {
602
397
  // got to the second tier (adapterBase)
603
398
  break;
604
399
  }
605
- if (myfunctions[m] !== 'hasEntity' && myfunctions[m] !== 'verifyCapability' && myfunctions[m] !== 'updateEntityCache'
606
- && myfunctions[m] !== 'healthCheck' && myfunctions[m] !== 'getWorkflowFunctions'
400
+ if (myfunctions[m] !== 'iapHasAdapterEntity' && myfunctions[m] !== 'iapVerifyAdapterCapability'
401
+ && myfunctions[m] !== 'iapUpdateAdapterEntityCache' && myfunctions[m] !== 'healthCheck'
402
+ && myfunctions[m] !== 'iapGetAdapterWorkflowFunctions'
607
403
  && !(myfunctions[m].endsWith('Emit') || myfunctions[m].match(/Emit__v[0-9]+/))) {
608
404
  let found = false;
609
405
  if (ignoreThese && Array.isArray(ignoreThese)) {
@@ -619,34 +415,140 @@ class AdapterBase extends EventEmitterCl {
619
415
  }
620
416
  }
621
417
 
622
- return wffunctions;
623
- }
624
-
625
- /**
626
- * checkActionFiles is used to update the validation of the action files.
627
- *
628
- * @function checkActionFiles
629
- */
630
- checkActionFiles() {
631
- const origin = `${this.id}-adapterBase-checkActionFiles`;
632
- log.trace(origin);
633
-
634
- // validate the action files for the adapter
635
- try {
636
- return this.requestHandlerInst.checkActionFiles();
637
- } catch (e) {
638
- return ['Exception increase log level'];
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
+ }
526
+
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);
639
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);
640
542
  }
641
543
 
642
544
  /**
643
545
  * See if the API path provided is found in this adapter
644
546
  *
645
- * @function findPath
547
+ * @function iapFindAdapterPath
646
548
  * @param {string} apiPath - the api path to check on
647
549
  * @param {Callback} callback - The results of the call
648
550
  */
649
- findPath(apiPath, callback) {
551
+ iapFindAdapterPath(apiPath, callback) {
650
552
  const result = {
651
553
  apiPath
652
554
  };
@@ -723,66 +625,90 @@ class AdapterBase extends EventEmitterCl {
723
625
  }
724
626
 
725
627
  /**
726
- * checkProperties is used to validate the adapter properties.
727
- *
728
- * @function checkProperties
729
- * @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
730
631
  */
731
- checkProperties(properties) {
732
- const origin = `${this.myid}-adapterBase-checkProperties`;
733
- log.trace(origin);
734
-
735
- // validate the properties for the adapter
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
+ }
736
637
  try {
737
- return this.requestHandlerInst.checkProperties(properties);
738
- } catch (e) {
739
- return { exception: 'Exception increase log level' };
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);
740
650
  }
741
651
  }
742
652
 
743
653
  /**
744
- * getQueue is used to get information for all of the requests currently in the queue.
654
+ * @summary Unsuspends the adapter
655
+ * @param {Callback} callback - The adapater suspension status
745
656
  *
746
- * @function getQueue
747
- * @param {Callback} callback - a callback function to return the result (Queue) or the error
657
+ * @function iapUnsuspendAdapter
748
658
  */
749
- getQueue(callback) {
750
- const origin = `${this.id}-adapterBase-getQueue`;
751
- log.trace(origin);
752
-
753
- return this.requestHandlerInst.getQueue(callback);
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
+ }
754
687
  }
755
688
 
756
689
  /**
757
- * @summary Takes in property text and an encoding/encryption and returns the resulting
758
- * encoded/encrypted string
759
- *
760
- * @function encryptProperty
761
- * @param {String} property - the property to encrypt
762
- * @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.
763
691
  *
764
- * @param {Callback} callback - a callback function to return the result
765
- * Encrypted String or the Error
692
+ * @function iapGetAdapterQueue
693
+ * @param {Callback} callback - a callback function to return the result (Queue) or the error
766
694
  */
767
- encryptProperty(property, technique, callback) {
768
- const origin = `${this.id}-adapterBase-encryptProperty`;
695
+ iapGetAdapterQueue(callback) {
696
+ const origin = `${this.id}-adapterBase-iapGetAdapterQueue`;
769
697
  log.trace(origin);
770
698
 
771
- // Make the call -
772
- // encryptProperty(property, technique, callback)
773
- return this.requestHandlerInst.encryptProperty(property, technique, callback);
699
+ return this.requestHandlerInst.getQueue(callback);
774
700
  }
775
701
 
776
702
  /**
777
703
  * @summary runs troubleshoot scripts for adapter
778
704
  *
779
- * @function troubleshoot
705
+ * @function iapTroubleshootAdapter
780
706
  * @param {Object} props - the connection, healthcheck and authentication properties
781
707
  * @param {boolean} persistFlag - whether the adapter properties should be updated
782
708
  * @param {Adapter} adapter - adapter instance to troubleshoot
783
709
  * @param {Callback} callback - callback function to return troubleshoot results
784
710
  */
785
- async troubleshoot(props, persistFlag, adapter, callback) {
711
+ async iapTroubleshootAdapter(props, persistFlag, adapter, callback) {
786
712
  try {
787
713
  const result = await troubleshootingAdapter.troubleshoot(props, false, persistFlag, adapter);
788
714
  if (result.healthCheck && result.connectivity.failCount === 0 && result.basicGet.failCount === 0) {
@@ -797,11 +723,11 @@ class AdapterBase extends EventEmitterCl {
797
723
  /**
798
724
  * @summary runs healthcheck script for adapter
799
725
  *
800
- * @function runHealthcheck
726
+ * @function iapRunAdapterHealthcheck
801
727
  * @param {Adapter} adapter - adapter instance to troubleshoot
802
728
  * @param {Callback} callback - callback function to return healthcheck status
803
729
  */
804
- async runHealthcheck(adapter, callback) {
730
+ async iapRunAdapterHealthcheck(adapter, callback) {
805
731
  try {
806
732
  const result = await tbUtils.healthCheck(adapter);
807
733
  if (result) {
@@ -816,11 +742,11 @@ class AdapterBase extends EventEmitterCl {
816
742
  /**
817
743
  * @summary runs connectivity check script for adapter
818
744
  *
819
- * @function runConnectivity
745
+ * @function iapRunAdapterConnectivity
820
746
  * @param {Adapter} adapter - adapter instance to troubleshoot
821
747
  * @param {Callback} callback - callback function to return connectivity status
822
748
  */
823
- async runConnectivity(callback) {
749
+ async iapRunAdapterConnectivity(callback) {
824
750
  try {
825
751
  const { serviceItem } = await tbUtils.getAdapterConfig();
826
752
  const { host } = serviceItem.properties.properties;
@@ -837,10 +763,10 @@ class AdapterBase extends EventEmitterCl {
837
763
  /**
838
764
  * @summary runs basicGet script for adapter
839
765
  *
840
- * @function runBasicGet
766
+ * @function iapRunAdapterBasicGet
841
767
  * @param {Callback} callback - callback function to return basicGet result
842
768
  */
843
- runBasicGet(callback) {
769
+ iapRunAdapterBasicGet(callback) {
844
770
  try {
845
771
  const result = tbUtils.runBasicGet(false);
846
772
  if (result.failCount > 0) {
@@ -852,6 +778,106 @@ class AdapterBase extends EventEmitterCl {
852
778
  }
853
779
  }
854
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
+
855
881
  /**
856
882
  * @summary take the entities and add them to the cache
857
883
  *
@@ -1004,21 +1030,260 @@ class AdapterBase extends EventEmitterCl {
1004
1030
  }
1005
1031
 
1006
1032
  /**
1007
- * @summary moves entities to mongo database
1033
+ * @summary Make one of the needed Broker calls - could be one of many
1008
1034
  *
1009
- * @function moveEntitiesToDB
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)
1010
1040
  *
1011
- * @return {Callback} - containing the response from the mongo transaction
1041
+ * @param {getCallback} callback - a callback function to return the result of the call
1012
1042
  */
1013
- moveEntitiesToDB(callback) {
1014
- const meth = 'adapterBase-moveEntitiesToDB';
1043
+ iapMakeBrokerCall(brokCall, callProps, devResp, filterName, callback) {
1044
+ const meth = 'adapter-iapMakeBrokerCall';
1015
1045
  const origin = `${this.id}-${meth}`;
1016
1046
  log.trace(origin);
1017
1047
 
1018
1048
  try {
1019
- return callback(entitiesToDB.moveEntitiesToDB(__dirname, { pronghornProps: this.allProps, id: this.id }), null);
1020
- } catch (err) {
1021
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, err);
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 && 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 = '';
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 && 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 = '';
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.statusValue) {
1141
+ statusValue = callProps.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) > 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 (nestedValue.toString() === statusValue.toString()) {
1198
+ thisDevice.isAlive = true;
1199
+ } else {
1200
+ thisDevice.isAlive = false;
1201
+ }
1202
+ }
1203
+ // if we found a good value
1204
+ thisDevice[rfKeys[rf]] = nestedValue;
1205
+ }
1206
+ }
1207
+
1208
+ // if there is no filter - add the device to the list
1209
+ if (!filterName || filterName.length === 0) {
1210
+ listDevices.push(thisDevice);
1211
+ } else {
1212
+ // if we have to match a filter
1213
+ let found = false;
1214
+ for (let f = 0; f < filterName.length; f += 1) {
1215
+ if (thisDevice.name.indexOf(filterName[f]) >= 0) {
1216
+ found = true;
1217
+ break;
1218
+ }
1219
+ }
1220
+ // matching device
1221
+ if (found) {
1222
+ listDevices.push(thisDevice);
1223
+ }
1224
+ }
1225
+ }
1226
+
1227
+ // return the array of devices
1228
+ return callback(listDevices, null);
1229
+ }
1230
+
1231
+ // if this is not an array - just about everything else, just handle as a single object
1232
+ let thisDevice = result.response;
1233
+ for (let rf = 0; rf < rfKeys.length; rf += 1) {
1234
+ // skip ostypePrefix since it is not a field
1235
+ if (rfKeys[rf] !== 'ostypePrefix') {
1236
+ // get the response field we are retrieving
1237
+ const loopField = callProps.responseFields[rfKeys[rf]];
1238
+ const loopArray = loopField.split('.');
1239
+ let nestedValue = thisDevice;
1240
+
1241
+ // loops through incase the field is nested
1242
+ for (let i = 0; i < loopArray.length; i += 1) {
1243
+ if (Object.hasOwnProperty.call(nestedValue, loopArray[i])) {
1244
+ nestedValue = nestedValue[loopArray[i]];
1245
+ } else {
1246
+ // failed to traverse
1247
+ nestedValue = '';
1248
+ break;
1249
+ }
1250
+ }
1251
+ // if the field is ostype - need to add prefix
1252
+ if (rfKeys[rf] === 'ostype' && typeof nestedValue === 'string') {
1253
+ nestedValue = ostypePrefix + nestedValue;
1254
+ }
1255
+ // if there is a status to set, set it
1256
+ if (rfKeys[rf] === 'status') {
1257
+ if (nestedValue.toString() === statusValue.toString()) {
1258
+ thisDevice.isAlive = true;
1259
+ } else {
1260
+ thisDevice.isAlive = false;
1261
+ }
1262
+ }
1263
+ // if we found a good value
1264
+ thisDevice[rfKeys[rf]] = nestedValue;
1265
+ }
1266
+ }
1267
+
1268
+ // if there is a filter - check the device is in the list
1269
+ if (filterName && filterName.length > 0) {
1270
+ let found = false;
1271
+ for (let f = 0; f < filterName.length; f += 1) {
1272
+ if (thisDevice.name.indexOf(filterName[f]) >= 0) {
1273
+ found = true;
1274
+ break;
1275
+ }
1276
+ }
1277
+ // no matching device - clear the device
1278
+ if (!found) {
1279
+ thisDevice = {};
1280
+ }
1281
+ }
1282
+
1283
+ return callback(thisDevice, null);
1284
+ });
1285
+ } catch (e) {
1286
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, e);
1022
1287
  log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1023
1288
  return callback(null, errorObj);
1024
1289
  }