@itentialopensource/adapter-robustel 0.1.1
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/.eslintignore +5 -0
- package/.eslintrc.js +18 -0
- package/.jshintrc +3 -0
- package/CHANGELOG.md +9 -0
- package/CODE_OF_CONDUCT.md +48 -0
- package/CONTRIBUTING.md +158 -0
- package/LICENSE +201 -0
- package/README.md +687 -0
- package/adapter.js +1660 -0
- package/adapterBase.js +1028 -0
- package/entities/.generic/action.json +109 -0
- package/entities/.generic/schema.json +23 -0
- package/entities/.system/action.json +50 -0
- package/entities/.system/mockdatafiles/getToken-default.json +3 -0
- package/entities/.system/mockdatafiles/healthcheck-default.json +3 -0
- package/entities/.system/schema.json +19 -0
- package/entities/.system/schemaTokenReq.json +53 -0
- package/entities/.system/schemaTokenResp.json +53 -0
- package/entities/Dashboard/action.json +46 -0
- package/entities/Dashboard/schema.json +20 -0
- package/entities/Device/action.json +87 -0
- package/entities/Device/schema.json +22 -0
- package/error.json +184 -0
- package/package.json +84 -0
- package/pronghorn.json +774 -0
- package/propertiesSchema.json +840 -0
- package/refs?service=git-upload-pack +0 -0
- package/report/Robustel.swagger-converted (3).json +204 -0
- package/report/creationReport.json +214 -0
- package/report/updateReport1645453224836.json +95 -0
- package/sampleProperties.json +106 -0
- package/test/integration/adapterTestBasicGet.js +85 -0
- package/test/integration/adapterTestConnectivity.js +93 -0
- package/test/integration/adapterTestIntegration.js +629 -0
- package/test/unit/adapterBaseTestUnit.js +944 -0
- package/test/unit/adapterTestUnit.js +1526 -0
- package/utils/addAuth.js +94 -0
- package/utils/artifactize.js +146 -0
- package/utils/basicGet.js +50 -0
- package/utils/checkMigrate.js +63 -0
- package/utils/entitiesToDB.js +224 -0
- package/utils/findPath.js +74 -0
- package/utils/modify.js +154 -0
- package/utils/packModificationScript.js +35 -0
- package/utils/patches2bundledDeps.js +90 -0
- package/utils/pre-commit.sh +27 -0
- package/utils/removeHooks.js +20 -0
- package/utils/setup.js +33 -0
- package/utils/tbScript.js +169 -0
- package/utils/tbUtils.js +451 -0
- package/utils/testRunner.js +298 -0
- package/utils/troubleshootingAdapter.js +190 -0
- package/workflows/README.md +3 -0
package/adapter.js
ADDED
|
@@ -0,0 +1,1660 @@
|
|
|
1
|
+
/* @copyright Itential, LLC 2019 (pre-modifications) */
|
|
2
|
+
|
|
3
|
+
/* eslint import/no-dynamic-require: warn */
|
|
4
|
+
/* eslint object-curly-newline: warn */
|
|
5
|
+
|
|
6
|
+
// Set globals
|
|
7
|
+
/* global log */
|
|
8
|
+
|
|
9
|
+
/* Required libraries. */
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const cryptoJS = require('crypto-js');
|
|
12
|
+
const querystring = require('querystring');
|
|
13
|
+
|
|
14
|
+
/* Fetch in the other needed components for the this Adaptor */
|
|
15
|
+
const AdapterBaseCl = require(path.join(__dirname, 'adapterBase.js'));
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* This is the adapter/interface into Robustel
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/* GENERAL ADAPTER FUNCTIONS */
|
|
22
|
+
class Robustel extends AdapterBaseCl {
|
|
23
|
+
/**
|
|
24
|
+
* Robustel Adapter
|
|
25
|
+
* @constructor
|
|
26
|
+
*/
|
|
27
|
+
/* Working on changing the way we do Emit methods due to size and time constrainsts
|
|
28
|
+
constructor(prongid, properties) {
|
|
29
|
+
// Instantiate the AdapterBase super class
|
|
30
|
+
super(prongid, properties);
|
|
31
|
+
|
|
32
|
+
const restFunctionNames = this.getWorkflowFunctions();
|
|
33
|
+
|
|
34
|
+
// Dynamically bind emit functions
|
|
35
|
+
for (let i = 0; i < restFunctionNames.length; i += 1) {
|
|
36
|
+
// Bind function to have name fnNameEmit for fnName
|
|
37
|
+
const version = restFunctionNames[i].match(/__v[0-9]+/);
|
|
38
|
+
const baseFnName = restFunctionNames[i].replace(/__v[0-9]+/, '');
|
|
39
|
+
const fnNameEmit = version ? `${baseFnName}Emit${version}` : `${baseFnName}Emit`;
|
|
40
|
+
this[fnNameEmit] = function (...args) {
|
|
41
|
+
// extract the callback
|
|
42
|
+
const callback = args[args.length - 1];
|
|
43
|
+
// slice the callback from args so we can insert our own
|
|
44
|
+
const functionArgs = args.slice(0, args.length - 1);
|
|
45
|
+
// create a random name for the listener
|
|
46
|
+
const eventName = `${restFunctionNames[i]}:${Math.random().toString(36)}`;
|
|
47
|
+
// tell the calling class to start listening
|
|
48
|
+
callback({ event: eventName, status: 'received' });
|
|
49
|
+
// store parent for use of this context later
|
|
50
|
+
const parent = this;
|
|
51
|
+
// store emission function
|
|
52
|
+
const func = function (val, err) {
|
|
53
|
+
parent.removeListener(eventName, func);
|
|
54
|
+
parent.emit(eventName, val, err);
|
|
55
|
+
};
|
|
56
|
+
// Use apply to call the function in a specific context
|
|
57
|
+
this[restFunctionNames[i]].apply(this, functionArgs.concat([func])); // eslint-disable-line prefer-spread
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Uncomment if you have things to add to the constructor like using your own properties.
|
|
62
|
+
// Otherwise the constructor in the adapterBase will be used.
|
|
63
|
+
// Capture my own properties - they need to be defined in propertiesSchema.json
|
|
64
|
+
// if (this.allProps && this.allProps.myownproperty) {
|
|
65
|
+
// mypropvariable = this.allProps.myownproperty;
|
|
66
|
+
// }
|
|
67
|
+
}
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @callback healthCallback
|
|
72
|
+
* @param {Object} reqObj - the request to send into the healthcheck
|
|
73
|
+
* @param {Callback} callback - The results of the call
|
|
74
|
+
*/
|
|
75
|
+
healthCheck(reqObj, callback) {
|
|
76
|
+
// you can modify what is passed into the healthcheck by changing things in the newReq
|
|
77
|
+
let newReq = null;
|
|
78
|
+
if (reqObj) {
|
|
79
|
+
newReq = Object.assign(...reqObj);
|
|
80
|
+
}
|
|
81
|
+
super.healthCheck(newReq, callback);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @getWorkflowFunctions
|
|
86
|
+
*/
|
|
87
|
+
getWorkflowFunctions(inIgnore) {
|
|
88
|
+
let myIgnore = ['getAuthorization', 'hasEntities', 'hasDevices'];
|
|
89
|
+
if (!inIgnore && Array.isArray(inIgnore)) {
|
|
90
|
+
myIgnore = inIgnore;
|
|
91
|
+
} else if (!inIgnore && typeof inIgnore === 'string') {
|
|
92
|
+
myIgnore = [inIgnore];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// The generic adapter functions should already be ignored (e.g. healthCheck)
|
|
96
|
+
// you can add specific methods that you do not want to be workflow functions to ignore like below
|
|
97
|
+
// myIgnore.push('myMethodNotInWorkflow');
|
|
98
|
+
|
|
99
|
+
return super.getWorkflowFunctions(myIgnore);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* updateAdapterConfiguration is used to update any of the adapter configuration files. This
|
|
104
|
+
* allows customers to make changes to adapter configuration without having to be on the
|
|
105
|
+
* file system.
|
|
106
|
+
*
|
|
107
|
+
* @function updateAdapterConfiguration
|
|
108
|
+
* @param {string} configFile - the name of the file being updated (required)
|
|
109
|
+
* @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
|
|
110
|
+
* @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
|
|
111
|
+
* @param {string} type - the type of entity file to change, (action, schema, mock) (optional)
|
|
112
|
+
* @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
|
|
113
|
+
* @param {Callback} callback - The results of the call
|
|
114
|
+
*/
|
|
115
|
+
updateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
|
|
116
|
+
const origin = `${this.id}-adapter-updateAdapterConfiguration`;
|
|
117
|
+
log.trace(origin);
|
|
118
|
+
super.updateAdapterConfiguration(configFile, changes, entity, type, action, callback);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* See if the API path provided is found in this adapter
|
|
123
|
+
*
|
|
124
|
+
* @function findPath
|
|
125
|
+
* @param {string} apiPath - the api path to check on
|
|
126
|
+
* @param {Callback} callback - The results of the call
|
|
127
|
+
*/
|
|
128
|
+
findPath(apiPath, callback) {
|
|
129
|
+
const origin = `${this.id}-adapter-findPath`;
|
|
130
|
+
log.trace(origin);
|
|
131
|
+
super.findPath(apiPath, callback);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @summary Suspends adapter
|
|
136
|
+
*
|
|
137
|
+
* @function suspend
|
|
138
|
+
* @param {Callback} callback - callback function
|
|
139
|
+
*/
|
|
140
|
+
suspend(mode, callback) {
|
|
141
|
+
const origin = `${this.id}-adapter-suspend`;
|
|
142
|
+
log.trace(origin);
|
|
143
|
+
try {
|
|
144
|
+
return super.suspend(mode, callback);
|
|
145
|
+
} catch (error) {
|
|
146
|
+
log.error(`${origin}: ${error}`);
|
|
147
|
+
return callback(null, error);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @summary Unsuspends adapter
|
|
153
|
+
*
|
|
154
|
+
* @function unsuspend
|
|
155
|
+
* @param {Callback} callback - callback function
|
|
156
|
+
*/
|
|
157
|
+
unsuspend(callback) {
|
|
158
|
+
const origin = `${this.id}-adapter-unsuspend`;
|
|
159
|
+
log.trace(origin);
|
|
160
|
+
try {
|
|
161
|
+
return super.unsuspend(callback);
|
|
162
|
+
} catch (error) {
|
|
163
|
+
log.error(`${origin}: ${error}`);
|
|
164
|
+
return callback(null, error);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @summary Get the Adaoter Queue
|
|
170
|
+
*
|
|
171
|
+
* @function getQueue
|
|
172
|
+
* @param {Callback} callback - callback function
|
|
173
|
+
*/
|
|
174
|
+
getQueue(callback) {
|
|
175
|
+
const origin = `${this.id}-adapter-getQueue`;
|
|
176
|
+
log.trace(origin);
|
|
177
|
+
return super.getQueue(callback);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* @summary Runs troubleshoot scripts for adapter
|
|
182
|
+
*
|
|
183
|
+
* @function troubleshoot
|
|
184
|
+
* @param {Object} props - the connection, healthcheck and authentication properties
|
|
185
|
+
*
|
|
186
|
+
* @param {boolean} persistFlag - whether the adapter properties should be updated
|
|
187
|
+
* @param {Callback} callback - The results of the call
|
|
188
|
+
*/
|
|
189
|
+
troubleshoot(props, persistFlag, callback) {
|
|
190
|
+
const origin = `${this.id}-adapter-troubleshoot`;
|
|
191
|
+
log.trace(origin);
|
|
192
|
+
try {
|
|
193
|
+
return super.troubleshoot(props, persistFlag, this, callback);
|
|
194
|
+
} catch (error) {
|
|
195
|
+
log.error(`${origin}: ${error}`);
|
|
196
|
+
return callback(null, error);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* @summary runs healthcheck script for adapter
|
|
202
|
+
*
|
|
203
|
+
* @function runHealthcheck
|
|
204
|
+
* @param {Adapter} adapter - adapter instance to troubleshoot
|
|
205
|
+
* @param {Callback} callback - callback function
|
|
206
|
+
*/
|
|
207
|
+
runHealthcheck(callback) {
|
|
208
|
+
const origin = `${this.id}-adapter-runHealthcheck`;
|
|
209
|
+
log.trace(origin);
|
|
210
|
+
try {
|
|
211
|
+
return super.runHealthcheck(this, callback);
|
|
212
|
+
} catch (error) {
|
|
213
|
+
log.error(`${origin}: ${error}`);
|
|
214
|
+
return callback(null, error);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* @summary runs connectivity check script for adapter
|
|
220
|
+
*
|
|
221
|
+
* @function runConnectivity
|
|
222
|
+
* @param {Callback} callback - callback function
|
|
223
|
+
*/
|
|
224
|
+
runConnectivity(callback) {
|
|
225
|
+
const origin = `${this.id}-adapter-runConnectivity`;
|
|
226
|
+
log.trace(origin);
|
|
227
|
+
try {
|
|
228
|
+
return super.runConnectivity(callback);
|
|
229
|
+
} catch (error) {
|
|
230
|
+
log.error(`${origin}: ${error}`);
|
|
231
|
+
return callback(null, error);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* @summary runs basicGet script for adapter
|
|
237
|
+
*
|
|
238
|
+
* @function runBasicGet
|
|
239
|
+
* @param {Callback} callback - callback function
|
|
240
|
+
*/
|
|
241
|
+
runBasicGet(callback) {
|
|
242
|
+
const origin = `${this.id}-adapter-runBasicGet`;
|
|
243
|
+
log.trace(origin);
|
|
244
|
+
try {
|
|
245
|
+
return super.runBasicGet(callback);
|
|
246
|
+
} catch (error) {
|
|
247
|
+
log.error(`${origin}: ${error}`);
|
|
248
|
+
return callback(null, error);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* @summary moves entites into Mongo DB
|
|
254
|
+
*
|
|
255
|
+
* @function moveEntitiesToDB
|
|
256
|
+
* @param {getCallback} callback - a callback function to return the result (Generics)
|
|
257
|
+
* or the error
|
|
258
|
+
*/
|
|
259
|
+
moveEntitiesToDB(callback) {
|
|
260
|
+
const origin = `${this.id}-adapter-moveEntitiesToDB`;
|
|
261
|
+
log.trace(origin);
|
|
262
|
+
try {
|
|
263
|
+
return super.moveEntitiesToDB(callback);
|
|
264
|
+
} catch (err) {
|
|
265
|
+
log.error(`${origin}: ${err}`);
|
|
266
|
+
return callback(null, err);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* @summary Determines if this adapter supports the specific entity
|
|
272
|
+
*
|
|
273
|
+
* @function hasEntity
|
|
274
|
+
* @param {String} entityType - the entity type to check for
|
|
275
|
+
* @param {String/Array} entityId - the specific entity we are looking for
|
|
276
|
+
*
|
|
277
|
+
* @param {Callback} callback - An array of whether the adapter can has the
|
|
278
|
+
* desired capability or an error
|
|
279
|
+
*/
|
|
280
|
+
hasEntity(entityType, entityId, callback) {
|
|
281
|
+
const origin = `${this.id}-adapter-hasEntity`;
|
|
282
|
+
log.trace(origin);
|
|
283
|
+
|
|
284
|
+
// Make the call -
|
|
285
|
+
// verifyCapability(entityType, actionType, entityId, callback)
|
|
286
|
+
return this.verifyCapability(entityType, null, entityId, callback);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* @summary Provides a way for the adapter to tell north bound integrations
|
|
291
|
+
* whether the adapter supports type, action and specific entity
|
|
292
|
+
*
|
|
293
|
+
* @function verifyCapability
|
|
294
|
+
* @param {String} entityType - the entity type to check for
|
|
295
|
+
* @param {String} actionType - the action type to check for
|
|
296
|
+
* @param {String/Array} entityId - the specific entity we are looking for
|
|
297
|
+
*
|
|
298
|
+
* @param {Callback} callback - An array of whether the adapter can has the
|
|
299
|
+
* desired capability or an error
|
|
300
|
+
*/
|
|
301
|
+
verifyCapability(entityType, actionType, entityId, callback) {
|
|
302
|
+
const meth = 'adapterBase-verifyCapability';
|
|
303
|
+
const origin = `${this.id}-${meth}`;
|
|
304
|
+
log.trace(origin);
|
|
305
|
+
|
|
306
|
+
// if caching
|
|
307
|
+
if (this.caching) {
|
|
308
|
+
// Make the call - verifyCapability(entityType, actionType, entityId, callback)
|
|
309
|
+
return this.requestHandlerInst.verifyCapability(entityType, actionType, entityId, (results, error) => {
|
|
310
|
+
if (error) {
|
|
311
|
+
return callback(null, error);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// if the cache needs to be updated, update and try again
|
|
315
|
+
if (results && results[0] === 'needupdate') {
|
|
316
|
+
switch (entityType) {
|
|
317
|
+
case 'template_entity': {
|
|
318
|
+
// if the cache is invalid, update the cache
|
|
319
|
+
return this.getEntities(null, null, null, null, (data, err) => {
|
|
320
|
+
if (err) {
|
|
321
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Could not update entity: $VARIABLE$, cache', [entityType], null, null, null);
|
|
322
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
323
|
+
return callback(null, errorObj);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// need to check the cache again since it has been updated
|
|
327
|
+
return this.requestHandlerInst.verifyCapability(entityType, actionType, entityId, (vcapable, verror) => {
|
|
328
|
+
if (verror) {
|
|
329
|
+
return callback(null, verror);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return this.capabilityResults(vcapable, callback);
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
default: {
|
|
337
|
+
// unsupported entity type
|
|
338
|
+
const result = [false];
|
|
339
|
+
|
|
340
|
+
// put false in array for all entities
|
|
341
|
+
if (Array.isArray(entityId)) {
|
|
342
|
+
for (let e = 1; e < entityId.length; e += 1) {
|
|
343
|
+
result.push(false);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return callback(result);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// return the results
|
|
353
|
+
return this.capabilityResults(results, callback);
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// if no entity id
|
|
358
|
+
if (!entityId) {
|
|
359
|
+
// need to check the cache again since it has been updated
|
|
360
|
+
return this.requestHandlerInst.verifyCapability(entityType, actionType, null, (vcapable, verror) => {
|
|
361
|
+
if (verror) {
|
|
362
|
+
return callback(null, verror);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
return this.capabilityResults(vcapable, callback);
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// if not caching
|
|
370
|
+
switch (entityType) {
|
|
371
|
+
case 'template_entity': {
|
|
372
|
+
// need to get the entities to check
|
|
373
|
+
return this.getEntities(null, null, null, null, (data, err) => {
|
|
374
|
+
if (err) {
|
|
375
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Could not update entity: $VARIABLE$, cache', [entityType], null, null, null);
|
|
376
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
377
|
+
return callback(null, errorObj);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// need to check the cache again since it has been updated
|
|
381
|
+
return this.requestHandlerInst.verifyCapability(entityType, actionType, null, (vcapable, verror) => {
|
|
382
|
+
if (verror) {
|
|
383
|
+
return callback(null, verror);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// is the entity in the list?
|
|
387
|
+
const isEntity = this.entityInList(entityId, data.response, callback);
|
|
388
|
+
const res = [];
|
|
389
|
+
|
|
390
|
+
// not found
|
|
391
|
+
for (let i = 0; i < isEntity.length; i += 1) {
|
|
392
|
+
if (vcapable) {
|
|
393
|
+
res.push(isEntity[i]);
|
|
394
|
+
} else {
|
|
395
|
+
res.push(false);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
return callback(res);
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
default: {
|
|
404
|
+
// unsupported entity type
|
|
405
|
+
const result = [false];
|
|
406
|
+
|
|
407
|
+
// put false in array for all entities
|
|
408
|
+
if (Array.isArray(entityId)) {
|
|
409
|
+
for (let e = 1; e < entityId.length; e += 1) {
|
|
410
|
+
result.push(false);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
return callback(result);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* @summary Updates the cache for all entities by call the get All entity method
|
|
421
|
+
*
|
|
422
|
+
* @function updateEntityCache
|
|
423
|
+
*
|
|
424
|
+
*/
|
|
425
|
+
updateEntityCache() {
|
|
426
|
+
const origin = `${this.id}-adapter-updateEntityCache`;
|
|
427
|
+
log.trace(origin);
|
|
428
|
+
|
|
429
|
+
if (this.caching) {
|
|
430
|
+
// if the cache is invalid, update the cache
|
|
431
|
+
this.getEntities(null, null, null, null, (data, err) => {
|
|
432
|
+
if (err) {
|
|
433
|
+
log.trace(`${origin}: Could not load template_entity into cache - ${err}`);
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Makes the requested generic call
|
|
441
|
+
*
|
|
442
|
+
* @function genericAdapterRequest
|
|
443
|
+
* @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
|
|
444
|
+
* @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
|
|
445
|
+
* @param {Object} queryData - the parameters to be put on the url (optional).
|
|
446
|
+
* Can be a stringified Object.
|
|
447
|
+
* @param {Object} requestBody - the body to add to the request (optional).
|
|
448
|
+
* Can be a stringified Object.
|
|
449
|
+
* @param {Object} addlHeaders - additional headers to be put on the call (optional).
|
|
450
|
+
* Can be a stringified Object.
|
|
451
|
+
* @param {getCallback} callback - a callback function to return the result (Generics)
|
|
452
|
+
* or the error
|
|
453
|
+
*/
|
|
454
|
+
genericAdapterRequest(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
|
|
455
|
+
const meth = 'adapter-genericAdapterRequest';
|
|
456
|
+
const origin = `${this.id}-${meth}`;
|
|
457
|
+
log.trace(origin);
|
|
458
|
+
|
|
459
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
460
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
461
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
462
|
+
return callback(null, errorObj);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
466
|
+
if (uriPath === undefined || uriPath === null || uriPath === '') {
|
|
467
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['uriPath'], null, null, null);
|
|
468
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
469
|
+
return callback(null, errorObj);
|
|
470
|
+
}
|
|
471
|
+
if (restMethod === undefined || restMethod === null || restMethod === '') {
|
|
472
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['restMethod'], null, null, null);
|
|
473
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
474
|
+
return callback(null, errorObj);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
478
|
+
// remove any leading / and split the uripath into path variables
|
|
479
|
+
let myPath = uriPath;
|
|
480
|
+
while (myPath.indexOf('/') === 0) {
|
|
481
|
+
myPath = myPath.substring(1);
|
|
482
|
+
}
|
|
483
|
+
const pathVars = myPath.split('/');
|
|
484
|
+
const queryParamsAvailable = queryData;
|
|
485
|
+
const queryParams = {};
|
|
486
|
+
const bodyVars = requestBody;
|
|
487
|
+
|
|
488
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
489
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
490
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
491
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
492
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
let usePath = uriPath;
|
|
497
|
+
if (queryParams && Object.keys(queryParams).length > 0) {
|
|
498
|
+
usePath = `${uriPath}?${querystring(queryData)}`;
|
|
499
|
+
}
|
|
500
|
+
const callSign = this.getAuthorization(restMethod, usePath, bodyVars);
|
|
501
|
+
|
|
502
|
+
// if the callAuth was unsuccessful
|
|
503
|
+
if (callSign === -1) {
|
|
504
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['call signature'], null, null, null);
|
|
505
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
506
|
+
return callback(null, errorObj);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
|
|
510
|
+
const reqObj = {
|
|
511
|
+
payload: bodyVars,
|
|
512
|
+
uriPathVars: pathVars,
|
|
513
|
+
uriQuery: queryParams,
|
|
514
|
+
uriOptions: {},
|
|
515
|
+
addlHeaders: callSign
|
|
516
|
+
};
|
|
517
|
+
// add headers if provided
|
|
518
|
+
if (addlHeaders) {
|
|
519
|
+
reqObj.addlHeaders = addlHeaders;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// determine the call and return flag
|
|
523
|
+
let action = 'getGenerics';
|
|
524
|
+
let returnF = true;
|
|
525
|
+
if (restMethod.toUpperCase() === 'POST') {
|
|
526
|
+
action = 'createGeneric';
|
|
527
|
+
} else if (restMethod.toUpperCase() === 'PUT') {
|
|
528
|
+
action = 'updateGeneric';
|
|
529
|
+
} else if (restMethod.toUpperCase() === 'PATCH') {
|
|
530
|
+
action = 'patchGeneric';
|
|
531
|
+
} else if (restMethod.toUpperCase() === 'DELETE') {
|
|
532
|
+
action = 'deleteGeneric';
|
|
533
|
+
returnF = false;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
try {
|
|
537
|
+
// Make the call -
|
|
538
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
539
|
+
return this.requestHandlerInst.identifyRequest('.generic', action, reqObj, returnF, (irReturnData, irReturnError) => {
|
|
540
|
+
// if we received an error or their is no response on the results
|
|
541
|
+
// return an error
|
|
542
|
+
if (irReturnError) {
|
|
543
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
544
|
+
return callback(null, irReturnError);
|
|
545
|
+
}
|
|
546
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
547
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['genericAdapterRequest'], null, null, null);
|
|
548
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
549
|
+
return callback(null, errorObj);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
553
|
+
// return the response
|
|
554
|
+
return callback(irReturnData, null);
|
|
555
|
+
});
|
|
556
|
+
} catch (ex) {
|
|
557
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
558
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
559
|
+
return callback(null, errorObj);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/* BROKER CALLS */
|
|
564
|
+
/**
|
|
565
|
+
* @summary Determines if this adapter supports any in a list of entities
|
|
566
|
+
*
|
|
567
|
+
* @function hasEntities
|
|
568
|
+
* @param {String} entityType - the entity type to check for
|
|
569
|
+
* @param {Array} entityList - the list of entities we are looking for
|
|
570
|
+
*
|
|
571
|
+
* @param {Callback} callback - A map where the entity is the key and the
|
|
572
|
+
* value is true or false
|
|
573
|
+
*/
|
|
574
|
+
hasEntities(entityType, entityList, callback) {
|
|
575
|
+
const origin = `${this.id}-adapter-hasEntities`;
|
|
576
|
+
log.trace(origin);
|
|
577
|
+
|
|
578
|
+
switch (entityType) {
|
|
579
|
+
case 'Device':
|
|
580
|
+
return this.hasDevices(entityList, callback);
|
|
581
|
+
default:
|
|
582
|
+
return callback(null, `${this.id} does not support entity ${entityType}`);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* @summary Helper method for hasEntities for the specific device case
|
|
588
|
+
*
|
|
589
|
+
* @param {Array} deviceList - array of unique device identifiers
|
|
590
|
+
* @param {Callback} callback - A map where the device is the key and the
|
|
591
|
+
* value is true or false
|
|
592
|
+
*/
|
|
593
|
+
hasDevices(deviceList, callback) {
|
|
594
|
+
const origin = `${this.id}-adapter-hasDevices`;
|
|
595
|
+
log.trace(origin);
|
|
596
|
+
|
|
597
|
+
const findings = deviceList.reduce((map, device) => {
|
|
598
|
+
// eslint-disable-next-line no-param-reassign
|
|
599
|
+
map[device] = false;
|
|
600
|
+
log.debug(`In reduce: ${JSON.stringify(map)}`);
|
|
601
|
+
return map;
|
|
602
|
+
}, {});
|
|
603
|
+
const apiCalls = deviceList.map((device) => new Promise((resolve) => {
|
|
604
|
+
this.getDevice(device, (result, error) => {
|
|
605
|
+
if (error) {
|
|
606
|
+
log.debug(`In map error: ${JSON.stringify(device)}`);
|
|
607
|
+
return resolve({ name: device, found: false });
|
|
608
|
+
}
|
|
609
|
+
log.debug(`In map: ${JSON.stringify(device)}`);
|
|
610
|
+
return resolve({ name: device, found: true });
|
|
611
|
+
});
|
|
612
|
+
}));
|
|
613
|
+
Promise.all(apiCalls).then((results) => {
|
|
614
|
+
results.forEach((device) => {
|
|
615
|
+
findings[device.name] = device.found;
|
|
616
|
+
});
|
|
617
|
+
log.debug(`FINDINGS: ${JSON.stringify(findings)}`);
|
|
618
|
+
return callback(findings);
|
|
619
|
+
}).catch((errors) => {
|
|
620
|
+
log.error('Unable to do device lookup.');
|
|
621
|
+
return callback(null, { code: 503, message: 'Unable to do device lookup.', error: errors });
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* @summary Get Appliance that match the deviceName
|
|
627
|
+
*
|
|
628
|
+
* @function getDevice
|
|
629
|
+
* @param {String} deviceName - the deviceName to find (required)
|
|
630
|
+
*
|
|
631
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
632
|
+
* (appliance) or the error
|
|
633
|
+
*/
|
|
634
|
+
getDevice(deviceName, callback) {
|
|
635
|
+
const meth = 'adapter-getDevice';
|
|
636
|
+
const origin = `${this.id}-${meth}`;
|
|
637
|
+
log.trace(origin);
|
|
638
|
+
|
|
639
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
640
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
641
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
642
|
+
return callback(null, errorObj);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
646
|
+
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
|
647
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
|
648
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
649
|
+
return callback(null, errorObj);
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
try {
|
|
653
|
+
// need to get the device so we can convert the deviceName to an id
|
|
654
|
+
// !! if we can do a lookup by name the getDevicesFiltered may not be necessary
|
|
655
|
+
const opts = {
|
|
656
|
+
filter: {
|
|
657
|
+
name: deviceName
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
|
661
|
+
// if we received an error or their is no response on the results return an error
|
|
662
|
+
if (ferr) {
|
|
663
|
+
return callback(null, ferr);
|
|
664
|
+
}
|
|
665
|
+
if (devs.list.length < 1) {
|
|
666
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
|
667
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
668
|
+
return callback(null, errorObj);
|
|
669
|
+
}
|
|
670
|
+
// get the uuid from the device
|
|
671
|
+
const { uuid } = devs.list[0];
|
|
672
|
+
|
|
673
|
+
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
674
|
+
// !! you can also replace with a specific call if that is easier
|
|
675
|
+
const uriPath = `/call/toget/device/${uuid}`;
|
|
676
|
+
return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
|
|
677
|
+
// if we received an error or their is no response on the results return an error
|
|
678
|
+
if (error) {
|
|
679
|
+
return callback(null, error);
|
|
680
|
+
}
|
|
681
|
+
if (!result.response || !result.response.applianceMo) {
|
|
682
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevice'], null, null, null);
|
|
683
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
684
|
+
return callback(null, errorObj);
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
// return the response
|
|
688
|
+
// !! format the data we send back
|
|
689
|
+
// !! these fields are config manager fields you need to map to the data we receive
|
|
690
|
+
const thisDevice = result.response;
|
|
691
|
+
thisDevice.name = thisDevice.systemName;
|
|
692
|
+
thisDevice.ostype = `System-${thisDevice.systemType}`;
|
|
693
|
+
thisDevice.port = thisDevice.systemPort;
|
|
694
|
+
thisDevice.ipaddress = thisDevice.systemIP;
|
|
695
|
+
return callback(thisDevice);
|
|
696
|
+
});
|
|
697
|
+
});
|
|
698
|
+
} catch (ex) {
|
|
699
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
700
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
701
|
+
return callback(null, errorObj);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* @summary Get Appliances that match the filter
|
|
707
|
+
*
|
|
708
|
+
* @function getDevicesFiltered
|
|
709
|
+
* @param {Object} options - the data to use to filter the appliances (optional)
|
|
710
|
+
*
|
|
711
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
712
|
+
* (appliances) or the error
|
|
713
|
+
*/
|
|
714
|
+
getDevicesFiltered(options, callback) {
|
|
715
|
+
const meth = 'adapter-getDevicesFiltered';
|
|
716
|
+
const origin = `${this.id}-${meth}`;
|
|
717
|
+
log.trace(origin);
|
|
718
|
+
|
|
719
|
+
// verify the required fields have been provided
|
|
720
|
+
if (options === undefined || options === null || options === '' || options.length === 0) {
|
|
721
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['options'], null, null, null);
|
|
722
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
723
|
+
return callback(null, errorObj);
|
|
724
|
+
}
|
|
725
|
+
log.debug(`Device Filter Options: ${JSON.stringify(options)}`);
|
|
726
|
+
|
|
727
|
+
// TODO - get pagination working
|
|
728
|
+
// const nextToken = options.start;
|
|
729
|
+
// const maxResults = options.limit;
|
|
730
|
+
|
|
731
|
+
// set up the filter of Device Names
|
|
732
|
+
let filterName = [];
|
|
733
|
+
if (options && options.filter && options.filter.name) {
|
|
734
|
+
// when this hack is removed, remove the lint ignore above
|
|
735
|
+
if (Array.isArray(options.filter.name)) {
|
|
736
|
+
// eslint-disable-next-line prefer-destructuring
|
|
737
|
+
filterName = options.filter.name;
|
|
738
|
+
} else {
|
|
739
|
+
filterName = [options.filter.name];
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
// TODO - get sort and order working
|
|
744
|
+
/*
|
|
745
|
+
if (options && options.sort) {
|
|
746
|
+
reqObj.uriOptions.sort = JSON.stringify(options.sort);
|
|
747
|
+
}
|
|
748
|
+
if (options && options.order) {
|
|
749
|
+
reqObj.uriOptions.order = options.order;
|
|
750
|
+
}
|
|
751
|
+
*/
|
|
752
|
+
try {
|
|
753
|
+
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
754
|
+
// !! you can also replace with a specific call if that is easier
|
|
755
|
+
const uriPath = '/call/toget/devices';
|
|
756
|
+
return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
|
|
757
|
+
// if we received an error or their is no response on the results return an error
|
|
758
|
+
if (error) {
|
|
759
|
+
return callback(null, error);
|
|
760
|
+
}
|
|
761
|
+
if (!result.response) {
|
|
762
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevicesFiltered'], null, null, null);
|
|
763
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
764
|
+
return callback(null, errorObj);
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// !! go through the response - may have to look for sub object
|
|
768
|
+
// handle an array of devices
|
|
769
|
+
if (Array.isArray(result.response)) {
|
|
770
|
+
const myDevices = [];
|
|
771
|
+
|
|
772
|
+
for (let d = 0; d < result.response.length; d += 1) {
|
|
773
|
+
// !! format the data we send back
|
|
774
|
+
// !! these fields are config manager fields you need to map to the data we receive
|
|
775
|
+
const thisDevice = result.response;
|
|
776
|
+
thisDevice.name = thisDevice.systemName;
|
|
777
|
+
thisDevice.ostype = `System-${thisDevice.systemType}`;
|
|
778
|
+
thisDevice.port = thisDevice.systemPort;
|
|
779
|
+
thisDevice.ipaddress = thisDevice.systemIP;
|
|
780
|
+
|
|
781
|
+
// if there is no filter - return the device
|
|
782
|
+
if (filterName.length === 0) {
|
|
783
|
+
myDevices.push(thisDevice);
|
|
784
|
+
} else {
|
|
785
|
+
// if we have to match a filter
|
|
786
|
+
let found = false;
|
|
787
|
+
for (let f = 0; f < filterName.length; f += 1) {
|
|
788
|
+
if (thisDevice.name.indexOf(filterName[f]) >= 0) {
|
|
789
|
+
found = true;
|
|
790
|
+
break;
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
// matching device
|
|
794
|
+
if (found) {
|
|
795
|
+
myDevices.push(thisDevice);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
log.debug(`${origin}: Found #${myDevices.length} devices.`);
|
|
800
|
+
log.debug(`Devices: ${JSON.stringify(myDevices)}`);
|
|
801
|
+
return callback({ total: myDevices.length, list: myDevices });
|
|
802
|
+
}
|
|
803
|
+
// handle a single device response
|
|
804
|
+
// !! format the data we send back
|
|
805
|
+
// !! these fields are config manager fields you need to map to the data we receive
|
|
806
|
+
const thisDevice = result.response;
|
|
807
|
+
thisDevice.name = thisDevice.systemName;
|
|
808
|
+
thisDevice.ostype = `System-${thisDevice.systemType}`;
|
|
809
|
+
thisDevice.port = thisDevice.systemPort;
|
|
810
|
+
thisDevice.ipaddress = thisDevice.systemIP;
|
|
811
|
+
|
|
812
|
+
// if there is no filter - return the device
|
|
813
|
+
if (filterName.length === 0) {
|
|
814
|
+
log.debug(`${origin}: Found #1 device.`);
|
|
815
|
+
log.debug(`Device: ${JSON.stringify(thisDevice)}`);
|
|
816
|
+
return callback({ total: 1, list: [thisDevice] });
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
// if there is a filter need to check for matching device
|
|
820
|
+
let found = false;
|
|
821
|
+
for (let f = 0; f < filterName.length; f += 1) {
|
|
822
|
+
if (thisDevice.name.indexOf(filterName[f]) >= 0) {
|
|
823
|
+
found = true;
|
|
824
|
+
break;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
// matching device
|
|
828
|
+
if (found) {
|
|
829
|
+
log.debug(`${origin}: Found #1 device.`);
|
|
830
|
+
log.debug(`Device Found: ${JSON.stringify(thisDevice)}`);
|
|
831
|
+
return callback({ total: 1, list: [thisDevice] });
|
|
832
|
+
}
|
|
833
|
+
// not a matching device
|
|
834
|
+
log.debug(`${origin}: No matching device found.`);
|
|
835
|
+
return callback({ total: 0, list: [] });
|
|
836
|
+
});
|
|
837
|
+
} catch (ex) {
|
|
838
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
839
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
840
|
+
return callback(null, errorObj);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
/**
|
|
845
|
+
* @summary Gets the status for the provided appliance
|
|
846
|
+
*
|
|
847
|
+
* @function isAlive
|
|
848
|
+
* @param {String} deviceName - the deviceName of the appliance. (required)
|
|
849
|
+
*
|
|
850
|
+
* @param {configCallback} callback - callback function to return the result
|
|
851
|
+
* (appliance isAlive) or the error
|
|
852
|
+
*/
|
|
853
|
+
isAlive(deviceName, callback) {
|
|
854
|
+
const meth = 'adapter-isAlive';
|
|
855
|
+
const origin = `${this.id}-${meth}`;
|
|
856
|
+
log.trace(origin);
|
|
857
|
+
|
|
858
|
+
// verify the required fields have been provided
|
|
859
|
+
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
|
860
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
|
861
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
862
|
+
return callback(null, errorObj);
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
try {
|
|
866
|
+
// need to get the device so we can convert the deviceName to an id
|
|
867
|
+
// !! if we can do a lookup by name the getDevicesFiltered may not be necessary
|
|
868
|
+
const opts = {
|
|
869
|
+
filter: {
|
|
870
|
+
name: deviceName
|
|
871
|
+
}
|
|
872
|
+
};
|
|
873
|
+
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
|
874
|
+
// if we received an error or their is no response on the results return an error
|
|
875
|
+
if (ferr) {
|
|
876
|
+
return callback(null, ferr);
|
|
877
|
+
}
|
|
878
|
+
if (devs.list.length < 1) {
|
|
879
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
|
880
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
881
|
+
return callback(null, errorObj);
|
|
882
|
+
}
|
|
883
|
+
// get the uuid from the device
|
|
884
|
+
const { uuid } = devs.list[0];
|
|
885
|
+
|
|
886
|
+
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
887
|
+
// !! you can also replace with a specific call if that is easier
|
|
888
|
+
const uriPath = `/call/toget/status/${uuid}`;
|
|
889
|
+
return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
|
|
890
|
+
// if we received an error or their is no response on the results return an error
|
|
891
|
+
if (error) {
|
|
892
|
+
return callback(null, error);
|
|
893
|
+
}
|
|
894
|
+
// !! should update this to make sure we are checking for the appropriate object/field
|
|
895
|
+
if (!result.response || !result.response.returnObj || !Object.hasOwnProperty.call(result.response.returnObj, 'statusField')) {
|
|
896
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['isAlive'], null, null, null);
|
|
897
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
898
|
+
return callback(null, errorObj);
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
// !! return the response - Update to the appropriate object/field
|
|
902
|
+
return callback(!result.response.returnObj.statusField);
|
|
903
|
+
});
|
|
904
|
+
});
|
|
905
|
+
} catch (ex) {
|
|
906
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
907
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
908
|
+
return callback(null, errorObj);
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
/**
|
|
913
|
+
* @summary Gets a config for the provided Appliance
|
|
914
|
+
*
|
|
915
|
+
* @function getConfig
|
|
916
|
+
* @param {String} deviceName - the deviceName of the appliance. (required)
|
|
917
|
+
* @param {String} format - the desired format of the config. (optional)
|
|
918
|
+
*
|
|
919
|
+
* @param {configCallback} callback - callback function to return the result
|
|
920
|
+
* (appliance config) or the error
|
|
921
|
+
*/
|
|
922
|
+
getConfig(deviceName, format, callback) {
|
|
923
|
+
const meth = 'adapter-getConfig';
|
|
924
|
+
const origin = `${this.id}-${meth}`;
|
|
925
|
+
log.trace(origin);
|
|
926
|
+
|
|
927
|
+
// verify the required fields have been provided
|
|
928
|
+
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
|
929
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
|
930
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
931
|
+
return callback(null, errorObj);
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
try {
|
|
935
|
+
// need to get the device so we can convert the deviceName to an id
|
|
936
|
+
// !! if we can do a lookup by name the getDevicesFiltered may not be necessary
|
|
937
|
+
const opts = {
|
|
938
|
+
filter: {
|
|
939
|
+
name: deviceName
|
|
940
|
+
}
|
|
941
|
+
};
|
|
942
|
+
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
|
943
|
+
// if we received an error or their is no response on the results return an error
|
|
944
|
+
if (ferr) {
|
|
945
|
+
return callback(null, ferr);
|
|
946
|
+
}
|
|
947
|
+
if (devs.list.length < 1) {
|
|
948
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
|
949
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
950
|
+
return callback(null, errorObj);
|
|
951
|
+
}
|
|
952
|
+
// get the uuid from the device
|
|
953
|
+
const { uuid } = devs.list[0];
|
|
954
|
+
|
|
955
|
+
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
956
|
+
// !! you can also replace with a specific call if that is easier
|
|
957
|
+
const uriPath = `/call/toget/config/${uuid}`;
|
|
958
|
+
return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
|
|
959
|
+
// if we received an error or their is no response on the results return an error
|
|
960
|
+
if (error) {
|
|
961
|
+
return callback(null, error);
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
// return the result
|
|
965
|
+
const newResponse = {
|
|
966
|
+
response: JSON.stringify(result.response, null, 2)
|
|
967
|
+
};
|
|
968
|
+
return callback(newResponse);
|
|
969
|
+
});
|
|
970
|
+
});
|
|
971
|
+
} catch (ex) {
|
|
972
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
973
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
974
|
+
return callback(null, errorObj);
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
/**
|
|
979
|
+
* @summary Gets the device count from the system
|
|
980
|
+
*
|
|
981
|
+
* @function getCount
|
|
982
|
+
*
|
|
983
|
+
* @param {getCallback} callback - callback function to return the result
|
|
984
|
+
* (count) or the error
|
|
985
|
+
*/
|
|
986
|
+
getCount(callback) {
|
|
987
|
+
const meth = 'adapter-getCount';
|
|
988
|
+
const origin = `${this.id}-${meth}`;
|
|
989
|
+
log.trace(origin);
|
|
990
|
+
|
|
991
|
+
// verify the required fields have been provided
|
|
992
|
+
|
|
993
|
+
try {
|
|
994
|
+
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
995
|
+
// !! you can also replace with a specific call if that is easier
|
|
996
|
+
const uriPath = '/call/toget/count';
|
|
997
|
+
return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
|
|
998
|
+
// if we received an error or their is no response on the results return an error
|
|
999
|
+
if (error) {
|
|
1000
|
+
return callback(null, error);
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
// return the result
|
|
1004
|
+
return callback({ count: result.response });
|
|
1005
|
+
});
|
|
1006
|
+
} catch (ex) {
|
|
1007
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
1008
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1009
|
+
return callback(null, errorObj);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
/**
|
|
1014
|
+
* @callback healthCallback
|
|
1015
|
+
* @param {Object} result - the result of the get request (contains an id and a status)
|
|
1016
|
+
*/
|
|
1017
|
+
/**
|
|
1018
|
+
* @callback getCallback
|
|
1019
|
+
* @param {Object} result - the result of the get request (entity/ies)
|
|
1020
|
+
* @param {String} error - any error that occurred
|
|
1021
|
+
*/
|
|
1022
|
+
/**
|
|
1023
|
+
* @callback createCallback
|
|
1024
|
+
* @param {Object} item - the newly created entity
|
|
1025
|
+
* @param {String} error - any error that occurred
|
|
1026
|
+
*/
|
|
1027
|
+
/**
|
|
1028
|
+
* @callback updateCallback
|
|
1029
|
+
* @param {String} status - the status of the update action
|
|
1030
|
+
* @param {String} error - any error that occurred
|
|
1031
|
+
*/
|
|
1032
|
+
/**
|
|
1033
|
+
* @callback deleteCallback
|
|
1034
|
+
* @param {String} status - the status of the delete action
|
|
1035
|
+
* @param {String} error - any error that occurred
|
|
1036
|
+
*/
|
|
1037
|
+
|
|
1038
|
+
/**
|
|
1039
|
+
* @summary Gets the hcma authorization for the call
|
|
1040
|
+
*
|
|
1041
|
+
* @function getAuthorization
|
|
1042
|
+
* @param {String} method - the method for the action we are setting authorization for
|
|
1043
|
+
* @param {String} uripath - the path for the action we are setting authorization for
|
|
1044
|
+
* @param {String} body - the body for the action we are setting authorization for
|
|
1045
|
+
*
|
|
1046
|
+
* @return {Object} the headers to add to the request
|
|
1047
|
+
*/
|
|
1048
|
+
getAuthorization(method, uripath, body) {
|
|
1049
|
+
const origin = `${this.id}-adapter-getAuthorization`;
|
|
1050
|
+
log.trace(origin);
|
|
1051
|
+
|
|
1052
|
+
// Account Info - properties (username, password)
|
|
1053
|
+
const apiVersion = this.allProps.authentication.api_version;
|
|
1054
|
+
const signatureVersion = this.allProps.authentication.signature_version;
|
|
1055
|
+
const uniqueCode = this.allProps.authentication.unique_code;
|
|
1056
|
+
const clientId = this.allProps.authentication.client_id;
|
|
1057
|
+
const clisecret = this.allProps.authentication.client_secret;
|
|
1058
|
+
|
|
1059
|
+
// if missing accessId or accessKey
|
|
1060
|
+
if (!apiVersion || !signatureVersion || !clientId || !uniqueCode || !clisecret) {
|
|
1061
|
+
return -1;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
let usePath = `${this.allProps.base_path}/${uripath}`;
|
|
1065
|
+
usePath = usePath.replace(/\/\//g, '/');
|
|
1066
|
+
let useQuery = '';
|
|
1067
|
+
|
|
1068
|
+
// need to extract the query from the uriPath
|
|
1069
|
+
if (usePath.split('?').length === 2) {
|
|
1070
|
+
const parts = usePath.split('?');
|
|
1071
|
+
useQuery = `${parts[1]}`;
|
|
1072
|
+
usePath = `${parts[0]}`;
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
// Get time + 10 seconds
|
|
1076
|
+
// const epoch = (new Date()).getTime();
|
|
1077
|
+
const epoch = (new Date()).getTime() + 10000;
|
|
1078
|
+
// const moment = require('moment');
|
|
1079
|
+
// const tepoch = moment().add(10, 'seconds').valueOf()
|
|
1080
|
+
|
|
1081
|
+
// add the timestamp into the result - will be added as headers
|
|
1082
|
+
const result = {
|
|
1083
|
+
apiVersion,
|
|
1084
|
+
signatureVersion,
|
|
1085
|
+
uniqueCode,
|
|
1086
|
+
clientId,
|
|
1087
|
+
timestamp: epoch
|
|
1088
|
+
};
|
|
1089
|
+
|
|
1090
|
+
try {
|
|
1091
|
+
let commandType = '';
|
|
1092
|
+
if (body) {
|
|
1093
|
+
commandType = `&${JSON.stringify(body)}`;
|
|
1094
|
+
}
|
|
1095
|
+
let canostring = `apiVersion=${apiVersion}&clientId=${clientId}&signatureVersion=${signatureVersion}×tamp=${epoch}&uniqueCode=${uniqueCode}`;
|
|
1096
|
+
if (useQuery) {
|
|
1097
|
+
canostring = `apiVersion=${apiVersion}&clientId=${clientId}&${useQuery}&signatureVersion=${signatureVersion}×tamp=${epoch}&uniqueCode=${uniqueCode}`;
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
// DO WE USE BODY ON A POST CALL
|
|
1101
|
+
const stringtosign = method + usePath + canostring + commandType + clisecret;
|
|
1102
|
+
|
|
1103
|
+
// get the signature - HMAC256 and Hex
|
|
1104
|
+
const accessKey = clientId + uniqueCode;
|
|
1105
|
+
const sign = cryptoJS.HmacSHA256(stringtosign, accessKey);
|
|
1106
|
+
const signHex = cryptoJS.enc.Hex.stringify(sign);
|
|
1107
|
+
// const sign = crypto.createHmac('sha256', accessKey).update(stringtosign).digest('hex');
|
|
1108
|
+
// const signHex = Buffer.from((sign).toString('base64'));
|
|
1109
|
+
|
|
1110
|
+
// add the signature into the result - will be added as headers
|
|
1111
|
+
result.signature = signHex;
|
|
1112
|
+
return result;
|
|
1113
|
+
} catch (ex) {
|
|
1114
|
+
log.error(`Took exception creating signature: ${ex}`);
|
|
1115
|
+
return -1;
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
/**
|
|
1120
|
+
* @function getDeviceTotal
|
|
1121
|
+
* @pronghornType method
|
|
1122
|
+
* @name getDeviceTotal
|
|
1123
|
+
* @summary Get Device Total
|
|
1124
|
+
*
|
|
1125
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
1126
|
+
* @return {object} results - An object containing the response of the action
|
|
1127
|
+
*
|
|
1128
|
+
* @route {GET} /getDeviceTotal
|
|
1129
|
+
* @roles admin
|
|
1130
|
+
* @task true
|
|
1131
|
+
*/
|
|
1132
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
1133
|
+
getDeviceTotal(callback) {
|
|
1134
|
+
const meth = 'adapter-getDeviceTotal';
|
|
1135
|
+
const origin = `${this.id}-${meth}`;
|
|
1136
|
+
log.trace(origin);
|
|
1137
|
+
|
|
1138
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
1139
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
1140
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1141
|
+
return callback(null, errorObj);
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
1145
|
+
|
|
1146
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
1147
|
+
const queryParamsAvailable = {};
|
|
1148
|
+
const queryParams = {};
|
|
1149
|
+
const pathVars = [];
|
|
1150
|
+
const bodyVars = {};
|
|
1151
|
+
const callSign = this.getAuthorization('GET', '/dashboard/deviceTotal', null);
|
|
1152
|
+
|
|
1153
|
+
// if the callAuth was unsuccessful
|
|
1154
|
+
if (callSign === -1) {
|
|
1155
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['call signature'], null, null, null);
|
|
1156
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1157
|
+
return callback(null, errorObj);
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
1161
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
1162
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
1163
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
1164
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
1165
|
+
}
|
|
1166
|
+
});
|
|
1167
|
+
|
|
1168
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
1169
|
+
// see adapter code documentation for more information on the request object's fields
|
|
1170
|
+
const reqObj = {
|
|
1171
|
+
payload: bodyVars,
|
|
1172
|
+
uriPathVars: pathVars,
|
|
1173
|
+
uriQuery: queryParams,
|
|
1174
|
+
addlHeaders: callSign
|
|
1175
|
+
};
|
|
1176
|
+
|
|
1177
|
+
try {
|
|
1178
|
+
// Make the call -
|
|
1179
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
1180
|
+
return this.requestHandlerInst.identifyRequest('Dashboard', 'getDeviceTotal', reqObj, true, (irReturnData, irReturnError) => {
|
|
1181
|
+
// if we received an error or their is no response on the results
|
|
1182
|
+
// return an error
|
|
1183
|
+
if (irReturnError) {
|
|
1184
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
1185
|
+
return callback(null, irReturnError);
|
|
1186
|
+
}
|
|
1187
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
1188
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDeviceTotal'], null, null, null);
|
|
1189
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1190
|
+
return callback(null, errorObj);
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
1194
|
+
// return the response
|
|
1195
|
+
return callback(irReturnData, null);
|
|
1196
|
+
});
|
|
1197
|
+
} catch (ex) {
|
|
1198
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
1199
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1200
|
+
return callback(null, errorObj);
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
/**
|
|
1205
|
+
* @function getNetworkTotal
|
|
1206
|
+
* @pronghornType method
|
|
1207
|
+
* @name getNetworkTotal
|
|
1208
|
+
* @summary Get Network Total
|
|
1209
|
+
*
|
|
1210
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
1211
|
+
* @return {object} results - An object containing the response of the action
|
|
1212
|
+
*
|
|
1213
|
+
* @route {GET} /getNetworkTotal
|
|
1214
|
+
* @roles admin
|
|
1215
|
+
* @task true
|
|
1216
|
+
*/
|
|
1217
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
1218
|
+
getNetworkTotal(callback) {
|
|
1219
|
+
const meth = 'adapter-getNetworkTotal';
|
|
1220
|
+
const origin = `${this.id}-${meth}`;
|
|
1221
|
+
log.trace(origin);
|
|
1222
|
+
|
|
1223
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
1224
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
1225
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1226
|
+
return callback(null, errorObj);
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
1230
|
+
|
|
1231
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
1232
|
+
const queryParamsAvailable = {};
|
|
1233
|
+
const queryParams = {};
|
|
1234
|
+
const pathVars = [];
|
|
1235
|
+
const bodyVars = {};
|
|
1236
|
+
const callSign = this.getAuthorization('GET', '/dashboard/networkTotal', null);
|
|
1237
|
+
|
|
1238
|
+
// if the callAuth was unsuccessful
|
|
1239
|
+
if (callSign === -1) {
|
|
1240
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['call signature'], null, null, null);
|
|
1241
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1242
|
+
return callback(null, errorObj);
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
1246
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
1247
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
1248
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
1249
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
1250
|
+
}
|
|
1251
|
+
});
|
|
1252
|
+
|
|
1253
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
1254
|
+
// see adapter code documentation for more information on the request object's fields
|
|
1255
|
+
const reqObj = {
|
|
1256
|
+
payload: bodyVars,
|
|
1257
|
+
uriPathVars: pathVars,
|
|
1258
|
+
uriQuery: queryParams,
|
|
1259
|
+
addlHeaders: callSign
|
|
1260
|
+
};
|
|
1261
|
+
|
|
1262
|
+
try {
|
|
1263
|
+
// Make the call -
|
|
1264
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
1265
|
+
return this.requestHandlerInst.identifyRequest('Dashboard', 'getNetworkTotal', reqObj, true, (irReturnData, irReturnError) => {
|
|
1266
|
+
// if we received an error or their is no response on the results
|
|
1267
|
+
// return an error
|
|
1268
|
+
if (irReturnError) {
|
|
1269
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
1270
|
+
return callback(null, irReturnError);
|
|
1271
|
+
}
|
|
1272
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
1273
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getNetworkTotal'], null, null, null);
|
|
1274
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1275
|
+
return callback(null, errorObj);
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
1279
|
+
// return the response
|
|
1280
|
+
return callback(irReturnData, null);
|
|
1281
|
+
});
|
|
1282
|
+
} catch (ex) {
|
|
1283
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
1284
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1285
|
+
return callback(null, errorObj);
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
/**
|
|
1290
|
+
* @function getDeviceDetails
|
|
1291
|
+
* @pronghornType method
|
|
1292
|
+
* @name getDeviceDetails
|
|
1293
|
+
* @summary Get Device Details
|
|
1294
|
+
*
|
|
1295
|
+
* @param {string} serialNumber - serial number
|
|
1296
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
1297
|
+
* @return {object} results - An object containing the response of the action
|
|
1298
|
+
*
|
|
1299
|
+
* @route {POST} /getDeviceDetails
|
|
1300
|
+
* @roles admin
|
|
1301
|
+
* @task true
|
|
1302
|
+
*/
|
|
1303
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
1304
|
+
getDeviceDetails(serialNumber, callback) {
|
|
1305
|
+
const meth = 'adapter-getDeviceDetails';
|
|
1306
|
+
const origin = `${this.id}-${meth}`;
|
|
1307
|
+
log.trace(origin);
|
|
1308
|
+
|
|
1309
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
1310
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
1311
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1312
|
+
return callback(null, errorObj);
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
1316
|
+
if (serialNumber === undefined || serialNumber === null || serialNumber === '') {
|
|
1317
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['serialNumber'], null, null, null);
|
|
1318
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1319
|
+
return callback(null, errorObj);
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
1323
|
+
const queryParamsAvailable = {};
|
|
1324
|
+
const queryParams = {};
|
|
1325
|
+
const pathVars = [serialNumber];
|
|
1326
|
+
const bodyVars = {};
|
|
1327
|
+
const callSign = this.getAuthorization('GET', `/device/devices/${serialNumber}`, null);
|
|
1328
|
+
|
|
1329
|
+
// if the callAuth was unsuccessful
|
|
1330
|
+
if (callSign === -1) {
|
|
1331
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['call signature'], null, null, null);
|
|
1332
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1333
|
+
return callback(null, errorObj);
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
1337
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
1338
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
1339
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
1340
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
1341
|
+
}
|
|
1342
|
+
});
|
|
1343
|
+
|
|
1344
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
1345
|
+
// see adapter code documentation for more information on the request object's fields
|
|
1346
|
+
const reqObj = {
|
|
1347
|
+
payload: bodyVars,
|
|
1348
|
+
uriPathVars: pathVars,
|
|
1349
|
+
uriQuery: queryParams,
|
|
1350
|
+
addlHeaders: callSign
|
|
1351
|
+
};
|
|
1352
|
+
|
|
1353
|
+
try {
|
|
1354
|
+
// Make the call -
|
|
1355
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
1356
|
+
return this.requestHandlerInst.identifyRequest('Device', 'getDeviceDetails', reqObj, true, (irReturnData, irReturnError) => {
|
|
1357
|
+
// if we received an error or their is no response on the results
|
|
1358
|
+
// return an error
|
|
1359
|
+
if (irReturnError) {
|
|
1360
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
1361
|
+
return callback(null, irReturnError);
|
|
1362
|
+
}
|
|
1363
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
1364
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDeviceDetails'], null, null, null);
|
|
1365
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1366
|
+
return callback(null, errorObj);
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
1370
|
+
// return the response
|
|
1371
|
+
return callback(irReturnData, null);
|
|
1372
|
+
});
|
|
1373
|
+
} catch (ex) {
|
|
1374
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
1375
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1376
|
+
return callback(null, errorObj);
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
/**
|
|
1381
|
+
* @function getDeviceFirmwareList
|
|
1382
|
+
* @pronghornType method
|
|
1383
|
+
* @name getDeviceFirmwareList
|
|
1384
|
+
* @summary Get Device Firmware List
|
|
1385
|
+
*
|
|
1386
|
+
* @param {string} serialNumber - device serial number
|
|
1387
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
1388
|
+
* @return {object} results - An object containing the response of the action
|
|
1389
|
+
*
|
|
1390
|
+
* @route {POST} /getDeviceFirmwareList
|
|
1391
|
+
* @roles admin
|
|
1392
|
+
* @task true
|
|
1393
|
+
*/
|
|
1394
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
1395
|
+
getDeviceFirmwareList(serialNumber, callback) {
|
|
1396
|
+
const meth = 'adapter-getDeviceFirmwareList';
|
|
1397
|
+
const origin = `${this.id}-${meth}`;
|
|
1398
|
+
log.trace(origin);
|
|
1399
|
+
|
|
1400
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
1401
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
1402
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1403
|
+
return callback(null, errorObj);
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
1407
|
+
if (serialNumber === undefined || serialNumber === null || serialNumber === '') {
|
|
1408
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['serialNumber'], null, null, null);
|
|
1409
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1410
|
+
return callback(null, errorObj);
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
1414
|
+
const queryParamsAvailable = {};
|
|
1415
|
+
const queryParams = {};
|
|
1416
|
+
const pathVars = [serialNumber];
|
|
1417
|
+
const bodyVars = {};
|
|
1418
|
+
const callSign = this.getAuthorization('GET', `/devices/${serialNumber}/firmwares`, null);
|
|
1419
|
+
|
|
1420
|
+
// if the callAuth was unsuccessful
|
|
1421
|
+
if (callSign === -1) {
|
|
1422
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['call signature'], null, null, null);
|
|
1423
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1424
|
+
return callback(null, errorObj);
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
1428
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
1429
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
1430
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
1431
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
1432
|
+
}
|
|
1433
|
+
});
|
|
1434
|
+
|
|
1435
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
1436
|
+
// see adapter code documentation for more information on the request object's fields
|
|
1437
|
+
const reqObj = {
|
|
1438
|
+
payload: bodyVars,
|
|
1439
|
+
uriPathVars: pathVars,
|
|
1440
|
+
uriQuery: queryParams,
|
|
1441
|
+
addlHeaders: callSign
|
|
1442
|
+
};
|
|
1443
|
+
|
|
1444
|
+
try {
|
|
1445
|
+
// Make the call -
|
|
1446
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
1447
|
+
return this.requestHandlerInst.identifyRequest('Device', 'getDeviceFirmwareList', reqObj, true, (irReturnData, irReturnError) => {
|
|
1448
|
+
// if we received an error or their is no response on the results
|
|
1449
|
+
// return an error
|
|
1450
|
+
if (irReturnError) {
|
|
1451
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
1452
|
+
return callback(null, irReturnError);
|
|
1453
|
+
}
|
|
1454
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
1455
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDeviceFirmwareList'], null, null, null);
|
|
1456
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1457
|
+
return callback(null, errorObj);
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
1461
|
+
// return the response
|
|
1462
|
+
return callback(irReturnData, null);
|
|
1463
|
+
});
|
|
1464
|
+
} catch (ex) {
|
|
1465
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
1466
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1467
|
+
return callback(null, errorObj);
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
/**
|
|
1472
|
+
* @function runCommandOnDevice
|
|
1473
|
+
* @pronghornType method
|
|
1474
|
+
* @name runCommandOnDevice
|
|
1475
|
+
* @summary Run Command on Device
|
|
1476
|
+
*
|
|
1477
|
+
* @param {} serialNumber - device serial number
|
|
1478
|
+
* @param {object} body - { commandType: , softwareVersionId: }
|
|
1479
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
1480
|
+
* @return {object} results - An object containing the response of the action
|
|
1481
|
+
*
|
|
1482
|
+
* @route {POST} /runCommandOnDevice
|
|
1483
|
+
* @roles admin
|
|
1484
|
+
* @task true
|
|
1485
|
+
*/
|
|
1486
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
1487
|
+
runCommandOnDevice(serialNumber, body, callback) {
|
|
1488
|
+
const meth = 'adapter-runCommandOnDevice';
|
|
1489
|
+
const origin = `${this.id}-${meth}`;
|
|
1490
|
+
log.trace(origin);
|
|
1491
|
+
|
|
1492
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
1493
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
1494
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1495
|
+
return callback(null, errorObj);
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
1499
|
+
if (serialNumber === undefined || serialNumber === null || serialNumber === '') {
|
|
1500
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['serialNumber'], null, null, null);
|
|
1501
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1502
|
+
return callback(null, errorObj);
|
|
1503
|
+
}
|
|
1504
|
+
if (body === undefined || body === null || body === '') {
|
|
1505
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
1506
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1507
|
+
return callback(null, errorObj);
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
1511
|
+
const queryParamsAvailable = {};
|
|
1512
|
+
const queryParams = {};
|
|
1513
|
+
const pathVars = [serialNumber];
|
|
1514
|
+
const bodyVars = body;
|
|
1515
|
+
const callSign = this.getAuthorization('PUT', `/devices/${serialNumber}`, bodyVars);
|
|
1516
|
+
|
|
1517
|
+
// if the callAuth was unsuccessful
|
|
1518
|
+
if (callSign === -1) {
|
|
1519
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['call signature'], null, null, null);
|
|
1520
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1521
|
+
return callback(null, errorObj);
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
1525
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
1526
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
1527
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
1528
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
1529
|
+
}
|
|
1530
|
+
});
|
|
1531
|
+
|
|
1532
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
1533
|
+
// see adapter code documentation for more information on the request object's fields
|
|
1534
|
+
const reqObj = {
|
|
1535
|
+
payload: bodyVars,
|
|
1536
|
+
uriPathVars: pathVars,
|
|
1537
|
+
uriQuery: queryParams,
|
|
1538
|
+
addlHeaders: callSign
|
|
1539
|
+
};
|
|
1540
|
+
|
|
1541
|
+
try {
|
|
1542
|
+
// Make the call -
|
|
1543
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
1544
|
+
return this.requestHandlerInst.identifyRequest('Device', 'runCommandOnDevice', reqObj, true, (irReturnData, irReturnError) => {
|
|
1545
|
+
// if we received an error or their is no response on the results
|
|
1546
|
+
// return an error
|
|
1547
|
+
if (irReturnError) {
|
|
1548
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
1549
|
+
return callback(null, irReturnError);
|
|
1550
|
+
}
|
|
1551
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
1552
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['runCommandOnDevice'], null, null, null);
|
|
1553
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1554
|
+
return callback(null, errorObj);
|
|
1555
|
+
}
|
|
1556
|
+
|
|
1557
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
1558
|
+
// return the response
|
|
1559
|
+
return callback(irReturnData, null);
|
|
1560
|
+
});
|
|
1561
|
+
} catch (ex) {
|
|
1562
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
1563
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1564
|
+
return callback(null, errorObj);
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
/**
|
|
1569
|
+
* @function getFirmwareUpdateResult
|
|
1570
|
+
* @pronghornType method
|
|
1571
|
+
* @name getFirmwareUpdateResult
|
|
1572
|
+
* @summary Get Firmware Update Result
|
|
1573
|
+
*
|
|
1574
|
+
* @param {string} commandId - commandId
|
|
1575
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
1576
|
+
* @return {object} results - An object containing the response of the action
|
|
1577
|
+
*
|
|
1578
|
+
* @route {POST} /getFirmwareUpdateResult
|
|
1579
|
+
* @roles admin
|
|
1580
|
+
* @task true
|
|
1581
|
+
*/
|
|
1582
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
1583
|
+
getFirmwareUpdateResult(commandId, callback) {
|
|
1584
|
+
const meth = 'adapter-getFirmwareUpdateResult';
|
|
1585
|
+
const origin = `${this.id}-${meth}`;
|
|
1586
|
+
log.trace(origin);
|
|
1587
|
+
|
|
1588
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
1589
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
1590
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1591
|
+
return callback(null, errorObj);
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
1595
|
+
if (commandId === undefined || commandId === null || commandId === '') {
|
|
1596
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['commandId'], null, null, null);
|
|
1597
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1598
|
+
return callback(null, errorObj);
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
1602
|
+
const queryParamsAvailable = {};
|
|
1603
|
+
const queryParams = {};
|
|
1604
|
+
const pathVars = [commandId];
|
|
1605
|
+
const bodyVars = {};
|
|
1606
|
+
const callSign = this.getAuthorization('GET', `/command/${commandId}`, null);
|
|
1607
|
+
|
|
1608
|
+
// if the callAuth was unsuccessful
|
|
1609
|
+
if (callSign === -1) {
|
|
1610
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['call signature'], null, null, null);
|
|
1611
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1612
|
+
return callback(null, errorObj);
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
1616
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
1617
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
1618
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
1619
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
1620
|
+
}
|
|
1621
|
+
});
|
|
1622
|
+
|
|
1623
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
1624
|
+
// see adapter code documentation for more information on the request object's fields
|
|
1625
|
+
const reqObj = {
|
|
1626
|
+
payload: bodyVars,
|
|
1627
|
+
uriPathVars: pathVars,
|
|
1628
|
+
uriQuery: queryParams,
|
|
1629
|
+
addlHeaders: callSign
|
|
1630
|
+
};
|
|
1631
|
+
|
|
1632
|
+
try {
|
|
1633
|
+
// Make the call -
|
|
1634
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
1635
|
+
return this.requestHandlerInst.identifyRequest('Device', 'getFirmwareUpdateResult', reqObj, true, (irReturnData, irReturnError) => {
|
|
1636
|
+
// if we received an error or their is no response on the results
|
|
1637
|
+
// return an error
|
|
1638
|
+
if (irReturnError) {
|
|
1639
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
1640
|
+
return callback(null, irReturnError);
|
|
1641
|
+
}
|
|
1642
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
1643
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getFirmwareUpdateResult'], null, null, null);
|
|
1644
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1645
|
+
return callback(null, errorObj);
|
|
1646
|
+
}
|
|
1647
|
+
|
|
1648
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
1649
|
+
// return the response
|
|
1650
|
+
return callback(irReturnData, null);
|
|
1651
|
+
});
|
|
1652
|
+
} catch (ex) {
|
|
1653
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
1654
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1655
|
+
return callback(null, errorObj);
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
|
|
1660
|
+
module.exports = Robustel;
|