@itentialopensource/adapter-robustel 0.1.1 → 0.2.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.
package/adapter.js CHANGED
@@ -82,10 +82,18 @@ class Robustel extends AdapterBaseCl {
82
82
  }
83
83
 
84
84
  /**
85
- * @getWorkflowFunctions
85
+ * @iapGetAdapterWorkflowFunctions
86
86
  */
87
- getWorkflowFunctions(inIgnore) {
88
- let myIgnore = ['getAuthorization', 'hasEntities', 'hasDevices'];
87
+ iapGetAdapterWorkflowFunctions(inIgnore) {
88
+ let myIgnore = [
89
+ 'healthCheck',
90
+ 'iapGetAdapterWorkflowFunctions',
91
+ 'iapHasAdapterEntity',
92
+ 'iapVerifyAdapterCapability',
93
+ 'iapUpdateAdapterEntityCache',
94
+ 'hasEntities',
95
+ 'getAuthorization'
96
+ ];
89
97
  if (!inIgnore && Array.isArray(inIgnore)) {
90
98
  myIgnore = inIgnore;
91
99
  } else if (!inIgnore && typeof inIgnore === 'string') {
@@ -96,15 +104,15 @@ class Robustel extends AdapterBaseCl {
96
104
  // you can add specific methods that you do not want to be workflow functions to ignore like below
97
105
  // myIgnore.push('myMethodNotInWorkflow');
98
106
 
99
- return super.getWorkflowFunctions(myIgnore);
107
+ return super.iapGetAdapterWorkflowFunctions(myIgnore);
100
108
  }
101
109
 
102
110
  /**
103
- * updateAdapterConfiguration is used to update any of the adapter configuration files. This
111
+ * iapUpdateAdapterConfiguration is used to update any of the adapter configuration files. This
104
112
  * allows customers to make changes to adapter configuration without having to be on the
105
113
  * file system.
106
114
  *
107
- * @function updateAdapterConfiguration
115
+ * @function iapUpdateAdapterConfiguration
108
116
  * @param {string} configFile - the name of the file being updated (required)
109
117
  * @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
110
118
  * @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
@@ -112,36 +120,42 @@ class Robustel extends AdapterBaseCl {
112
120
  * @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
113
121
  * @param {Callback} callback - The results of the call
114
122
  */
115
- updateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
116
- const origin = `${this.id}-adapter-updateAdapterConfiguration`;
123
+ iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
124
+ const meth = 'adapter-iapUpdateAdapterConfiguration';
125
+ const origin = `${this.id}-${meth}`;
117
126
  log.trace(origin);
118
- super.updateAdapterConfiguration(configFile, changes, entity, type, action, callback);
127
+
128
+ super.iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback);
119
129
  }
120
130
 
121
131
  /**
122
132
  * See if the API path provided is found in this adapter
123
133
  *
124
- * @function findPath
134
+ * @function iapFindAdapterPath
125
135
  * @param {string} apiPath - the api path to check on
126
136
  * @param {Callback} callback - The results of the call
127
137
  */
128
- findPath(apiPath, callback) {
129
- const origin = `${this.id}-adapter-findPath`;
138
+ iapFindAdapterPath(apiPath, callback) {
139
+ const meth = 'adapter-iapFindAdapterPath';
140
+ const origin = `${this.id}-${meth}`;
130
141
  log.trace(origin);
131
- super.findPath(apiPath, callback);
142
+
143
+ super.iapFindAdapterPath(apiPath, callback);
132
144
  }
133
145
 
134
146
  /**
135
147
  * @summary Suspends adapter
136
148
  *
137
- * @function suspend
149
+ * @function iapSuspendAdapter
138
150
  * @param {Callback} callback - callback function
139
151
  */
140
- suspend(mode, callback) {
141
- const origin = `${this.id}-adapter-suspend`;
152
+ iapSuspendAdapter(mode, callback) {
153
+ const meth = 'adapter-iapSuspendAdapter';
154
+ const origin = `${this.id}-${meth}`;
142
155
  log.trace(origin);
156
+
143
157
  try {
144
- return super.suspend(mode, callback);
158
+ return super.iapSuspendAdapter(mode, callback);
145
159
  } catch (error) {
146
160
  log.error(`${origin}: ${error}`);
147
161
  return callback(null, error);
@@ -151,14 +165,16 @@ class Robustel extends AdapterBaseCl {
151
165
  /**
152
166
  * @summary Unsuspends adapter
153
167
  *
154
- * @function unsuspend
168
+ * @function iapUnsuspendAdapter
155
169
  * @param {Callback} callback - callback function
156
170
  */
157
- unsuspend(callback) {
158
- const origin = `${this.id}-adapter-unsuspend`;
171
+ iapUnsuspendAdapter(callback) {
172
+ const meth = 'adapter-iapUnsuspendAdapter';
173
+ const origin = `${this.id}-${meth}`;
159
174
  log.trace(origin);
175
+
160
176
  try {
161
- return super.unsuspend(callback);
177
+ return super.iapUnsuspendAdapter(callback);
162
178
  } catch (error) {
163
179
  log.error(`${origin}: ${error}`);
164
180
  return callback(null, error);
@@ -168,29 +184,33 @@ class Robustel extends AdapterBaseCl {
168
184
  /**
169
185
  * @summary Get the Adaoter Queue
170
186
  *
171
- * @function getQueue
187
+ * @function iapGetAdapterQueue
172
188
  * @param {Callback} callback - callback function
173
189
  */
174
- getQueue(callback) {
175
- const origin = `${this.id}-adapter-getQueue`;
190
+ iapGetAdapterQueue(callback) {
191
+ const meth = 'adapter-iapGetAdapterQueue';
192
+ const origin = `${this.id}-${meth}`;
176
193
  log.trace(origin);
177
- return super.getQueue(callback);
194
+
195
+ return super.iapGetAdapterQueue(callback);
178
196
  }
179
197
 
180
198
  /**
181
199
  * @summary Runs troubleshoot scripts for adapter
182
200
  *
183
- * @function troubleshoot
201
+ * @function iapTroubleshootAdapter
184
202
  * @param {Object} props - the connection, healthcheck and authentication properties
185
203
  *
186
204
  * @param {boolean} persistFlag - whether the adapter properties should be updated
187
205
  * @param {Callback} callback - The results of the call
188
206
  */
189
- troubleshoot(props, persistFlag, callback) {
190
- const origin = `${this.id}-adapter-troubleshoot`;
207
+ iapTroubleshootAdapter(props, persistFlag, callback) {
208
+ const meth = 'adapter-iapTroubleshootAdapter';
209
+ const origin = `${this.id}-${meth}`;
191
210
  log.trace(origin);
211
+
192
212
  try {
193
- return super.troubleshoot(props, persistFlag, this, callback);
213
+ return super.iapTroubleshootAdapter(props, persistFlag, this, callback);
194
214
  } catch (error) {
195
215
  log.error(`${origin}: ${error}`);
196
216
  return callback(null, error);
@@ -200,15 +220,17 @@ class Robustel extends AdapterBaseCl {
200
220
  /**
201
221
  * @summary runs healthcheck script for adapter
202
222
  *
203
- * @function runHealthcheck
223
+ * @function iapRunAdapterHealthcheck
204
224
  * @param {Adapter} adapter - adapter instance to troubleshoot
205
225
  * @param {Callback} callback - callback function
206
226
  */
207
- runHealthcheck(callback) {
208
- const origin = `${this.id}-adapter-runHealthcheck`;
227
+ iapRunAdapterHealthcheck(callback) {
228
+ const meth = 'adapter-iapRunAdapterHealthcheck';
229
+ const origin = `${this.id}-${meth}`;
209
230
  log.trace(origin);
231
+
210
232
  try {
211
- return super.runHealthcheck(this, callback);
233
+ return super.iapRunAdapterHealthcheck(this, callback);
212
234
  } catch (error) {
213
235
  log.error(`${origin}: ${error}`);
214
236
  return callback(null, error);
@@ -218,14 +240,16 @@ class Robustel extends AdapterBaseCl {
218
240
  /**
219
241
  * @summary runs connectivity check script for adapter
220
242
  *
221
- * @function runConnectivity
243
+ * @function iapRunAdapterConnectivity
222
244
  * @param {Callback} callback - callback function
223
245
  */
224
- runConnectivity(callback) {
225
- const origin = `${this.id}-adapter-runConnectivity`;
246
+ iapRunAdapterConnectivity(callback) {
247
+ const meth = 'adapter-iapRunAdapterConnectivity';
248
+ const origin = `${this.id}-${meth}`;
226
249
  log.trace(origin);
250
+
227
251
  try {
228
- return super.runConnectivity(callback);
252
+ return super.iapRunAdapterConnectivity(callback);
229
253
  } catch (error) {
230
254
  log.error(`${origin}: ${error}`);
231
255
  return callback(null, error);
@@ -235,14 +259,16 @@ class Robustel extends AdapterBaseCl {
235
259
  /**
236
260
  * @summary runs basicGet script for adapter
237
261
  *
238
- * @function runBasicGet
262
+ * @function iapRunAdapterBasicGet
239
263
  * @param {Callback} callback - callback function
240
264
  */
241
- runBasicGet(callback) {
242
- const origin = `${this.id}-adapter-runBasicGet`;
265
+ iapRunAdapterBasicGet(callback) {
266
+ const meth = 'adapter-iapRunAdapterBasicGet';
267
+ const origin = `${this.id}-${meth}`;
243
268
  log.trace(origin);
269
+
244
270
  try {
245
- return super.runBasicGet(callback);
271
+ return super.iapRunAdapterBasicGet(callback);
246
272
  } catch (error) {
247
273
  log.error(`${origin}: ${error}`);
248
274
  return callback(null, error);
@@ -252,45 +278,48 @@ class Robustel extends AdapterBaseCl {
252
278
  /**
253
279
  * @summary moves entites into Mongo DB
254
280
  *
255
- * @function moveEntitiesToDB
281
+ * @function iapMoveAdapterEntitiesToDB
256
282
  * @param {getCallback} callback - a callback function to return the result (Generics)
257
283
  * or the error
258
284
  */
259
- moveEntitiesToDB(callback) {
260
- const origin = `${this.id}-adapter-moveEntitiesToDB`;
285
+ iapMoveAdapterEntitiesToDB(callback) {
286
+ const meth = 'adapter-iapMoveAdapterEntitiesToDB';
287
+ const origin = `${this.id}-${meth}`;
261
288
  log.trace(origin);
289
+
262
290
  try {
263
- return super.moveEntitiesToDB(callback);
291
+ return super.iapMoveAdapterEntitiesToDB(callback);
264
292
  } catch (err) {
265
293
  log.error(`${origin}: ${err}`);
266
294
  return callback(null, err);
267
295
  }
268
296
  }
269
297
 
298
+ /* BROKER CALLS */
270
299
  /**
271
300
  * @summary Determines if this adapter supports the specific entity
272
301
  *
273
- * @function hasEntity
302
+ * @function iapHasAdapterEntity
274
303
  * @param {String} entityType - the entity type to check for
275
304
  * @param {String/Array} entityId - the specific entity we are looking for
276
305
  *
277
306
  * @param {Callback} callback - An array of whether the adapter can has the
278
307
  * desired capability or an error
279
308
  */
280
- hasEntity(entityType, entityId, callback) {
281
- const origin = `${this.id}-adapter-hasEntity`;
309
+ iapHasAdapterEntity(entityType, entityId, callback) {
310
+ const origin = `${this.id}-adapter-iapHasAdapterEntity`;
282
311
  log.trace(origin);
283
312
 
284
313
  // Make the call -
285
- // verifyCapability(entityType, actionType, entityId, callback)
286
- return this.verifyCapability(entityType, null, entityId, callback);
314
+ // iapVerifyAdapterCapability(entityType, actionType, entityId, callback)
315
+ return this.iapVerifyAdapterCapability(entityType, null, entityId, callback);
287
316
  }
288
317
 
289
318
  /**
290
319
  * @summary Provides a way for the adapter to tell north bound integrations
291
320
  * whether the adapter supports type, action and specific entity
292
321
  *
293
- * @function verifyCapability
322
+ * @function iapVerifyAdapterCapability
294
323
  * @param {String} entityType - the entity type to check for
295
324
  * @param {String} actionType - the action type to check for
296
325
  * @param {String/Array} entityId - the specific entity we are looking for
@@ -298,15 +327,15 @@ class Robustel extends AdapterBaseCl {
298
327
  * @param {Callback} callback - An array of whether the adapter can has the
299
328
  * desired capability or an error
300
329
  */
301
- verifyCapability(entityType, actionType, entityId, callback) {
302
- const meth = 'adapterBase-verifyCapability';
330
+ iapVerifyAdapterCapability(entityType, actionType, entityId, callback) {
331
+ const meth = 'adapterBase-iapVerifyAdapterCapability';
303
332
  const origin = `${this.id}-${meth}`;
304
333
  log.trace(origin);
305
334
 
306
335
  // if caching
307
336
  if (this.caching) {
308
- // Make the call - verifyCapability(entityType, actionType, entityId, callback)
309
- return this.requestHandlerInst.verifyCapability(entityType, actionType, entityId, (results, error) => {
337
+ // Make the call - iapVerifyAdapterCapability(entityType, actionType, entityId, callback)
338
+ return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, entityId, (results, error) => {
310
339
  if (error) {
311
340
  return callback(null, error);
312
341
  }
@@ -324,7 +353,7 @@ class Robustel extends AdapterBaseCl {
324
353
  }
325
354
 
326
355
  // need to check the cache again since it has been updated
327
- return this.requestHandlerInst.verifyCapability(entityType, actionType, entityId, (vcapable, verror) => {
356
+ return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, entityId, (vcapable, verror) => {
328
357
  if (verror) {
329
358
  return callback(null, verror);
330
359
  }
@@ -357,7 +386,7 @@ class Robustel extends AdapterBaseCl {
357
386
  // if no entity id
358
387
  if (!entityId) {
359
388
  // need to check the cache again since it has been updated
360
- return this.requestHandlerInst.verifyCapability(entityType, actionType, null, (vcapable, verror) => {
389
+ return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, null, (vcapable, verror) => {
361
390
  if (verror) {
362
391
  return callback(null, verror);
363
392
  }
@@ -378,7 +407,7 @@ class Robustel extends AdapterBaseCl {
378
407
  }
379
408
 
380
409
  // need to check the cache again since it has been updated
381
- return this.requestHandlerInst.verifyCapability(entityType, actionType, null, (vcapable, verror) => {
410
+ return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, null, (vcapable, verror) => {
382
411
  if (verror) {
383
412
  return callback(null, verror);
384
413
  }
@@ -419,11 +448,11 @@ class Robustel extends AdapterBaseCl {
419
448
  /**
420
449
  * @summary Updates the cache for all entities by call the get All entity method
421
450
  *
422
- * @function updateEntityCache
451
+ * @function iapUpdateAdapterEntityCache
423
452
  *
424
453
  */
425
- updateEntityCache() {
426
- const origin = `${this.id}-adapter-updateEntityCache`;
454
+ iapUpdateAdapterEntityCache() {
455
+ const origin = `${this.id}-adapter-iapUpdateAdapterEntityCache`;
427
456
  log.trace(origin);
428
457
 
429
458
  if (this.caching) {
@@ -436,6 +465,140 @@ class Robustel extends AdapterBaseCl {
436
465
  }
437
466
  }
438
467
 
468
+ /**
469
+ * @summary Determines if this adapter supports any in a list of entities
470
+ *
471
+ * @function hasEntities
472
+ * @param {String} entityType - the entity type to check for
473
+ * @param {Array} entityList - the list of entities we are looking for
474
+ *
475
+ * @param {Callback} callback - A map where the entity is the key and the
476
+ * value is true or false
477
+ */
478
+ hasEntities(entityType, entityList, callback) {
479
+ const meth = 'adapter-hasEntities';
480
+ const origin = `${this.id}-${meth}`;
481
+ log.trace(origin);
482
+
483
+ try {
484
+ return super.hasEntities(entityType, entityList, callback);
485
+ } catch (err) {
486
+ log.error(`${origin}: ${err}`);
487
+ return callback(null, err);
488
+ }
489
+ }
490
+
491
+ /**
492
+ * @summary Get Appliance that match the deviceName
493
+ *
494
+ * @function getDevice
495
+ * @param {String} deviceName - the deviceName to find (required)
496
+ *
497
+ * @param {getCallback} callback - a callback function to return the result
498
+ * (appliance) or the error
499
+ */
500
+ getDevice(deviceName, callback) {
501
+ const meth = 'adapter-getDevice';
502
+ const origin = `${this.id}-${meth}`;
503
+ log.trace(origin);
504
+
505
+ try {
506
+ return super.getDevice(deviceName, callback);
507
+ } catch (err) {
508
+ log.error(`${origin}: ${err}`);
509
+ return callback(null, err);
510
+ }
511
+ }
512
+
513
+ /**
514
+ * @summary Get Appliances that match the filter
515
+ *
516
+ * @function getDevicesFiltered
517
+ * @param {Object} options - the data to use to filter the appliances (optional)
518
+ *
519
+ * @param {getCallback} callback - a callback function to return the result
520
+ * (appliances) or the error
521
+ */
522
+ getDevicesFiltered(options, callback) {
523
+ const meth = 'adapter-getDevicesFiltered';
524
+ const origin = `${this.id}-${meth}`;
525
+ log.trace(origin);
526
+
527
+ try {
528
+ return super.getDevicesFiltered(options, callback);
529
+ } catch (err) {
530
+ log.error(`${origin}: ${err}`);
531
+ return callback(null, err);
532
+ }
533
+ }
534
+
535
+ /**
536
+ * @summary Gets the status for the provided appliance
537
+ *
538
+ * @function isAlive
539
+ * @param {String} deviceName - the deviceName of the appliance. (required)
540
+ *
541
+ * @param {configCallback} callback - callback function to return the result
542
+ * (appliance isAlive) or the error
543
+ */
544
+ isAlive(deviceName, callback) {
545
+ const meth = 'adapter-isAlive';
546
+ const origin = `${this.id}-${meth}`;
547
+ log.trace(origin);
548
+
549
+ try {
550
+ return super.isAlive(deviceName, callback);
551
+ } catch (err) {
552
+ log.error(`${origin}: ${err}`);
553
+ return callback(null, err);
554
+ }
555
+ }
556
+
557
+ /**
558
+ * @summary Gets a config for the provided Appliance
559
+ *
560
+ * @function getConfig
561
+ * @param {String} deviceName - the deviceName of the appliance. (required)
562
+ * @param {String} format - the desired format of the config. (optional)
563
+ *
564
+ * @param {configCallback} callback - callback function to return the result
565
+ * (appliance config) or the error
566
+ */
567
+ getConfig(deviceName, format, callback) {
568
+ const meth = 'adapter-getConfig';
569
+ const origin = `${this.id}-${meth}`;
570
+ log.trace(origin);
571
+
572
+ try {
573
+ return super.getConfig(deviceName, format, callback);
574
+ } catch (err) {
575
+ log.error(`${origin}: ${err}`);
576
+ return callback(null, err);
577
+ }
578
+ }
579
+
580
+ /**
581
+ * @summary Gets the device count from the system
582
+ *
583
+ * @function iapGetDeviceCount
584
+ *
585
+ * @param {getCallback} callback - callback function to return the result
586
+ * (count) or the error
587
+ */
588
+ iapGetDeviceCount(callback) {
589
+ const meth = 'adapter-iapGetDeviceCount';
590
+ const origin = `${this.id}-${meth}`;
591
+ log.trace(origin);
592
+
593
+ try {
594
+ return super.iapGetDeviceCount(callback);
595
+ } catch (err) {
596
+ log.error(`${origin}: ${err}`);
597
+ return callback(null, err);
598
+ }
599
+ }
600
+
601
+ /* GENERIC ADAPTER REQUEST - allows extension of adapter without new calls being added */
439
602
  /**
440
603
  * Makes the requested generic call
441
604
  *
@@ -560,79 +723,23 @@ class Robustel extends AdapterBaseCl {
560
723
  }
561
724
  }
562
725
 
563
- /* BROKER CALLS */
564
- /**
565
- * @summary Determines if this adapter supports any in a list of entities
566
- *
567
- * @function hasEntities
568
- * @param {String} entityType - the entity type to check for
569
- * @param {Array} entityList - the list of entities we are looking for
570
- *
571
- * @param {Callback} callback - A map where the entity is the key and the
572
- * value is true or false
573
- */
574
- hasEntities(entityType, entityList, callback) {
575
- const origin = `${this.id}-adapter-hasEntities`;
576
- log.trace(origin);
577
-
578
- switch (entityType) {
579
- case 'Device':
580
- return this.hasDevices(entityList, callback);
581
- default:
582
- return callback(null, `${this.id} does not support entity ${entityType}`);
583
- }
584
- }
585
-
586
726
  /**
587
- * @summary Helper method for hasEntities for the specific device case
727
+ * Makes the requested generic call with no base path or version
588
728
  *
589
- * @param {Array} deviceList - array of unique device identifiers
590
- * @param {Callback} callback - A map where the device is the key and the
591
- * value is true or false
592
- */
593
- hasDevices(deviceList, callback) {
594
- const origin = `${this.id}-adapter-hasDevices`;
595
- log.trace(origin);
596
-
597
- const findings = deviceList.reduce((map, device) => {
598
- // eslint-disable-next-line no-param-reassign
599
- map[device] = false;
600
- log.debug(`In reduce: ${JSON.stringify(map)}`);
601
- return map;
602
- }, {});
603
- const apiCalls = deviceList.map((device) => new Promise((resolve) => {
604
- this.getDevice(device, (result, error) => {
605
- if (error) {
606
- log.debug(`In map error: ${JSON.stringify(device)}`);
607
- return resolve({ name: device, found: false });
608
- }
609
- log.debug(`In map: ${JSON.stringify(device)}`);
610
- return resolve({ name: device, found: true });
611
- });
612
- }));
613
- Promise.all(apiCalls).then((results) => {
614
- results.forEach((device) => {
615
- findings[device.name] = device.found;
616
- });
617
- log.debug(`FINDINGS: ${JSON.stringify(findings)}`);
618
- return callback(findings);
619
- }).catch((errors) => {
620
- log.error('Unable to do device lookup.');
621
- return callback(null, { code: 503, message: 'Unable to do device lookup.', error: errors });
622
- });
623
- }
624
-
625
- /**
626
- * @summary Get Appliance that match the deviceName
627
- *
628
- * @function getDevice
629
- * @param {String} deviceName - the deviceName to find (required)
630
- *
631
- * @param {getCallback} callback - a callback function to return the result
632
- * (appliance) or the error
729
+ * @function genericAdapterRequestNoBasePath
730
+ * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
731
+ * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
732
+ * @param {Object} queryData - the parameters to be put on the url (optional).
733
+ * Can be a stringified Object.
734
+ * @param {Object} requestBody - the body to add to the request (optional).
735
+ * Can be a stringified Object.
736
+ * @param {Object} addlHeaders - additional headers to be put on the call (optional).
737
+ * Can be a stringified Object.
738
+ * @param {getCallback} callback - a callback function to return the result (Generics)
739
+ * or the error
633
740
  */
634
- getDevice(deviceName, callback) {
635
- const meth = 'adapter-getDevice';
741
+ genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
742
+ const meth = 'adapter-genericAdapterRequestNoBasePath';
636
743
  const origin = `${this.id}-${meth}`;
637
744
  log.trace(origin);
638
745
 
@@ -643,365 +750,95 @@ class Robustel extends AdapterBaseCl {
643
750
  }
644
751
 
645
752
  /* HERE IS WHERE YOU VALIDATE DATA */
646
- if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
647
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
648
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
649
- return callback(null, errorObj);
650
- }
651
-
652
- try {
653
- // need to get the device so we can convert the deviceName to an id
654
- // !! if we can do a lookup by name the getDevicesFiltered may not be necessary
655
- const opts = {
656
- filter: {
657
- name: deviceName
658
- }
659
- };
660
- return this.getDevicesFiltered(opts, (devs, ferr) => {
661
- // if we received an error or their is no response on the results return an error
662
- if (ferr) {
663
- return callback(null, ferr);
664
- }
665
- if (devs.list.length < 1) {
666
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
667
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
668
- return callback(null, errorObj);
669
- }
670
- // get the uuid from the device
671
- const { uuid } = devs.list[0];
672
-
673
- // !! using Generic makes it easier on the Adapter Builder (just need to change the path)
674
- // !! you can also replace with a specific call if that is easier
675
- const uriPath = `/call/toget/device/${uuid}`;
676
- return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
677
- // if we received an error or their is no response on the results return an error
678
- if (error) {
679
- return callback(null, error);
680
- }
681
- if (!result.response || !result.response.applianceMo) {
682
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevice'], null, null, null);
683
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
684
- return callback(null, errorObj);
685
- }
686
-
687
- // return the response
688
- // !! format the data we send back
689
- // !! these fields are config manager fields you need to map to the data we receive
690
- const thisDevice = result.response;
691
- thisDevice.name = thisDevice.systemName;
692
- thisDevice.ostype = `System-${thisDevice.systemType}`;
693
- thisDevice.port = thisDevice.systemPort;
694
- thisDevice.ipaddress = thisDevice.systemIP;
695
- return callback(thisDevice);
696
- });
697
- });
698
- } catch (ex) {
699
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
753
+ if (uriPath === undefined || uriPath === null || uriPath === '') {
754
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['uriPath'], null, null, null);
700
755
  log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
701
756
  return callback(null, errorObj);
702
757
  }
703
- }
704
-
705
- /**
706
- * @summary Get Appliances that match the filter
707
- *
708
- * @function getDevicesFiltered
709
- * @param {Object} options - the data to use to filter the appliances (optional)
710
- *
711
- * @param {getCallback} callback - a callback function to return the result
712
- * (appliances) or the error
713
- */
714
- getDevicesFiltered(options, callback) {
715
- const meth = 'adapter-getDevicesFiltered';
716
- const origin = `${this.id}-${meth}`;
717
- log.trace(origin);
718
-
719
- // verify the required fields have been provided
720
- if (options === undefined || options === null || options === '' || options.length === 0) {
721
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['options'], null, null, null);
758
+ if (restMethod === undefined || restMethod === null || restMethod === '') {
759
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['restMethod'], null, null, null);
722
760
  log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
723
761
  return callback(null, errorObj);
724
762
  }
725
- log.debug(`Device Filter Options: ${JSON.stringify(options)}`);
726
-
727
- // TODO - get pagination working
728
- // const nextToken = options.start;
729
- // const maxResults = options.limit;
730
-
731
- // set up the filter of Device Names
732
- let filterName = [];
733
- if (options && options.filter && options.filter.name) {
734
- // when this hack is removed, remove the lint ignore above
735
- if (Array.isArray(options.filter.name)) {
736
- // eslint-disable-next-line prefer-destructuring
737
- filterName = options.filter.name;
738
- } else {
739
- filterName = [options.filter.name];
740
- }
741
- }
742
763
 
743
- // TODO - get sort and order working
744
- /*
745
- if (options && options.sort) {
746
- reqObj.uriOptions.sort = JSON.stringify(options.sort);
747
- }
748
- if (options && options.order) {
749
- reqObj.uriOptions.order = options.order;
764
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
765
+ // remove any leading / and split the uripath into path variables
766
+ let myPath = uriPath;
767
+ while (myPath.indexOf('/') === 0) {
768
+ myPath = myPath.substring(1);
750
769
  }
751
- */
752
- try {
753
- // !! using Generic makes it easier on the Adapter Builder (just need to change the path)
754
- // !! you can also replace with a specific call if that is easier
755
- const uriPath = '/call/toget/devices';
756
- return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
757
- // if we received an error or their is no response on the results return an error
758
- if (error) {
759
- return callback(null, error);
760
- }
761
- if (!result.response) {
762
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevicesFiltered'], null, null, null);
763
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
764
- return callback(null, errorObj);
765
- }
770
+ const pathVars = myPath.split('/');
771
+ const queryParamsAvailable = queryData;
772
+ const queryParams = {};
773
+ const bodyVars = requestBody;
766
774
 
767
- // !! go through the response - may have to look for sub object
768
- // handle an array of devices
769
- if (Array.isArray(result.response)) {
770
- const myDevices = [];
771
-
772
- for (let d = 0; d < result.response.length; d += 1) {
773
- // !! format the data we send back
774
- // !! these fields are config manager fields you need to map to the data we receive
775
- const thisDevice = result.response;
776
- thisDevice.name = thisDevice.systemName;
777
- thisDevice.ostype = `System-${thisDevice.systemType}`;
778
- thisDevice.port = thisDevice.systemPort;
779
- thisDevice.ipaddress = thisDevice.systemIP;
780
-
781
- // if there is no filter - return the device
782
- if (filterName.length === 0) {
783
- myDevices.push(thisDevice);
784
- } else {
785
- // if we have to match a filter
786
- let found = false;
787
- for (let f = 0; f < filterName.length; f += 1) {
788
- if (thisDevice.name.indexOf(filterName[f]) >= 0) {
789
- found = true;
790
- break;
791
- }
792
- }
793
- // matching device
794
- if (found) {
795
- myDevices.push(thisDevice);
796
- }
797
- }
798
- }
799
- log.debug(`${origin}: Found #${myDevices.length} devices.`);
800
- log.debug(`Devices: ${JSON.stringify(myDevices)}`);
801
- return callback({ total: myDevices.length, list: myDevices });
802
- }
803
- // handle a single device response
804
- // !! format the data we send back
805
- // !! these fields are config manager fields you need to map to the data we receive
806
- const thisDevice = result.response;
807
- thisDevice.name = thisDevice.systemName;
808
- thisDevice.ostype = `System-${thisDevice.systemType}`;
809
- thisDevice.port = thisDevice.systemPort;
810
- thisDevice.ipaddress = thisDevice.systemIP;
811
-
812
- // if there is no filter - return the device
813
- if (filterName.length === 0) {
814
- log.debug(`${origin}: Found #1 device.`);
815
- log.debug(`Device: ${JSON.stringify(thisDevice)}`);
816
- return callback({ total: 1, list: [thisDevice] });
817
- }
775
+ // loop in template. long callback arg name to avoid identifier conflicts
776
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
777
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
778
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
779
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
780
+ }
781
+ });
818
782
 
819
- // if there is a filter need to check for matching device
820
- let found = false;
821
- for (let f = 0; f < filterName.length; f += 1) {
822
- if (thisDevice.name.indexOf(filterName[f]) >= 0) {
823
- found = true;
824
- break;
825
- }
826
- }
827
- // matching device
828
- if (found) {
829
- log.debug(`${origin}: Found #1 device.`);
830
- log.debug(`Device Found: ${JSON.stringify(thisDevice)}`);
831
- return callback({ total: 1, list: [thisDevice] });
832
- }
833
- // not a matching device
834
- log.debug(`${origin}: No matching device found.`);
835
- return callback({ total: 0, list: [] });
836
- });
837
- } catch (ex) {
838
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
839
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
840
- return callback(null, errorObj);
783
+ let usePath = uriPath;
784
+ if (queryParams && Object.keys(queryParams).length > 0) {
785
+ usePath = `${uriPath}?${querystring(queryData)}`;
841
786
  }
842
- }
843
-
844
- /**
845
- * @summary Gets the status for the provided appliance
846
- *
847
- * @function isAlive
848
- * @param {String} deviceName - the deviceName of the appliance. (required)
849
- *
850
- * @param {configCallback} callback - callback function to return the result
851
- * (appliance isAlive) or the error
852
- */
853
- isAlive(deviceName, callback) {
854
- const meth = 'adapter-isAlive';
855
- const origin = `${this.id}-${meth}`;
856
- log.trace(origin);
787
+ const callSign = this.getAuthorization(restMethod, usePath, bodyVars);
857
788
 
858
- // verify the required fields have been provided
859
- if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
860
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
789
+ // if the callAuth was unsuccessful
790
+ if (callSign === -1) {
791
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['call signature'], null, null, null);
861
792
  log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
862
793
  return callback(null, errorObj);
863
794
  }
864
795
 
865
- try {
866
- // need to get the device so we can convert the deviceName to an id
867
- // !! if we can do a lookup by name the getDevicesFiltered may not be necessary
868
- const opts = {
869
- filter: {
870
- name: deviceName
871
- }
872
- };
873
- return this.getDevicesFiltered(opts, (devs, ferr) => {
874
- // if we received an error or their is no response on the results return an error
875
- if (ferr) {
876
- return callback(null, ferr);
877
- }
878
- if (devs.list.length < 1) {
879
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
880
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
881
- return callback(null, errorObj);
882
- }
883
- // get the uuid from the device
884
- const { uuid } = devs.list[0];
885
-
886
- // !! using Generic makes it easier on the Adapter Builder (just need to change the path)
887
- // !! you can also replace with a specific call if that is easier
888
- const uriPath = `/call/toget/status/${uuid}`;
889
- return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
890
- // if we received an error or their is no response on the results return an error
891
- if (error) {
892
- return callback(null, error);
893
- }
894
- // !! should update this to make sure we are checking for the appropriate object/field
895
- if (!result.response || !result.response.returnObj || !Object.hasOwnProperty.call(result.response.returnObj, 'statusField')) {
896
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['isAlive'], null, null, null);
897
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
898
- return callback(null, errorObj);
899
- }
900
-
901
- // !! return the response - Update to the appropriate object/field
902
- return callback(!result.response.returnObj.statusField);
903
- });
904
- });
905
- } catch (ex) {
906
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
907
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
908
- return callback(null, errorObj);
796
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
797
+ const reqObj = {
798
+ payload: bodyVars,
799
+ uriPathVars: pathVars,
800
+ uriQuery: queryParams,
801
+ uriOptions: {},
802
+ addlHeaders: callSign
803
+ };
804
+ // add headers if provided
805
+ if (addlHeaders) {
806
+ reqObj.addlHeaders = addlHeaders;
909
807
  }
910
- }
911
-
912
- /**
913
- * @summary Gets a config for the provided Appliance
914
- *
915
- * @function getConfig
916
- * @param {String} deviceName - the deviceName of the appliance. (required)
917
- * @param {String} format - the desired format of the config. (optional)
918
- *
919
- * @param {configCallback} callback - callback function to return the result
920
- * (appliance config) or the error
921
- */
922
- getConfig(deviceName, format, callback) {
923
- const meth = 'adapter-getConfig';
924
- const origin = `${this.id}-${meth}`;
925
- log.trace(origin);
926
808
 
927
- // verify the required fields have been provided
928
- if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
929
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
930
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
931
- return callback(null, errorObj);
809
+ // determine the call and return flag
810
+ let action = 'getGenericsNoBase';
811
+ let returnF = true;
812
+ if (restMethod.toUpperCase() === 'POST') {
813
+ action = 'createGenericNoBase';
814
+ } else if (restMethod.toUpperCase() === 'PUT') {
815
+ action = 'updateGenericNoBase';
816
+ } else if (restMethod.toUpperCase() === 'PATCH') {
817
+ action = 'patchGenericNoBase';
818
+ } else if (restMethod.toUpperCase() === 'DELETE') {
819
+ action = 'deleteGenericNoBase';
820
+ returnF = false;
932
821
  }
933
822
 
934
823
  try {
935
- // need to get the device so we can convert the deviceName to an id
936
- // !! if we can do a lookup by name the getDevicesFiltered may not be necessary
937
- const opts = {
938
- filter: {
939
- name: deviceName
940
- }
941
- };
942
- return this.getDevicesFiltered(opts, (devs, ferr) => {
943
- // if we received an error or their is no response on the results return an error
944
- if (ferr) {
945
- return callback(null, ferr);
824
+ // Make the call -
825
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
826
+ return this.requestHandlerInst.identifyRequest('.generic', action, reqObj, returnF, (irReturnData, irReturnError) => {
827
+ // if we received an error or their is no response on the results
828
+ // return an error
829
+ if (irReturnError) {
830
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
831
+ return callback(null, irReturnError);
946
832
  }
947
- if (devs.list.length < 1) {
948
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
833
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
834
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['genericAdapterRequestNoBasePath'], null, null, null);
949
835
  log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
950
836
  return callback(null, errorObj);
951
837
  }
952
- // get the uuid from the device
953
- const { uuid } = devs.list[0];
954
-
955
- // !! using Generic makes it easier on the Adapter Builder (just need to change the path)
956
- // !! you can also replace with a specific call if that is easier
957
- const uriPath = `/call/toget/config/${uuid}`;
958
- return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
959
- // if we received an error or their is no response on the results return an error
960
- if (error) {
961
- return callback(null, error);
962
- }
963
-
964
- // return the result
965
- const newResponse = {
966
- response: JSON.stringify(result.response, null, 2)
967
- };
968
- return callback(newResponse);
969
- });
970
- });
971
- } catch (ex) {
972
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
973
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
974
- return callback(null, errorObj);
975
- }
976
- }
977
-
978
- /**
979
- * @summary Gets the device count from the system
980
- *
981
- * @function getCount
982
- *
983
- * @param {getCallback} callback - callback function to return the result
984
- * (count) or the error
985
- */
986
- getCount(callback) {
987
- const meth = 'adapter-getCount';
988
- const origin = `${this.id}-${meth}`;
989
- log.trace(origin);
990
-
991
- // verify the required fields have been provided
992
-
993
- try {
994
- // !! using Generic makes it easier on the Adapter Builder (just need to change the path)
995
- // !! you can also replace with a specific call if that is easier
996
- const uriPath = '/call/toget/count';
997
- return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
998
- // if we received an error or their is no response on the results return an error
999
- if (error) {
1000
- return callback(null, error);
1001
- }
1002
838
 
1003
- // return the result
1004
- return callback({ count: result.response });
839
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
840
+ // return the response
841
+ return callback(irReturnData, null);
1005
842
  });
1006
843
  } catch (ex) {
1007
844
  const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);