@itentialopensource/adapter-netbrain 1.0.2 → 1.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.
Files changed (41) hide show
  1. package/AUTH.md +39 -0
  2. package/BROKER.md +199 -0
  3. package/CALLS.md +169 -0
  4. package/CHANGELOG.md +63 -27
  5. package/CODE_OF_CONDUCT.md +12 -17
  6. package/CONTRIBUTING.md +88 -74
  7. package/ENHANCE.md +69 -0
  8. package/PROPERTIES.md +641 -0
  9. package/README.md +225 -502
  10. package/SUMMARY.md +9 -0
  11. package/SYSTEMINFO.md +11 -0
  12. package/TROUBLESHOOT.md +47 -0
  13. package/adapter.js +434 -76
  14. package/adapterBase.js +1021 -245
  15. package/entities/.generic/action.json +110 -5
  16. package/entities/.generic/schema.json +6 -1
  17. package/error.json +12 -0
  18. package/package.json +18 -11
  19. package/pronghorn.json +646 -382
  20. package/propertiesDecorators.json +14 -0
  21. package/propertiesSchema.json +438 -2
  22. package/refs?service=git-upload-pack +0 -0
  23. package/report/adapterInfo.json +10 -0
  24. package/report/updateReport1653178689558.json +120 -0
  25. package/sampleProperties.json +94 -2
  26. package/test/integration/adapterTestBasicGet.js +1 -1
  27. package/test/integration/adapterTestIntegration.js +28 -104
  28. package/test/unit/adapterBaseTestUnit.js +34 -26
  29. package/test/unit/adapterTestUnit.js +641 -114
  30. package/utils/adapterInfo.js +206 -0
  31. package/utils/addAuth.js +94 -0
  32. package/utils/basicGet.js +1 -14
  33. package/utils/entitiesToDB.js +179 -0
  34. package/utils/modify.js +1 -1
  35. package/utils/patches2bundledDeps.js +90 -0
  36. package/utils/pre-commit.sh +3 -0
  37. package/utils/removeHooks.js +20 -0
  38. package/utils/tbScript.js +43 -22
  39. package/utils/tbUtils.js +126 -29
  40. package/utils/testRunner.js +16 -16
  41. package/utils/troubleshootingAdapter.js +2 -26
package/adapter.js CHANGED
@@ -73,19 +73,66 @@ class Netbrain extends AdapterBaseCl {
73
73
  * @param {Callback} callback - The results of the call
74
74
  */
75
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);
76
+ let myRequest = reqObj;
77
+ const origin = `${this.id}-adapter-healthCheck`;
78
+
79
+ // we are overriding the adapterBase healthcheck so that it goes through the same process as other NetBrain calls.
80
+ if (this.healthcheckQuery && Object.keys(this.healthcheckQuery).length > 0) {
81
+ if (myRequest && myRequest.uriQuery) {
82
+ myRequest.uriQuery = { ...myRequest.uriQuery, ...this.healthcheckQuery };
83
+ } else if (myRequest) {
84
+ myRequest.uriQuery = this.healthcheckQuery;
85
+ } else {
86
+ myRequest = {
87
+ uriQuery: this.healthcheckQuery
88
+ };
89
+ }
80
90
  }
81
- super.healthCheck(newReq, callback);
91
+ // super.healthCheck(newReq, callback);
92
+ return this.processRequest('.system', 'healthcheck', myRequest, false, 0, (irReturnData, irReturnError) => {
93
+ // unhealthy
94
+ if (irReturnError) {
95
+ // if we were healthy, toggle health
96
+ if (this.healthy) {
97
+ this.emit('OFFLINE', { id: this.id });
98
+ this.emit('DEGRADED', { id: this.id });
99
+ this.healthy = false;
100
+ log.error(`${origin}: HEALTH CHECK - Error ${irReturnError}`);
101
+ } else {
102
+ // still log but set the level to trace
103
+ log.trace(`${origin}: HEALTH CHECK - Still Errors ${irReturnError}`);
104
+ }
105
+
106
+ return callback(false);
107
+ }
108
+ // if we were unhealthy, toggle health
109
+ if (!this.healthy) {
110
+ this.emit('FIXED', { id: this.id });
111
+ this.emit('ONLINE', { id: this.id });
112
+ this.healthy = true;
113
+ log.info(`${origin}: HEALTH CHECK SUCCESSFUL`);
114
+ } else {
115
+ // still log but set the level to trace
116
+ log.trace(`${origin}: HEALTH CHECK STILL SUCCESSFUL`);
117
+ }
118
+ return callback(true);
119
+ });
82
120
  }
83
121
 
84
122
  /**
85
- * @getWorkflowFunctions
123
+ * @iapGetAdapterWorkflowFunctions
86
124
  */
87
- getWorkflowFunctions(inIgnore) {
88
- let myIgnore = ['processRequest'];
125
+ iapGetAdapterWorkflowFunctions(inIgnore) {
126
+ let myIgnore = [
127
+ 'healthCheck',
128
+ 'iapGetAdapterWorkflowFunctions',
129
+ 'iapHasAdapterEntity',
130
+ 'iapVerifyAdapterCapability',
131
+ 'iapUpdateAdapterEntityCache',
132
+ 'hasEntities',
133
+ 'getAuthorization',
134
+ 'processRequest'
135
+ ];
89
136
  if (!inIgnore && Array.isArray(inIgnore)) {
90
137
  myIgnore = inIgnore;
91
138
  } else if (!inIgnore && typeof inIgnore === 'string') {
@@ -96,15 +143,15 @@ class Netbrain extends AdapterBaseCl {
96
143
  // you can add specific methods that you do not want to be workflow functions to ignore like below
97
144
  // myIgnore.push('myMethodNotInWorkflow');
98
145
 
99
- return super.getWorkflowFunctions(myIgnore);
146
+ return super.iapGetAdapterWorkflowFunctions(myIgnore);
100
147
  }
101
148
 
102
149
  /**
103
- * updateAdapterConfiguration is used to update any of the adapter configuration files. This
150
+ * iapUpdateAdapterConfiguration is used to update any of the adapter configuration files. This
104
151
  * allows customers to make changes to adapter configuration without having to be on the
105
152
  * file system.
106
153
  *
107
- * @function updateAdapterConfiguration
154
+ * @function iapUpdateAdapterConfiguration
108
155
  * @param {string} configFile - the name of the file being updated (required)
109
156
  * @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
110
157
  * @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
@@ -112,36 +159,42 @@ class Netbrain extends AdapterBaseCl {
112
159
  * @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
113
160
  * @param {Callback} callback - The results of the call
114
161
  */
115
- updateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
116
- const origin = `${this.id}-adapter-updateAdapterConfiguration`;
162
+ iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
163
+ const meth = 'adapter-iapUpdateAdapterConfiguration';
164
+ const origin = `${this.id}-${meth}`;
117
165
  log.trace(origin);
118
- super.updateAdapterConfiguration(configFile, changes, entity, type, action, callback);
166
+
167
+ super.iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback);
119
168
  }
120
169
 
121
170
  /**
122
171
  * See if the API path provided is found in this adapter
123
172
  *
124
- * @function findPath
173
+ * @function iapFindAdapterPath
125
174
  * @param {string} apiPath - the api path to check on
126
175
  * @param {Callback} callback - The results of the call
127
176
  */
128
- findPath(apiPath, callback) {
129
- const origin = `${this.id}-adapter-findPath`;
177
+ iapFindAdapterPath(apiPath, callback) {
178
+ const meth = 'adapter-iapFindAdapterPath';
179
+ const origin = `${this.id}-${meth}`;
130
180
  log.trace(origin);
131
- super.findPath(apiPath, callback);
181
+
182
+ super.iapFindAdapterPath(apiPath, callback);
132
183
  }
133
184
 
134
185
  /**
135
186
  * @summary Suspends adapter
136
187
  *
137
- * @function suspend
188
+ * @function iapSuspendAdapter
138
189
  * @param {Callback} callback - callback function
139
190
  */
140
- suspend(mode, callback) {
141
- const origin = `${this.id}-adapter-suspend`;
191
+ iapSuspendAdapter(mode, callback) {
192
+ const meth = 'adapter-iapSuspendAdapter';
193
+ const origin = `${this.id}-${meth}`;
142
194
  log.trace(origin);
195
+
143
196
  try {
144
- return super.suspend(mode, callback);
197
+ return super.iapSuspendAdapter(mode, callback);
145
198
  } catch (error) {
146
199
  log.error(`${origin}: ${error}`);
147
200
  return callback(null, error);
@@ -151,14 +204,16 @@ class Netbrain extends AdapterBaseCl {
151
204
  /**
152
205
  * @summary Unsuspends adapter
153
206
  *
154
- * @function unsuspend
207
+ * @function iapUnsuspendAdapter
155
208
  * @param {Callback} callback - callback function
156
209
  */
157
- unsuspend(callback) {
158
- const origin = `${this.id}-adapter-unsuspend`;
210
+ iapUnsuspendAdapter(callback) {
211
+ const meth = 'adapter-iapUnsuspendAdapter';
212
+ const origin = `${this.id}-${meth}`;
159
213
  log.trace(origin);
214
+
160
215
  try {
161
- return super.unsuspend(callback);
216
+ return super.iapUnsuspendAdapter(callback);
162
217
  } catch (error) {
163
218
  log.error(`${origin}: ${error}`);
164
219
  return callback(null, error);
@@ -168,29 +223,33 @@ class Netbrain extends AdapterBaseCl {
168
223
  /**
169
224
  * @summary Get the Adaoter Queue
170
225
  *
171
- * @function getQueue
226
+ * @function iapGetAdapterQueue
172
227
  * @param {Callback} callback - callback function
173
228
  */
174
- getQueue(callback) {
175
- const origin = `${this.id}-adapter-getQueue`;
229
+ iapGetAdapterQueue(callback) {
230
+ const meth = 'adapter-iapGetAdapterQueue';
231
+ const origin = `${this.id}-${meth}`;
176
232
  log.trace(origin);
177
- return super.getQueue(callback);
233
+
234
+ return super.iapGetAdapterQueue(callback);
178
235
  }
179
236
 
180
237
  /**
181
238
  * @summary Runs troubleshoot scripts for adapter
182
239
  *
183
- * @function troubleshoot
240
+ * @function iapTroubleshootAdapter
184
241
  * @param {Object} props - the connection, healthcheck and authentication properties
185
242
  *
186
243
  * @param {boolean} persistFlag - whether the adapter properties should be updated
187
244
  * @param {Callback} callback - The results of the call
188
245
  */
189
- troubleshoot(props, persistFlag, callback) {
190
- const origin = `${this.id}-adapter-troubleshoot`;
246
+ iapTroubleshootAdapter(props, persistFlag, callback) {
247
+ const meth = 'adapter-iapTroubleshootAdapter';
248
+ const origin = `${this.id}-${meth}`;
191
249
  log.trace(origin);
250
+
192
251
  try {
193
- return super.troubleshoot(props, persistFlag, this, callback);
252
+ return super.iapTroubleshootAdapter(props, persistFlag, this, callback);
194
253
  } catch (error) {
195
254
  log.error(`${origin}: ${error}`);
196
255
  return callback(null, error);
@@ -200,15 +259,17 @@ class Netbrain extends AdapterBaseCl {
200
259
  /**
201
260
  * @summary runs healthcheck script for adapter
202
261
  *
203
- * @function runHealthcheck
262
+ * @function iapRunAdapterHealthcheck
204
263
  * @param {Adapter} adapter - adapter instance to troubleshoot
205
264
  * @param {Callback} callback - callback function
206
265
  */
207
- runHealthcheck(callback) {
208
- const origin = `${this.id}-adapter-runHealthcheck`;
266
+ iapRunAdapterHealthcheck(callback) {
267
+ const meth = 'adapter-iapRunAdapterHealthcheck';
268
+ const origin = `${this.id}-${meth}`;
209
269
  log.trace(origin);
270
+
210
271
  try {
211
- return super.runHealthcheck(this, callback);
272
+ return super.iapRunAdapterHealthcheck(this, callback);
212
273
  } catch (error) {
213
274
  log.error(`${origin}: ${error}`);
214
275
  return callback(null, error);
@@ -218,14 +279,16 @@ class Netbrain extends AdapterBaseCl {
218
279
  /**
219
280
  * @summary runs connectivity check script for adapter
220
281
  *
221
- * @function runConnectivity
282
+ * @function iapRunAdapterConnectivity
222
283
  * @param {Callback} callback - callback function
223
284
  */
224
- runConnectivity(callback) {
225
- const origin = `${this.id}-adapter-runConnectivity`;
285
+ iapRunAdapterConnectivity(callback) {
286
+ const meth = 'adapter-iapRunAdapterConnectivity';
287
+ const origin = `${this.id}-${meth}`;
226
288
  log.trace(origin);
289
+
227
290
  try {
228
- return super.runConnectivity(callback);
291
+ return super.iapRunAdapterConnectivity(callback);
229
292
  } catch (error) {
230
293
  log.error(`${origin}: ${error}`);
231
294
  return callback(null, error);
@@ -235,44 +298,67 @@ class Netbrain extends AdapterBaseCl {
235
298
  /**
236
299
  * @summary runs basicGet script for adapter
237
300
  *
238
- * @function runBasicGet
301
+ * @function iapRunAdapterBasicGet
239
302
  * @param {Callback} callback - callback function
240
303
  */
241
- runBasicGet(callback) {
242
- const origin = `${this.id}-adapter-runBasicGet`;
304
+ iapRunAdapterBasicGet(callback) {
305
+ const meth = 'adapter-iapRunAdapterBasicGet';
306
+ const origin = `${this.id}-${meth}`;
243
307
  log.trace(origin);
308
+
244
309
  try {
245
- return super.runBasicGet(callback);
310
+ return super.iapRunAdapterBasicGet(callback);
246
311
  } catch (error) {
247
312
  log.error(`${origin}: ${error}`);
248
313
  return callback(null, error);
249
314
  }
250
315
  }
251
316
 
317
+ /**
318
+ * @summary moves entites into Mongo DB
319
+ *
320
+ * @function iapMoveAdapterEntitiesToDB
321
+ * @param {getCallback} callback - a callback function to return the result (Generics)
322
+ * or the error
323
+ */
324
+ iapMoveAdapterEntitiesToDB(callback) {
325
+ const meth = 'adapter-iapMoveAdapterEntitiesToDB';
326
+ const origin = `${this.id}-${meth}`;
327
+ log.trace(origin);
328
+
329
+ try {
330
+ return super.iapMoveAdapterEntitiesToDB(callback);
331
+ } catch (err) {
332
+ log.error(`${origin}: ${err}`);
333
+ return callback(null, err);
334
+ }
335
+ }
336
+
337
+ /* BROKER CALLS */
252
338
  /**
253
339
  * @summary Determines if this adapter supports the specific entity
254
340
  *
255
- * @function hasEntity
341
+ * @function iapHasAdapterEntity
256
342
  * @param {String} entityType - the entity type to check for
257
343
  * @param {String/Array} entityId - the specific entity we are looking for
258
344
  *
259
345
  * @param {Callback} callback - An array of whether the adapter can has the
260
346
  * desired capability or an error
261
347
  */
262
- hasEntity(entityType, entityId, callback) {
263
- const origin = `${this.id}-adapter-hasEntity`;
348
+ iapHasAdapterEntity(entityType, entityId, callback) {
349
+ const origin = `${this.id}-adapter-iapHasAdapterEntity`;
264
350
  log.trace(origin);
265
351
 
266
352
  // Make the call -
267
- // verifyCapability(entityType, actionType, entityId, callback)
268
- return this.verifyCapability(entityType, null, entityId, callback);
353
+ // iapVerifyAdapterCapability(entityType, actionType, entityId, callback)
354
+ return this.iapVerifyAdapterCapability(entityType, null, entityId, callback);
269
355
  }
270
356
 
271
357
  /**
272
358
  * @summary Provides a way for the adapter to tell north bound integrations
273
359
  * whether the adapter supports type, action and specific entity
274
360
  *
275
- * @function verifyCapability
361
+ * @function iapVerifyAdapterCapability
276
362
  * @param {String} entityType - the entity type to check for
277
363
  * @param {String} actionType - the action type to check for
278
364
  * @param {String/Array} entityId - the specific entity we are looking for
@@ -280,15 +366,15 @@ class Netbrain extends AdapterBaseCl {
280
366
  * @param {Callback} callback - An array of whether the adapter can has the
281
367
  * desired capability or an error
282
368
  */
283
- verifyCapability(entityType, actionType, entityId, callback) {
284
- const meth = 'adapterBase-verifyCapability';
369
+ iapVerifyAdapterCapability(entityType, actionType, entityId, callback) {
370
+ const meth = 'adapterBase-iapVerifyAdapterCapability';
285
371
  const origin = `${this.id}-${meth}`;
286
372
  log.trace(origin);
287
373
 
288
374
  // if caching
289
375
  if (this.caching) {
290
- // Make the call - verifyCapability(entityType, actionType, entityId, callback)
291
- return this.requestHandlerInst.verifyCapability(entityType, actionType, entityId, (results, error) => {
376
+ // Make the call - iapVerifyAdapterCapability(entityType, actionType, entityId, callback)
377
+ return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, entityId, (results, error) => {
292
378
  if (error) {
293
379
  return callback(null, error);
294
380
  }
@@ -306,7 +392,7 @@ class Netbrain extends AdapterBaseCl {
306
392
  }
307
393
 
308
394
  // need to check the cache again since it has been updated
309
- return this.requestHandlerInst.verifyCapability(entityType, actionType, entityId, (vcapable, verror) => {
395
+ return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, entityId, (vcapable, verror) => {
310
396
  if (verror) {
311
397
  return callback(null, verror);
312
398
  }
@@ -339,7 +425,7 @@ class Netbrain extends AdapterBaseCl {
339
425
  // if no entity id
340
426
  if (!entityId) {
341
427
  // need to check the cache again since it has been updated
342
- return this.requestHandlerInst.verifyCapability(entityType, actionType, null, (vcapable, verror) => {
428
+ return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, null, (vcapable, verror) => {
343
429
  if (verror) {
344
430
  return callback(null, verror);
345
431
  }
@@ -360,7 +446,7 @@ class Netbrain extends AdapterBaseCl {
360
446
  }
361
447
 
362
448
  // need to check the cache again since it has been updated
363
- return this.requestHandlerInst.verifyCapability(entityType, actionType, null, (vcapable, verror) => {
449
+ return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, null, (vcapable, verror) => {
364
450
  if (verror) {
365
451
  return callback(null, verror);
366
452
  }
@@ -401,11 +487,11 @@ class Netbrain extends AdapterBaseCl {
401
487
  /**
402
488
  * @summary Updates the cache for all entities by call the get All entity method
403
489
  *
404
- * @function updateEntityCache
490
+ * @function iapUpdateAdapterEntityCache
405
491
  *
406
492
  */
407
- updateEntityCache() {
408
- const origin = `${this.id}-adapter-updateEntityCache`;
493
+ iapUpdateAdapterEntityCache() {
494
+ const origin = `${this.id}-adapter-iapUpdateAdapterEntityCache`;
409
495
  log.trace(origin);
410
496
 
411
497
  if (this.caching) {
@@ -418,6 +504,140 @@ class Netbrain extends AdapterBaseCl {
418
504
  }
419
505
  }
420
506
 
507
+ /**
508
+ * @summary Determines if this adapter supports any in a list of entities
509
+ *
510
+ * @function hasEntities
511
+ * @param {String} entityType - the entity type to check for
512
+ * @param {Array} entityList - the list of entities we are looking for
513
+ *
514
+ * @param {Callback} callback - A map where the entity is the key and the
515
+ * value is true or false
516
+ */
517
+ hasEntities(entityType, entityList, callback) {
518
+ const meth = 'adapter-hasEntities';
519
+ const origin = `${this.id}-${meth}`;
520
+ log.trace(origin);
521
+
522
+ try {
523
+ return super.hasEntities(entityType, entityList, callback);
524
+ } catch (err) {
525
+ log.error(`${origin}: ${err}`);
526
+ return callback(null, err);
527
+ }
528
+ }
529
+
530
+ /**
531
+ * @summary Get Appliance that match the deviceName
532
+ *
533
+ * @function getDevice
534
+ * @param {String} deviceName - the deviceName to find (required)
535
+ *
536
+ * @param {getCallback} callback - a callback function to return the result
537
+ * (appliance) or the error
538
+ */
539
+ getDevice(deviceName, callback) {
540
+ const meth = 'adapter-getDevice';
541
+ const origin = `${this.id}-${meth}`;
542
+ log.trace(origin);
543
+
544
+ try {
545
+ return super.getDevice(deviceName, callback);
546
+ } catch (err) {
547
+ log.error(`${origin}: ${err}`);
548
+ return callback(null, err);
549
+ }
550
+ }
551
+
552
+ /**
553
+ * @summary Get Appliances that match the filter
554
+ *
555
+ * @function getDevicesFiltered
556
+ * @param {Object} options - the data to use to filter the appliances (optional)
557
+ *
558
+ * @param {getCallback} callback - a callback function to return the result
559
+ * (appliances) or the error
560
+ */
561
+ getDevicesFiltered(options, callback) {
562
+ const meth = 'adapter-getDevicesFiltered';
563
+ const origin = `${this.id}-${meth}`;
564
+ log.trace(origin);
565
+
566
+ try {
567
+ return super.getDevicesFiltered(options, callback);
568
+ } catch (err) {
569
+ log.error(`${origin}: ${err}`);
570
+ return callback(null, err);
571
+ }
572
+ }
573
+
574
+ /**
575
+ * @summary Gets the status for the provided appliance
576
+ *
577
+ * @function isAlive
578
+ * @param {String} deviceName - the deviceName of the appliance. (required)
579
+ *
580
+ * @param {configCallback} callback - callback function to return the result
581
+ * (appliance isAlive) or the error
582
+ */
583
+ isAlive(deviceName, callback) {
584
+ const meth = 'adapter-isAlive';
585
+ const origin = `${this.id}-${meth}`;
586
+ log.trace(origin);
587
+
588
+ try {
589
+ return super.isAlive(deviceName, callback);
590
+ } catch (err) {
591
+ log.error(`${origin}: ${err}`);
592
+ return callback(null, err);
593
+ }
594
+ }
595
+
596
+ /**
597
+ * @summary Gets a config for the provided Appliance
598
+ *
599
+ * @function getConfig
600
+ * @param {String} deviceName - the deviceName of the appliance. (required)
601
+ * @param {String} format - the desired format of the config. (optional)
602
+ *
603
+ * @param {configCallback} callback - callback function to return the result
604
+ * (appliance config) or the error
605
+ */
606
+ getConfig(deviceName, format, callback) {
607
+ const meth = 'adapter-getConfig';
608
+ const origin = `${this.id}-${meth}`;
609
+ log.trace(origin);
610
+
611
+ try {
612
+ return super.getConfig(deviceName, format, callback);
613
+ } catch (err) {
614
+ log.error(`${origin}: ${err}`);
615
+ return callback(null, err);
616
+ }
617
+ }
618
+
619
+ /**
620
+ * @summary Gets the device count from the system
621
+ *
622
+ * @function iapGetDeviceCount
623
+ *
624
+ * @param {getCallback} callback - callback function to return the result
625
+ * (count) or the error
626
+ */
627
+ iapGetDeviceCount(callback) {
628
+ const meth = 'adapter-iapGetDeviceCount';
629
+ const origin = `${this.id}-${meth}`;
630
+ log.trace(origin);
631
+
632
+ try {
633
+ return super.iapGetDeviceCount(callback);
634
+ } catch (err) {
635
+ log.error(`${origin}: ${err}`);
636
+ return callback(null, err);
637
+ }
638
+ }
639
+
640
+ /* GENERIC ADAPTER REQUEST - allows extension of adapter without new calls being added */
421
641
  /**
422
642
  * Makes the requested generic call
423
643
  *
@@ -528,6 +748,116 @@ class Netbrain extends AdapterBaseCl {
528
748
  }
529
749
  }
530
750
 
751
+ /**
752
+ * Makes the requested generic call with no base path or version
753
+ *
754
+ * @function genericAdapterRequestNoBasePath
755
+ * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
756
+ * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
757
+ * @param {Object} queryData - the parameters to be put on the url (optional).
758
+ * Can be a stringified Object.
759
+ * @param {Object} requestBody - the body to add to the request (optional).
760
+ * Can be a stringified Object.
761
+ * @param {Object} addlHeaders - additional headers to be put on the call (optional).
762
+ * Can be a stringified Object.
763
+ * @param {getCallback} callback - a callback function to return the result (Generics)
764
+ * or the error
765
+ */
766
+ genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
767
+ const meth = 'adapter-genericAdapterRequestNoBasePath';
768
+ const origin = `${this.id}-${meth}`;
769
+ log.trace(origin);
770
+
771
+ if (this.suspended && this.suspendMode === 'error') {
772
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
773
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
774
+ return callback(null, errorObj);
775
+ }
776
+
777
+ /* HERE IS WHERE YOU VALIDATE DATA */
778
+ if (uriPath === undefined || uriPath === null || uriPath === '') {
779
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['uriPath'], null, null, null);
780
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
781
+ return callback(null, errorObj);
782
+ }
783
+ if (restMethod === undefined || restMethod === null || restMethod === '') {
784
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['restMethod'], null, null, null);
785
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
786
+ return callback(null, errorObj);
787
+ }
788
+
789
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
790
+ // remove any leading / and split the uripath into path variables
791
+ let myPath = uriPath;
792
+ while (myPath.indexOf('/') === 0) {
793
+ myPath = myPath.substring(1);
794
+ }
795
+ const pathVars = myPath.split('/');
796
+ const queryParamsAvailable = queryData;
797
+ const queryParams = {};
798
+ const bodyVars = requestBody;
799
+
800
+ // loop in template. long callback arg name to avoid identifier conflicts
801
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
802
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
803
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
804
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
805
+ }
806
+ });
807
+
808
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
809
+ const reqObj = {
810
+ payload: bodyVars,
811
+ uriPathVars: pathVars,
812
+ uriQuery: queryParams,
813
+ uriOptions: {}
814
+ };
815
+ // add headers if provided
816
+ if (addlHeaders) {
817
+ reqObj.addlHeaders = addlHeaders;
818
+ }
819
+
820
+ // determine the call and return flag
821
+ let action = 'getGenericsNoBase';
822
+ let returnF = true;
823
+ if (restMethod.toUpperCase() === 'POST') {
824
+ action = 'createGenericNoBase';
825
+ } else if (restMethod.toUpperCase() === 'PUT') {
826
+ action = 'updateGenericNoBase';
827
+ } else if (restMethod.toUpperCase() === 'PATCH') {
828
+ action = 'patchGenericNoBase';
829
+ } else if (restMethod.toUpperCase() === 'DELETE') {
830
+ action = 'deleteGenericNoBase';
831
+ returnF = false;
832
+ }
833
+
834
+ try {
835
+ // Make the call -
836
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
837
+ return this.requestHandlerInst.identifyRequest('.generic', action, reqObj, returnF, (irReturnData, irReturnError) => {
838
+ // if we received an error or their is no response on the results
839
+ // return an error
840
+ if (irReturnError) {
841
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
842
+ return callback(null, irReturnError);
843
+ }
844
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
845
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['genericAdapterRequestNoBasePath'], null, null, null);
846
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
847
+ return callback(null, errorObj);
848
+ }
849
+
850
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
851
+ // return the response
852
+ return callback(irReturnData, null);
853
+ });
854
+ } catch (ex) {
855
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
856
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
857
+ return callback(null, errorObj);
858
+ }
859
+ }
860
+
531
861
  /**
532
862
  * @callback healthCallback
533
863
  * @param {Object} result - the result of the get request (contains an id and a status)
@@ -927,7 +1257,7 @@ class Netbrain extends AdapterBaseCl {
927
1257
  * @summary Query all the domains info in system.
928
1258
  *
929
1259
  * @function getV1CMDBDomains
930
- * @param {string} tenantId - tenantId param
1260
+ * @param {string} tenantId - tenantId param, if passed empty it will get it from the adapter config
931
1261
  * @param {getCallback} callback - a callback function to return the result
932
1262
  */
933
1263
 
@@ -943,14 +1273,25 @@ class Netbrain extends AdapterBaseCl {
943
1273
  return callback(null, errorObj);
944
1274
  }
945
1275
 
946
- /* HERE IS WHERE YOU VALIDATE DATA */
947
-
948
1276
  /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
949
- const queryParamsAvailable = { tenantId };
1277
+ let configtenantId = tenantId;
1278
+ if (configtenantId === undefined || configtenantId === null || configtenantId === '') {
1279
+ if (this.allProps.authentication.tenantId) {
1280
+ configtenantId = this.allProps.authentication.tenantId;
1281
+ }
1282
+ }
1283
+ const queryParamsAvailable = { configtenantId };
950
1284
  const queryParams = {};
951
1285
  const pathVars = [];
952
1286
  const bodyVars = {};
953
1287
 
1288
+ /* HERE IS WHERE YOU VALIDATE DATA */
1289
+ if (configtenantId === undefined || configtenantId === null || configtenantId === '') {
1290
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['tenantId'], null, null, null);
1291
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1292
+ return callback(null, errorObj);
1293
+ }
1294
+
954
1295
  // loop in template. long callback arg name to avoid identifier conflicts
955
1296
  Object.keys(queryParamsAvailable)
956
1297
  .forEach((thisKeyInQueryParamsAvailable) => {
@@ -1408,19 +1749,25 @@ class Netbrain extends AdapterBaseCl {
1408
1749
  return callback(null, errorObj);
1409
1750
  }
1410
1751
 
1752
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
1753
+ let configtenantId = tenantId;
1754
+ if (configtenantId === undefined || configtenantId === null || configtenantId === '') {
1755
+ if (this.allProps.authentication.tenantId) {
1756
+ configtenantId = this.allProps.authentication.tenantId;
1757
+ }
1758
+ }
1759
+ const queryParamsAvailable = {};
1760
+ const queryParams = {};
1761
+ const pathVars = [configtenantId];
1762
+ const bodyVars = {};
1763
+
1411
1764
  /* HERE IS WHERE YOU VALIDATE DATA */
1412
- if (tenantId === undefined || tenantId === null || tenantId === '') {
1765
+ if (configtenantId === undefined || configtenantId === null || configtenantId === '') {
1413
1766
  const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['tenantId'], null, null, null);
1414
1767
  log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1415
1768
  return callback(null, errorObj);
1416
1769
  }
1417
1770
 
1418
- /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
1419
- const queryParamsAvailable = {};
1420
- const queryParams = {};
1421
- const pathVars = [tenantId];
1422
- const bodyVars = {};
1423
-
1424
1771
  // loop in template. long callback arg name to avoid identifier conflicts
1425
1772
  Object.keys(queryParamsAvailable)
1426
1773
  .forEach((thisKeyInQueryParamsAvailable) => {
@@ -8360,11 +8707,15 @@ class Netbrain extends AdapterBaseCl {
8360
8707
  return callback(null, errorObj);
8361
8708
  }
8362
8709
 
8363
- /* HERE IS WHERE YOU VALIDATE DATA */
8364
-
8365
8710
  /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
8711
+ let configtenantId = tenantId;
8712
+ if (configtenantId === undefined || configtenantId === null || configtenantId === '') {
8713
+ if (this.allProps.authentication.tenantId) {
8714
+ configtenantId = this.allProps.authentication.tenantId;
8715
+ }
8716
+ }
8366
8717
  const queryParamsAvailable = {
8367
- tenantId,
8718
+ configtenantId,
8368
8719
  domainId,
8369
8720
  fromDate,
8370
8721
  toDate
@@ -8373,6 +8724,13 @@ class Netbrain extends AdapterBaseCl {
8373
8724
  const pathVars = [];
8374
8725
  const bodyVars = {};
8375
8726
 
8727
+ /* HERE IS WHERE YOU VALIDATE DATA */
8728
+ if (configtenantId === undefined || configtenantId === null || configtenantId === '') {
8729
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['tenantId'], null, null, null);
8730
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
8731
+ return callback(null, errorObj);
8732
+ }
8733
+
8376
8734
  // loop in template. long callback arg name to avoid identifier conflicts
8377
8735
  Object.keys(queryParamsAvailable)
8378
8736
  .forEach((thisKeyInQueryParamsAvailable) => {