@itentialopensource/adapter-netbox 0.9.0 → 0.11.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.
- package/AUTH.md +9 -15
- package/CALLS.md +2447 -22
- package/CHANGELOG.md +16 -0
- package/CONTRIBUTING.md +1 -160
- package/ENHANCE.md +2 -2
- package/README.md +32 -23
- package/SYSTEMINFO.md +12 -3
- package/adapter.js +162 -333
- package/adapterBase.js +549 -879
- package/changelogs/changelog.md +181 -0
- package/metadata.json +69 -0
- package/package.json +24 -24
- package/pronghorn.json +470 -138
- package/propertiesSchema.json +422 -31
- package/refs?service=git-upload-pack +0 -0
- package/report/adapter-openapi.json +52536 -0
- package/report/adapter-openapi.yaml +37346 -0
- package/report/adapterInfo.json +8 -8
- package/report/updateReport1691508495299.json +120 -0
- package/report/updateReport1692202980865.json +120 -0
- package/report/updateReport1694466470665.json +120 -0
- package/sampleProperties.json +65 -4
- package/test/integration/adapterTestBasicGet.js +2 -4
- package/test/integration/adapterTestConnectivity.js +91 -42
- package/test/integration/adapterTestIntegration.js +130 -2
- package/test/unit/adapterBaseTestUnit.js +388 -313
- package/test/unit/adapterTestUnit.js +338 -112
- package/utils/adapterInfo.js +1 -1
- package/utils/addAuth.js +1 -1
- package/utils/artifactize.js +1 -1
- package/utils/checkMigrate.js +1 -1
- package/utils/entitiesToDB.js +2 -2
- package/utils/findPath.js +1 -1
- package/utils/methodDocumentor.js +260 -0
- package/utils/modify.js +13 -15
- package/utils/packModificationScript.js +1 -1
- package/utils/pre-commit.sh +2 -0
- package/utils/taskMover.js +309 -0
- package/utils/tbScript.js +89 -34
- package/utils/tbUtils.js +41 -21
- package/utils/testRunner.js +1 -1
- package/utils/troubleshootingAdapter.js +9 -6
- package/workflows/README.md +0 -3
package/adapter.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
/* eslint import/no-dynamic-require: warn */
|
|
4
4
|
/* eslint object-curly-newline: warn */
|
|
5
|
+
/* eslint default-param-last: warn */
|
|
5
6
|
|
|
6
7
|
// Set globals
|
|
7
8
|
/* global log */
|
|
@@ -101,9 +102,6 @@ class Netbox extends AdapterBaseCl {
|
|
|
101
102
|
let myIgnore = [
|
|
102
103
|
'healthCheck',
|
|
103
104
|
'iapGetAdapterWorkflowFunctions',
|
|
104
|
-
'iapHasAdapterEntity',
|
|
105
|
-
'iapVerifyAdapterCapability',
|
|
106
|
-
'iapUpdateAdapterEntityCache',
|
|
107
105
|
'hasEntities',
|
|
108
106
|
'getAuthorization'
|
|
109
107
|
];
|
|
@@ -131,29 +129,15 @@ class Netbox extends AdapterBaseCl {
|
|
|
131
129
|
* @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
|
|
132
130
|
* @param {string} type - the type of entity file to change, (action, schema, mock) (optional)
|
|
133
131
|
* @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
|
|
132
|
+
* @param {boolean} replace - true to replace entire mock data, false to merge/append
|
|
134
133
|
* @param {Callback} callback - The results of the call
|
|
135
134
|
*/
|
|
136
|
-
iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
|
|
135
|
+
iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, replace, callback) {
|
|
137
136
|
const meth = 'adapter-iapUpdateAdapterConfiguration';
|
|
138
137
|
const origin = `${this.id}-${meth}`;
|
|
139
138
|
log.trace(origin);
|
|
140
139
|
|
|
141
|
-
super.iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* See if the API path provided is found in this adapter
|
|
146
|
-
*
|
|
147
|
-
* @function iapFindAdapterPath
|
|
148
|
-
* @param {string} apiPath - the api path to check on
|
|
149
|
-
* @param {Callback} callback - The results of the call
|
|
150
|
-
*/
|
|
151
|
-
iapFindAdapterPath(apiPath, callback) {
|
|
152
|
-
const meth = 'adapter-iapFindAdapterPath';
|
|
153
|
-
const origin = `${this.id}-${meth}`;
|
|
154
|
-
log.trace(origin);
|
|
155
|
-
|
|
156
|
-
super.iapFindAdapterPath(apiPath, callback);
|
|
140
|
+
super.iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, replace, callback);
|
|
157
141
|
}
|
|
158
142
|
|
|
159
143
|
/**
|
|
@@ -195,7 +179,7 @@ class Netbox extends AdapterBaseCl {
|
|
|
195
179
|
}
|
|
196
180
|
|
|
197
181
|
/**
|
|
198
|
-
* @summary Get the
|
|
182
|
+
* @summary Get the Adapter Queue
|
|
199
183
|
*
|
|
200
184
|
* @function iapGetAdapterQueue
|
|
201
185
|
* @param {Callback} callback - callback function
|
|
@@ -208,6 +192,22 @@ class Netbox extends AdapterBaseCl {
|
|
|
208
192
|
return super.iapGetAdapterQueue(callback);
|
|
209
193
|
}
|
|
210
194
|
|
|
195
|
+
/* SCRIPT CALLS */
|
|
196
|
+
/**
|
|
197
|
+
* See if the API path provided is found in this adapter
|
|
198
|
+
*
|
|
199
|
+
* @function iapFindAdapterPath
|
|
200
|
+
* @param {string} apiPath - the api path to check on
|
|
201
|
+
* @param {Callback} callback - The results of the call
|
|
202
|
+
*/
|
|
203
|
+
iapFindAdapterPath(apiPath, callback) {
|
|
204
|
+
const meth = 'adapter-iapFindAdapterPath';
|
|
205
|
+
const origin = `${this.id}-${meth}`;
|
|
206
|
+
log.trace(origin);
|
|
207
|
+
|
|
208
|
+
super.iapFindAdapterPath(apiPath, callback);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
211
|
/**
|
|
212
212
|
* @summary Runs troubleshoot scripts for adapter
|
|
213
213
|
*
|
|
@@ -308,176 +308,93 @@ class Netbox extends AdapterBaseCl {
|
|
|
308
308
|
}
|
|
309
309
|
}
|
|
310
310
|
|
|
311
|
-
/* BROKER CALLS */
|
|
312
311
|
/**
|
|
313
|
-
* @summary
|
|
312
|
+
* @summary Deactivate adapter tasks
|
|
314
313
|
*
|
|
315
|
-
* @function
|
|
316
|
-
* @param {String} entityType - the entity type to check for
|
|
317
|
-
* @param {String/Array} entityId - the specific entity we are looking for
|
|
314
|
+
* @function iapDeactivateTasks
|
|
318
315
|
*
|
|
319
|
-
* @param {
|
|
320
|
-
*
|
|
316
|
+
* @param {Array} tasks - List of tasks to deactivate
|
|
317
|
+
* @param {Callback} callback
|
|
321
318
|
*/
|
|
322
|
-
|
|
323
|
-
const
|
|
319
|
+
iapDeactivateTasks(tasks, callback) {
|
|
320
|
+
const meth = 'adapter-iapDeactivateTasks';
|
|
321
|
+
const origin = `${this.id}-${meth}`;
|
|
324
322
|
log.trace(origin);
|
|
325
323
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
324
|
+
try {
|
|
325
|
+
return super.iapDeactivateTasks(tasks, callback);
|
|
326
|
+
} catch (err) {
|
|
327
|
+
log.error(`${origin}: ${err}`);
|
|
328
|
+
return callback(null, err);
|
|
329
|
+
}
|
|
329
330
|
}
|
|
330
331
|
|
|
331
332
|
/**
|
|
332
|
-
* @summary
|
|
333
|
-
* whether the adapter supports type, action and specific entity
|
|
333
|
+
* @summary Activate adapter tasks that have previously been deactivated
|
|
334
334
|
*
|
|
335
|
-
* @function
|
|
336
|
-
*
|
|
337
|
-
* @param {
|
|
338
|
-
* @param {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
const meth = 'adapterBase-iapVerifyAdapterCapability';
|
|
345
|
-
const origin = `${this.id}-${meth}`;
|
|
346
|
-
log.trace(origin);
|
|
347
|
-
|
|
348
|
-
// if caching
|
|
349
|
-
if (this.caching) {
|
|
350
|
-
// Make the call - iapVerifyAdapterCapability(entityType, actionType, entityId, callback)
|
|
351
|
-
return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, entityId, (results, error) => {
|
|
352
|
-
if (error) {
|
|
353
|
-
return callback(null, error);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
// if the cache needs to be updated, update and try again
|
|
357
|
-
if (results && results[0] === 'needupdate') {
|
|
358
|
-
switch (entityType) {
|
|
359
|
-
case 'template_entity': {
|
|
360
|
-
// if the cache is invalid, update the cache
|
|
361
|
-
return this.getEntities(null, null, null, null, (data, err) => {
|
|
362
|
-
if (err) {
|
|
363
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Could not update entity: $VARIABLE$, cache', [entityType], null, null, null);
|
|
364
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
365
|
-
return callback(null, errorObj);
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
// need to check the cache again since it has been updated
|
|
369
|
-
return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, entityId, (vcapable, verror) => {
|
|
370
|
-
if (verror) {
|
|
371
|
-
return callback(null, verror);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
return this.capabilityResults(vcapable, callback);
|
|
375
|
-
});
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
default: {
|
|
379
|
-
// unsupported entity type
|
|
380
|
-
const result = [false];
|
|
381
|
-
|
|
382
|
-
// put false in array for all entities
|
|
383
|
-
if (Array.isArray(entityId)) {
|
|
384
|
-
for (let e = 1; e < entityId.length; e += 1) {
|
|
385
|
-
result.push(false);
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
return callback(result);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
// return the results
|
|
395
|
-
return this.capabilityResults(results, callback);
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
// if no entity id
|
|
400
|
-
if (!entityId) {
|
|
401
|
-
// need to check the cache again since it has been updated
|
|
402
|
-
return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, null, (vcapable, verror) => {
|
|
403
|
-
if (verror) {
|
|
404
|
-
return callback(null, verror);
|
|
405
|
-
}
|
|
335
|
+
* @function iapActivateTasks
|
|
336
|
+
*
|
|
337
|
+
* @param {Array} tasks - List of tasks to activate
|
|
338
|
+
* @param {Callback} callback
|
|
339
|
+
*/
|
|
340
|
+
iapActivateTasks(tasks, callback) {
|
|
341
|
+
const meth = 'adapter-iapActivateTasks';
|
|
342
|
+
const origin = `${this.id}-${meth}`;
|
|
343
|
+
log.trace(origin);
|
|
406
344
|
|
|
407
|
-
|
|
408
|
-
|
|
345
|
+
try {
|
|
346
|
+
return super.iapActivateTasks(tasks, callback);
|
|
347
|
+
} catch (err) {
|
|
348
|
+
log.error(`${origin}: ${err}`);
|
|
349
|
+
return callback(null, err);
|
|
409
350
|
}
|
|
351
|
+
}
|
|
410
352
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
return callback(null, verror);
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
// is the entity in the list?
|
|
429
|
-
const isEntity = this.entityInList(entityId, data.response, callback);
|
|
430
|
-
const res = [];
|
|
431
|
-
|
|
432
|
-
// not found
|
|
433
|
-
for (let i = 0; i < isEntity.length; i += 1) {
|
|
434
|
-
if (vcapable) {
|
|
435
|
-
res.push(isEntity[i]);
|
|
436
|
-
} else {
|
|
437
|
-
res.push(false);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
return callback(res);
|
|
442
|
-
});
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
default: {
|
|
446
|
-
// unsupported entity type
|
|
447
|
-
const result = [false];
|
|
448
|
-
|
|
449
|
-
// put false in array for all entities
|
|
450
|
-
if (Array.isArray(entityId)) {
|
|
451
|
-
for (let e = 1; e < entityId.length; e += 1) {
|
|
452
|
-
result.push(false);
|
|
453
|
-
}
|
|
454
|
-
}
|
|
353
|
+
/* CACHE CALLS */
|
|
354
|
+
/**
|
|
355
|
+
* @summary Populate the cache for the given entities
|
|
356
|
+
*
|
|
357
|
+
* @function iapPopulateEntityCache
|
|
358
|
+
* @param {String/Array of Strings} entityType - the entity type(s) to populate
|
|
359
|
+
* @param {Callback} callback - whether the cache was updated or not for each entity type
|
|
360
|
+
*
|
|
361
|
+
* @returns status of the populate
|
|
362
|
+
*/
|
|
363
|
+
iapPopulateEntityCache(entityTypes, callback) {
|
|
364
|
+
const meth = 'adapter-iapPopulateEntityCache';
|
|
365
|
+
const origin = `${this.id}-${meth}`;
|
|
366
|
+
log.trace(origin);
|
|
455
367
|
|
|
456
|
-
|
|
457
|
-
|
|
368
|
+
try {
|
|
369
|
+
return super.iapPopulateEntityCache(entityTypes, callback);
|
|
370
|
+
} catch (err) {
|
|
371
|
+
log.error(`${origin}: ${err}`);
|
|
372
|
+
return callback(null, err);
|
|
458
373
|
}
|
|
459
374
|
}
|
|
460
375
|
|
|
461
376
|
/**
|
|
462
|
-
* @summary
|
|
463
|
-
*
|
|
464
|
-
* @function iapUpdateAdapterEntityCache
|
|
377
|
+
* @summary Retrieves data from cache for specified entity type
|
|
465
378
|
*
|
|
379
|
+
* @function iapRetrieveEntitiesCache
|
|
380
|
+
* @param {String} entityType - entity of which to retrieve
|
|
381
|
+
* @param {Object} options - settings of which data to return and how to return it
|
|
382
|
+
* @param {Callback} callback - the data if it was retrieved
|
|
466
383
|
*/
|
|
467
|
-
|
|
468
|
-
const
|
|
384
|
+
iapRetrieveEntitiesCache(entityType, options, callback) {
|
|
385
|
+
const meth = 'adapter-iapCheckEiapRetrieveEntitiesCachentityCached';
|
|
386
|
+
const origin = `${this.id}-${meth}`;
|
|
469
387
|
log.trace(origin);
|
|
470
388
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
}
|
|
477
|
-
});
|
|
389
|
+
try {
|
|
390
|
+
return super.iapRetrieveEntitiesCache(entityType, options, callback);
|
|
391
|
+
} catch (err) {
|
|
392
|
+
log.error(`${origin}: ${err}`);
|
|
393
|
+
return callback(null, err);
|
|
478
394
|
}
|
|
479
395
|
}
|
|
480
396
|
|
|
397
|
+
/* BROKER CALLS */
|
|
481
398
|
/**
|
|
482
399
|
* @summary Determines if this adapter supports any in a list of entities
|
|
483
400
|
*
|
|
@@ -612,6 +529,38 @@ class Netbox extends AdapterBaseCl {
|
|
|
612
529
|
}
|
|
613
530
|
|
|
614
531
|
/* GENERIC ADAPTER REQUEST - allows extension of adapter without new calls being added */
|
|
532
|
+
/**
|
|
533
|
+
* Makes the requested generic call
|
|
534
|
+
*
|
|
535
|
+
* @function iapExpandedGenericAdapterRequest
|
|
536
|
+
* @param {Object} metadata - metadata for the call (optional).
|
|
537
|
+
* Can be a stringified Object.
|
|
538
|
+
* @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (optional)
|
|
539
|
+
* @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (optional)
|
|
540
|
+
* @param {Object} pathVars - the parameters to be put within the url path (optional).
|
|
541
|
+
* Can be a stringified Object.
|
|
542
|
+
* @param {Object} queryData - the parameters to be put on the url (optional).
|
|
543
|
+
* Can be a stringified Object.
|
|
544
|
+
* @param {Object} requestBody - the body to add to the request (optional).
|
|
545
|
+
* Can be a stringified Object.
|
|
546
|
+
* @param {Object} addlHeaders - additional headers to be put on the call (optional).
|
|
547
|
+
* Can be a stringified Object.
|
|
548
|
+
* @param {getCallback} callback - a callback function to return the result (Generics)
|
|
549
|
+
* or the error
|
|
550
|
+
*/
|
|
551
|
+
iapExpandedGenericAdapterRequest(metadata, uriPath, restMethod, pathVars, queryData, requestBody, addlHeaders, callback) {
|
|
552
|
+
const meth = 'adapter-iapExpandedGenericAdapterRequest';
|
|
553
|
+
const origin = `${this.id}-${meth}`;
|
|
554
|
+
log.trace(origin);
|
|
555
|
+
|
|
556
|
+
try {
|
|
557
|
+
return super.iapExpandedGenericAdapterRequest(metadata, uriPath, restMethod, pathVars, queryData, requestBody, addlHeaders, callback);
|
|
558
|
+
} catch (err) {
|
|
559
|
+
log.error(`${origin}: ${err}`);
|
|
560
|
+
return callback(null, err);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
615
564
|
/**
|
|
616
565
|
* Makes the requested generic call
|
|
617
566
|
*
|
|
@@ -632,93 +581,11 @@ class Netbox extends AdapterBaseCl {
|
|
|
632
581
|
const origin = `${this.id}-${meth}`;
|
|
633
582
|
log.trace(origin);
|
|
634
583
|
|
|
635
|
-
if (this.suspended && this.suspendMode === 'error') {
|
|
636
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
637
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
638
|
-
return callback(null, errorObj);
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
642
|
-
if (uriPath === undefined || uriPath === null || uriPath === '') {
|
|
643
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['uriPath'], null, null, null);
|
|
644
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
645
|
-
return callback(null, errorObj);
|
|
646
|
-
}
|
|
647
|
-
if (restMethod === undefined || restMethod === null || restMethod === '') {
|
|
648
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['restMethod'], null, null, null);
|
|
649
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
650
|
-
return callback(null, errorObj);
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
654
|
-
// remove any leading / and split the uripath into path variables
|
|
655
|
-
let myPath = uriPath;
|
|
656
|
-
while (myPath.indexOf('/') === 0) {
|
|
657
|
-
myPath = myPath.substring(1);
|
|
658
|
-
}
|
|
659
|
-
const pathVars = myPath.split('/');
|
|
660
|
-
const queryParamsAvailable = queryData;
|
|
661
|
-
const queryParams = {};
|
|
662
|
-
const bodyVars = requestBody;
|
|
663
|
-
|
|
664
|
-
// loop in template. long callback arg name to avoid identifier conflicts
|
|
665
|
-
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
666
|
-
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
667
|
-
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
668
|
-
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
669
|
-
}
|
|
670
|
-
});
|
|
671
|
-
|
|
672
|
-
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
|
|
673
|
-
const reqObj = {
|
|
674
|
-
payload: bodyVars,
|
|
675
|
-
uriPathVars: pathVars,
|
|
676
|
-
uriQuery: queryParams,
|
|
677
|
-
uriOptions: {}
|
|
678
|
-
};
|
|
679
|
-
// add headers if provided
|
|
680
|
-
if (addlHeaders) {
|
|
681
|
-
reqObj.addlHeaders = addlHeaders;
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
// determine the call and return flag
|
|
685
|
-
let action = 'getGenerics';
|
|
686
|
-
let returnF = true;
|
|
687
|
-
if (restMethod.toUpperCase() === 'POST') {
|
|
688
|
-
action = 'createGeneric';
|
|
689
|
-
} else if (restMethod.toUpperCase() === 'PUT') {
|
|
690
|
-
action = 'updateGeneric';
|
|
691
|
-
} else if (restMethod.toUpperCase() === 'PATCH') {
|
|
692
|
-
action = 'patchGeneric';
|
|
693
|
-
} else if (restMethod.toUpperCase() === 'DELETE') {
|
|
694
|
-
action = 'deleteGeneric';
|
|
695
|
-
returnF = false;
|
|
696
|
-
}
|
|
697
|
-
|
|
698
584
|
try {
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
// return an error
|
|
704
|
-
if (irReturnError) {
|
|
705
|
-
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
706
|
-
return callback(null, irReturnError);
|
|
707
|
-
}
|
|
708
|
-
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
709
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['genericAdapterRequest'], null, null, null);
|
|
710
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
711
|
-
return callback(null, errorObj);
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
715
|
-
// return the response
|
|
716
|
-
return callback(irReturnData, null);
|
|
717
|
-
});
|
|
718
|
-
} catch (ex) {
|
|
719
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
720
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
721
|
-
return callback(null, errorObj);
|
|
585
|
+
return super.genericAdapterRequest(uriPath, restMethod, queryData, requestBody, addlHeaders, callback);
|
|
586
|
+
} catch (err) {
|
|
587
|
+
log.error(`${origin}: ${err}`);
|
|
588
|
+
return callback(null, err);
|
|
722
589
|
}
|
|
723
590
|
}
|
|
724
591
|
|
|
@@ -742,94 +609,56 @@ class Netbox extends AdapterBaseCl {
|
|
|
742
609
|
const origin = `${this.id}-${meth}`;
|
|
743
610
|
log.trace(origin);
|
|
744
611
|
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
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);
|
|
612
|
+
try {
|
|
613
|
+
return super.genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback);
|
|
614
|
+
} catch (err) {
|
|
615
|
+
log.error(`${origin}: ${err}`);
|
|
616
|
+
return callback(null, err);
|
|
761
617
|
}
|
|
618
|
+
}
|
|
762
619
|
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
const
|
|
772
|
-
const
|
|
620
|
+
/* INVENTORY CALLS */
|
|
621
|
+
/**
|
|
622
|
+
* @summary run the adapter lint script to return the results.
|
|
623
|
+
*
|
|
624
|
+
* @function iapRunAdapterLint
|
|
625
|
+
* @param {Callback} callback - callback function
|
|
626
|
+
*/
|
|
627
|
+
iapRunAdapterLint(callback) {
|
|
628
|
+
const meth = 'adapter-iapRunAdapterLint';
|
|
629
|
+
const origin = `${this.id}-${meth}`;
|
|
630
|
+
log.trace(origin);
|
|
773
631
|
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
777
|
-
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
778
|
-
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
779
|
-
}
|
|
780
|
-
});
|
|
632
|
+
return super.iapRunAdapterLint(callback);
|
|
633
|
+
}
|
|
781
634
|
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
635
|
+
/**
|
|
636
|
+
* @summary run the adapter test scripts (baseunit and unit) to return the results.
|
|
637
|
+
* can not run integration as there can be implications with that.
|
|
638
|
+
*
|
|
639
|
+
* @function iapRunAdapterTests
|
|
640
|
+
* @param {Callback} callback - callback function
|
|
641
|
+
*/
|
|
642
|
+
iapRunAdapterTests(callback) {
|
|
643
|
+
const meth = 'adapter-iapRunAdapterTests';
|
|
644
|
+
const origin = `${this.id}-${meth}`;
|
|
645
|
+
log.trace(origin);
|
|
793
646
|
|
|
794
|
-
|
|
795
|
-
|
|
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
|
-
}
|
|
647
|
+
return super.iapRunAdapterTests(callback);
|
|
648
|
+
}
|
|
807
649
|
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
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
|
-
}
|
|
650
|
+
/**
|
|
651
|
+
* @summary provide inventory information abbout the adapter
|
|
652
|
+
*
|
|
653
|
+
* @function iapGetAdapterInventory
|
|
654
|
+
* @param {Callback} callback - callback function
|
|
655
|
+
*/
|
|
656
|
+
iapGetAdapterInventory(callback) {
|
|
657
|
+
const meth = 'adapter-iapGetAdapterInventory';
|
|
658
|
+
const origin = `${this.id}-${meth}`;
|
|
659
|
+
log.trace(origin);
|
|
823
660
|
|
|
824
|
-
|
|
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
|
-
}
|
|
661
|
+
return super.iapGetAdapterInventory(callback);
|
|
833
662
|
}
|
|
834
663
|
|
|
835
664
|
/**
|