@itentialopensource/adapter-netbox 0.6.4 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/AUTH.md +39 -0
  2. package/BROKER.md +199 -0
  3. package/CALLS.md +169 -0
  4. package/CHANGELOG.md +86 -20
  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 +431 -58
  14. package/adapterBase.js +1021 -245
  15. package/entities/.generic/action.json +110 -5
  16. package/entities/.generic/schema.json +6 -1
  17. package/entities/Graphql/action.json +25 -0
  18. package/entities/Graphql/schema.json +19 -0
  19. package/error.json +12 -0
  20. package/package.json +20 -13
  21. package/pronghorn.json +676 -378
  22. package/propertiesDecorators.json +14 -0
  23. package/propertiesSchema.json +436 -0
  24. package/refs?service=git-upload-pack +0 -0
  25. package/report/adapterInfo.json +10 -0
  26. package/report/updateReport1644854487087.json +95 -0
  27. package/report/updateReport1653302322815.json +120 -0
  28. package/sampleProperties.json +94 -2
  29. package/test/integration/adapterTestBasicGet.js +2 -2
  30. package/test/integration/adapterTestIntegration.js +54 -103
  31. package/test/unit/adapterBaseTestUnit.js +35 -27
  32. package/test/unit/adapterTestUnit.js +569 -142
  33. package/utils/adapterInfo.js +206 -0
  34. package/utils/addAuth.js +94 -0
  35. package/utils/basicGet.js +1 -14
  36. package/utils/entitiesToDB.js +179 -0
  37. package/utils/modify.js +1 -1
  38. package/utils/packModificationScript.js +1 -1
  39. package/utils/patches2bundledDeps.js +90 -0
  40. package/utils/pre-commit.sh +3 -0
  41. package/utils/removeHooks.js +20 -0
  42. package/utils/tbScript.js +43 -22
  43. package/utils/tbUtils.js +126 -29
  44. package/utils/testRunner.js +16 -16
  45. package/utils/troubleshootingAdapter.js +2 -26
package/adapter.js CHANGED
@@ -95,10 +95,18 @@ class Netbox extends AdapterBaseCl {
95
95
  }
96
96
 
97
97
  /**
98
- * @getWorkflowFunctions
99
- */
100
- getWorkflowFunctions(inIgnore) {
101
- let myIgnore = [];
98
+ * @iapGetAdapterWorkflowFunctions
99
+ */
100
+ iapGetAdapterWorkflowFunctions(inIgnore) {
101
+ let myIgnore = [
102
+ 'healthCheck',
103
+ 'iapGetAdapterWorkflowFunctions',
104
+ 'iapHasAdapterEntity',
105
+ 'iapVerifyAdapterCapability',
106
+ 'iapUpdateAdapterEntityCache',
107
+ 'hasEntities',
108
+ 'getAuthorization'
109
+ ];
102
110
  if (!inIgnore && Array.isArray(inIgnore)) {
103
111
  myIgnore = inIgnore;
104
112
  } else if (!inIgnore && typeof inIgnore === 'string') {
@@ -109,15 +117,15 @@ class Netbox extends AdapterBaseCl {
109
117
  // you can add specific methods that you do not want to be workflow functions to ignore like below
110
118
  // myIgnore.push('myMethodNotInWorkflow');
111
119
 
112
- return super.getWorkflowFunctions(myIgnore);
120
+ return super.iapGetAdapterWorkflowFunctions(myIgnore);
113
121
  }
114
122
 
115
123
  /**
116
- * updateAdapterConfiguration is used to update any of the adapter configuration files. This
124
+ * iapUpdateAdapterConfiguration is used to update any of the adapter configuration files. This
117
125
  * allows customers to make changes to adapter configuration without having to be on the
118
126
  * file system.
119
127
  *
120
- * @function updateAdapterConfiguration
128
+ * @function iapUpdateAdapterConfiguration
121
129
  * @param {string} configFile - the name of the file being updated (required)
122
130
  * @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
123
131
  * @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
@@ -125,36 +133,42 @@ class Netbox extends AdapterBaseCl {
125
133
  * @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
126
134
  * @param {Callback} callback - The results of the call
127
135
  */
128
- updateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
129
- const origin = `${this.id}-adapter-updateAdapterConfiguration`;
136
+ iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
137
+ const meth = 'adapter-iapUpdateAdapterConfiguration';
138
+ const origin = `${this.id}-${meth}`;
130
139
  log.trace(origin);
131
- super.updateAdapterConfiguration(configFile, changes, entity, type, action, callback);
140
+
141
+ super.iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback);
132
142
  }
133
143
 
134
144
  /**
135
145
  * See if the API path provided is found in this adapter
136
146
  *
137
- * @function findPath
147
+ * @function iapFindAdapterPath
138
148
  * @param {string} apiPath - the api path to check on
139
149
  * @param {Callback} callback - The results of the call
140
150
  */
141
- findPath(apiPath, callback) {
142
- const origin = `${this.id}-adapter-findPath`;
151
+ iapFindAdapterPath(apiPath, callback) {
152
+ const meth = 'adapter-iapFindAdapterPath';
153
+ const origin = `${this.id}-${meth}`;
143
154
  log.trace(origin);
144
- super.findPath(apiPath, callback);
155
+
156
+ super.iapFindAdapterPath(apiPath, callback);
145
157
  }
146
158
 
147
159
  /**
148
160
  * @summary Suspends adapter
149
161
  *
150
- * @function suspend
162
+ * @function iapSuspendAdapter
151
163
  * @param {Callback} callback - callback function
152
164
  */
153
- suspend(mode, callback) {
154
- const origin = `${this.id}-adapter-suspend`;
165
+ iapSuspendAdapter(mode, callback) {
166
+ const meth = 'adapter-iapSuspendAdapter';
167
+ const origin = `${this.id}-${meth}`;
155
168
  log.trace(origin);
169
+
156
170
  try {
157
- return super.suspend(mode, callback);
171
+ return super.iapSuspendAdapter(mode, callback);
158
172
  } catch (error) {
159
173
  log.error(`${origin}: ${error}`);
160
174
  return callback(null, error);
@@ -164,14 +178,16 @@ class Netbox extends AdapterBaseCl {
164
178
  /**
165
179
  * @summary Unsuspends adapter
166
180
  *
167
- * @function unsuspend
181
+ * @function iapUnsuspendAdapter
168
182
  * @param {Callback} callback - callback function
169
183
  */
170
- unsuspend(callback) {
171
- const origin = `${this.id}-adapter-unsuspend`;
184
+ iapUnsuspendAdapter(callback) {
185
+ const meth = 'adapter-iapUnsuspendAdapter';
186
+ const origin = `${this.id}-${meth}`;
172
187
  log.trace(origin);
188
+
173
189
  try {
174
- return super.unsuspend(callback);
190
+ return super.iapUnsuspendAdapter(callback);
175
191
  } catch (error) {
176
192
  log.error(`${origin}: ${error}`);
177
193
  return callback(null, error);
@@ -181,29 +197,33 @@ class Netbox extends AdapterBaseCl {
181
197
  /**
182
198
  * @summary Get the Adaoter Queue
183
199
  *
184
- * @function getQueue
200
+ * @function iapGetAdapterQueue
185
201
  * @param {Callback} callback - callback function
186
202
  */
187
- getQueue(callback) {
188
- const origin = `${this.id}-adapter-getQueue`;
203
+ iapGetAdapterQueue(callback) {
204
+ const meth = 'adapter-iapGetAdapterQueue';
205
+ const origin = `${this.id}-${meth}`;
189
206
  log.trace(origin);
190
- return super.getQueue(callback);
207
+
208
+ return super.iapGetAdapterQueue(callback);
191
209
  }
192
210
 
193
211
  /**
194
212
  * @summary Runs troubleshoot scripts for adapter
195
213
  *
196
- * @function troubleshoot
214
+ * @function iapTroubleshootAdapter
197
215
  * @param {Object} props - the connection, healthcheck and authentication properties
198
216
  *
199
217
  * @param {boolean} persistFlag - whether the adapter properties should be updated
200
218
  * @param {Callback} callback - The results of the call
201
219
  */
202
- troubleshoot(props, persistFlag, callback) {
203
- const origin = `${this.id}-adapter-troubleshoot`;
220
+ iapTroubleshootAdapter(props, persistFlag, callback) {
221
+ const meth = 'adapter-iapTroubleshootAdapter';
222
+ const origin = `${this.id}-${meth}`;
204
223
  log.trace(origin);
224
+
205
225
  try {
206
- return super.troubleshoot(props, persistFlag, this, callback);
226
+ return super.iapTroubleshootAdapter(props, persistFlag, this, callback);
207
227
  } catch (error) {
208
228
  log.error(`${origin}: ${error}`);
209
229
  return callback(null, error);
@@ -213,15 +233,17 @@ class Netbox extends AdapterBaseCl {
213
233
  /**
214
234
  * @summary runs healthcheck script for adapter
215
235
  *
216
- * @function runHealthcheck
236
+ * @function iapRunAdapterHealthcheck
217
237
  * @param {Adapter} adapter - adapter instance to troubleshoot
218
238
  * @param {Callback} callback - callback function
219
239
  */
220
- runHealthcheck(callback) {
221
- const origin = `${this.id}-adapter-runHealthcheck`;
240
+ iapRunAdapterHealthcheck(callback) {
241
+ const meth = 'adapter-iapRunAdapterHealthcheck';
242
+ const origin = `${this.id}-${meth}`;
222
243
  log.trace(origin);
244
+
223
245
  try {
224
- return super.runHealthcheck(this, callback);
246
+ return super.iapRunAdapterHealthcheck(this, callback);
225
247
  } catch (error) {
226
248
  log.error(`${origin}: ${error}`);
227
249
  return callback(null, error);
@@ -231,14 +253,16 @@ class Netbox extends AdapterBaseCl {
231
253
  /**
232
254
  * @summary runs connectivity check script for adapter
233
255
  *
234
- * @function runConnectivity
256
+ * @function iapRunAdapterConnectivity
235
257
  * @param {Callback} callback - callback function
236
258
  */
237
- runConnectivity(callback) {
238
- const origin = `${this.id}-adapter-runConnectivity`;
259
+ iapRunAdapterConnectivity(callback) {
260
+ const meth = 'adapter-iapRunAdapterConnectivity';
261
+ const origin = `${this.id}-${meth}`;
239
262
  log.trace(origin);
263
+
240
264
  try {
241
- return super.runConnectivity(callback);
265
+ return super.iapRunAdapterConnectivity(callback);
242
266
  } catch (error) {
243
267
  log.error(`${origin}: ${error}`);
244
268
  return callback(null, error);
@@ -248,44 +272,67 @@ class Netbox extends AdapterBaseCl {
248
272
  /**
249
273
  * @summary runs basicGet script for adapter
250
274
  *
251
- * @function runBasicGet
275
+ * @function iapRunAdapterBasicGet
252
276
  * @param {Callback} callback - callback function
253
277
  */
254
- runBasicGet(callback) {
255
- const origin = `${this.id}-adapter-runBasicGet`;
278
+ iapRunAdapterBasicGet(callback) {
279
+ const meth = 'adapter-iapRunAdapterBasicGet';
280
+ const origin = `${this.id}-${meth}`;
256
281
  log.trace(origin);
282
+
257
283
  try {
258
- return super.runBasicGet(callback);
284
+ return super.iapRunAdapterBasicGet(callback);
259
285
  } catch (error) {
260
286
  log.error(`${origin}: ${error}`);
261
287
  return callback(null, error);
262
288
  }
263
289
  }
264
290
 
291
+ /**
292
+ * @summary moves entites into Mongo DB
293
+ *
294
+ * @function iapMoveAdapterEntitiesToDB
295
+ * @param {getCallback} callback - a callback function to return the result (Generics)
296
+ * or the error
297
+ */
298
+ iapMoveAdapterEntitiesToDB(callback) {
299
+ const meth = 'adapter-iapMoveAdapterEntitiesToDB';
300
+ const origin = `${this.id}-${meth}`;
301
+ log.trace(origin);
302
+
303
+ try {
304
+ return super.iapMoveAdapterEntitiesToDB(callback);
305
+ } catch (err) {
306
+ log.error(`${origin}: ${err}`);
307
+ return callback(null, err);
308
+ }
309
+ }
310
+
311
+ /* BROKER CALLS */
265
312
  /**
266
313
  * @summary Determines if this adapter supports the specific entity
267
314
  *
268
- * @function hasEntity
315
+ * @function iapHasAdapterEntity
269
316
  * @param {String} entityType - the entity type to check for
270
317
  * @param {String/Array} entityId - the specific entity we are looking for
271
318
  *
272
319
  * @param {Callback} callback - An array of whether the adapter can has the
273
320
  * desired capability or an error
274
321
  */
275
- hasEntity(entityType, entityId, callback) {
276
- const origin = `${this.id}-adapter-hasEntity`;
322
+ iapHasAdapterEntity(entityType, entityId, callback) {
323
+ const origin = `${this.id}-adapter-iapHasAdapterEntity`;
277
324
  log.trace(origin);
278
325
 
279
326
  // Make the call -
280
- // verifyCapability(entityType, actionType, entityId, callback)
281
- return this.verifyCapability(entityType, null, entityId, callback);
327
+ // iapVerifyAdapterCapability(entityType, actionType, entityId, callback)
328
+ return this.iapVerifyAdapterCapability(entityType, null, entityId, callback);
282
329
  }
283
330
 
284
331
  /**
285
332
  * @summary Provides a way for the adapter to tell north bound integrations
286
333
  * whether the adapter supports type, action and specific entity
287
334
  *
288
- * @function verifyCapability
335
+ * @function iapVerifyAdapterCapability
289
336
  * @param {String} entityType - the entity type to check for
290
337
  * @param {String} actionType - the action type to check for
291
338
  * @param {String/Array} entityId - the specific entity we are looking for
@@ -293,15 +340,15 @@ class Netbox extends AdapterBaseCl {
293
340
  * @param {Callback} callback - An array of whether the adapter can has the
294
341
  * desired capability or an error
295
342
  */
296
- verifyCapability(entityType, actionType, entityId, callback) {
297
- const meth = 'adapterBase-verifyCapability';
343
+ iapVerifyAdapterCapability(entityType, actionType, entityId, callback) {
344
+ const meth = 'adapterBase-iapVerifyAdapterCapability';
298
345
  const origin = `${this.id}-${meth}`;
299
346
  log.trace(origin);
300
347
 
301
348
  // if caching
302
349
  if (this.caching) {
303
- // Make the call - verifyCapability(entityType, actionType, entityId, callback)
304
- return this.requestHandlerInst.verifyCapability(entityType, actionType, entityId, (results, error) => {
350
+ // Make the call - iapVerifyAdapterCapability(entityType, actionType, entityId, callback)
351
+ return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, entityId, (results, error) => {
305
352
  if (error) {
306
353
  return callback(null, error);
307
354
  }
@@ -319,7 +366,7 @@ class Netbox extends AdapterBaseCl {
319
366
  }
320
367
 
321
368
  // need to check the cache again since it has been updated
322
- return this.requestHandlerInst.verifyCapability(entityType, actionType, entityId, (vcapable, verror) => {
369
+ return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, entityId, (vcapable, verror) => {
323
370
  if (verror) {
324
371
  return callback(null, verror);
325
372
  }
@@ -352,7 +399,7 @@ class Netbox extends AdapterBaseCl {
352
399
  // if no entity id
353
400
  if (!entityId) {
354
401
  // need to check the cache again since it has been updated
355
- return this.requestHandlerInst.verifyCapability(entityType, actionType, null, (vcapable, verror) => {
402
+ return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, null, (vcapable, verror) => {
356
403
  if (verror) {
357
404
  return callback(null, verror);
358
405
  }
@@ -373,7 +420,7 @@ class Netbox extends AdapterBaseCl {
373
420
  }
374
421
 
375
422
  // need to check the cache again since it has been updated
376
- return this.requestHandlerInst.verifyCapability(entityType, actionType, null, (vcapable, verror) => {
423
+ return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, null, (vcapable, verror) => {
377
424
  if (verror) {
378
425
  return callback(null, verror);
379
426
  }
@@ -414,11 +461,11 @@ class Netbox extends AdapterBaseCl {
414
461
  /**
415
462
  * @summary Updates the cache for all entities by call the get All entity method
416
463
  *
417
- * @function updateEntityCache
464
+ * @function iapUpdateAdapterEntityCache
418
465
  *
419
466
  */
420
- updateEntityCache() {
421
- const origin = `${this.id}-adapter-updateEntityCache`;
467
+ iapUpdateAdapterEntityCache() {
468
+ const origin = `${this.id}-adapter-iapUpdateAdapterEntityCache`;
422
469
  log.trace(origin);
423
470
 
424
471
  if (this.caching) {
@@ -431,6 +478,140 @@ class Netbox extends AdapterBaseCl {
431
478
  }
432
479
  }
433
480
 
481
+ /**
482
+ * @summary Determines if this adapter supports any in a list of entities
483
+ *
484
+ * @function hasEntities
485
+ * @param {String} entityType - the entity type to check for
486
+ * @param {Array} entityList - the list of entities we are looking for
487
+ *
488
+ * @param {Callback} callback - A map where the entity is the key and the
489
+ * value is true or false
490
+ */
491
+ hasEntities(entityType, entityList, callback) {
492
+ const meth = 'adapter-hasEntities';
493
+ const origin = `${this.id}-${meth}`;
494
+ log.trace(origin);
495
+
496
+ try {
497
+ return super.hasEntities(entityType, entityList, callback);
498
+ } catch (err) {
499
+ log.error(`${origin}: ${err}`);
500
+ return callback(null, err);
501
+ }
502
+ }
503
+
504
+ /**
505
+ * @summary Get Appliance that match the deviceName
506
+ *
507
+ * @function getDevice
508
+ * @param {String} deviceName - the deviceName to find (required)
509
+ *
510
+ * @param {getCallback} callback - a callback function to return the result
511
+ * (appliance) or the error
512
+ */
513
+ getDevice(deviceName, callback) {
514
+ const meth = 'adapter-getDevice';
515
+ const origin = `${this.id}-${meth}`;
516
+ log.trace(origin);
517
+
518
+ try {
519
+ return super.getDevice(deviceName, callback);
520
+ } catch (err) {
521
+ log.error(`${origin}: ${err}`);
522
+ return callback(null, err);
523
+ }
524
+ }
525
+
526
+ /**
527
+ * @summary Get Appliances that match the filter
528
+ *
529
+ * @function getDevicesFiltered
530
+ * @param {Object} options - the data to use to filter the appliances (optional)
531
+ *
532
+ * @param {getCallback} callback - a callback function to return the result
533
+ * (appliances) or the error
534
+ */
535
+ getDevicesFiltered(options, callback) {
536
+ const meth = 'adapter-getDevicesFiltered';
537
+ const origin = `${this.id}-${meth}`;
538
+ log.trace(origin);
539
+
540
+ try {
541
+ return super.getDevicesFiltered(options, callback);
542
+ } catch (err) {
543
+ log.error(`${origin}: ${err}`);
544
+ return callback(null, err);
545
+ }
546
+ }
547
+
548
+ /**
549
+ * @summary Gets the status for the provided appliance
550
+ *
551
+ * @function isAlive
552
+ * @param {String} deviceName - the deviceName of the appliance. (required)
553
+ *
554
+ * @param {configCallback} callback - callback function to return the result
555
+ * (appliance isAlive) or the error
556
+ */
557
+ isAlive(deviceName, callback) {
558
+ const meth = 'adapter-isAlive';
559
+ const origin = `${this.id}-${meth}`;
560
+ log.trace(origin);
561
+
562
+ try {
563
+ return super.isAlive(deviceName, callback);
564
+ } catch (err) {
565
+ log.error(`${origin}: ${err}`);
566
+ return callback(null, err);
567
+ }
568
+ }
569
+
570
+ /**
571
+ * @summary Gets a config for the provided Appliance
572
+ *
573
+ * @function getConfig
574
+ * @param {String} deviceName - the deviceName of the appliance. (required)
575
+ * @param {String} format - the desired format of the config. (optional)
576
+ *
577
+ * @param {configCallback} callback - callback function to return the result
578
+ * (appliance config) or the error
579
+ */
580
+ getConfig(deviceName, format, callback) {
581
+ const meth = 'adapter-getConfig';
582
+ const origin = `${this.id}-${meth}`;
583
+ log.trace(origin);
584
+
585
+ try {
586
+ return super.getConfig(deviceName, format, callback);
587
+ } catch (err) {
588
+ log.error(`${origin}: ${err}`);
589
+ return callback(null, err);
590
+ }
591
+ }
592
+
593
+ /**
594
+ * @summary Gets the device count from the system
595
+ *
596
+ * @function iapGetDeviceCount
597
+ *
598
+ * @param {getCallback} callback - callback function to return the result
599
+ * (count) or the error
600
+ */
601
+ iapGetDeviceCount(callback) {
602
+ const meth = 'adapter-iapGetDeviceCount';
603
+ const origin = `${this.id}-${meth}`;
604
+ log.trace(origin);
605
+
606
+ try {
607
+ return super.iapGetDeviceCount(callback);
608
+ } catch (err) {
609
+ log.error(`${origin}: ${err}`);
610
+ return callback(null, err);
611
+ }
612
+ }
613
+
614
+ /* GENERIC ADAPTER REQUEST - allows extension of adapter without new calls being added */
434
615
  /**
435
616
  * Makes the requested generic call
436
617
  *
@@ -541,6 +722,116 @@ class Netbox extends AdapterBaseCl {
541
722
  }
542
723
  }
543
724
 
725
+ /**
726
+ * Makes the requested generic call with no base path or version
727
+ *
728
+ * @function genericAdapterRequestNoBasePath
729
+ * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
730
+ * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
731
+ * @param {Object} queryData - the parameters to be put on the url (optional).
732
+ * Can be a stringified Object.
733
+ * @param {Object} requestBody - the body to add to the request (optional).
734
+ * Can be a stringified Object.
735
+ * @param {Object} addlHeaders - additional headers to be put on the call (optional).
736
+ * Can be a stringified Object.
737
+ * @param {getCallback} callback - a callback function to return the result (Generics)
738
+ * or the error
739
+ */
740
+ genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
741
+ const meth = 'adapter-genericAdapterRequestNoBasePath';
742
+ const origin = `${this.id}-${meth}`;
743
+ log.trace(origin);
744
+
745
+ if (this.suspended && this.suspendMode === 'error') {
746
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
747
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
748
+ return callback(null, errorObj);
749
+ }
750
+
751
+ /* HERE IS WHERE YOU VALIDATE DATA */
752
+ if (uriPath === undefined || uriPath === null || uriPath === '') {
753
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['uriPath'], null, null, null);
754
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
755
+ return callback(null, errorObj);
756
+ }
757
+ if (restMethod === undefined || restMethod === null || restMethod === '') {
758
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['restMethod'], null, null, null);
759
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
760
+ return callback(null, errorObj);
761
+ }
762
+
763
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
764
+ // remove any leading / and split the uripath into path variables
765
+ let myPath = uriPath;
766
+ while (myPath.indexOf('/') === 0) {
767
+ myPath = myPath.substring(1);
768
+ }
769
+ const pathVars = myPath.split('/');
770
+ const queryParamsAvailable = queryData;
771
+ const queryParams = {};
772
+ const bodyVars = requestBody;
773
+
774
+ // loop in template. long callback arg name to avoid identifier conflicts
775
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
776
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
777
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
778
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
779
+ }
780
+ });
781
+
782
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
783
+ const reqObj = {
784
+ payload: bodyVars,
785
+ uriPathVars: pathVars,
786
+ uriQuery: queryParams,
787
+ uriOptions: {}
788
+ };
789
+ // add headers if provided
790
+ if (addlHeaders) {
791
+ reqObj.addlHeaders = addlHeaders;
792
+ }
793
+
794
+ // determine the call and return flag
795
+ let action = 'getGenericsNoBase';
796
+ let returnF = true;
797
+ if (restMethod.toUpperCase() === 'POST') {
798
+ action = 'createGenericNoBase';
799
+ } else if (restMethod.toUpperCase() === 'PUT') {
800
+ action = 'updateGenericNoBase';
801
+ } else if (restMethod.toUpperCase() === 'PATCH') {
802
+ action = 'patchGenericNoBase';
803
+ } else if (restMethod.toUpperCase() === 'DELETE') {
804
+ action = 'deleteGenericNoBase';
805
+ returnF = false;
806
+ }
807
+
808
+ try {
809
+ // Make the call -
810
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
811
+ return this.requestHandlerInst.identifyRequest('.generic', action, reqObj, returnF, (irReturnData, irReturnError) => {
812
+ // if we received an error or their is no response on the results
813
+ // return an error
814
+ if (irReturnError) {
815
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
816
+ return callback(null, irReturnError);
817
+ }
818
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
819
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['genericAdapterRequestNoBasePath'], null, null, null);
820
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
821
+ return callback(null, errorObj);
822
+ }
823
+
824
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
825
+ // return the response
826
+ return callback(irReturnData, null);
827
+ });
828
+ } catch (ex) {
829
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
830
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
831
+ return callback(null, errorObj);
832
+ }
833
+ }
834
+
544
835
  /**
545
836
  * @callback healthCallback
546
837
  * @param {Object} result - the result of the get request (contains an id and a status)
@@ -32529,6 +32820,88 @@ This request will yield a base64-encoded session key to be included in an `X-Ses
32529
32820
  return callback(null, errorObj);
32530
32821
  }
32531
32822
  }
32823
+
32824
+ /**
32825
+ * @function getGraphql
32826
+ * @pronghornType method
32827
+ * @name getGraphql
32828
+ * @summary A lightweight read-only endpoint for conveying querying using graphql.
32829
+ *
32830
+ * @param {object} body - graphql query data
32831
+ * @param {getCallback} callback - a callback function to return the result
32832
+ * @return {object} results - An object containing the response of the action
32833
+ *
32834
+ * @route {GET} /getGraphql
32835
+ * @roles admin
32836
+ * @task true
32837
+ */
32838
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
32839
+ getGraphql(body, callback) {
32840
+ const meth = 'adapter-getGraphql';
32841
+ const origin = `${this.id}-${meth}`;
32842
+ log.trace(origin);
32843
+
32844
+ if (this.suspended && this.suspendMode === 'error') {
32845
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
32846
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
32847
+ return callback(null, errorObj);
32848
+ }
32849
+
32850
+ /* HERE IS WHERE YOU VALIDATE DATA */
32851
+ if (body === undefined || body === null || body === '') {
32852
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
32853
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
32854
+ return callback(null, errorObj);
32855
+ }
32856
+
32857
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
32858
+ const queryParamsAvailable = {};
32859
+ const queryParams = {};
32860
+ const pathVars = [];
32861
+ const bodyVars = body;
32862
+
32863
+ // loop in template. long callback arg name to avoid identifier conflicts
32864
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
32865
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
32866
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
32867
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
32868
+ }
32869
+ });
32870
+
32871
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
32872
+ // see adapter code documentation for more information on the request object's fields
32873
+ const reqObj = {
32874
+ payload: bodyVars,
32875
+ uriPathVars: pathVars,
32876
+ uriQuery: queryParams
32877
+ };
32878
+
32879
+ try {
32880
+ // Make the call -
32881
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
32882
+ return this.requestHandlerInst.identifyRequest('Graphql', 'getGraphql', reqObj, true, (irReturnData, irReturnError) => {
32883
+ // if we received an error or their is no response on the results
32884
+ // return an error
32885
+ if (irReturnError) {
32886
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
32887
+ return callback(null, irReturnError);
32888
+ }
32889
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
32890
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getGraphql'], null, null, null);
32891
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
32892
+ return callback(null, errorObj);
32893
+ }
32894
+
32895
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
32896
+ // return the response
32897
+ return callback(irReturnData, null);
32898
+ });
32899
+ } catch (ex) {
32900
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
32901
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
32902
+ return callback(null, errorObj);
32903
+ }
32904
+ }
32532
32905
  }
32533
32906
 
32534
32907
  module.exports = Netbox;