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