@itentialopensource/adapter-meraki 0.7.3 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AUTH.md +40 -0
- package/CALLS.md +100 -0
- package/CHANGELOG.md +24 -0
- package/ENHANCE.md +69 -0
- package/PROPERTIES.md +247 -0
- package/README.md +113 -470
- package/SUMMARY.md +9 -0
- package/SYSTEMINFO.md +11 -0
- package/TROUBLESHOOT.md +46 -0
- package/adapter.js +566 -59
- package/adapterBase.js +571 -278
- package/entities/.generic/action.json +5 -5
- package/error.json +12 -0
- package/package.json +18 -13
- package/pronghorn.json +273 -88
- package/propertiesDecorators.json +14 -0
- package/propertiesSchema.json +382 -0
- package/refs?service=git-upload-pack +0 -0
- package/report/updateReport1642739939352.json +95 -0
- package/report/updateReport1651511176919.json +115 -0
- package/sampleProperties.json +4 -1
- package/test/integration/adapterTestIntegration.js +10 -1
- package/test/unit/adapterBaseTestUnit.js +26 -25
- package/test/unit/adapterTestUnit.js +631 -10
- package/utils/addAuth.js +94 -0
- package/utils/basicGet.js +1 -14
- package/utils/entitiesToDB.js +224 -0
- package/utils/modify.js +1 -1
- package/utils/patches2bundledDeps.js +90 -0
- package/utils/removeHooks.js +20 -0
- package/utils/tbScript.js +14 -8
- package/utils/tbUtils.js +111 -19
- package/utils/troubleshootingAdapter.js +2 -26
package/adapter.js
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
/* eslint import/no-dynamic-require: warn */
|
4
4
|
/* eslint object-curly-newline: warn */
|
5
|
-
/* eslint no-underscore-dangle: warn */
|
6
|
-
/* eslint camelcase: warn */
|
7
5
|
|
8
6
|
// Set globals
|
9
7
|
/* global log */
|
@@ -82,10 +80,10 @@ class Meraki extends AdapterBaseCl {
|
|
82
80
|
}
|
83
81
|
|
84
82
|
/**
|
85
|
-
* @
|
83
|
+
* @iapGetAdapterWorkflowFunctions
|
86
84
|
*/
|
87
|
-
|
88
|
-
let myIgnore = [];
|
85
|
+
iapGetAdapterWorkflowFunctions(inIgnore) {
|
86
|
+
let myIgnore = ['hasEntities', 'hasDevices'];
|
89
87
|
if (!inIgnore && Array.isArray(inIgnore)) {
|
90
88
|
myIgnore = inIgnore;
|
91
89
|
} else if (!inIgnore && typeof inIgnore === 'string') {
|
@@ -96,15 +94,15 @@ class Meraki extends AdapterBaseCl {
|
|
96
94
|
// you can add specific methods that you do not want to be workflow functions to ignore like below
|
97
95
|
// myIgnore.push('myMethodNotInWorkflow');
|
98
96
|
|
99
|
-
return super.
|
97
|
+
return super.iapGetAdapterWorkflowFunctions(myIgnore);
|
100
98
|
}
|
101
99
|
|
102
100
|
/**
|
103
|
-
*
|
101
|
+
* iapUpdateAdapterConfiguration is used to update any of the adapter configuration files. This
|
104
102
|
* allows customers to make changes to adapter configuration without having to be on the
|
105
103
|
* file system.
|
106
104
|
*
|
107
|
-
* @function
|
105
|
+
* @function iapUpdateAdapterConfiguration
|
108
106
|
* @param {string} configFile - the name of the file being updated (required)
|
109
107
|
* @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
|
110
108
|
* @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
|
@@ -112,36 +110,36 @@ class Meraki extends AdapterBaseCl {
|
|
112
110
|
* @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
|
113
111
|
* @param {Callback} callback - The results of the call
|
114
112
|
*/
|
115
|
-
|
116
|
-
const origin = `${this.id}-adapter-
|
113
|
+
iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
|
114
|
+
const origin = `${this.id}-adapter-iapUpdateAdapterConfiguration`;
|
117
115
|
log.trace(origin);
|
118
|
-
super.
|
116
|
+
super.iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback);
|
119
117
|
}
|
120
118
|
|
121
119
|
/**
|
122
120
|
* See if the API path provided is found in this adapter
|
123
121
|
*
|
124
|
-
* @function
|
122
|
+
* @function iapFindAdapterPath
|
125
123
|
* @param {string} apiPath - the api path to check on
|
126
124
|
* @param {Callback} callback - The results of the call
|
127
125
|
*/
|
128
|
-
|
129
|
-
const origin = `${this.id}-adapter-
|
126
|
+
iapFindAdapterPath(apiPath, callback) {
|
127
|
+
const origin = `${this.id}-adapter-iapFindAdapterPath`;
|
130
128
|
log.trace(origin);
|
131
|
-
super.
|
129
|
+
super.iapFindAdapterPath(apiPath, callback);
|
132
130
|
}
|
133
131
|
|
134
132
|
/**
|
135
133
|
* @summary Suspends adapter
|
136
134
|
*
|
137
|
-
* @function
|
135
|
+
* @function iapSuspendAdapter
|
138
136
|
* @param {Callback} callback - callback function
|
139
137
|
*/
|
140
|
-
|
141
|
-
const origin = `${this.id}-adapter-
|
138
|
+
iapSuspendAdapter(mode, callback) {
|
139
|
+
const origin = `${this.id}-adapter-iapSuspendAdapter`;
|
142
140
|
log.trace(origin);
|
143
141
|
try {
|
144
|
-
return super.
|
142
|
+
return super.iapSuspendAdapter(mode, callback);
|
145
143
|
} catch (error) {
|
146
144
|
log.error(`${origin}: ${error}`);
|
147
145
|
return callback(null, error);
|
@@ -151,14 +149,14 @@ class Meraki extends AdapterBaseCl {
|
|
151
149
|
/**
|
152
150
|
* @summary Unsuspends adapter
|
153
151
|
*
|
154
|
-
* @function
|
152
|
+
* @function iapUnsuspendAdapter
|
155
153
|
* @param {Callback} callback - callback function
|
156
154
|
*/
|
157
|
-
|
158
|
-
const origin = `${this.id}-adapter-
|
155
|
+
iapUnsuspendAdapter(callback) {
|
156
|
+
const origin = `${this.id}-adapter-iapUnsuspendAdapter`;
|
159
157
|
log.trace(origin);
|
160
158
|
try {
|
161
|
-
return super.
|
159
|
+
return super.iapUnsuspendAdapter(callback);
|
162
160
|
} catch (error) {
|
163
161
|
log.error(`${origin}: ${error}`);
|
164
162
|
return callback(null, error);
|
@@ -168,29 +166,29 @@ class Meraki extends AdapterBaseCl {
|
|
168
166
|
/**
|
169
167
|
* @summary Get the Adaoter Queue
|
170
168
|
*
|
171
|
-
* @function
|
169
|
+
* @function iapGetAdapterQueue
|
172
170
|
* @param {Callback} callback - callback function
|
173
171
|
*/
|
174
|
-
|
175
|
-
const origin = `${this.id}-adapter-
|
172
|
+
iapGetAdapterQueue(callback) {
|
173
|
+
const origin = `${this.id}-adapter-iapGetAdapterQueue`;
|
176
174
|
log.trace(origin);
|
177
|
-
return super.
|
175
|
+
return super.iapGetAdapterQueue(callback);
|
178
176
|
}
|
179
177
|
|
180
178
|
/**
|
181
179
|
* @summary Runs troubleshoot scripts for adapter
|
182
180
|
*
|
183
|
-
* @function
|
181
|
+
* @function iapTroubleshootAdapter
|
184
182
|
* @param {Object} props - the connection, healthcheck and authentication properties
|
185
183
|
*
|
186
184
|
* @param {boolean} persistFlag - whether the adapter properties should be updated
|
187
185
|
* @param {Callback} callback - The results of the call
|
188
186
|
*/
|
189
|
-
|
190
|
-
const origin = `${this.id}-adapter-
|
187
|
+
iapTroubleshootAdapter(props, persistFlag, callback) {
|
188
|
+
const origin = `${this.id}-adapter-iapTroubleshootAdapter`;
|
191
189
|
log.trace(origin);
|
192
190
|
try {
|
193
|
-
return super.
|
191
|
+
return super.iapTroubleshootAdapter(props, persistFlag, this, callback);
|
194
192
|
} catch (error) {
|
195
193
|
log.error(`${origin}: ${error}`);
|
196
194
|
return callback(null, error);
|
@@ -200,15 +198,15 @@ class Meraki extends AdapterBaseCl {
|
|
200
198
|
/**
|
201
199
|
* @summary runs healthcheck script for adapter
|
202
200
|
*
|
203
|
-
* @function
|
201
|
+
* @function iapRunAdapterHealthcheck
|
204
202
|
* @param {Adapter} adapter - adapter instance to troubleshoot
|
205
203
|
* @param {Callback} callback - callback function
|
206
204
|
*/
|
207
|
-
|
208
|
-
const origin = `${this.id}-adapter-
|
205
|
+
iapRunAdapterHealthcheck(callback) {
|
206
|
+
const origin = `${this.id}-adapter-iapRunAdapterHealthcheck`;
|
209
207
|
log.trace(origin);
|
210
208
|
try {
|
211
|
-
return super.
|
209
|
+
return super.iapRunAdapterHealthcheck(this, callback);
|
212
210
|
} catch (error) {
|
213
211
|
log.error(`${origin}: ${error}`);
|
214
212
|
return callback(null, error);
|
@@ -218,14 +216,14 @@ class Meraki extends AdapterBaseCl {
|
|
218
216
|
/**
|
219
217
|
* @summary runs connectivity check script for adapter
|
220
218
|
*
|
221
|
-
* @function
|
219
|
+
* @function iapRunAdapterConnectivity
|
222
220
|
* @param {Callback} callback - callback function
|
223
221
|
*/
|
224
|
-
|
225
|
-
const origin = `${this.id}-adapter-
|
222
|
+
iapRunAdapterConnectivity(callback) {
|
223
|
+
const origin = `${this.id}-adapter-iapRunAdapterConnectivity`;
|
226
224
|
log.trace(origin);
|
227
225
|
try {
|
228
|
-
return super.
|
226
|
+
return super.iapRunAdapterConnectivity(callback);
|
229
227
|
} catch (error) {
|
230
228
|
log.error(`${origin}: ${error}`);
|
231
229
|
return callback(null, error);
|
@@ -235,44 +233,63 @@ class Meraki extends AdapterBaseCl {
|
|
235
233
|
/**
|
236
234
|
* @summary runs basicGet script for adapter
|
237
235
|
*
|
238
|
-
* @function
|
236
|
+
* @function iapRunAdapterBasicGet
|
239
237
|
* @param {Callback} callback - callback function
|
240
238
|
*/
|
241
|
-
|
242
|
-
const origin = `${this.id}-adapter-
|
239
|
+
iapRunAdapterBasicGet(callback) {
|
240
|
+
const origin = `${this.id}-adapter-iapRunAdapterBasicGet`;
|
243
241
|
log.trace(origin);
|
244
242
|
try {
|
245
|
-
return super.
|
243
|
+
return super.iapRunAdapterBasicGet(callback);
|
246
244
|
} catch (error) {
|
247
245
|
log.error(`${origin}: ${error}`);
|
248
246
|
return callback(null, error);
|
249
247
|
}
|
250
248
|
}
|
251
249
|
|
250
|
+
/**
|
251
|
+
* @summary moves entites into Mongo DB
|
252
|
+
*
|
253
|
+
* @function iapMoveAdapterEntitiesToDB
|
254
|
+
* @param {getCallback} callback - a callback function to return the result (Generics)
|
255
|
+
* or the error
|
256
|
+
*/
|
257
|
+
iapMoveAdapterEntitiesToDB(callback) {
|
258
|
+
const origin = `${this.id}-adapter-iapMoveAdapterEntitiesToDB`;
|
259
|
+
log.trace(origin);
|
260
|
+
try {
|
261
|
+
return super.iapMoveAdapterEntitiesToDB(callback);
|
262
|
+
} catch (err) {
|
263
|
+
log.error(`${origin}: ${err}`);
|
264
|
+
return callback(null, err);
|
265
|
+
}
|
266
|
+
}
|
267
|
+
|
268
|
+
/* BROKER CALLS */
|
252
269
|
/**
|
253
270
|
* @summary Determines if this adapter supports the specific entity
|
254
271
|
*
|
255
|
-
* @function
|
272
|
+
* @function iapHasAdapterEntity
|
256
273
|
* @param {String} entityType - the entity type to check for
|
257
274
|
* @param {String/Array} entityId - the specific entity we are looking for
|
258
275
|
*
|
259
276
|
* @param {Callback} callback - An array of whether the adapter can has the
|
260
277
|
* desired capability or an error
|
261
278
|
*/
|
262
|
-
|
263
|
-
const origin = `${this.id}-adapter-
|
279
|
+
iapHasAdapterEntity(entityType, entityId, callback) {
|
280
|
+
const origin = `${this.id}-adapter-iapHasAdapterEntity`;
|
264
281
|
log.trace(origin);
|
265
282
|
|
266
283
|
// Make the call -
|
267
|
-
//
|
268
|
-
return this.
|
284
|
+
// iapVerifyAdapterCapability(entityType, actionType, entityId, callback)
|
285
|
+
return this.iapVerifyAdapterCapability(entityType, null, entityId, callback);
|
269
286
|
}
|
270
287
|
|
271
288
|
/**
|
272
289
|
* @summary Provides a way for the adapter to tell north bound integrations
|
273
290
|
* whether the adapter supports type, action and specific entity
|
274
291
|
*
|
275
|
-
* @function
|
292
|
+
* @function iapVerifyAdapterCapability
|
276
293
|
* @param {String} entityType - the entity type to check for
|
277
294
|
* @param {String} actionType - the action type to check for
|
278
295
|
* @param {String/Array} entityId - the specific entity we are looking for
|
@@ -280,15 +297,15 @@ class Meraki extends AdapterBaseCl {
|
|
280
297
|
* @param {Callback} callback - An array of whether the adapter can has the
|
281
298
|
* desired capability or an error
|
282
299
|
*/
|
283
|
-
|
284
|
-
const meth = 'adapterBase-
|
300
|
+
iapVerifyAdapterCapability(entityType, actionType, entityId, callback) {
|
301
|
+
const meth = 'adapterBase-iapVerifyAdapterCapability';
|
285
302
|
const origin = `${this.id}-${meth}`;
|
286
303
|
log.trace(origin);
|
287
304
|
|
288
305
|
// if caching
|
289
306
|
if (this.caching) {
|
290
|
-
// Make the call -
|
291
|
-
return this.requestHandlerInst.
|
307
|
+
// Make the call - iapVerifyAdapterCapability(entityType, actionType, entityId, callback)
|
308
|
+
return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, entityId, (results, error) => {
|
292
309
|
if (error) {
|
293
310
|
return callback(null, error);
|
294
311
|
}
|
@@ -306,7 +323,7 @@ class Meraki extends AdapterBaseCl {
|
|
306
323
|
}
|
307
324
|
|
308
325
|
// need to check the cache again since it has been updated
|
309
|
-
return this.requestHandlerInst.
|
326
|
+
return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, entityId, (vcapable, verror) => {
|
310
327
|
if (verror) {
|
311
328
|
return callback(null, verror);
|
312
329
|
}
|
@@ -339,7 +356,7 @@ class Meraki extends AdapterBaseCl {
|
|
339
356
|
// if no entity id
|
340
357
|
if (!entityId) {
|
341
358
|
// need to check the cache again since it has been updated
|
342
|
-
return this.requestHandlerInst.
|
359
|
+
return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, null, (vcapable, verror) => {
|
343
360
|
if (verror) {
|
344
361
|
return callback(null, verror);
|
345
362
|
}
|
@@ -360,7 +377,7 @@ class Meraki extends AdapterBaseCl {
|
|
360
377
|
}
|
361
378
|
|
362
379
|
// need to check the cache again since it has been updated
|
363
|
-
return this.requestHandlerInst.
|
380
|
+
return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, null, (vcapable, verror) => {
|
364
381
|
if (verror) {
|
365
382
|
return callback(null, verror);
|
366
383
|
}
|
@@ -401,11 +418,11 @@ class Meraki extends AdapterBaseCl {
|
|
401
418
|
/**
|
402
419
|
* @summary Updates the cache for all entities by call the get All entity method
|
403
420
|
*
|
404
|
-
* @function
|
421
|
+
* @function iapUpdateAdapterEntityCache
|
405
422
|
*
|
406
423
|
*/
|
407
|
-
|
408
|
-
const origin = `${this.id}-adapter-
|
424
|
+
iapUpdateAdapterEntityCache() {
|
425
|
+
const origin = `${this.id}-adapter-iapUpdateAdapterEntityCache`;
|
409
426
|
log.trace(origin);
|
410
427
|
|
411
428
|
if (this.caching) {
|
@@ -418,6 +435,496 @@ class Meraki extends AdapterBaseCl {
|
|
418
435
|
}
|
419
436
|
}
|
420
437
|
|
438
|
+
/**
|
439
|
+
* @summary Determines if this adapter supports any in a list of entities
|
440
|
+
*
|
441
|
+
* @function hasEntities
|
442
|
+
* @param {String} entityType - the entity type to check for
|
443
|
+
* @param {Array} entityList - the list of entities we are looking for
|
444
|
+
*
|
445
|
+
* @param {Callback} callback - A map where the entity is the key and the
|
446
|
+
* value is true or false
|
447
|
+
*/
|
448
|
+
hasEntities(entityType, entityList, callback) {
|
449
|
+
const origin = `${this.id}-adapter-hasEntities`;
|
450
|
+
log.trace(origin);
|
451
|
+
|
452
|
+
switch (entityType) {
|
453
|
+
case 'Device':
|
454
|
+
return this.hasDevices(entityList, callback);
|
455
|
+
default:
|
456
|
+
return callback(null, `${this.id} does not support entity ${entityType}`);
|
457
|
+
}
|
458
|
+
}
|
459
|
+
|
460
|
+
/**
|
461
|
+
* @summary Helper method for hasEntities for the specific device case
|
462
|
+
*
|
463
|
+
* @param {Array} deviceList - array of unique device identifiers
|
464
|
+
* @param {Callback} callback - A map where the device is the key and the
|
465
|
+
* value is true or false
|
466
|
+
*/
|
467
|
+
hasDevices(deviceList, callback) {
|
468
|
+
const origin = `${this.id}-adapter-hasDevices`;
|
469
|
+
log.trace(origin);
|
470
|
+
|
471
|
+
const findings = deviceList.reduce((map, device) => {
|
472
|
+
// eslint-disable-next-line no-param-reassign
|
473
|
+
map[device] = false;
|
474
|
+
log.debug(`In reduce: ${JSON.stringify(map)}`);
|
475
|
+
return map;
|
476
|
+
}, {});
|
477
|
+
const apiCalls = deviceList.map((device) => new Promise((resolve) => {
|
478
|
+
this.getDevice(device, (result, error) => {
|
479
|
+
if (error) {
|
480
|
+
log.debug(`In map error: ${JSON.stringify(device)}`);
|
481
|
+
return resolve({ name: device, found: false });
|
482
|
+
}
|
483
|
+
log.debug(`In map: ${JSON.stringify(device)}`);
|
484
|
+
return resolve({ name: device, found: true });
|
485
|
+
});
|
486
|
+
}));
|
487
|
+
Promise.all(apiCalls).then((results) => {
|
488
|
+
results.forEach((device) => {
|
489
|
+
findings[device.name] = device.found;
|
490
|
+
});
|
491
|
+
log.debug(`FINDINGS: ${JSON.stringify(findings)}`);
|
492
|
+
return callback(findings);
|
493
|
+
}).catch((errors) => {
|
494
|
+
log.error('Unable to do device lookup.');
|
495
|
+
return callback(null, { code: 503, message: 'Unable to do device lookup.', error: errors });
|
496
|
+
});
|
497
|
+
}
|
498
|
+
|
499
|
+
/**
|
500
|
+
* @summary Get Appliance that match the deviceName
|
501
|
+
*
|
502
|
+
* @function getDevice
|
503
|
+
* @param {String} deviceName - the deviceName to find (required)
|
504
|
+
*
|
505
|
+
* @param {getCallback} callback - a callback function to return the result
|
506
|
+
* (appliance) or the error
|
507
|
+
*/
|
508
|
+
getDevice(deviceName, callback) {
|
509
|
+
const meth = 'adapter-getDevice';
|
510
|
+
const origin = `${this.id}-${meth}`;
|
511
|
+
log.trace(origin);
|
512
|
+
|
513
|
+
// make sure we are set up for device broker getDevice
|
514
|
+
if (!this.allProps.devicebroker || !this.allProps.devicebroker.getDevice || this.allProps.devicebroker.getDevice.length === 0 || !this.allProps.devicebroker.getDevice[0].path) {
|
515
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getDevice.path'], null, null, null);
|
516
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
517
|
+
return callback(null, errorObj);
|
518
|
+
}
|
519
|
+
|
520
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
521
|
+
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
522
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
523
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
524
|
+
return callback(null, errorObj);
|
525
|
+
}
|
526
|
+
|
527
|
+
try {
|
528
|
+
// need to get the device so we can convert the deviceName to an id
|
529
|
+
// !! if we can do a lookup by name the getDevicesFiltered may not be necessary
|
530
|
+
const opts = {
|
531
|
+
filter: {
|
532
|
+
name: deviceName
|
533
|
+
}
|
534
|
+
};
|
535
|
+
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
536
|
+
// if we received an error or their is no response on the results return an error
|
537
|
+
if (ferr) {
|
538
|
+
return callback(null, ferr);
|
539
|
+
}
|
540
|
+
if (devs.list.length < 1) {
|
541
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
542
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
543
|
+
return callback(null, errorObj);
|
544
|
+
}
|
545
|
+
|
546
|
+
const callPromises = [];
|
547
|
+
for (let i = 0; i < this.allProps.devicebroker.getDevice.length; i += 1) {
|
548
|
+
// Perform component calls here.
|
549
|
+
callPromises.push(
|
550
|
+
new Promise((resolve, reject) => {
|
551
|
+
this.iapMakeBrokerCall('getDevice', this.allProps.devicebroker.getDevice[i], devs.list[0], null, (callRet, callErr) => {
|
552
|
+
// return an error
|
553
|
+
if (callErr) {
|
554
|
+
reject(callErr);
|
555
|
+
} else {
|
556
|
+
// return the data
|
557
|
+
resolve(callRet);
|
558
|
+
}
|
559
|
+
});
|
560
|
+
})
|
561
|
+
);
|
562
|
+
}
|
563
|
+
|
564
|
+
// return an array of repsonses
|
565
|
+
return Promise.all(callPromises).then((results) => {
|
566
|
+
let myResult = {};
|
567
|
+
results.forEach((result) => {
|
568
|
+
myResult = { ...myResult, ...result };
|
569
|
+
});
|
570
|
+
|
571
|
+
return callback(myResult, null);
|
572
|
+
})
|
573
|
+
.catch((error) => {
|
574
|
+
log.debug(`Caught ${JSON.stringify(error)}`);
|
575
|
+
return callback(null, error);
|
576
|
+
});
|
577
|
+
});
|
578
|
+
} catch (ex) {
|
579
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
580
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
581
|
+
return callback(null, errorObj);
|
582
|
+
}
|
583
|
+
}
|
584
|
+
|
585
|
+
/**
|
586
|
+
* @summary Get Appliances that match the filter
|
587
|
+
*
|
588
|
+
* @function getDevicesFiltered
|
589
|
+
* @param {Object} options - the data to use to filter the appliances (optional)
|
590
|
+
*
|
591
|
+
* @param {getCallback} callback - a callback function to return the result
|
592
|
+
* (appliances) or the error
|
593
|
+
*/
|
594
|
+
getDevicesFiltered(options, callback) {
|
595
|
+
const meth = 'adapter-getDevicesFiltered';
|
596
|
+
const origin = `${this.id}-${meth}`;
|
597
|
+
log.trace(origin);
|
598
|
+
|
599
|
+
// make sure we are set up for device broker getDevicesFiltered
|
600
|
+
if (!this.allProps.devicebroker || !this.allProps.devicebroker.getDevicesFiltered || this.allProps.devicebroker.getDevicesFiltered.length === 0 || !this.allProps.devicebroker.getDevicesFiltered[0].path) {
|
601
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getDevicesFiltered.path'], null, null, null);
|
602
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
603
|
+
return callback(null, errorObj);
|
604
|
+
}
|
605
|
+
|
606
|
+
// verify the required fields have been provided
|
607
|
+
if (options === undefined || options === null || options === '' || options.length === 0) {
|
608
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['options'], null, null, null);
|
609
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
610
|
+
return callback(null, errorObj);
|
611
|
+
}
|
612
|
+
log.debug(`Device Filter Options: ${JSON.stringify(options)}`);
|
613
|
+
|
614
|
+
try {
|
615
|
+
// TODO - get pagination working
|
616
|
+
// const nextToken = options.start;
|
617
|
+
// const maxResults = options.limit;
|
618
|
+
|
619
|
+
// set up the filter of Device Names
|
620
|
+
let filterName = [];
|
621
|
+
if (options && options.filter && options.filter.name) {
|
622
|
+
// when this hack is removed, remove the lint ignore above
|
623
|
+
if (Array.isArray(options.filter.name)) {
|
624
|
+
// eslint-disable-next-line prefer-destructuring
|
625
|
+
filterName = options.filter.name;
|
626
|
+
} else {
|
627
|
+
filterName = [options.filter.name];
|
628
|
+
}
|
629
|
+
}
|
630
|
+
|
631
|
+
// TODO - get sort and order working
|
632
|
+
/*
|
633
|
+
if (options && options.sort) {
|
634
|
+
reqObj.uriOptions.sort = JSON.stringify(options.sort);
|
635
|
+
}
|
636
|
+
if (options && options.order) {
|
637
|
+
reqObj.uriOptions.order = options.order;
|
638
|
+
}
|
639
|
+
*/
|
640
|
+
const callPromises = [];
|
641
|
+
for (let i = 0; i < this.allProps.devicebroker.getDevicesFiltered.length; i += 1) {
|
642
|
+
// Perform component calls here.
|
643
|
+
callPromises.push(
|
644
|
+
new Promise((resolve, reject) => {
|
645
|
+
this.iapMakeBrokerCall('getDevicesFiltered', this.allProps.devicebroker.getDevicesFiltered[i], {}, filterName, (callRet, callErr) => {
|
646
|
+
// return an error
|
647
|
+
if (callErr) {
|
648
|
+
reject(callErr);
|
649
|
+
} else {
|
650
|
+
// return the data
|
651
|
+
resolve(callRet);
|
652
|
+
}
|
653
|
+
});
|
654
|
+
})
|
655
|
+
);
|
656
|
+
}
|
657
|
+
|
658
|
+
// return an array of repsonses
|
659
|
+
return Promise.all(callPromises).then((results) => {
|
660
|
+
let myResult = [];
|
661
|
+
results.forEach((result) => {
|
662
|
+
if (Array.isArray(result)) {
|
663
|
+
myResult = [...myResult, ...result];
|
664
|
+
} else if (Object.keys(result).length > 0) {
|
665
|
+
myResult.push(result);
|
666
|
+
}
|
667
|
+
});
|
668
|
+
|
669
|
+
log.debug(`${origin}: Found #${myResult.length} devices.`);
|
670
|
+
log.debug(`Devices: ${JSON.stringify(myResult)}`);
|
671
|
+
return callback({ total: myResult.length, list: myResult });
|
672
|
+
})
|
673
|
+
.catch((error) => {
|
674
|
+
log.debug(`Caught ${JSON.stringify(error)}`);
|
675
|
+
return callback(null, error);
|
676
|
+
});
|
677
|
+
} catch (ex) {
|
678
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
679
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
680
|
+
return callback(null, errorObj);
|
681
|
+
}
|
682
|
+
}
|
683
|
+
|
684
|
+
/**
|
685
|
+
* @summary Gets the status for the provided appliance
|
686
|
+
*
|
687
|
+
* @function isAlive
|
688
|
+
* @param {String} deviceName - the deviceName of the appliance. (required)
|
689
|
+
*
|
690
|
+
* @param {configCallback} callback - callback function to return the result
|
691
|
+
* (appliance isAlive) or the error
|
692
|
+
*/
|
693
|
+
isAlive(deviceName, callback) {
|
694
|
+
const meth = 'adapter-isAlive';
|
695
|
+
const origin = `${this.id}-${meth}`;
|
696
|
+
log.trace(origin);
|
697
|
+
|
698
|
+
// make sure we are set up for device broker isAlive
|
699
|
+
if (!this.allProps.devicebroker || !this.allProps.devicebroker.isAlive || this.allProps.devicebroker.isAlive.length === 0 || !this.allProps.devicebroker.isAlive[0].path) {
|
700
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.isAlive.path'], null, null, null);
|
701
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
702
|
+
return callback(null, errorObj);
|
703
|
+
}
|
704
|
+
|
705
|
+
// verify the required fields have been provided
|
706
|
+
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
707
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
708
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
709
|
+
return callback(null, errorObj);
|
710
|
+
}
|
711
|
+
|
712
|
+
try {
|
713
|
+
// need to get the device so we can convert the deviceName to an id
|
714
|
+
// !! if we can do a lookup by name the getDevicesFiltered may not be necessary
|
715
|
+
const opts = {
|
716
|
+
filter: {
|
717
|
+
name: deviceName
|
718
|
+
}
|
719
|
+
};
|
720
|
+
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
721
|
+
// if we received an error or their is no response on the results return an error
|
722
|
+
if (ferr) {
|
723
|
+
return callback(null, ferr);
|
724
|
+
}
|
725
|
+
if (devs.list.length < 1) {
|
726
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
727
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
728
|
+
return callback(null, errorObj);
|
729
|
+
}
|
730
|
+
|
731
|
+
const callPromises = [];
|
732
|
+
for (let i = 0; i < this.allProps.devicebroker.isAlive.length; i += 1) {
|
733
|
+
// Perform component calls here.
|
734
|
+
callPromises.push(
|
735
|
+
new Promise((resolve, reject) => {
|
736
|
+
this.iapMakeBrokerCall('isAlive', this.allProps.devicebroker.isAlive[i], devs.list[0], null, (callRet, callErr) => {
|
737
|
+
// return an error
|
738
|
+
if (callErr) {
|
739
|
+
reject(callErr);
|
740
|
+
} else {
|
741
|
+
// return the data
|
742
|
+
resolve(callRet);
|
743
|
+
}
|
744
|
+
});
|
745
|
+
})
|
746
|
+
);
|
747
|
+
}
|
748
|
+
|
749
|
+
// return an array of repsonses
|
750
|
+
return Promise.all(callPromises).then((results) => {
|
751
|
+
let myResult = {};
|
752
|
+
results.forEach((result) => {
|
753
|
+
myResult = { ...myResult, ...result };
|
754
|
+
});
|
755
|
+
|
756
|
+
let response = true;
|
757
|
+
if (myResult.isAlive !== null && myResult.isAlive !== undefined && myResult.isAlive === false) {
|
758
|
+
response = false;
|
759
|
+
}
|
760
|
+
return callback(response);
|
761
|
+
})
|
762
|
+
.catch((error) => {
|
763
|
+
log.debug(`Caught ${JSON.stringify(error)}`);
|
764
|
+
return callback(null, error);
|
765
|
+
});
|
766
|
+
});
|
767
|
+
} catch (ex) {
|
768
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
769
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
770
|
+
return callback(null, errorObj);
|
771
|
+
}
|
772
|
+
}
|
773
|
+
|
774
|
+
/**
|
775
|
+
* @summary Gets a config for the provided Appliance
|
776
|
+
*
|
777
|
+
* @function getConfig
|
778
|
+
* @param {String} deviceName - the deviceName of the appliance. (required)
|
779
|
+
* @param {String} format - the desired format of the config. (optional)
|
780
|
+
*
|
781
|
+
* @param {configCallback} callback - callback function to return the result
|
782
|
+
* (appliance config) or the error
|
783
|
+
*/
|
784
|
+
getConfig(deviceName, format, callback) {
|
785
|
+
const meth = 'adapter-getConfig';
|
786
|
+
const origin = `${this.id}-${meth}`;
|
787
|
+
log.trace(origin);
|
788
|
+
|
789
|
+
// make sure we are set up for device broker getConfig
|
790
|
+
if (!this.allProps.devicebroker || !this.allProps.devicebroker.getConfig || this.allProps.devicebroker.getConfig.length === 0 || !this.allProps.devicebroker.getConfig[0].path) {
|
791
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getConfig.path'], null, null, null);
|
792
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
793
|
+
return callback(null, errorObj);
|
794
|
+
}
|
795
|
+
|
796
|
+
// verify the required fields have been provided
|
797
|
+
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
798
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
799
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
800
|
+
return callback(null, errorObj);
|
801
|
+
}
|
802
|
+
|
803
|
+
try {
|
804
|
+
// need to get the device so we can convert the deviceName to an id
|
805
|
+
// !! if we can do a lookup by name the getDevicesFiltered may not be necessary
|
806
|
+
const opts = {
|
807
|
+
filter: {
|
808
|
+
name: deviceName
|
809
|
+
}
|
810
|
+
};
|
811
|
+
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
812
|
+
// if we received an error or their is no response on the results return an error
|
813
|
+
if (ferr) {
|
814
|
+
return callback(null, ferr);
|
815
|
+
}
|
816
|
+
if (devs.list.length < 1) {
|
817
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
818
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
819
|
+
return callback(null, errorObj);
|
820
|
+
}
|
821
|
+
|
822
|
+
const callPromises = [];
|
823
|
+
for (let i = 0; i < this.allProps.devicebroker.getConfig.length; i += 1) {
|
824
|
+
// Perform component calls here.
|
825
|
+
callPromises.push(
|
826
|
+
new Promise((resolve, reject) => {
|
827
|
+
this.iapMakeBrokerCall('getConfig', this.allProps.devicebroker.getConfig[i], devs.list[0], null, (callRet, callErr) => {
|
828
|
+
// return an error
|
829
|
+
if (callErr) {
|
830
|
+
reject(callErr);
|
831
|
+
} else {
|
832
|
+
// return the data
|
833
|
+
resolve(callRet);
|
834
|
+
}
|
835
|
+
});
|
836
|
+
})
|
837
|
+
);
|
838
|
+
}
|
839
|
+
|
840
|
+
// return an array of repsonses
|
841
|
+
return Promise.all(callPromises).then((results) => {
|
842
|
+
let myResult = {};
|
843
|
+
results.forEach((result) => {
|
844
|
+
myResult = { ...myResult, ...result };
|
845
|
+
});
|
846
|
+
|
847
|
+
// return the result
|
848
|
+
const newResponse = {
|
849
|
+
response: JSON.stringify(myResult, null, 2)
|
850
|
+
};
|
851
|
+
return callback(newResponse, null);
|
852
|
+
})
|
853
|
+
.catch((error) => {
|
854
|
+
log.debug(`Caught ${JSON.stringify(error)}`);
|
855
|
+
return callback(null, error);
|
856
|
+
});
|
857
|
+
});
|
858
|
+
} catch (ex) {
|
859
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
860
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
861
|
+
return callback(null, errorObj);
|
862
|
+
}
|
863
|
+
}
|
864
|
+
|
865
|
+
/**
|
866
|
+
* @summary Gets the device count from the system
|
867
|
+
*
|
868
|
+
* @function iapGetDeviceCount
|
869
|
+
*
|
870
|
+
* @param {getCallback} callback - callback function to return the result
|
871
|
+
* (count) or the error
|
872
|
+
*/
|
873
|
+
iapGetDeviceCount(callback) {
|
874
|
+
const meth = 'adapter-iapGetDeviceCount';
|
875
|
+
const origin = `${this.id}-${meth}`;
|
876
|
+
log.trace(origin);
|
877
|
+
|
878
|
+
// make sure we are set up for device broker getCount
|
879
|
+
if (!this.allProps.devicebroker || !this.allProps.devicebroker.getCount || this.allProps.devicebroker.getCount.length === 0 || !this.allProps.devicebroker.getCount[0].path) {
|
880
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getCount.path'], null, null, null);
|
881
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
882
|
+
return callback(null, errorObj);
|
883
|
+
}
|
884
|
+
|
885
|
+
// verify the required fields have been provided
|
886
|
+
|
887
|
+
try {
|
888
|
+
const callPromises = [];
|
889
|
+
for (let i = 0; i < this.allProps.devicebroker.getCount.length; i += 1) {
|
890
|
+
// Perform component calls here.
|
891
|
+
callPromises.push(
|
892
|
+
new Promise((resolve, reject) => {
|
893
|
+
this.iapMakeBrokerCall('getCount', this.allProps.devicebroker.getCount[i], null, null, (callRet, callErr) => {
|
894
|
+
// return an error
|
895
|
+
if (callErr) {
|
896
|
+
reject(callErr);
|
897
|
+
} else {
|
898
|
+
// return the data
|
899
|
+
resolve(callRet);
|
900
|
+
}
|
901
|
+
});
|
902
|
+
})
|
903
|
+
);
|
904
|
+
}
|
905
|
+
|
906
|
+
// return an array of repsonses
|
907
|
+
return Promise.all(callPromises).then((results) => {
|
908
|
+
let myResult = {};
|
909
|
+
results.forEach((result) => {
|
910
|
+
myResult = { ...myResult, ...result };
|
911
|
+
});
|
912
|
+
|
913
|
+
// return the result
|
914
|
+
return callback({ count: myResult.length });
|
915
|
+
})
|
916
|
+
.catch((error) => {
|
917
|
+
log.debug(`Caught ${JSON.stringify(error)}`);
|
918
|
+
return callback(null, error);
|
919
|
+
});
|
920
|
+
} catch (ex) {
|
921
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
922
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
923
|
+
return callback(null, errorObj);
|
924
|
+
}
|
925
|
+
}
|
926
|
+
|
927
|
+
/* GENERIC ADAPTER REQUEST - allows extension of adapter without new calls being added */
|
421
928
|
/**
|
422
929
|
* Makes the requested generic call
|
423
930
|
*
|