@itentialopensource/adapter-checkpoint_reputation_service 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 (70) hide show
  1. package/.eslintignore +5 -0
  2. package/.eslintrc.js +18 -0
  3. package/.jshintrc +3 -0
  4. package/AUTH.md +44 -0
  5. package/BROKER.md +211 -0
  6. package/CALLS.md +207 -0
  7. package/CHANGELOG.md +9 -0
  8. package/CODE_OF_CONDUCT.md +43 -0
  9. package/CONTRIBUTING.md +13 -0
  10. package/ENHANCE.md +69 -0
  11. package/LICENSE +201 -0
  12. package/PROPERTIES.md +646 -0
  13. package/README.md +343 -0
  14. package/SUMMARY.md +9 -0
  15. package/SYSTEMINFO.md +18 -0
  16. package/TAB1.md +10 -0
  17. package/TAB2.md +318 -0
  18. package/TROUBLESHOOT.md +47 -0
  19. package/adapter.js +919 -0
  20. package/adapterBase.js +1452 -0
  21. package/changelogs/CHANGELOG.md +0 -0
  22. package/entities/.generic/action.json +214 -0
  23. package/entities/.generic/schema.json +28 -0
  24. package/entities/.system/action.json +50 -0
  25. package/entities/.system/mockdatafiles/getToken-default.json +1 -0
  26. package/entities/.system/mockdatafiles/healthcheck-default.json +3 -0
  27. package/entities/.system/schema.json +19 -0
  28. package/entities/.system/schemaTokenReq.json +53 -0
  29. package/entities/.system/schemaTokenResp.json +31 -0
  30. package/entities/Authentication/action.json +25 -0
  31. package/entities/Authentication/schema.json +19 -0
  32. package/entities/Query/action.json +24 -0
  33. package/entities/Query/schema.json +19 -0
  34. package/error.json +190 -0
  35. package/metadata.json +82 -0
  36. package/package.json +81 -0
  37. package/pronghorn.json +1092 -0
  38. package/propertiesDecorators.json +14 -0
  39. package/propertiesSchema.json +1574 -0
  40. package/refs?service=git-upload-pack +0 -0
  41. package/report/adapter-openapi.json +502 -0
  42. package/report/adapter-openapi.yaml +333 -0
  43. package/report/auto-adapter-openapi.json +95 -0
  44. package/report/checkpoint.yaml +333 -0
  45. package/report/creationReport.json +235 -0
  46. package/sampleProperties.json +260 -0
  47. package/test/integration/adapterTestBasicGet.js +83 -0
  48. package/test/integration/adapterTestConnectivity.js +118 -0
  49. package/test/integration/adapterTestIntegration.js +533 -0
  50. package/test/unit/adapterBaseTestUnit.js +1024 -0
  51. package/test/unit/adapterTestUnit.js +1579 -0
  52. package/utils/adapterInfo.js +206 -0
  53. package/utils/addAuth.js +94 -0
  54. package/utils/artifactize.js +146 -0
  55. package/utils/basicGet.js +50 -0
  56. package/utils/checkMigrate.js +63 -0
  57. package/utils/entitiesToDB.js +179 -0
  58. package/utils/findPath.js +74 -0
  59. package/utils/methodDocumentor.js +273 -0
  60. package/utils/modify.js +152 -0
  61. package/utils/packModificationScript.js +35 -0
  62. package/utils/patches2bundledDeps.js +90 -0
  63. package/utils/pre-commit.sh +32 -0
  64. package/utils/removeHooks.js +20 -0
  65. package/utils/setup.js +33 -0
  66. package/utils/taskMover.js +309 -0
  67. package/utils/tbScript.js +239 -0
  68. package/utils/tbUtils.js +489 -0
  69. package/utils/testRunner.js +298 -0
  70. package/utils/troubleshootingAdapter.js +193 -0
package/adapter.js ADDED
@@ -0,0 +1,919 @@
1
+ /* @copyright Itential, LLC 2019 (pre-modifications) */
2
+
3
+ /* eslint import/no-dynamic-require: warn */
4
+ /* eslint object-curly-newline: warn */
5
+ /* eslint default-param-last: warn */
6
+
7
+ // Set globals
8
+ /* global log */
9
+
10
+ /* Required libraries. */
11
+ const path = require('path');
12
+
13
+ /* Fetch in the other needed components for the this Adaptor */
14
+ const AdapterBaseCl = require(path.join(__dirname, 'adapterBase.js'));
15
+
16
+ /**
17
+ * This is the adapter/interface into Checkpoint_reputation_service
18
+ */
19
+
20
+ /* GENERAL ADAPTER FUNCTIONS */
21
+ class CheckpointReputationService extends AdapterBaseCl {
22
+ /**
23
+ * CheckpointReputationService Adapter
24
+ * @constructor
25
+ */
26
+ /* Working on changing the way we do Emit methods due to size and time constrainsts
27
+ constructor(prongid, properties) {
28
+ // Instantiate the AdapterBase super class
29
+ super(prongid, properties);
30
+
31
+ const restFunctionNames = this.iapGetAdapterWorkflowFunctions();
32
+
33
+ // Dynamically bind emit functions
34
+ for (let i = 0; i < restFunctionNames.length; i += 1) {
35
+ // Bind function to have name fnNameEmit for fnName
36
+ const version = restFunctionNames[i].match(/__v[0-9]+/);
37
+ const baseFnName = restFunctionNames[i].replace(/__v[0-9]+/, '');
38
+ const fnNameEmit = version ? `${baseFnName}Emit${version}` : `${baseFnName}Emit`;
39
+ this[fnNameEmit] = function (...args) {
40
+ // extract the callback
41
+ const callback = args[args.length - 1];
42
+ // slice the callback from args so we can insert our own
43
+ const functionArgs = args.slice(0, args.length - 1);
44
+ // create a random name for the listener
45
+ const eventName = `${restFunctionNames[i]}:${Math.random().toString(36)}`;
46
+ // tell the calling class to start listening
47
+ callback({ event: eventName, status: 'received' });
48
+ // store parent for use of this context later
49
+ const parent = this;
50
+ // store emission function
51
+ const func = function (val, err) {
52
+ parent.removeListener(eventName, func);
53
+ parent.emit(eventName, val, err);
54
+ };
55
+ // Use apply to call the function in a specific context
56
+ this[restFunctionNames[i]].apply(this, functionArgs.concat([func])); // eslint-disable-line prefer-spread
57
+ };
58
+ }
59
+
60
+ // Uncomment if you have things to add to the constructor like using your own properties.
61
+ // Otherwise the constructor in the adapterBase will be used.
62
+ // Capture my own properties - they need to be defined in propertiesSchema.json
63
+ // if (this.allProps && this.allProps.myownproperty) {
64
+ // mypropvariable = this.allProps.myownproperty;
65
+ // }
66
+ }
67
+ */
68
+
69
+ /**
70
+ * @callback healthCallback
71
+ * @param {Object} reqObj - the request to send into the healthcheck
72
+ * @param {Callback} callback - The results of the call
73
+ */
74
+ healthCheck(reqObj, callback) {
75
+ // you can modify what is passed into the healthcheck by changing things in the newReq
76
+ let newReq = null;
77
+ if (reqObj) {
78
+ newReq = Object.assign(...reqObj);
79
+ }
80
+ super.healthCheck(newReq, callback);
81
+ }
82
+
83
+ /**
84
+ * @iapGetAdapterWorkflowFunctions
85
+ */
86
+ iapGetAdapterWorkflowFunctions(inIgnore) {
87
+ let myIgnore = [
88
+ 'healthCheck',
89
+ 'iapGetAdapterWorkflowFunctions',
90
+ 'hasEntities',
91
+ 'getAuthorization'
92
+ ];
93
+ if (!inIgnore && Array.isArray(inIgnore)) {
94
+ myIgnore = inIgnore;
95
+ } else if (!inIgnore && typeof inIgnore === 'string') {
96
+ myIgnore = [inIgnore];
97
+ }
98
+
99
+ // The generic adapter functions should already be ignored (e.g. healthCheck)
100
+ // you can add specific methods that you do not want to be workflow functions to ignore like below
101
+ // myIgnore.push('myMethodNotInWorkflow');
102
+
103
+ return super.iapGetAdapterWorkflowFunctions(myIgnore);
104
+ }
105
+
106
+ /**
107
+ * iapUpdateAdapterConfiguration is used to update any of the adapter configuration files. This
108
+ * allows customers to make changes to adapter configuration without having to be on the
109
+ * file system.
110
+ *
111
+ * @function iapUpdateAdapterConfiguration
112
+ * @param {string} configFile - the name of the file being updated (required)
113
+ * @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
114
+ * @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
115
+ * @param {string} type - the type of entity file to change, (action, schema, mock) (optional)
116
+ * @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
117
+ * @param {boolean} replace - true to replace entire mock data, false to merge/append
118
+ * @param {Callback} callback - The results of the call
119
+ */
120
+ iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, replace, callback) {
121
+ const meth = 'adapter-iapUpdateAdapterConfiguration';
122
+ const origin = `${this.id}-${meth}`;
123
+ log.trace(origin);
124
+
125
+ super.iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, replace, callback);
126
+ }
127
+
128
+ /**
129
+ * @summary Suspends adapter
130
+ *
131
+ * @function iapSuspendAdapter
132
+ * @param {Callback} callback - callback function
133
+ */
134
+ iapSuspendAdapter(mode, callback) {
135
+ const meth = 'adapter-iapSuspendAdapter';
136
+ const origin = `${this.id}-${meth}`;
137
+ log.trace(origin);
138
+
139
+ try {
140
+ return super.iapSuspendAdapter(mode, callback);
141
+ } catch (error) {
142
+ log.error(`${origin}: ${error}`);
143
+ return callback(null, error);
144
+ }
145
+ }
146
+
147
+ /**
148
+ * @summary Unsuspends adapter
149
+ *
150
+ * @function iapUnsuspendAdapter
151
+ * @param {Callback} callback - callback function
152
+ */
153
+ iapUnsuspendAdapter(callback) {
154
+ const meth = 'adapter-iapUnsuspendAdapter';
155
+ const origin = `${this.id}-${meth}`;
156
+ log.trace(origin);
157
+
158
+ try {
159
+ return super.iapUnsuspendAdapter(callback);
160
+ } catch (error) {
161
+ log.error(`${origin}: ${error}`);
162
+ return callback(null, error);
163
+ }
164
+ }
165
+
166
+ /**
167
+ * @summary Get the Adapter Queue
168
+ *
169
+ * @function iapGetAdapterQueue
170
+ * @param {Callback} callback - callback function
171
+ */
172
+ iapGetAdapterQueue(callback) {
173
+ const meth = 'adapter-iapGetAdapterQueue';
174
+ const origin = `${this.id}-${meth}`;
175
+ log.trace(origin);
176
+
177
+ return super.iapGetAdapterQueue(callback);
178
+ }
179
+
180
+ /* SCRIPT CALLS */
181
+ /**
182
+ * See if the API path provided is found in this adapter
183
+ *
184
+ * @function iapFindAdapterPath
185
+ * @param {string} apiPath - the api path to check on
186
+ * @param {Callback} callback - The results of the call
187
+ */
188
+ iapFindAdapterPath(apiPath, callback) {
189
+ const meth = 'adapter-iapFindAdapterPath';
190
+ const origin = `${this.id}-${meth}`;
191
+ log.trace(origin);
192
+
193
+ super.iapFindAdapterPath(apiPath, callback);
194
+ }
195
+
196
+ /**
197
+ * @summary Runs troubleshoot scripts for adapter
198
+ *
199
+ * @function iapTroubleshootAdapter
200
+ * @param {Object} props - the connection, healthcheck and authentication properties
201
+ *
202
+ * @param {boolean} persistFlag - whether the adapter properties should be updated
203
+ * @param {Callback} callback - The results of the call
204
+ */
205
+ iapTroubleshootAdapter(props, persistFlag, callback) {
206
+ const meth = 'adapter-iapTroubleshootAdapter';
207
+ const origin = `${this.id}-${meth}`;
208
+ log.trace(origin);
209
+
210
+ try {
211
+ return super.iapTroubleshootAdapter(props, persistFlag, this, callback);
212
+ } catch (error) {
213
+ log.error(`${origin}: ${error}`);
214
+ return callback(null, error);
215
+ }
216
+ }
217
+
218
+ /**
219
+ * @summary runs healthcheck script for adapter
220
+ *
221
+ * @function iapRunAdapterHealthcheck
222
+ * @param {Adapter} adapter - adapter instance to troubleshoot
223
+ * @param {Callback} callback - callback function
224
+ */
225
+ iapRunAdapterHealthcheck(callback) {
226
+ const meth = 'adapter-iapRunAdapterHealthcheck';
227
+ const origin = `${this.id}-${meth}`;
228
+ log.trace(origin);
229
+
230
+ try {
231
+ return super.iapRunAdapterHealthcheck(this, callback);
232
+ } catch (error) {
233
+ log.error(`${origin}: ${error}`);
234
+ return callback(null, error);
235
+ }
236
+ }
237
+
238
+ /**
239
+ * @summary runs connectivity check script for adapter
240
+ *
241
+ * @function iapRunAdapterConnectivity
242
+ * @param {Callback} callback - callback function
243
+ */
244
+ iapRunAdapterConnectivity(callback) {
245
+ const meth = 'adapter-iapRunAdapterConnectivity';
246
+ const origin = `${this.id}-${meth}`;
247
+ log.trace(origin);
248
+
249
+ try {
250
+ return super.iapRunAdapterConnectivity(callback);
251
+ } catch (error) {
252
+ log.error(`${origin}: ${error}`);
253
+ return callback(null, error);
254
+ }
255
+ }
256
+
257
+ /**
258
+ * @summary runs basicGet script for adapter
259
+ *
260
+ * @function iapRunAdapterBasicGet
261
+ * @param {Callback} callback - callback function
262
+ */
263
+ iapRunAdapterBasicGet(callback) {
264
+ const meth = 'adapter-iapRunAdapterBasicGet';
265
+ const origin = `${this.id}-${meth}`;
266
+ log.trace(origin);
267
+
268
+ try {
269
+ return super.iapRunAdapterBasicGet(callback);
270
+ } catch (error) {
271
+ log.error(`${origin}: ${error}`);
272
+ return callback(null, error);
273
+ }
274
+ }
275
+
276
+ /**
277
+ * @summary moves entites into Mongo DB
278
+ *
279
+ * @function iapMoveAdapterEntitiesToDB
280
+ * @param {getCallback} callback - a callback function to return the result (Generics)
281
+ * or the error
282
+ */
283
+ iapMoveAdapterEntitiesToDB(callback) {
284
+ const meth = 'adapter-iapMoveAdapterEntitiesToDB';
285
+ const origin = `${this.id}-${meth}`;
286
+ log.trace(origin);
287
+
288
+ try {
289
+ return super.iapMoveAdapterEntitiesToDB(callback);
290
+ } catch (err) {
291
+ log.error(`${origin}: ${err}`);
292
+ return callback(null, err);
293
+ }
294
+ }
295
+
296
+ /**
297
+ * @summary Deactivate adapter tasks
298
+ *
299
+ * @function iapDeactivateTasks
300
+ *
301
+ * @param {Array} tasks - List of tasks to deactivate
302
+ * @param {Callback} callback
303
+ */
304
+ iapDeactivateTasks(tasks, callback) {
305
+ const meth = 'adapter-iapDeactivateTasks';
306
+ const origin = `${this.id}-${meth}`;
307
+ log.trace(origin);
308
+
309
+ try {
310
+ return super.iapDeactivateTasks(tasks, callback);
311
+ } catch (err) {
312
+ log.error(`${origin}: ${err}`);
313
+ return callback(null, err);
314
+ }
315
+ }
316
+
317
+ /**
318
+ * @summary Activate adapter tasks that have previously been deactivated
319
+ *
320
+ * @function iapActivateTasks
321
+ *
322
+ * @param {Array} tasks - List of tasks to activate
323
+ * @param {Callback} callback
324
+ */
325
+ iapActivateTasks(tasks, callback) {
326
+ const meth = 'adapter-iapActivateTasks';
327
+ const origin = `${this.id}-${meth}`;
328
+ log.trace(origin);
329
+
330
+ try {
331
+ return super.iapActivateTasks(tasks, callback);
332
+ } catch (err) {
333
+ log.error(`${origin}: ${err}`);
334
+ return callback(null, err);
335
+ }
336
+ }
337
+
338
+ /* CACHE CALLS */
339
+ /**
340
+ * @summary Populate the cache for the given entities
341
+ *
342
+ * @function iapPopulateEntityCache
343
+ * @param {String/Array of Strings} entityType - the entity type(s) to populate
344
+ * @param {Callback} callback - whether the cache was updated or not for each entity type
345
+ *
346
+ * @returns status of the populate
347
+ */
348
+ iapPopulateEntityCache(entityTypes, callback) {
349
+ const meth = 'adapter-iapPopulateEntityCache';
350
+ const origin = `${this.id}-${meth}`;
351
+ log.trace(origin);
352
+
353
+ try {
354
+ return super.iapPopulateEntityCache(entityTypes, callback);
355
+ } catch (err) {
356
+ log.error(`${origin}: ${err}`);
357
+ return callback(null, err);
358
+ }
359
+ }
360
+
361
+ /**
362
+ * @summary Retrieves data from cache for specified entity type
363
+ *
364
+ * @function iapRetrieveEntitiesCache
365
+ * @param {String} entityType - entity of which to retrieve
366
+ * @param {Object} options - settings of which data to return and how to return it
367
+ * @param {Callback} callback - the data if it was retrieved
368
+ */
369
+ iapRetrieveEntitiesCache(entityType, options, callback) {
370
+ const meth = 'adapter-iapCheckEiapRetrieveEntitiesCachentityCached';
371
+ const origin = `${this.id}-${meth}`;
372
+ log.trace(origin);
373
+
374
+ try {
375
+ return super.iapRetrieveEntitiesCache(entityType, options, callback);
376
+ } catch (err) {
377
+ log.error(`${origin}: ${err}`);
378
+ return callback(null, err);
379
+ }
380
+ }
381
+
382
+ /* BROKER CALLS */
383
+ /**
384
+ * @summary Determines if this adapter supports any in a list of entities
385
+ *
386
+ * @function hasEntities
387
+ * @param {String} entityType - the entity type to check for
388
+ * @param {Array} entityList - the list of entities we are looking for
389
+ *
390
+ * @param {Callback} callback - A map where the entity is the key and the
391
+ * value is true or false
392
+ */
393
+ hasEntities(entityType, entityList, callback) {
394
+ const meth = 'adapter-hasEntities';
395
+ const origin = `${this.id}-${meth}`;
396
+ log.trace(origin);
397
+
398
+ try {
399
+ return super.hasEntities(entityType, entityList, callback);
400
+ } catch (err) {
401
+ log.error(`${origin}: ${err}`);
402
+ return callback(null, err);
403
+ }
404
+ }
405
+
406
+ /**
407
+ * @summary Get Appliance that match the deviceName
408
+ *
409
+ * @function getDevice
410
+ * @param {String} deviceName - the deviceName to find (required)
411
+ *
412
+ * @param {getCallback} callback - a callback function to return the result
413
+ * (appliance) or the error
414
+ */
415
+ getDevice(deviceName, callback) {
416
+ const meth = 'adapter-getDevice';
417
+ const origin = `${this.id}-${meth}`;
418
+ log.trace(origin);
419
+
420
+ try {
421
+ return super.getDevice(deviceName, callback);
422
+ } catch (err) {
423
+ log.error(`${origin}: ${err}`);
424
+ return callback(null, err);
425
+ }
426
+ }
427
+
428
+ /**
429
+ * @summary Get Appliances that match the filter
430
+ *
431
+ * @function getDevicesFiltered
432
+ * @param {Object} options - the data to use to filter the appliances (optional)
433
+ *
434
+ * @param {getCallback} callback - a callback function to return the result
435
+ * (appliances) or the error
436
+ */
437
+ getDevicesFiltered(options, callback) {
438
+ const meth = 'adapter-getDevicesFiltered';
439
+ const origin = `${this.id}-${meth}`;
440
+ log.trace(origin);
441
+
442
+ try {
443
+ return super.getDevicesFiltered(options, callback);
444
+ } catch (err) {
445
+ log.error(`${origin}: ${err}`);
446
+ return callback(null, err);
447
+ }
448
+ }
449
+
450
+ /**
451
+ * @summary Gets the status for the provided appliance
452
+ *
453
+ * @function isAlive
454
+ * @param {String} deviceName - the deviceName of the appliance. (required)
455
+ *
456
+ * @param {configCallback} callback - callback function to return the result
457
+ * (appliance isAlive) or the error
458
+ */
459
+ isAlive(deviceName, callback) {
460
+ const meth = 'adapter-isAlive';
461
+ const origin = `${this.id}-${meth}`;
462
+ log.trace(origin);
463
+
464
+ try {
465
+ return super.isAlive(deviceName, callback);
466
+ } catch (err) {
467
+ log.error(`${origin}: ${err}`);
468
+ return callback(null, err);
469
+ }
470
+ }
471
+
472
+ /**
473
+ * @summary Gets a config for the provided Appliance
474
+ *
475
+ * @function getConfig
476
+ * @param {String} deviceName - the deviceName of the appliance. (required)
477
+ * @param {String} format - the desired format of the config. (optional)
478
+ *
479
+ * @param {configCallback} callback - callback function to return the result
480
+ * (appliance config) or the error
481
+ */
482
+ getConfig(deviceName, format, callback) {
483
+ const meth = 'adapter-getConfig';
484
+ const origin = `${this.id}-${meth}`;
485
+ log.trace(origin);
486
+
487
+ try {
488
+ return super.getConfig(deviceName, format, callback);
489
+ } catch (err) {
490
+ log.error(`${origin}: ${err}`);
491
+ return callback(null, err);
492
+ }
493
+ }
494
+
495
+ /**
496
+ * @summary Gets the device count from the system
497
+ *
498
+ * @function iapGetDeviceCount
499
+ *
500
+ * @param {getCallback} callback - callback function to return the result
501
+ * (count) or the error
502
+ */
503
+ iapGetDeviceCount(callback) {
504
+ const meth = 'adapter-iapGetDeviceCount';
505
+ const origin = `${this.id}-${meth}`;
506
+ log.trace(origin);
507
+
508
+ try {
509
+ return super.iapGetDeviceCount(callback);
510
+ } catch (err) {
511
+ log.error(`${origin}: ${err}`);
512
+ return callback(null, err);
513
+ }
514
+ }
515
+
516
+ /* GENERIC ADAPTER REQUEST - allows extension of adapter without new calls being added */
517
+ /**
518
+ * Makes the requested generic call
519
+ *
520
+ * @function iapExpandedGenericAdapterRequest
521
+ * @param {Object} metadata - metadata for the call (optional).
522
+ * Can be a stringified Object.
523
+ * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (optional)
524
+ * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (optional)
525
+ * @param {Object} pathVars - the parameters to be put within the url path (optional).
526
+ * Can be a stringified Object.
527
+ * @param {Object} queryData - the parameters to be put on the url (optional).
528
+ * Can be a stringified Object.
529
+ * @param {Object} requestBody - the body to add to the request (optional).
530
+ * Can be a stringified Object.
531
+ * @param {Object} addlHeaders - additional headers to be put on the call (optional).
532
+ * Can be a stringified Object.
533
+ * @param {getCallback} callback - a callback function to return the result (Generics)
534
+ * or the error
535
+ */
536
+ iapExpandedGenericAdapterRequest(metadata, uriPath, restMethod, pathVars, queryData, requestBody, addlHeaders, callback) {
537
+ const meth = 'adapter-iapExpandedGenericAdapterRequest';
538
+ const origin = `${this.id}-${meth}`;
539
+ log.trace(origin);
540
+
541
+ try {
542
+ return super.iapExpandedGenericAdapterRequest(metadata, uriPath, restMethod, pathVars, queryData, requestBody, addlHeaders, callback);
543
+ } catch (err) {
544
+ log.error(`${origin}: ${err}`);
545
+ return callback(null, err);
546
+ }
547
+ }
548
+
549
+ /**
550
+ * Makes the requested generic call
551
+ *
552
+ * @function genericAdapterRequest
553
+ * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
554
+ * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
555
+ * @param {Object} queryData - the parameters to be put on the url (optional).
556
+ * Can be a stringified Object.
557
+ * @param {Object} requestBody - the body to add to the request (optional).
558
+ * Can be a stringified Object.
559
+ * @param {Object} addlHeaders - additional headers to be put on the call (optional).
560
+ * Can be a stringified Object.
561
+ * @param {getCallback} callback - a callback function to return the result (Generics)
562
+ * or the error
563
+ */
564
+ genericAdapterRequest(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
565
+ const meth = 'adapter-genericAdapterRequest';
566
+ const origin = `${this.id}-${meth}`;
567
+ log.trace(origin);
568
+
569
+ try {
570
+ return super.genericAdapterRequest(uriPath, restMethod, queryData, requestBody, addlHeaders, callback);
571
+ } catch (err) {
572
+ log.error(`${origin}: ${err}`);
573
+ return callback(null, err);
574
+ }
575
+ }
576
+
577
+ /**
578
+ * Makes the requested generic call with no base path or version
579
+ *
580
+ * @function genericAdapterRequestNoBasePath
581
+ * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
582
+ * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
583
+ * @param {Object} queryData - the parameters to be put on the url (optional).
584
+ * Can be a stringified Object.
585
+ * @param {Object} requestBody - the body to add to the request (optional).
586
+ * Can be a stringified Object.
587
+ * @param {Object} addlHeaders - additional headers to be put on the call (optional).
588
+ * Can be a stringified Object.
589
+ * @param {getCallback} callback - a callback function to return the result (Generics)
590
+ * or the error
591
+ */
592
+ genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
593
+ const meth = 'adapter-genericAdapterRequestNoBasePath';
594
+ const origin = `${this.id}-${meth}`;
595
+ log.trace(origin);
596
+
597
+ try {
598
+ return super.genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback);
599
+ } catch (err) {
600
+ log.error(`${origin}: ${err}`);
601
+ return callback(null, err);
602
+ }
603
+ }
604
+
605
+ /* INVENTORY CALLS */
606
+ /**
607
+ * @summary run the adapter lint script to return the results.
608
+ *
609
+ * @function iapRunAdapterLint
610
+ * @param {Callback} callback - callback function
611
+ */
612
+ iapRunAdapterLint(callback) {
613
+ const meth = 'adapter-iapRunAdapterLint';
614
+ const origin = `${this.id}-${meth}`;
615
+ log.trace(origin);
616
+
617
+ return super.iapRunAdapterLint(callback);
618
+ }
619
+
620
+ /**
621
+ * @summary run the adapter test scripts (baseunit and unit) to return the results.
622
+ * can not run integration as there can be implications with that.
623
+ *
624
+ * @function iapRunAdapterTests
625
+ * @param {Callback} callback - callback function
626
+ */
627
+ iapRunAdapterTests(callback) {
628
+ const meth = 'adapter-iapRunAdapterTests';
629
+ const origin = `${this.id}-${meth}`;
630
+ log.trace(origin);
631
+
632
+ return super.iapRunAdapterTests(callback);
633
+ }
634
+
635
+ /**
636
+ * @summary provide inventory information abbout the adapter
637
+ *
638
+ * @function iapGetAdapterInventory
639
+ * @param {Callback} callback - callback function
640
+ */
641
+ iapGetAdapterInventory(callback) {
642
+ const meth = 'adapter-iapGetAdapterInventory';
643
+ const origin = `${this.id}-${meth}`;
644
+ log.trace(origin);
645
+
646
+ return super.iapGetAdapterInventory(callback);
647
+ }
648
+
649
+ /**
650
+ * @callback healthCallback
651
+ * @param {Object} result - the result of the get request (contains an id and a status)
652
+ */
653
+ /**
654
+ * @callback getCallback
655
+ * @param {Object} result - the result of the get request (entity/ies)
656
+ * @param {String} error - any error that occurred
657
+ */
658
+ /**
659
+ * @callback createCallback
660
+ * @param {Object} item - the newly created entity
661
+ * @param {String} error - any error that occurred
662
+ */
663
+ /**
664
+ * @callback updateCallback
665
+ * @param {String} status - the status of the update action
666
+ * @param {String} error - any error that occurred
667
+ */
668
+ /**
669
+ * @callback deleteCallback
670
+ * @param {String} status - the status of the delete action
671
+ * @param {String} error - any error that occurred
672
+ */
673
+
674
+ /**
675
+ * @function getSessionToken
676
+ * @pronghornType method
677
+ * @name getSessionToken
678
+ * @summary Request a session token
679
+ *
680
+ * @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
681
+ * @param {getCallback} callback - a callback function to return the result
682
+ * @return {object} results - An object containing the response of the action
683
+ *
684
+ * @route {GET} /getSessionToken
685
+ * @roles admin
686
+ * @task true
687
+ */
688
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
689
+ getSessionToken(iapMetadata, callback) {
690
+ const meth = 'adapter-getSessionToken';
691
+ const origin = `${this.id}-${meth}`;
692
+ log.trace(origin);
693
+
694
+ if (this.suspended && this.suspendMode === 'error') {
695
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
696
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
697
+ return callback(null, errorObj);
698
+ }
699
+
700
+ /* HERE IS WHERE YOU VALIDATE DATA */
701
+
702
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
703
+ const queryParamsAvailable = {};
704
+ const queryParams = {};
705
+ const pathVars = [];
706
+ const bodyVars = {};
707
+
708
+ // loop in template. long callback arg name to avoid identifier conflicts
709
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
710
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
711
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
712
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
713
+ }
714
+ });
715
+
716
+ // if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
717
+ let thisHeaderData = null;
718
+ // if the additional headers was passed in as a string parse the json into an object
719
+ if (thisHeaderData !== null && thisHeaderData.constructor === String) {
720
+ try {
721
+ // parse the additional headers object that was passed in
722
+ thisHeaderData = JSON.parse(thisHeaderData);
723
+ } catch (err) {
724
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
725
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
726
+ return callback(null, errorObj);
727
+ }
728
+ } else if (thisHeaderData === null) {
729
+ thisHeaderData = { clientKey: '' };
730
+ }
731
+
732
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
733
+ // see adapter code documentation for more information on the request object's fields
734
+ const reqObj = {
735
+ payload: bodyVars,
736
+ uriPathVars: pathVars,
737
+ uriQuery: queryParams
738
+ };
739
+
740
+ const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
741
+
742
+ // Merge and add new iapMetadata fields in reqObj
743
+ if (iapMetadata && typeof iapMetadata === 'object') {
744
+ Object.keys(iapMetadata).forEach((iapField) => {
745
+ if (reqFields.includes(iapField) && iapMetadata[iapField]) {
746
+ if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
747
+ reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
748
+ } else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
749
+ reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
750
+ } else {
751
+ // Otherwise, add new iapMetadata fields to reqObj
752
+ reqObj[iapField] = iapMetadata[iapField];
753
+ }
754
+ }
755
+ });
756
+ // Add iapMetadata to reqObj for further work
757
+ reqObj.iapMetadata = iapMetadata;
758
+ }
759
+
760
+ try {
761
+ // Make the call -
762
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
763
+ return this.requestHandlerInst.identifyRequest('Authentication', 'getSessionToken', reqObj, true, (irReturnData, irReturnError) => {
764
+ // if we received an error or their is no response on the results
765
+ // return an error
766
+ if (irReturnError) {
767
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
768
+ return callback(null, irReturnError);
769
+ }
770
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
771
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getSessionToken'], null, null, null);
772
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
773
+ return callback(null, errorObj);
774
+ }
775
+
776
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
777
+ // return the response
778
+ return callback(irReturnData, null);
779
+ });
780
+ } catch (ex) {
781
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
782
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
783
+ return callback(null, errorObj);
784
+ }
785
+ }
786
+
787
+ /**
788
+ * @function postQueryResource
789
+ * @pronghornType method
790
+ * @name postQueryResource
791
+ * @summary Query your resource
792
+ *
793
+ * @param {string} service - The service you want to query
794
+ * @param {string} resource - The resource you want to query
795
+ * @param {object} body - body param
796
+ * @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
797
+ * @param {getCallback} callback - a callback function to return the result
798
+ * @return {object} results - An object containing the response of the action
799
+ *
800
+ * @route {POST} /postQueryResource
801
+ * @roles admin
802
+ * @task true
803
+ */
804
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
805
+ postQueryResource(service, resource, body, iapMetadata, callback) {
806
+ const meth = 'adapter-postQueryResource';
807
+ const origin = `${this.id}-${meth}`;
808
+ log.trace(origin);
809
+
810
+ if (this.suspended && this.suspendMode === 'error') {
811
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
812
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
813
+ return callback(null, errorObj);
814
+ }
815
+
816
+ /* HERE IS WHERE YOU VALIDATE DATA */
817
+ if (service === undefined || service === null || service === '') {
818
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['service'], null, null, null);
819
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
820
+ return callback(null, errorObj);
821
+ }
822
+ if (resource === undefined || resource === null || resource === '') {
823
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['resource'], null, null, null);
824
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
825
+ return callback(null, errorObj);
826
+ }
827
+ if (body === undefined || body === null || body === '') {
828
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
829
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
830
+ return callback(null, errorObj);
831
+ }
832
+
833
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
834
+ const queryParamsAvailable = { resource };
835
+ const queryParams = {};
836
+ const pathVars = [service];
837
+ const bodyVars = body;
838
+
839
+ // loop in template. long callback arg name to avoid identifier conflicts
840
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
841
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
842
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
843
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
844
+ }
845
+ });
846
+
847
+ // if you want to expose addlHeaders to workflow, add it to the method signature here and in pronghorn.json
848
+ let thisHeaderData = null;
849
+ // if the additional headers was passed in as a string parse the json into an object
850
+ if (thisHeaderData !== null && thisHeaderData.constructor === String) {
851
+ try {
852
+ // parse the additional headers object that was passed in
853
+ thisHeaderData = JSON.parse(thisHeaderData);
854
+ } catch (err) {
855
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'addlHeaders string must be a stringified JSON', [], null, null, null);
856
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
857
+ return callback(null, errorObj);
858
+ }
859
+ } else if (thisHeaderData === null) {
860
+ thisHeaderData = { clientKey: '', token: '' };
861
+ }
862
+
863
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
864
+ // see adapter code documentation for more information on the request object's fields
865
+ const reqObj = {
866
+ payload: bodyVars,
867
+ uriPathVars: pathVars,
868
+ uriQuery: queryParams
869
+ };
870
+
871
+ const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
872
+
873
+ // Merge and add new iapMetadata fields in reqObj
874
+ if (iapMetadata && typeof iapMetadata === 'object') {
875
+ Object.keys(iapMetadata).forEach((iapField) => {
876
+ if (reqFields.includes(iapField) && iapMetadata[iapField]) {
877
+ if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
878
+ reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
879
+ } else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
880
+ reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
881
+ } else {
882
+ // Otherwise, add new iapMetadata fields to reqObj
883
+ reqObj[iapField] = iapMetadata[iapField];
884
+ }
885
+ }
886
+ });
887
+ // Add iapMetadata to reqObj for further work
888
+ reqObj.iapMetadata = iapMetadata;
889
+ }
890
+
891
+ try {
892
+ // Make the call -
893
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
894
+ return this.requestHandlerInst.identifyRequest('Query', 'postQueryResource', reqObj, true, (irReturnData, irReturnError) => {
895
+ // if we received an error or their is no response on the results
896
+ // return an error
897
+ if (irReturnError) {
898
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
899
+ return callback(null, irReturnError);
900
+ }
901
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
902
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['postQueryResource'], null, null, null);
903
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
904
+ return callback(null, errorObj);
905
+ }
906
+
907
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
908
+ // return the response
909
+ return callback(irReturnData, null);
910
+ });
911
+ } catch (ex) {
912
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
913
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
914
+ return callback(null, errorObj);
915
+ }
916
+ }
917
+ }
918
+
919
+ module.exports = CheckpointReputationService;