@itentialopensource/adapter-generic 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.
Files changed (69) hide show
  1. package/.eslintignore +5 -0
  2. package/.eslintrc.js +18 -0
  3. package/.gitlab/.gitkeep +0 -0
  4. package/.gitlab/issue_templates/.gitkeep +0 -0
  5. package/.gitlab/issue_templates/Default.md +17 -0
  6. package/.gitlab/issue_templates/bugReportTemplate.md +76 -0
  7. package/.gitlab/issue_templates/featureRequestTemplate.md +14 -0
  8. package/.jshintrc +3 -0
  9. package/BROKER.md +199 -0
  10. package/CALLS.md +207 -0
  11. package/CHANGELOG.md +9 -0
  12. package/CODE_OF_CONDUCT.md +43 -0
  13. package/CONTRIBUTING.md +13 -0
  14. package/ENHANCE.md +69 -0
  15. package/LICENSE +201 -0
  16. package/PROPERTIES.md +641 -0
  17. package/README.md +346 -0
  18. package/SUMMARY.md +9 -0
  19. package/TROUBLESHOOT.md +47 -0
  20. package/adapter.js +797 -0
  21. package/adapterBase.js +1452 -0
  22. package/changelogs/CHANGELOG.md +0 -0
  23. package/compliance-report.json +9 -0
  24. package/compliance-report.txt +5 -0
  25. package/entities/.generic/action.json +214 -0
  26. package/entities/.generic/schema.json +28 -0
  27. package/entities/.system/action.json +50 -0
  28. package/entities/.system/mockdatafiles/getToken-default.json +3 -0
  29. package/entities/.system/mockdatafiles/healthcheck-default.json +3 -0
  30. package/entities/.system/schema.json +19 -0
  31. package/entities/.system/schemaTokenReq.json +53 -0
  32. package/entities/.system/schemaTokenResp.json +53 -0
  33. package/error.json +190 -0
  34. package/metadata.json +47 -0
  35. package/package.json +82 -0
  36. package/pronghorn.json +1029 -0
  37. package/propertiesDecorators.json +14 -0
  38. package/propertiesSchema.json +1661 -0
  39. package/refs?service=git-upload-pack +0 -0
  40. package/report/adapterInfo.json +10 -0
  41. package/report/updateReport1691507318175.json +120 -0
  42. package/report/updateReport1692202361946.json +120 -0
  43. package/report/updateReport1694459763364.json +120 -0
  44. package/report/updateReport1698420283787.json +120 -0
  45. package/sampleProperties.json +256 -0
  46. package/test/integration/adapterTestBasicGet.js +83 -0
  47. package/test/integration/adapterTestConnectivity.js +142 -0
  48. package/test/integration/adapterTestIntegration.js +475 -0
  49. package/test/unit/adapterBaseTestUnit.js +1024 -0
  50. package/test/unit/adapterTestUnit.js +1508 -0
  51. package/utils/adapterInfo.js +206 -0
  52. package/utils/addAuth.js +94 -0
  53. package/utils/artifactize.js +146 -0
  54. package/utils/basicGet.js +50 -0
  55. package/utils/checkMigrate.js +63 -0
  56. package/utils/entitiesToDB.js +179 -0
  57. package/utils/findPath.js +74 -0
  58. package/utils/methodDocumentor.js +273 -0
  59. package/utils/modify.js +152 -0
  60. package/utils/packModificationScript.js +35 -0
  61. package/utils/patches2bundledDeps.js +90 -0
  62. package/utils/pre-commit.sh +32 -0
  63. package/utils/removeHooks.js +20 -0
  64. package/utils/setup.js +33 -0
  65. package/utils/taskMover.js +309 -0
  66. package/utils/tbScript.js +239 -0
  67. package/utils/tbUtils.js +489 -0
  68. package/utils/testRunner.js +298 -0
  69. package/utils/troubleshootingAdapter.js +193 -0
package/adapter.js ADDED
@@ -0,0 +1,797 @@
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 axios = require('axios');
12
+ /* Fetch in the other needed components for the this Adaptor */
13
+ const AdapterBaseCl = require(path.join(__dirname, 'adapterBase.js'));
14
+
15
+ function parseCurlCommand(curlCommand) {
16
+ const curlArgs = curlCommand.match(/'(?:\\'|[^'])*'|"(?:\\"|[^"])*"|\S+/g);
17
+ let url = '';
18
+ const requestOptions = {
19
+ method: 'GET',
20
+ headers: {},
21
+ maxRedirects: 0,
22
+ data: {}
23
+ };
24
+
25
+ // Process flags and options
26
+ for (let i = 1; i < curlArgs.length; i += 1) {
27
+ let arg = curlArgs[i];
28
+
29
+ if (arg.startsWith("'") && arg.endsWith("'")) {
30
+ arg = arg.slice(1, -1);
31
+ }
32
+ log.debug('arg', arg);
33
+
34
+ // URL
35
+ if (!url) {
36
+ url = arg; // Remove leading and trailing single quotes
37
+ }
38
+
39
+ // Follow redirects
40
+ if (arg === '--location') {
41
+ requestOptions.maxRedirects = 5; // Maximum number of redirects to follow
42
+ }
43
+
44
+ // Request method
45
+ if (arg === '-X' || arg === '--request') {
46
+ requestOptions.method = curlArgs[i + 1].toUpperCase();
47
+ i += 1;
48
+ }
49
+
50
+ // Headers
51
+ if (arg === '-H' || arg === '--header') {
52
+ let header = curlArgs[i + 1];
53
+ if (header.startsWith("'") && header.endsWith("'")) {
54
+ header = header.slice(1, -1);
55
+ }
56
+ const headerMatch = header.match(/^(.+?):\s*(.+)$/);
57
+ if (headerMatch) {
58
+ const headerKey = headerMatch[1].trim();
59
+ const headerValue = headerMatch[2].trim();
60
+ requestOptions.headers[headerKey] = headerValue;
61
+ }
62
+ i += 1;
63
+ }
64
+
65
+ // Data payload
66
+ if (arg === '-d' || arg === '--data') {
67
+ const dataValue = curlArgs[i + 1];
68
+ if (requestOptions.method === 'GET') {
69
+ // Convert data to query parameters for GET requests
70
+ const params = new URLSearchParams(dataValue);
71
+ url += (url.includes('?') ? '&' : '?') + params.toString();
72
+ } else {
73
+ // Set request body for other methods
74
+ requestOptions.data = dataValue;
75
+ }
76
+ i += 1;
77
+ }
78
+
79
+ // Additional flags/options can be processed similarly
80
+ // ...
81
+
82
+ // Handle authentication
83
+ if (arg === '-u' || arg === '--user') {
84
+ const authString = curlArgs[i + 1];
85
+ const [username, password] = authString.split(':');
86
+ requestOptions.auth = { username, password };
87
+ i += 1;
88
+ }
89
+
90
+ // If an argument is not recognized, you can handle it accordingly
91
+ log.warn('Unrecognized argument:', arg);
92
+ }
93
+
94
+ log.debug('url', url);
95
+ log.debug('requestOptions', requestOptions);
96
+
97
+ return { url, requestOptions };
98
+ }
99
+
100
+ /**
101
+ * This is the adapter/interface into Generic
102
+ */
103
+
104
+ /* GENERAL ADAPTER FUNCTIONS */
105
+ class Generic extends AdapterBaseCl {
106
+ /**
107
+ * Generic Adapter
108
+ * @constructor
109
+ */
110
+ /* Working on changing the way we do Emit methods due to size and time constrainsts
111
+ constructor(prongid, properties) {
112
+ // Instantiate the AdapterBase super class
113
+ super(prongid, properties);
114
+
115
+ const restFunctionNames = this.iapGetAdapterWorkflowFunctions();
116
+
117
+ // Dynamically bind emit functions
118
+ for (let i = 0; i < restFunctionNames.length; i += 1) {
119
+ // Bind function to have name fnNameEmit for fnName
120
+ const version = restFunctionNames[i].match(/__v[0-9]+/);
121
+ const baseFnName = restFunctionNames[i].replace(/__v[0-9]+/, '');
122
+ const fnNameEmit = version ? `${baseFnName}Emit${version}` : `${baseFnName}Emit`;
123
+ this[fnNameEmit] = function (...args) {
124
+ // extract the callback
125
+ const callback = args[args.length - 1];
126
+ // slice the callback from args so we can insert our own
127
+ const functionArgs = args.slice(0, args.length - 1);
128
+ // create a random name for the listener
129
+ const eventName = `${restFunctionNames[i]}:${Math.random().toString(36)}`;
130
+ // tell the calling class to start listening
131
+ callback({ event: eventName, status: 'received' });
132
+ // store parent for use of this context later
133
+ const parent = this;
134
+ // store emission function
135
+ const func = function (val, err) {
136
+ parent.removeListener(eventName, func);
137
+ parent.emit(eventName, val, err);
138
+ };
139
+ // Use apply to call the function in a specific context
140
+ this[restFunctionNames[i]].apply(this, functionArgs.concat([func])); // eslint-disable-line prefer-spread
141
+ };
142
+ }
143
+
144
+ // Uncomment if you have things to add to the constructor like using your own properties.
145
+ // Otherwise the constructor in the adapterBase will be used.
146
+ // Capture my own properties - they need to be defined in propertiesSchema.json
147
+ // if (this.allProps && this.allProps.myownproperty) {
148
+ // mypropvariable = this.allProps.myownproperty;
149
+ // }
150
+ }
151
+ */
152
+
153
+ /**
154
+ * @callback healthCallback
155
+ * @param {Object} reqObj - the request to send into the healthcheck
156
+ * @param {Callback} callback - The results of the call
157
+ */
158
+ healthCheck(reqObj, callback) {
159
+ // you can modify what is passed into the healthcheck by changing things in the newReq
160
+ let newReq = null;
161
+ if (reqObj) {
162
+ newReq = Object.assign(...reqObj);
163
+ }
164
+ super.healthCheck(newReq, callback);
165
+ }
166
+
167
+ /**
168
+ * @iapGetAdapterWorkflowFunctions
169
+ */
170
+ iapGetAdapterWorkflowFunctions(inIgnore) {
171
+ let myIgnore = [
172
+ 'healthCheck',
173
+ 'iapGetAdapterWorkflowFunctions',
174
+ 'hasEntities',
175
+ 'getAuthorization'
176
+ ];
177
+ if (!inIgnore && Array.isArray(inIgnore)) {
178
+ myIgnore = inIgnore;
179
+ } else if (!inIgnore && typeof inIgnore === 'string') {
180
+ myIgnore = [inIgnore];
181
+ }
182
+
183
+ // The generic adapter functions should already be ignored (e.g. healthCheck)
184
+ // you can add specific methods that you do not want to be workflow functions to ignore like below
185
+ // myIgnore.push('myMethodNotInWorkflow');
186
+
187
+ return super.iapGetAdapterWorkflowFunctions(myIgnore);
188
+ }
189
+
190
+ /**
191
+ * iapUpdateAdapterConfiguration is used to update any of the adapter configuration files. This
192
+ * allows customers to make changes to adapter configuration without having to be on the
193
+ * file system.
194
+ *
195
+ * @function iapUpdateAdapterConfiguration
196
+ * @param {string} configFile - the name of the file being updated (required)
197
+ * @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
198
+ * @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
199
+ * @param {string} type - the type of entity file to change, (action, schema, mock) (optional)
200
+ * @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
201
+ * @param {boolean} replace - true to replace entire mock data, false to merge/append
202
+ * @param {Callback} callback - The results of the call
203
+ */
204
+ iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, replace, callback) {
205
+ const meth = 'adapter-iapUpdateAdapterConfiguration';
206
+ const origin = `${this.id}-${meth}`;
207
+ log.trace(origin);
208
+
209
+ super.iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, replace, callback);
210
+ }
211
+
212
+ /**
213
+ * @summary Suspends adapter
214
+ *
215
+ * @function iapSuspendAdapter
216
+ * @param {Callback} callback - callback function
217
+ */
218
+ iapSuspendAdapter(mode, callback) {
219
+ const meth = 'adapter-iapSuspendAdapter';
220
+ const origin = `${this.id}-${meth}`;
221
+ log.trace(origin);
222
+
223
+ try {
224
+ return super.iapSuspendAdapter(mode, callback);
225
+ } catch (error) {
226
+ log.error(`${origin}: ${error}`);
227
+ return callback(null, error);
228
+ }
229
+ }
230
+
231
+ /**
232
+ * @summary Unsuspends adapter
233
+ *
234
+ * @function iapUnsuspendAdapter
235
+ * @param {Callback} callback - callback function
236
+ */
237
+ iapUnsuspendAdapter(callback) {
238
+ const meth = 'adapter-iapUnsuspendAdapter';
239
+ const origin = `${this.id}-${meth}`;
240
+ log.trace(origin);
241
+
242
+ try {
243
+ return super.iapUnsuspendAdapter(callback);
244
+ } catch (error) {
245
+ log.error(`${origin}: ${error}`);
246
+ return callback(null, error);
247
+ }
248
+ }
249
+
250
+ /**
251
+ * @summary Get the Adapter Queue
252
+ *
253
+ * @function iapGetAdapterQueue
254
+ * @param {Callback} callback - callback function
255
+ */
256
+ iapGetAdapterQueue(callback) {
257
+ const meth = 'adapter-iapGetAdapterQueue';
258
+ const origin = `${this.id}-${meth}`;
259
+ log.trace(origin);
260
+
261
+ return super.iapGetAdapterQueue(callback);
262
+ }
263
+
264
+ /* SCRIPT CALLS */
265
+ /**
266
+ * See if the API path provided is found in this adapter
267
+ *
268
+ * @function iapFindAdapterPath
269
+ * @param {string} apiPath - the api path to check on
270
+ * @param {Callback} callback - The results of the call
271
+ */
272
+ iapFindAdapterPath(apiPath, callback) {
273
+ const meth = 'adapter-iapFindAdapterPath';
274
+ const origin = `${this.id}-${meth}`;
275
+ log.trace(origin);
276
+
277
+ super.iapFindAdapterPath(apiPath, callback);
278
+ }
279
+
280
+ /**
281
+ * @summary Runs troubleshoot scripts for adapter
282
+ *
283
+ * @function iapTroubleshootAdapter
284
+ * @param {Object} props - the connection, healthcheck and authentication properties
285
+ *
286
+ * @param {boolean} persistFlag - whether the adapter properties should be updated
287
+ * @param {Callback} callback - The results of the call
288
+ */
289
+ iapTroubleshootAdapter(props, persistFlag, callback) {
290
+ const meth = 'adapter-iapTroubleshootAdapter';
291
+ const origin = `${this.id}-${meth}`;
292
+ log.trace(origin);
293
+
294
+ try {
295
+ return super.iapTroubleshootAdapter(props, persistFlag, this, callback);
296
+ } catch (error) {
297
+ log.error(`${origin}: ${error}`);
298
+ return callback(null, error);
299
+ }
300
+ }
301
+
302
+ /**
303
+ * @summary runs healthcheck script for adapter
304
+ *
305
+ * @function iapRunAdapterHealthcheck
306
+ * @param {Adapter} adapter - adapter instance to troubleshoot
307
+ * @param {Callback} callback - callback function
308
+ */
309
+ iapRunAdapterHealthcheck(callback) {
310
+ const meth = 'adapter-iapRunAdapterHealthcheck';
311
+ const origin = `${this.id}-${meth}`;
312
+ log.trace(origin);
313
+
314
+ try {
315
+ return super.iapRunAdapterHealthcheck(this, callback);
316
+ } catch (error) {
317
+ log.error(`${origin}: ${error}`);
318
+ return callback(null, error);
319
+ }
320
+ }
321
+
322
+ /**
323
+ * @summary runs connectivity check script for adapter
324
+ *
325
+ * @function iapRunAdapterConnectivity
326
+ * @param {Callback} callback - callback function
327
+ */
328
+ iapRunAdapterConnectivity(callback) {
329
+ const meth = 'adapter-iapRunAdapterConnectivity';
330
+ const origin = `${this.id}-${meth}`;
331
+ log.trace(origin);
332
+
333
+ try {
334
+ return super.iapRunAdapterConnectivity(callback);
335
+ } catch (error) {
336
+ log.error(`${origin}: ${error}`);
337
+ return callback(null, error);
338
+ }
339
+ }
340
+
341
+ /**
342
+ * @summary runs basicGet script for adapter
343
+ *
344
+ * @function iapRunAdapterBasicGet
345
+ * @param {Callback} callback - callback function
346
+ */
347
+ iapRunAdapterBasicGet(callback) {
348
+ const meth = 'adapter-iapRunAdapterBasicGet';
349
+ const origin = `${this.id}-${meth}`;
350
+ log.trace(origin);
351
+
352
+ try {
353
+ return super.iapRunAdapterBasicGet(callback);
354
+ } catch (error) {
355
+ log.error(`${origin}: ${error}`);
356
+ return callback(null, error);
357
+ }
358
+ }
359
+
360
+ /**
361
+ * @summary moves entites into Mongo DB
362
+ *
363
+ * @function iapMoveAdapterEntitiesToDB
364
+ * @param {getCallback} callback - a callback function to return the result (Generics)
365
+ * or the error
366
+ */
367
+ iapMoveAdapterEntitiesToDB(callback) {
368
+ const meth = 'adapter-iapMoveAdapterEntitiesToDB';
369
+ const origin = `${this.id}-${meth}`;
370
+ log.trace(origin);
371
+
372
+ try {
373
+ return super.iapMoveAdapterEntitiesToDB(callback);
374
+ } catch (err) {
375
+ log.error(`${origin}: ${err}`);
376
+ return callback(null, err);
377
+ }
378
+ }
379
+
380
+ /**
381
+ * @summary Deactivate adapter tasks
382
+ *
383
+ * @function iapDeactivateTasks
384
+ *
385
+ * @param {Array} tasks - List of tasks to deactivate
386
+ * @param {Callback} callback
387
+ */
388
+ iapDeactivateTasks(tasks, callback) {
389
+ const meth = 'adapter-iapDeactivateTasks';
390
+ const origin = `${this.id}-${meth}`;
391
+ log.trace(origin);
392
+
393
+ try {
394
+ return super.iapDeactivateTasks(tasks, callback);
395
+ } catch (err) {
396
+ log.error(`${origin}: ${err}`);
397
+ return callback(null, err);
398
+ }
399
+ }
400
+
401
+ /**
402
+ * @summary Activate adapter tasks that have previously been deactivated
403
+ *
404
+ * @function iapActivateTasks
405
+ *
406
+ * @param {Array} tasks - List of tasks to activate
407
+ * @param {Callback} callback
408
+ */
409
+ iapActivateTasks(tasks, callback) {
410
+ const meth = 'adapter-iapActivateTasks';
411
+ const origin = `${this.id}-${meth}`;
412
+ log.trace(origin);
413
+
414
+ try {
415
+ return super.iapActivateTasks(tasks, callback);
416
+ } catch (err) {
417
+ log.error(`${origin}: ${err}`);
418
+ return callback(null, err);
419
+ }
420
+ }
421
+
422
+ /* CACHE CALLS */
423
+ /**
424
+ * @summary Populate the cache for the given entities
425
+ *
426
+ * @function iapPopulateEntityCache
427
+ * @param {String/Array of Strings} entityType - the entity type(s) to populate
428
+ * @param {Callback} callback - whether the cache was updated or not for each entity type
429
+ *
430
+ * @returns status of the populate
431
+ */
432
+ iapPopulateEntityCache(entityTypes, callback) {
433
+ const meth = 'adapter-iapPopulateEntityCache';
434
+ const origin = `${this.id}-${meth}`;
435
+ log.trace(origin);
436
+
437
+ try {
438
+ return super.iapPopulateEntityCache(entityTypes, callback);
439
+ } catch (err) {
440
+ log.error(`${origin}: ${err}`);
441
+ return callback(null, err);
442
+ }
443
+ }
444
+
445
+ /**
446
+ * @summary Retrieves data from cache for specified entity type
447
+ *
448
+ * @function iapRetrieveEntitiesCache
449
+ * @param {String} entityType - entity of which to retrieve
450
+ * @param {Object} options - settings of which data to return and how to return it
451
+ * @param {Callback} callback - the data if it was retrieved
452
+ */
453
+ iapRetrieveEntitiesCache(entityType, options, callback) {
454
+ const meth = 'adapter-iapCheckEiapRetrieveEntitiesCachentityCached';
455
+ const origin = `${this.id}-${meth}`;
456
+ log.trace(origin);
457
+
458
+ try {
459
+ return super.iapRetrieveEntitiesCache(entityType, options, callback);
460
+ } catch (err) {
461
+ log.error(`${origin}: ${err}`);
462
+ return callback(null, err);
463
+ }
464
+ }
465
+
466
+ /* BROKER CALLS */
467
+ /**
468
+ * @summary Determines if this adapter supports any in a list of entities
469
+ *
470
+ * @function hasEntities
471
+ * @param {String} entityType - the entity type to check for
472
+ * @param {Array} entityList - the list of entities we are looking for
473
+ *
474
+ * @param {Callback} callback - A map where the entity is the key and the
475
+ * value is true or false
476
+ */
477
+ hasEntities(entityType, entityList, callback) {
478
+ const meth = 'adapter-hasEntities';
479
+ const origin = `${this.id}-${meth}`;
480
+ log.trace(origin);
481
+
482
+ try {
483
+ return super.hasEntities(entityType, entityList, callback);
484
+ } catch (err) {
485
+ log.error(`${origin}: ${err}`);
486
+ return callback(null, err);
487
+ }
488
+ }
489
+
490
+ /**
491
+ * @summary Get Appliance that match the deviceName
492
+ *
493
+ * @function getDevice
494
+ * @param {String} deviceName - the deviceName to find (required)
495
+ *
496
+ * @param {getCallback} callback - a callback function to return the result
497
+ * (appliance) or the error
498
+ */
499
+ getDevice(deviceName, callback) {
500
+ const meth = 'adapter-getDevice';
501
+ const origin = `${this.id}-${meth}`;
502
+ log.trace(origin);
503
+
504
+ try {
505
+ return super.getDevice(deviceName, callback);
506
+ } catch (err) {
507
+ log.error(`${origin}: ${err}`);
508
+ return callback(null, err);
509
+ }
510
+ }
511
+
512
+ /**
513
+ * @summary Get Appliances that match the filter
514
+ *
515
+ * @function getDevicesFiltered
516
+ * @param {Object} options - the data to use to filter the appliances (optional)
517
+ *
518
+ * @param {getCallback} callback - a callback function to return the result
519
+ * (appliances) or the error
520
+ */
521
+ getDevicesFiltered(options, callback) {
522
+ const meth = 'adapter-getDevicesFiltered';
523
+ const origin = `${this.id}-${meth}`;
524
+ log.trace(origin);
525
+
526
+ try {
527
+ return super.getDevicesFiltered(options, callback);
528
+ } catch (err) {
529
+ log.error(`${origin}: ${err}`);
530
+ return callback(null, err);
531
+ }
532
+ }
533
+
534
+ /**
535
+ * @summary Gets the status for the provided appliance
536
+ *
537
+ * @function isAlive
538
+ * @param {String} deviceName - the deviceName of the appliance. (required)
539
+ *
540
+ * @param {configCallback} callback - callback function to return the result
541
+ * (appliance isAlive) or the error
542
+ */
543
+ isAlive(deviceName, callback) {
544
+ const meth = 'adapter-isAlive';
545
+ const origin = `${this.id}-${meth}`;
546
+ log.trace(origin);
547
+
548
+ try {
549
+ return super.isAlive(deviceName, callback);
550
+ } catch (err) {
551
+ log.error(`${origin}: ${err}`);
552
+ return callback(null, err);
553
+ }
554
+ }
555
+
556
+ /**
557
+ * @summary Gets a config for the provided Appliance
558
+ *
559
+ * @function getConfig
560
+ * @param {String} deviceName - the deviceName of the appliance. (required)
561
+ * @param {String} format - the desired format of the config. (optional)
562
+ *
563
+ * @param {configCallback} callback - callback function to return the result
564
+ * (appliance config) or the error
565
+ */
566
+ getConfig(deviceName, format, callback) {
567
+ const meth = 'adapter-getConfig';
568
+ const origin = `${this.id}-${meth}`;
569
+ log.trace(origin);
570
+
571
+ try {
572
+ return super.getConfig(deviceName, format, callback);
573
+ } catch (err) {
574
+ log.error(`${origin}: ${err}`);
575
+ return callback(null, err);
576
+ }
577
+ }
578
+
579
+ /**
580
+ * @summary Gets the device count from the system
581
+ *
582
+ * @function iapGetDeviceCount
583
+ *
584
+ * @param {getCallback} callback - callback function to return the result
585
+ * (count) or the error
586
+ */
587
+ iapGetDeviceCount(callback) {
588
+ const meth = 'adapter-iapGetDeviceCount';
589
+ const origin = `${this.id}-${meth}`;
590
+ log.trace(origin);
591
+
592
+ try {
593
+ return super.iapGetDeviceCount(callback);
594
+ } catch (err) {
595
+ log.error(`${origin}: ${err}`);
596
+ return callback(null, err);
597
+ }
598
+ }
599
+
600
+ /* GENERIC ADAPTER REQUEST - allows extension of adapter without new calls being added */
601
+ /**
602
+ * Makes the requested generic call
603
+ *
604
+ * @function iapExpandedGenericAdapterRequest
605
+ * @param {Object} metadata - metadata for the call (optional).
606
+ * Can be a stringified Object.
607
+ * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (optional)
608
+ * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (optional)
609
+ * @param {Object} pathVars - the parameters to be put within the url path (optional).
610
+ * Can be a stringified Object.
611
+ * @param {Object} queryData - the parameters to be put on the url (optional).
612
+ * Can be a stringified Object.
613
+ * @param {Object} requestBody - the body to add to the request (optional).
614
+ * Can be a stringified Object.
615
+ * @param {Object} addlHeaders - additional headers to be put on the call (optional).
616
+ * Can be a stringified Object.
617
+ * @param {getCallback} callback - a callback function to return the result (Generics)
618
+ * or the error
619
+ */
620
+ iapExpandedGenericAdapterRequest(metadata, uriPath, restMethod, pathVars, queryData, requestBody, addlHeaders, callback) {
621
+ const meth = 'adapter-iapExpandedGenericAdapterRequest';
622
+ const origin = `${this.id}-${meth}`;
623
+ log.trace(origin);
624
+
625
+ try {
626
+ return super.iapExpandedGenericAdapterRequest(metadata, uriPath, restMethod, pathVars, queryData, requestBody, addlHeaders, callback);
627
+ } catch (err) {
628
+ log.error(`${origin}: ${err}`);
629
+ return callback(null, err);
630
+ }
631
+ }
632
+
633
+ /**
634
+ * Makes the requested generic call
635
+ *
636
+ * @function genericAdapterRequest
637
+ * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
638
+ * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
639
+ * @param {Object} queryData - the parameters to be put on the url (optional).
640
+ * Can be a stringified Object.
641
+ * @param {Object} requestBody - the body to add to the request (optional).
642
+ * Can be a stringified Object.
643
+ * @param {Object} addlHeaders - additional headers to be put on the call (optional).
644
+ * Can be a stringified Object.
645
+ * @param {getCallback} callback - a callback function to return the result (Generics)
646
+ * or the error
647
+ */
648
+ genericAdapterRequest(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
649
+ const meth = 'adapter-genericAdapterRequest';
650
+ const origin = `${this.id}-${meth}`;
651
+ log.trace(origin);
652
+
653
+ try {
654
+ return super.genericAdapterRequest(uriPath, restMethod, queryData, requestBody, addlHeaders, callback);
655
+ } catch (err) {
656
+ log.error(`${origin}: ${err}`);
657
+ return callback(null, err);
658
+ }
659
+ }
660
+
661
+ /**
662
+ * Makes the requested generic call with no base path or version
663
+ *
664
+ * @function genericAdapterRequestNoBasePath
665
+ * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
666
+ * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
667
+ * @param {Object} queryData - the parameters to be put on the url (optional).
668
+ * Can be a stringified Object.
669
+ * @param {Object} requestBody - the body to add to the request (optional).
670
+ * Can be a stringified Object.
671
+ * @param {Object} addlHeaders - additional headers to be put on the call (optional).
672
+ * Can be a stringified Object.
673
+ * @param {getCallback} callback - a callback function to return the result (Generics)
674
+ * or the error
675
+ */
676
+ genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
677
+ const meth = 'adapter-genericAdapterRequestNoBasePath';
678
+ const origin = `${this.id}-${meth}`;
679
+ log.trace(origin);
680
+
681
+ try {
682
+ return super.genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback);
683
+ } catch (err) {
684
+ log.error(`${origin}: ${err}`);
685
+ return callback(null, err);
686
+ }
687
+ }
688
+
689
+ /* INVENTORY CALLS */
690
+ /**
691
+ * @summary run the adapter lint script to return the results.
692
+ *
693
+ * @function iapRunAdapterLint
694
+ * @param {Callback} callback - callback function
695
+ */
696
+ iapRunAdapterLint(callback) {
697
+ const meth = 'adapter-iapRunAdapterLint';
698
+ const origin = `${this.id}-${meth}`;
699
+ log.trace(origin);
700
+
701
+ return super.iapRunAdapterLint(callback);
702
+ }
703
+
704
+ /**
705
+ * @summary run the adapter test scripts (baseunit and unit) to return the results.
706
+ * can not run integration as there can be implications with that.
707
+ *
708
+ * @function iapRunAdapterTests
709
+ * @param {Callback} callback - callback function
710
+ */
711
+ iapRunAdapterTests(callback) {
712
+ const meth = 'adapter-iapRunAdapterTests';
713
+ const origin = `${this.id}-${meth}`;
714
+ log.trace(origin);
715
+
716
+ return super.iapRunAdapterTests(callback);
717
+ }
718
+
719
+ /**
720
+ * @summary provide inventory information abbout the adapter
721
+ *
722
+ * @function iapGetAdapterInventory
723
+ * @param {Callback} callback - callback function
724
+ */
725
+ iapGetAdapterInventory(callback) {
726
+ const meth = 'adapter-iapGetAdapterInventory';
727
+ const origin = `${this.id}-${meth}`;
728
+ log.trace(origin);
729
+
730
+ return super.iapGetAdapterInventory(callback);
731
+ }
732
+
733
+ /**
734
+ * @summary Makes the requested curl call
735
+ *
736
+ * @function genericCurl
737
+ * @param {string} curlCommand - Eg: curl 'https://myhost/api/v1/organizations/deviceId/devices' --header 'X-Cisco-Meraki-API-Key: mykey' --location
738
+ * @param {getCallback} callback - a callback function to return the result (Generics)
739
+ * or the error
740
+ */
741
+ async genericCurl(curlCommand, callback) {
742
+ const meth = 'adapter-genericCurl';
743
+ const origin = `${this.id}-${meth}`;
744
+ log.trace(origin);
745
+
746
+ try {
747
+ log.debug(parseCurlCommand(curlCommand));
748
+ const { url, requestOptions } = parseCurlCommand(curlCommand);
749
+ const { method } = requestOptions;
750
+ const { headers } = requestOptions;
751
+ const { data } = requestOptions;
752
+
753
+ const response = await axios({
754
+ method,
755
+ url,
756
+ headers,
757
+ data
758
+ });
759
+
760
+ log.debug('Response Headers:', response.headers);
761
+ log.debug('Response Body:', response.data);
762
+ const result = { response_headers: response.headers, response_body: response.data };
763
+ return callback(result);
764
+ } catch (ex) {
765
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception, make sure to pass all flags in the end of curl command', {}, null, null, ex);
766
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
767
+ return callback(null, errorObj);
768
+ }
769
+ }
770
+
771
+ /**
772
+ * @callback healthCallback
773
+ * @param {Object} result - the result of the get request (contains an id and a status)
774
+ */
775
+ /**
776
+ * @callback getCallback
777
+ * @param {Object} result - the result of the get request (entity/ies)
778
+ * @param {String} error - any error that occurred
779
+ */
780
+ /**
781
+ * @callback createCallback
782
+ * @param {Object} item - the newly created entity
783
+ * @param {String} error - any error that occurred
784
+ */
785
+ /**
786
+ * @callback updateCallback
787
+ * @param {String} status - the status of the update action
788
+ * @param {String} error - any error that occurred
789
+ */
790
+ /**
791
+ * @callback deleteCallback
792
+ * @param {String} status - the status of the delete action
793
+ * @param {String} error - any error that occurred
794
+ */
795
+ }
796
+
797
+ module.exports = Generic;