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