@itentialopensource/adapter-netbox_v210 0.1.2 → 0.2.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/CHANGELOG.md +8 -0
- package/adapter.js +551 -1
- package/entities/Graphql/action.json +25 -0
- package/entities/Graphql/schema.json +19 -0
- package/package.json +1 -1
- package/pronghorn.json +226 -0
- package/refs?service=git-upload-pack +0 -0
- package/report/updateReport1644852199348.json +95 -0
- package/test/integration/adapterTestIntegration.js +25 -0
- package/test/unit/adapterTestUnit.js +113 -0
- package/utils/patches2bundledDeps.js +90 -0
package/CHANGELOG.md
CHANGED
package/adapter.js
CHANGED
|
@@ -83,7 +83,7 @@ class NetboxV210 extends AdapterBaseCl {
|
|
|
83
83
|
* @getWorkflowFunctions
|
|
84
84
|
*/
|
|
85
85
|
getWorkflowFunctions(inIgnore) {
|
|
86
|
-
let myIgnore = [];
|
|
86
|
+
let myIgnore = ['hasEntities', 'hasDevices'];
|
|
87
87
|
if (!inIgnore && Array.isArray(inIgnore)) {
|
|
88
88
|
myIgnore = inIgnore;
|
|
89
89
|
} else if (!inIgnore && typeof inIgnore === 'string') {
|
|
@@ -247,6 +247,24 @@ class NetboxV210 extends AdapterBaseCl {
|
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
+
/**
|
|
251
|
+
* @summary moves entites into Mongo DB
|
|
252
|
+
*
|
|
253
|
+
* @function moveEntitiesToDB
|
|
254
|
+
* @param {getCallback} callback - a callback function to return the result (Generics)
|
|
255
|
+
* or the error
|
|
256
|
+
*/
|
|
257
|
+
moveEntitiesToDB(callback) {
|
|
258
|
+
const origin = `${this.id}-adapter-moveEntitiesToDB`;
|
|
259
|
+
log.trace(origin);
|
|
260
|
+
try {
|
|
261
|
+
return super.moveEntitiesToDB(callback);
|
|
262
|
+
} catch (err) {
|
|
263
|
+
log.error(`${origin}: ${err}`);
|
|
264
|
+
return callback(null, err);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
250
268
|
/**
|
|
251
269
|
* @summary Determines if this adapter supports the specific entity
|
|
252
270
|
*
|
|
@@ -526,6 +544,456 @@ class NetboxV210 extends AdapterBaseCl {
|
|
|
526
544
|
}
|
|
527
545
|
}
|
|
528
546
|
|
|
547
|
+
/* BROKER CALLS */
|
|
548
|
+
/**
|
|
549
|
+
* @summary Determines if this adapter supports any in a list of entities
|
|
550
|
+
*
|
|
551
|
+
* @function hasEntities
|
|
552
|
+
* @param {String} entityType - the entity type to check for
|
|
553
|
+
* @param {Array} entityList - the list of entities we are looking for
|
|
554
|
+
*
|
|
555
|
+
* @param {Callback} callback - A map where the entity is the key and the
|
|
556
|
+
* value is true or false
|
|
557
|
+
*/
|
|
558
|
+
hasEntities(entityType, entityList, callback) {
|
|
559
|
+
const origin = `${this.id}-adapter-hasEntities`;
|
|
560
|
+
log.trace(origin);
|
|
561
|
+
|
|
562
|
+
switch (entityType) {
|
|
563
|
+
case 'Device':
|
|
564
|
+
return this.hasDevices(entityList, callback);
|
|
565
|
+
default:
|
|
566
|
+
return callback(null, `${this.id} does not support entity ${entityType}`);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* @summary Helper method for hasEntities for the specific device case
|
|
572
|
+
*
|
|
573
|
+
* @param {Array} deviceList - array of unique device identifiers
|
|
574
|
+
* @param {Callback} callback - A map where the device is the key and the
|
|
575
|
+
* value is true or false
|
|
576
|
+
*/
|
|
577
|
+
hasDevices(deviceList, callback) {
|
|
578
|
+
const origin = `${this.id}-adapter-hasDevices`;
|
|
579
|
+
log.trace(origin);
|
|
580
|
+
|
|
581
|
+
const findings = deviceList.reduce((map, device) => {
|
|
582
|
+
// eslint-disable-next-line no-param-reassign
|
|
583
|
+
map[device] = false;
|
|
584
|
+
log.debug(`In reduce: ${JSON.stringify(map)}`);
|
|
585
|
+
return map;
|
|
586
|
+
}, {});
|
|
587
|
+
const apiCalls = deviceList.map((device) => new Promise((resolve) => {
|
|
588
|
+
this.getDevice(device, (result, error) => {
|
|
589
|
+
if (error) {
|
|
590
|
+
log.debug(`In map error: ${JSON.stringify(device)}`);
|
|
591
|
+
return resolve({ name: device, found: false });
|
|
592
|
+
}
|
|
593
|
+
log.debug(`In map: ${JSON.stringify(device)}`);
|
|
594
|
+
return resolve({ name: device, found: true });
|
|
595
|
+
});
|
|
596
|
+
}));
|
|
597
|
+
Promise.all(apiCalls).then((results) => {
|
|
598
|
+
results.forEach((device) => {
|
|
599
|
+
findings[device.name] = device.found;
|
|
600
|
+
});
|
|
601
|
+
log.debug(`FINDINGS: ${JSON.stringify(findings)}`);
|
|
602
|
+
return callback(findings);
|
|
603
|
+
}).catch((errors) => {
|
|
604
|
+
log.error('Unable to do device lookup.');
|
|
605
|
+
return callback(null, { code: 503, message: 'Unable to do device lookup.', error: errors });
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* @summary Get Appliance that match the deviceName
|
|
611
|
+
*
|
|
612
|
+
* @function getDevice
|
|
613
|
+
* @param {String} deviceName - the deviceName to find (required)
|
|
614
|
+
*
|
|
615
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
616
|
+
* (appliance) or the error
|
|
617
|
+
*/
|
|
618
|
+
getDevice(deviceName, callback) {
|
|
619
|
+
const meth = 'adapter-getDevice';
|
|
620
|
+
const origin = `${this.id}-${meth}`;
|
|
621
|
+
log.trace(origin);
|
|
622
|
+
|
|
623
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
624
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
625
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
626
|
+
return callback(null, errorObj);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
630
|
+
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
|
631
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
|
632
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
633
|
+
return callback(null, errorObj);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
try {
|
|
637
|
+
// need to get the device so we can convert the deviceName to an id
|
|
638
|
+
// !! if we can do a lookup by name the getDevicesFiltered may not be necessary
|
|
639
|
+
const opts = {
|
|
640
|
+
filter: {
|
|
641
|
+
name: deviceName
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
|
645
|
+
// if we received an error or their is no response on the results return an error
|
|
646
|
+
if (ferr) {
|
|
647
|
+
return callback(null, ferr);
|
|
648
|
+
}
|
|
649
|
+
if (devs.list.length < 1) {
|
|
650
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
|
651
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
652
|
+
return callback(null, errorObj);
|
|
653
|
+
}
|
|
654
|
+
// get the uuid from the device
|
|
655
|
+
const { uuid } = devs.list[0];
|
|
656
|
+
|
|
657
|
+
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
658
|
+
// !! you can also replace with a specific call if that is easier
|
|
659
|
+
const uriPath = `/call/toget/device/${uuid}`;
|
|
660
|
+
return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
|
|
661
|
+
// if we received an error or their is no response on the results return an error
|
|
662
|
+
if (error) {
|
|
663
|
+
return callback(null, error);
|
|
664
|
+
}
|
|
665
|
+
if (!result.response || !result.response.applianceMo) {
|
|
666
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevice'], null, null, null);
|
|
667
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
668
|
+
return callback(null, errorObj);
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
// return the response
|
|
672
|
+
// !! format the data we send back
|
|
673
|
+
// !! these fields are config manager fields you need to map to the data we receive
|
|
674
|
+
const thisDevice = result.response;
|
|
675
|
+
thisDevice.name = thisDevice.systemName;
|
|
676
|
+
thisDevice.ostype = `System-${thisDevice.systemType}`;
|
|
677
|
+
thisDevice.port = thisDevice.systemPort;
|
|
678
|
+
thisDevice.ipaddress = thisDevice.systemIP;
|
|
679
|
+
return callback(thisDevice);
|
|
680
|
+
});
|
|
681
|
+
});
|
|
682
|
+
} catch (ex) {
|
|
683
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
684
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
685
|
+
return callback(null, errorObj);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* @summary Get Appliances that match the filter
|
|
691
|
+
*
|
|
692
|
+
* @function getDevicesFiltered
|
|
693
|
+
* @param {Object} options - the data to use to filter the appliances (optional)
|
|
694
|
+
*
|
|
695
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
696
|
+
* (appliances) or the error
|
|
697
|
+
*/
|
|
698
|
+
getDevicesFiltered(options, callback) {
|
|
699
|
+
const meth = 'adapter-getDevicesFiltered';
|
|
700
|
+
const origin = `${this.id}-${meth}`;
|
|
701
|
+
log.trace(origin);
|
|
702
|
+
|
|
703
|
+
// verify the required fields have been provided
|
|
704
|
+
if (options === undefined || options === null || options === '' || options.length === 0) {
|
|
705
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['options'], null, null, null);
|
|
706
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
707
|
+
return callback(null, errorObj);
|
|
708
|
+
}
|
|
709
|
+
log.debug(`Device Filter Options: ${JSON.stringify(options)}`);
|
|
710
|
+
|
|
711
|
+
// TODO - get pagination working
|
|
712
|
+
// const nextToken = options.start;
|
|
713
|
+
// const maxResults = options.limit;
|
|
714
|
+
|
|
715
|
+
// set up the filter of Device Names
|
|
716
|
+
let filterName = [];
|
|
717
|
+
if (options && options.filter && options.filter.name) {
|
|
718
|
+
// when this hack is removed, remove the lint ignore above
|
|
719
|
+
if (Array.isArray(options.filter.name)) {
|
|
720
|
+
// eslint-disable-next-line prefer-destructuring
|
|
721
|
+
filterName = options.filter.name;
|
|
722
|
+
} else {
|
|
723
|
+
filterName = [options.filter.name];
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
// TODO - get sort and order working
|
|
728
|
+
/*
|
|
729
|
+
if (options && options.sort) {
|
|
730
|
+
reqObj.uriOptions.sort = JSON.stringify(options.sort);
|
|
731
|
+
}
|
|
732
|
+
if (options && options.order) {
|
|
733
|
+
reqObj.uriOptions.order = options.order;
|
|
734
|
+
}
|
|
735
|
+
*/
|
|
736
|
+
try {
|
|
737
|
+
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
738
|
+
// !! you can also replace with a specific call if that is easier
|
|
739
|
+
const uriPath = '/call/toget/devices';
|
|
740
|
+
return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
|
|
741
|
+
// if we received an error or their is no response on the results return an error
|
|
742
|
+
if (error) {
|
|
743
|
+
return callback(null, error);
|
|
744
|
+
}
|
|
745
|
+
if (!result.response) {
|
|
746
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevicesFiltered'], null, null, null);
|
|
747
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
748
|
+
return callback(null, errorObj);
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
// !! go through the response - may have to look for sub object
|
|
752
|
+
// handle an array of devices
|
|
753
|
+
if (Array.isArray(result.response)) {
|
|
754
|
+
const myDevices = [];
|
|
755
|
+
|
|
756
|
+
for (let d = 0; d < result.response.length; d += 1) {
|
|
757
|
+
// !! format the data we send back
|
|
758
|
+
// !! these fields are config manager fields you need to map to the data we receive
|
|
759
|
+
const thisDevice = result.response;
|
|
760
|
+
thisDevice.name = thisDevice.systemName;
|
|
761
|
+
thisDevice.ostype = `System-${thisDevice.systemType}`;
|
|
762
|
+
thisDevice.port = thisDevice.systemPort;
|
|
763
|
+
thisDevice.ipaddress = thisDevice.systemIP;
|
|
764
|
+
|
|
765
|
+
// if there is no filter - return the device
|
|
766
|
+
if (filterName.length === 0) {
|
|
767
|
+
myDevices.push(thisDevice);
|
|
768
|
+
} else {
|
|
769
|
+
// if we have to match a filter
|
|
770
|
+
let found = false;
|
|
771
|
+
for (let f = 0; f < filterName.length; f += 1) {
|
|
772
|
+
if (thisDevice.name.indexOf(filterName[f]) >= 0) {
|
|
773
|
+
found = true;
|
|
774
|
+
break;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
// matching device
|
|
778
|
+
if (found) {
|
|
779
|
+
myDevices.push(thisDevice);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
log.debug(`${origin}: Found #${myDevices.length} devices.`);
|
|
784
|
+
log.debug(`Devices: ${JSON.stringify(myDevices)}`);
|
|
785
|
+
return callback({ total: myDevices.length, list: myDevices });
|
|
786
|
+
}
|
|
787
|
+
// handle a single device response
|
|
788
|
+
// !! format the data we send back
|
|
789
|
+
// !! these fields are config manager fields you need to map to the data we receive
|
|
790
|
+
const thisDevice = result.response;
|
|
791
|
+
thisDevice.name = thisDevice.systemName;
|
|
792
|
+
thisDevice.ostype = `System-${thisDevice.systemType}`;
|
|
793
|
+
thisDevice.port = thisDevice.systemPort;
|
|
794
|
+
thisDevice.ipaddress = thisDevice.systemIP;
|
|
795
|
+
|
|
796
|
+
// if there is no filter - return the device
|
|
797
|
+
if (filterName.length === 0) {
|
|
798
|
+
log.debug(`${origin}: Found #1 device.`);
|
|
799
|
+
log.debug(`Device: ${JSON.stringify(thisDevice)}`);
|
|
800
|
+
return callback({ total: 1, list: [thisDevice] });
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
// if there is a filter need to check for matching device
|
|
804
|
+
let found = false;
|
|
805
|
+
for (let f = 0; f < filterName.length; f += 1) {
|
|
806
|
+
if (thisDevice.name.indexOf(filterName[f]) >= 0) {
|
|
807
|
+
found = true;
|
|
808
|
+
break;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
// matching device
|
|
812
|
+
if (found) {
|
|
813
|
+
log.debug(`${origin}: Found #1 device.`);
|
|
814
|
+
log.debug(`Device Found: ${JSON.stringify(thisDevice)}`);
|
|
815
|
+
return callback({ total: 1, list: [thisDevice] });
|
|
816
|
+
}
|
|
817
|
+
// not a matching device
|
|
818
|
+
log.debug(`${origin}: No matching device found.`);
|
|
819
|
+
return callback({ total: 0, list: [] });
|
|
820
|
+
});
|
|
821
|
+
} catch (ex) {
|
|
822
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
823
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
824
|
+
return callback(null, errorObj);
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* @summary Gets the status for the provided appliance
|
|
830
|
+
*
|
|
831
|
+
* @function isAlive
|
|
832
|
+
* @param {String} deviceName - the deviceName of the appliance. (required)
|
|
833
|
+
*
|
|
834
|
+
* @param {configCallback} callback - callback function to return the result
|
|
835
|
+
* (appliance isAlive) or the error
|
|
836
|
+
*/
|
|
837
|
+
isAlive(deviceName, callback) {
|
|
838
|
+
const meth = 'adapter-isAlive';
|
|
839
|
+
const origin = `${this.id}-${meth}`;
|
|
840
|
+
log.trace(origin);
|
|
841
|
+
|
|
842
|
+
// verify the required fields have been provided
|
|
843
|
+
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
|
844
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
|
845
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
846
|
+
return callback(null, errorObj);
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
try {
|
|
850
|
+
// need to get the device so we can convert the deviceName to an id
|
|
851
|
+
// !! if we can do a lookup by name the getDevicesFiltered may not be necessary
|
|
852
|
+
const opts = {
|
|
853
|
+
filter: {
|
|
854
|
+
name: deviceName
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
|
858
|
+
// if we received an error or their is no response on the results return an error
|
|
859
|
+
if (ferr) {
|
|
860
|
+
return callback(null, ferr);
|
|
861
|
+
}
|
|
862
|
+
if (devs.list.length < 1) {
|
|
863
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
|
864
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
865
|
+
return callback(null, errorObj);
|
|
866
|
+
}
|
|
867
|
+
// get the uuid from the device
|
|
868
|
+
const { uuid } = devs.list[0];
|
|
869
|
+
|
|
870
|
+
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
871
|
+
// !! you can also replace with a specific call if that is easier
|
|
872
|
+
const uriPath = `/call/toget/status/${uuid}`;
|
|
873
|
+
return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
|
|
874
|
+
// if we received an error or their is no response on the results return an error
|
|
875
|
+
if (error) {
|
|
876
|
+
return callback(null, error);
|
|
877
|
+
}
|
|
878
|
+
// !! should update this to make sure we are checking for the appropriate object/field
|
|
879
|
+
if (!result.response || !result.response.returnObj || !Object.hasOwnProperty.call(result.response.returnObj, 'statusField')) {
|
|
880
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['isAlive'], null, null, null);
|
|
881
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
882
|
+
return callback(null, errorObj);
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
// !! return the response - Update to the appropriate object/field
|
|
886
|
+
return callback(!result.response.returnObj.statusField);
|
|
887
|
+
});
|
|
888
|
+
});
|
|
889
|
+
} catch (ex) {
|
|
890
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
891
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
892
|
+
return callback(null, errorObj);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
/**
|
|
897
|
+
* @summary Gets a config for the provided Appliance
|
|
898
|
+
*
|
|
899
|
+
* @function getConfig
|
|
900
|
+
* @param {String} deviceName - the deviceName of the appliance. (required)
|
|
901
|
+
* @param {String} format - the desired format of the config. (optional)
|
|
902
|
+
*
|
|
903
|
+
* @param {configCallback} callback - callback function to return the result
|
|
904
|
+
* (appliance config) or the error
|
|
905
|
+
*/
|
|
906
|
+
getConfig(deviceName, format, callback) {
|
|
907
|
+
const meth = 'adapter-getConfig';
|
|
908
|
+
const origin = `${this.id}-${meth}`;
|
|
909
|
+
log.trace(origin);
|
|
910
|
+
|
|
911
|
+
// verify the required fields have been provided
|
|
912
|
+
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
|
913
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
|
914
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
915
|
+
return callback(null, errorObj);
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
try {
|
|
919
|
+
// need to get the device so we can convert the deviceName to an id
|
|
920
|
+
// !! if we can do a lookup by name the getDevicesFiltered may not be necessary
|
|
921
|
+
const opts = {
|
|
922
|
+
filter: {
|
|
923
|
+
name: deviceName
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
|
927
|
+
// if we received an error or their is no response on the results return an error
|
|
928
|
+
if (ferr) {
|
|
929
|
+
return callback(null, ferr);
|
|
930
|
+
}
|
|
931
|
+
if (devs.list.length < 1) {
|
|
932
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
|
933
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
934
|
+
return callback(null, errorObj);
|
|
935
|
+
}
|
|
936
|
+
// get the uuid from the device
|
|
937
|
+
const { uuid } = devs.list[0];
|
|
938
|
+
|
|
939
|
+
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
940
|
+
// !! you can also replace with a specific call if that is easier
|
|
941
|
+
const uriPath = `/call/toget/config/${uuid}`;
|
|
942
|
+
return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
|
|
943
|
+
// if we received an error or their is no response on the results return an error
|
|
944
|
+
if (error) {
|
|
945
|
+
return callback(null, error);
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
// return the result
|
|
949
|
+
const newResponse = {
|
|
950
|
+
response: JSON.stringify(result.response, null, 2)
|
|
951
|
+
};
|
|
952
|
+
return callback(newResponse);
|
|
953
|
+
});
|
|
954
|
+
});
|
|
955
|
+
} catch (ex) {
|
|
956
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
957
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
958
|
+
return callback(null, errorObj);
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
/**
|
|
963
|
+
* @summary Gets the device count from the system
|
|
964
|
+
*
|
|
965
|
+
* @function getCount
|
|
966
|
+
*
|
|
967
|
+
* @param {getCallback} callback - callback function to return the result
|
|
968
|
+
* (count) or the error
|
|
969
|
+
*/
|
|
970
|
+
getCount(callback) {
|
|
971
|
+
const meth = 'adapter-getCount';
|
|
972
|
+
const origin = `${this.id}-${meth}`;
|
|
973
|
+
log.trace(origin);
|
|
974
|
+
|
|
975
|
+
// verify the required fields have been provided
|
|
976
|
+
|
|
977
|
+
try {
|
|
978
|
+
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
979
|
+
// !! you can also replace with a specific call if that is easier
|
|
980
|
+
const uriPath = '/call/toget/count';
|
|
981
|
+
return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
|
|
982
|
+
// if we received an error or their is no response on the results return an error
|
|
983
|
+
if (error) {
|
|
984
|
+
return callback(null, error);
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
// return the result
|
|
988
|
+
return callback({ count: result.response });
|
|
989
|
+
});
|
|
990
|
+
} catch (ex) {
|
|
991
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
992
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
993
|
+
return callback(null, errorObj);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
|
|
529
997
|
/**
|
|
530
998
|
* @callback healthCallback
|
|
531
999
|
* @param {Object} result - the result of the get request (contains an id and a status)
|
|
@@ -44593,6 +45061,88 @@ This request will yield a base64-encoded session key to be included in an `X-Ses
|
|
|
44593
45061
|
}
|
|
44594
45062
|
}
|
|
44595
45063
|
|
|
45064
|
+
/**
|
|
45065
|
+
* @function getGraphql
|
|
45066
|
+
* @pronghornType method
|
|
45067
|
+
* @name getGraphql
|
|
45068
|
+
* @summary A lightweight read-only endpoint for conveying querying using graphql.
|
|
45069
|
+
*
|
|
45070
|
+
* @param {object} body - graphql query data
|
|
45071
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
45072
|
+
* @return {object} results - An object containing the response of the action
|
|
45073
|
+
*
|
|
45074
|
+
* @route {GET} /getGraphql
|
|
45075
|
+
* @roles admin
|
|
45076
|
+
* @task true
|
|
45077
|
+
*/
|
|
45078
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
45079
|
+
getGraphql(body, callback) {
|
|
45080
|
+
const meth = 'adapter-getGraphql';
|
|
45081
|
+
const origin = `${this.id}-${meth}`;
|
|
45082
|
+
log.trace(origin);
|
|
45083
|
+
|
|
45084
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
45085
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
45086
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
45087
|
+
return callback(null, errorObj);
|
|
45088
|
+
}
|
|
45089
|
+
|
|
45090
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
45091
|
+
if (body === undefined || body === null || body === '') {
|
|
45092
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
|
|
45093
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
45094
|
+
return callback(null, errorObj);
|
|
45095
|
+
}
|
|
45096
|
+
|
|
45097
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
45098
|
+
const queryParamsAvailable = {};
|
|
45099
|
+
const queryParams = {};
|
|
45100
|
+
const pathVars = [];
|
|
45101
|
+
const bodyVars = body;
|
|
45102
|
+
|
|
45103
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
45104
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
45105
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
45106
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
45107
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
45108
|
+
}
|
|
45109
|
+
});
|
|
45110
|
+
|
|
45111
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
|
|
45112
|
+
// see adapter code documentation for more information on the request object's fields
|
|
45113
|
+
const reqObj = {
|
|
45114
|
+
payload: bodyVars,
|
|
45115
|
+
uriPathVars: pathVars,
|
|
45116
|
+
uriQuery: queryParams
|
|
45117
|
+
};
|
|
45118
|
+
|
|
45119
|
+
try {
|
|
45120
|
+
// Make the call -
|
|
45121
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
45122
|
+
return this.requestHandlerInst.identifyRequest('Graphql', 'getGraphql', reqObj, true, (irReturnData, irReturnError) => {
|
|
45123
|
+
// if we received an error or their is no response on the results
|
|
45124
|
+
// return an error
|
|
45125
|
+
if (irReturnError) {
|
|
45126
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
45127
|
+
return callback(null, irReturnError);
|
|
45128
|
+
}
|
|
45129
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
45130
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getGraphql'], null, null, null);
|
|
45131
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
45132
|
+
return callback(null, errorObj);
|
|
45133
|
+
}
|
|
45134
|
+
|
|
45135
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
45136
|
+
// return the response
|
|
45137
|
+
return callback(irReturnData, null);
|
|
45138
|
+
});
|
|
45139
|
+
} catch (ex) {
|
|
45140
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
45141
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
45142
|
+
return callback(null, errorObj);
|
|
45143
|
+
}
|
|
45144
|
+
}
|
|
45145
|
+
|
|
44596
45146
|
/**
|
|
44597
45147
|
* @function getTenancyTenantGroups
|
|
44598
45148
|
* @pronghornType method
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"actions": [
|
|
3
|
+
{
|
|
4
|
+
"name": "getGraphql",
|
|
5
|
+
"protocol": "REST",
|
|
6
|
+
"method": "GET",
|
|
7
|
+
"entitypath": "/graphql/?{query}",
|
|
8
|
+
"requestSchema": "schema.json",
|
|
9
|
+
"responseSchema": "schema.json",
|
|
10
|
+
"timeout": 0,
|
|
11
|
+
"sendEmpty": false,
|
|
12
|
+
"sendGetBody": false,
|
|
13
|
+
"requestDatatype": "JSON",
|
|
14
|
+
"responseDatatype": "JSON",
|
|
15
|
+
"headers": {},
|
|
16
|
+
"responseObjects": [
|
|
17
|
+
{
|
|
18
|
+
"type": "default",
|
|
19
|
+
"key": "",
|
|
20
|
+
"mockFile": ""
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$id": "schema.json",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"schema": "http://json-schema.org/draft-07/schema#",
|
|
5
|
+
"translate": false,
|
|
6
|
+
"dynamicfields": true,
|
|
7
|
+
"properties": {
|
|
8
|
+
"ph_request_type": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "type of request (internal to adapter)",
|
|
11
|
+
"default": "getGraphql",
|
|
12
|
+
"enum": [
|
|
13
|
+
"getGraphql"
|
|
14
|
+
],
|
|
15
|
+
"external_name": "ph_request_type"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"definitions": {}
|
|
19
|
+
}
|
package/package.json
CHANGED
package/pronghorn.json
CHANGED
|
@@ -386,6 +386,198 @@
|
|
|
386
386
|
},
|
|
387
387
|
"task": true
|
|
388
388
|
},
|
|
389
|
+
{
|
|
390
|
+
"name": "moveEntitiesToDB",
|
|
391
|
+
"summary": "Moves entities from an adapter into the IAP database",
|
|
392
|
+
"description": "Moves entities from an adapter into the IAP database",
|
|
393
|
+
"input": [],
|
|
394
|
+
"output": {
|
|
395
|
+
"name": "res",
|
|
396
|
+
"type": "object",
|
|
397
|
+
"description": "A JSON Object containing status, code and the response from the mongo transaction",
|
|
398
|
+
"schema": {
|
|
399
|
+
"title": "res",
|
|
400
|
+
"type": "object"
|
|
401
|
+
}
|
|
402
|
+
},
|
|
403
|
+
"roles": [
|
|
404
|
+
"admin"
|
|
405
|
+
],
|
|
406
|
+
"route": {
|
|
407
|
+
"verb": "POST",
|
|
408
|
+
"path": "/moveEntitiesToDB"
|
|
409
|
+
},
|
|
410
|
+
"task": true
|
|
411
|
+
},
|
|
412
|
+
{
|
|
413
|
+
"name": "getDevice",
|
|
414
|
+
"summary": "Get the Appliance",
|
|
415
|
+
"description": "Get the Appliance",
|
|
416
|
+
"input": [
|
|
417
|
+
{
|
|
418
|
+
"name": "deviceName",
|
|
419
|
+
"type": "string",
|
|
420
|
+
"info": "An Appliance Device Name",
|
|
421
|
+
"required": true,
|
|
422
|
+
"schema": {
|
|
423
|
+
"title": "deviceName",
|
|
424
|
+
"type": "string"
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
],
|
|
428
|
+
"output": {
|
|
429
|
+
"name": "result",
|
|
430
|
+
"type": "object",
|
|
431
|
+
"description": "A JSON Object containing status, code and the result",
|
|
432
|
+
"schema": {
|
|
433
|
+
"title": "result",
|
|
434
|
+
"type": "object"
|
|
435
|
+
}
|
|
436
|
+
},
|
|
437
|
+
"roles": [
|
|
438
|
+
"admin"
|
|
439
|
+
],
|
|
440
|
+
"route": {
|
|
441
|
+
"verb": "POST",
|
|
442
|
+
"path": "/getDevice"
|
|
443
|
+
},
|
|
444
|
+
"task": false
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
"name": "getDevicesFiltered",
|
|
448
|
+
"summary": "Get Appliances that match the filter",
|
|
449
|
+
"description": "Get Appliances that match the filter",
|
|
450
|
+
"input": [
|
|
451
|
+
{
|
|
452
|
+
"name": "options",
|
|
453
|
+
"type": "object",
|
|
454
|
+
"info": "options - e.g. { 'start': 1, 'limit': 20, 'filter': { 'name': 'abc123' } }",
|
|
455
|
+
"required": true,
|
|
456
|
+
"schema": {
|
|
457
|
+
"title": "options",
|
|
458
|
+
"type": "object"
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
],
|
|
462
|
+
"output": {
|
|
463
|
+
"name": "result",
|
|
464
|
+
"type": "array",
|
|
465
|
+
"description": "A JSON Object containing status, code and the result",
|
|
466
|
+
"schema": {
|
|
467
|
+
"title": "result",
|
|
468
|
+
"type": "array"
|
|
469
|
+
}
|
|
470
|
+
},
|
|
471
|
+
"roles": [
|
|
472
|
+
"admin"
|
|
473
|
+
],
|
|
474
|
+
"route": {
|
|
475
|
+
"verb": "POST",
|
|
476
|
+
"path": "/getDevicesFiltered"
|
|
477
|
+
},
|
|
478
|
+
"task": false
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
"name": "isAlive",
|
|
482
|
+
"summary": "Checks the status for the provided Appliance",
|
|
483
|
+
"description": "Checks the status for the provided Appliance",
|
|
484
|
+
"input": [
|
|
485
|
+
{
|
|
486
|
+
"name": "deviceName",
|
|
487
|
+
"type": "string",
|
|
488
|
+
"info": "An Appliance Device Name",
|
|
489
|
+
"required": true,
|
|
490
|
+
"schema": {
|
|
491
|
+
"title": "deviceName",
|
|
492
|
+
"type": "string"
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
],
|
|
496
|
+
"output": {
|
|
497
|
+
"name": "result",
|
|
498
|
+
"type": "boolean",
|
|
499
|
+
"description": "A JSON Object containing status, code and the result",
|
|
500
|
+
"schema": {
|
|
501
|
+
"title": "result",
|
|
502
|
+
"type": "boolean"
|
|
503
|
+
}
|
|
504
|
+
},
|
|
505
|
+
"roles": [
|
|
506
|
+
"admin"
|
|
507
|
+
],
|
|
508
|
+
"route": {
|
|
509
|
+
"verb": "POST",
|
|
510
|
+
"path": "/isAlive"
|
|
511
|
+
},
|
|
512
|
+
"task": false
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
"name": "getConfig",
|
|
516
|
+
"summary": "Gets a config for the provided Appliance",
|
|
517
|
+
"description": "Gets a config for the provided Appliance",
|
|
518
|
+
"input": [
|
|
519
|
+
{
|
|
520
|
+
"name": "deviceName",
|
|
521
|
+
"type": "string",
|
|
522
|
+
"info": "An Appliance Device Name",
|
|
523
|
+
"required": true,
|
|
524
|
+
"schema": {
|
|
525
|
+
"title": "deviceName",
|
|
526
|
+
"type": "string"
|
|
527
|
+
}
|
|
528
|
+
},
|
|
529
|
+
{
|
|
530
|
+
"name": "format",
|
|
531
|
+
"type": "string",
|
|
532
|
+
"info": "The format to be returned - this is ignored as we always return json",
|
|
533
|
+
"required": false,
|
|
534
|
+
"schema": {
|
|
535
|
+
"title": "format",
|
|
536
|
+
"type": "string"
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
],
|
|
540
|
+
"output": {
|
|
541
|
+
"name": "result",
|
|
542
|
+
"type": "object",
|
|
543
|
+
"description": "A JSON Object containing status, code and the result",
|
|
544
|
+
"schema": {
|
|
545
|
+
"title": "result",
|
|
546
|
+
"type": "object"
|
|
547
|
+
}
|
|
548
|
+
},
|
|
549
|
+
"roles": [
|
|
550
|
+
"admin"
|
|
551
|
+
],
|
|
552
|
+
"route": {
|
|
553
|
+
"verb": "POST",
|
|
554
|
+
"path": "/getConfig"
|
|
555
|
+
},
|
|
556
|
+
"task": false
|
|
557
|
+
},
|
|
558
|
+
{
|
|
559
|
+
"name": "getCount",
|
|
560
|
+
"summary": "Gets a device count from the system",
|
|
561
|
+
"description": "Gets a device count from the system",
|
|
562
|
+
"input": [],
|
|
563
|
+
"output": {
|
|
564
|
+
"name": "result",
|
|
565
|
+
"type": "object",
|
|
566
|
+
"description": "A JSON Object containing status, code and the result",
|
|
567
|
+
"schema": {
|
|
568
|
+
"title": "result",
|
|
569
|
+
"type": "object"
|
|
570
|
+
}
|
|
571
|
+
},
|
|
572
|
+
"roles": [
|
|
573
|
+
"admin"
|
|
574
|
+
],
|
|
575
|
+
"route": {
|
|
576
|
+
"verb": "POST",
|
|
577
|
+
"path": "/getCount"
|
|
578
|
+
},
|
|
579
|
+
"task": false
|
|
580
|
+
},
|
|
389
581
|
{
|
|
390
582
|
"name": "getCircuitsCircuitTerminations",
|
|
391
583
|
"summary": "circuits_circuit-terminations_list",
|
|
@@ -150156,6 +150348,40 @@
|
|
|
150156
150348
|
},
|
|
150157
150349
|
"task": true
|
|
150158
150350
|
},
|
|
150351
|
+
{
|
|
150352
|
+
"name": "getGraphql",
|
|
150353
|
+
"summary": "A lightweight read-only endpoint for conveying querying using graphql.",
|
|
150354
|
+
"description": "A lightweight read-only endpoint for conveying querying using graphql.",
|
|
150355
|
+
"input": [
|
|
150356
|
+
{
|
|
150357
|
+
"name": "body",
|
|
150358
|
+
"type": "object",
|
|
150359
|
+
"info": "JSON object containing the graphql query",
|
|
150360
|
+
"required": true,
|
|
150361
|
+
"schema": {
|
|
150362
|
+
"title": "body",
|
|
150363
|
+
"type": "object"
|
|
150364
|
+
}
|
|
150365
|
+
}
|
|
150366
|
+
],
|
|
150367
|
+
"output": {
|
|
150368
|
+
"name": "result",
|
|
150369
|
+
"type": "object",
|
|
150370
|
+
"description": "A JSON Object containing status, code and the result",
|
|
150371
|
+
"schema": {
|
|
150372
|
+
"title": "result",
|
|
150373
|
+
"type": "object"
|
|
150374
|
+
}
|
|
150375
|
+
},
|
|
150376
|
+
"roles": [
|
|
150377
|
+
"admin"
|
|
150378
|
+
],
|
|
150379
|
+
"route": {
|
|
150380
|
+
"verb": "GET",
|
|
150381
|
+
"path": "/getGraphql"
|
|
150382
|
+
},
|
|
150383
|
+
"task": true
|
|
150384
|
+
},
|
|
150159
150385
|
{
|
|
150160
150386
|
"name": "getTenancyTenantGroups",
|
|
150161
150387
|
"summary": "tenancy_tenant-groups_list",
|
|
Binary file
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
{
|
|
2
|
+
"errors": [],
|
|
3
|
+
"statistics": [
|
|
4
|
+
{
|
|
5
|
+
"owner": "errorJson",
|
|
6
|
+
"description": "New adapter errors available for use",
|
|
7
|
+
"value": 0
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"owner": "errorJson",
|
|
11
|
+
"description": "Adapter errors no longer available for use",
|
|
12
|
+
"value": 0
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"owner": "errorJson",
|
|
16
|
+
"description": "Adapter errors that have been updated (e.g. recommendation changes)",
|
|
17
|
+
"value": 30
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"owner": "packageJson",
|
|
21
|
+
"description": "Number of production dependencies",
|
|
22
|
+
"value": 13
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"owner": "packageJson",
|
|
26
|
+
"description": "Number of development dependencies",
|
|
27
|
+
"value": 7
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"owner": "packageJson",
|
|
31
|
+
"description": "Number of npm scripts",
|
|
32
|
+
"value": 23
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"owner": "packageJson",
|
|
36
|
+
"description": "Runtime Library dependency",
|
|
37
|
+
"value": "^4.44.11"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"owner": "propertiesSchemaJson",
|
|
41
|
+
"description": "Adapter properties defined in the propertiesSchema file",
|
|
42
|
+
"value": 64
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"owner": "readmeMd",
|
|
46
|
+
"description": "Number of lines in the README.md",
|
|
47
|
+
"value": 688
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"owner": "unitTestJS",
|
|
51
|
+
"description": "Number of lines of code in unit tests",
|
|
52
|
+
"value": 18675
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"owner": "unitTestJS",
|
|
56
|
+
"description": "Number of unit tests",
|
|
57
|
+
"value": 1250
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"owner": "integrationTestJS",
|
|
61
|
+
"description": "Number of lines of code in integration tests",
|
|
62
|
+
"value": 18771
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"owner": "integrationTestJS",
|
|
66
|
+
"description": "Number of integration tests",
|
|
67
|
+
"value": 607
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"owner": "staticFile",
|
|
71
|
+
"description": "Number of lines of code in adapterBase.js",
|
|
72
|
+
"value": 1029
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"owner": "staticFile",
|
|
76
|
+
"description": "Number of static files added",
|
|
77
|
+
"value": 34
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"owner": "Overall",
|
|
81
|
+
"description": "Total lines of Code",
|
|
82
|
+
"value": 38475
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"owner": "Overall",
|
|
86
|
+
"description": "Total Tests",
|
|
87
|
+
"value": 1857
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"owner": "Overall",
|
|
91
|
+
"description": "Total Files",
|
|
92
|
+
"value": 6
|
|
93
|
+
}
|
|
94
|
+
]
|
|
95
|
+
}
|
|
@@ -13354,6 +13354,31 @@ describe('[integration] Netbox_v210 Adapter Test', () => {
|
|
|
13354
13354
|
}).timeout(attemptTimeout);
|
|
13355
13355
|
});
|
|
13356
13356
|
|
|
13357
|
+
describe('#getGraphql - errors', () => {
|
|
13358
|
+
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
|
|
13359
|
+
try {
|
|
13360
|
+
a.getGraphql({ query: 'fakeq' }, (data, error) => {
|
|
13361
|
+
try {
|
|
13362
|
+
if (stub) {
|
|
13363
|
+
const displayE = 'Error 400 received on request';
|
|
13364
|
+
runErrorAsserts(data, error, 'AD.500', 'Test-netbox_v210-connectorRest-handleEndResponse', displayE);
|
|
13365
|
+
} else {
|
|
13366
|
+
runCommonAsserts(data, error);
|
|
13367
|
+
}
|
|
13368
|
+
saveMockData('Status', 'getGraphql', 'default', data);
|
|
13369
|
+
done();
|
|
13370
|
+
} catch (err) {
|
|
13371
|
+
log.error(`Test Failure: ${err}`);
|
|
13372
|
+
done(err);
|
|
13373
|
+
}
|
|
13374
|
+
});
|
|
13375
|
+
} catch (error) {
|
|
13376
|
+
log.error(`Adapter Exception: ${error}`);
|
|
13377
|
+
done(error);
|
|
13378
|
+
}
|
|
13379
|
+
}).timeout(attemptTimeout);
|
|
13380
|
+
});
|
|
13381
|
+
|
|
13357
13382
|
let tenancyId = 'fakedata';
|
|
13358
13383
|
const tenancyPostTenancyTenantGroupsBodyParam = {
|
|
13359
13384
|
name: 'string',
|
|
@@ -1273,6 +1273,90 @@ describe('[unit] Netbox_v210 Adapter Test', () => {
|
|
|
1273
1273
|
// }).timeout(attemptTimeout);
|
|
1274
1274
|
// });
|
|
1275
1275
|
|
|
1276
|
+
describe('#hasEntities', () => {
|
|
1277
|
+
it('should have a hasEntities function', (done) => {
|
|
1278
|
+
try {
|
|
1279
|
+
assert.equal(true, typeof a.hasEntities === 'function');
|
|
1280
|
+
done();
|
|
1281
|
+
} catch (error) {
|
|
1282
|
+
log.error(`Test Failure: ${error}`);
|
|
1283
|
+
done(error);
|
|
1284
|
+
}
|
|
1285
|
+
});
|
|
1286
|
+
});
|
|
1287
|
+
|
|
1288
|
+
describe('#hasDevices', () => {
|
|
1289
|
+
it('should have a hasDevices function', (done) => {
|
|
1290
|
+
try {
|
|
1291
|
+
assert.equal(true, typeof a.hasDevices === 'function');
|
|
1292
|
+
done();
|
|
1293
|
+
} catch (error) {
|
|
1294
|
+
log.error(`Test Failure: ${error}`);
|
|
1295
|
+
done(error);
|
|
1296
|
+
}
|
|
1297
|
+
});
|
|
1298
|
+
});
|
|
1299
|
+
|
|
1300
|
+
describe('#getDevice', () => {
|
|
1301
|
+
it('should have a getDevice function', (done) => {
|
|
1302
|
+
try {
|
|
1303
|
+
assert.equal(true, typeof a.getDevice === 'function');
|
|
1304
|
+
done();
|
|
1305
|
+
} catch (error) {
|
|
1306
|
+
log.error(`Test Failure: ${error}`);
|
|
1307
|
+
done(error);
|
|
1308
|
+
}
|
|
1309
|
+
});
|
|
1310
|
+
});
|
|
1311
|
+
|
|
1312
|
+
describe('#getDevicesFiltered', () => {
|
|
1313
|
+
it('should have a getDevicesFiltered function', (done) => {
|
|
1314
|
+
try {
|
|
1315
|
+
assert.equal(true, typeof a.getDevicesFiltered === 'function');
|
|
1316
|
+
done();
|
|
1317
|
+
} catch (error) {
|
|
1318
|
+
log.error(`Test Failure: ${error}`);
|
|
1319
|
+
done(error);
|
|
1320
|
+
}
|
|
1321
|
+
});
|
|
1322
|
+
});
|
|
1323
|
+
|
|
1324
|
+
describe('#isAlive', () => {
|
|
1325
|
+
it('should have a isAlive function', (done) => {
|
|
1326
|
+
try {
|
|
1327
|
+
assert.equal(true, typeof a.isAlive === 'function');
|
|
1328
|
+
done();
|
|
1329
|
+
} catch (error) {
|
|
1330
|
+
log.error(`Test Failure: ${error}`);
|
|
1331
|
+
done(error);
|
|
1332
|
+
}
|
|
1333
|
+
});
|
|
1334
|
+
});
|
|
1335
|
+
|
|
1336
|
+
describe('#getConfig', () => {
|
|
1337
|
+
it('should have a getConfig function', (done) => {
|
|
1338
|
+
try {
|
|
1339
|
+
assert.equal(true, typeof a.getConfig === 'function');
|
|
1340
|
+
done();
|
|
1341
|
+
} catch (error) {
|
|
1342
|
+
log.error(`Test Failure: ${error}`);
|
|
1343
|
+
done(error);
|
|
1344
|
+
}
|
|
1345
|
+
});
|
|
1346
|
+
});
|
|
1347
|
+
|
|
1348
|
+
describe('#getCount', () => {
|
|
1349
|
+
it('should have a getCount function', (done) => {
|
|
1350
|
+
try {
|
|
1351
|
+
assert.equal(true, typeof a.getCount === 'function');
|
|
1352
|
+
done();
|
|
1353
|
+
} catch (error) {
|
|
1354
|
+
log.error(`Test Failure: ${error}`);
|
|
1355
|
+
done(error);
|
|
1356
|
+
}
|
|
1357
|
+
});
|
|
1358
|
+
});
|
|
1359
|
+
|
|
1276
1360
|
/*
|
|
1277
1361
|
-----------------------------------------------------------------------
|
|
1278
1362
|
-----------------------------------------------------------------------
|
|
@@ -15953,6 +16037,35 @@ describe('[unit] Netbox_v210 Adapter Test', () => {
|
|
|
15953
16037
|
}).timeout(attemptTimeout);
|
|
15954
16038
|
});
|
|
15955
16039
|
|
|
16040
|
+
describe('#getGraphql - errors', () => {
|
|
16041
|
+
it('should have a getGraphql function', (done) => {
|
|
16042
|
+
try {
|
|
16043
|
+
assert.equal(true, typeof a.getGraphql === 'function');
|
|
16044
|
+
done();
|
|
16045
|
+
} catch (error) {
|
|
16046
|
+
log.error(`Test Failure: ${error}`);
|
|
16047
|
+
done(error);
|
|
16048
|
+
}
|
|
16049
|
+
}).timeout(attemptTimeout);
|
|
16050
|
+
it('should error if - missing body', (done) => {
|
|
16051
|
+
try {
|
|
16052
|
+
a.getGraphql(null, (data, error) => {
|
|
16053
|
+
try {
|
|
16054
|
+
const displayE = 'body is required';
|
|
16055
|
+
runErrorAsserts(data, error, 'AD.300', 'Test-netbox_v210-adapter-getGraphql', displayE);
|
|
16056
|
+
done();
|
|
16057
|
+
} catch (err) {
|
|
16058
|
+
log.error(`Test Failure: ${err}`);
|
|
16059
|
+
done(err);
|
|
16060
|
+
}
|
|
16061
|
+
});
|
|
16062
|
+
} catch (error) {
|
|
16063
|
+
log.error(`Adapter Exception: ${error}`);
|
|
16064
|
+
done(error);
|
|
16065
|
+
}
|
|
16066
|
+
}).timeout(attemptTimeout);
|
|
16067
|
+
});
|
|
16068
|
+
|
|
15956
16069
|
describe('#getTenancyTenantGroups - errors', () => {
|
|
15957
16070
|
it('should have a getTenancyTenantGroups function', (done) => {
|
|
15958
16071
|
try {
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const semverSatisfies = require('semver/functions/satisfies');
|
|
3
|
+
const packageJson = require('../package.json');
|
|
4
|
+
|
|
5
|
+
try {
|
|
6
|
+
// pattern supplied by semver.org via https://regex101.com/r/vkijKf/1/ but removed gm from end to only match a single semver
|
|
7
|
+
// const semverPat = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
|
8
|
+
// pattern supplied by semver.org via https://regex101.com/r/Ly7O1x/3/ with following changes
|
|
9
|
+
// removed P's from before capturing group names and
|
|
10
|
+
// removed gm from end to only match a single semver
|
|
11
|
+
// const semverPat = /^(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
|
12
|
+
|
|
13
|
+
const patches = (fs.existsSync('./patches')) ? fs.readdirSync('./patches', { withFileTypes: true }) : [];
|
|
14
|
+
if (!patches.length) {
|
|
15
|
+
console.error('\nno patches - nothing to do\n');
|
|
16
|
+
process.exitCode = 1;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const dependencies = packageJson.dependencies || {};
|
|
20
|
+
if (!Object.keys(dependencies).length) {
|
|
21
|
+
console.error('\nno dependencies - nothing to do\n');
|
|
22
|
+
process.exitCode = 1;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let changed = false;
|
|
26
|
+
console.error('\nprocessing patches');
|
|
27
|
+
const bundledDependencies = packageJson.bundledDependencies || packageJson.bundleDependencies || [];
|
|
28
|
+
|
|
29
|
+
patches.forEach((patch) => {
|
|
30
|
+
if (!patch.isFile()) {
|
|
31
|
+
console.error(`${patch.name} skipped, is not a regular file`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (!patch.name.endsWith('.patch')) {
|
|
35
|
+
console.error(`${patch.name} skipped, does not end with .patch`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const splits = patch.name.slice(0, -6).split('+');
|
|
39
|
+
if (splits.length > 4) {
|
|
40
|
+
console.error(`${patch.name} skipped, does not follow the naming convention (cannot use '+' other than to separate scope/package/semver and at most once within semver)`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const scope = splits[0][0] === '@' ? splits.shift() : null;
|
|
44
|
+
const packageName = splits.shift();
|
|
45
|
+
const semver = splits.join('+');
|
|
46
|
+
// const { groups } = semver.match(semverPat);
|
|
47
|
+
const file = scope ? `${scope}/${packageName}` : packageName;
|
|
48
|
+
if (dependencies[file] && semverSatisfies(semver, dependencies[file])) {
|
|
49
|
+
if (!bundledDependencies.includes(file)) {
|
|
50
|
+
bundledDependencies.push(file);
|
|
51
|
+
console.error(`added ${file} to bundledDependencies`);
|
|
52
|
+
changed = true;
|
|
53
|
+
} else {
|
|
54
|
+
console.error(`bundledDependencies already has ${file}`);
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
const depmsg = dependencies[file] ? `version mismatch (${dependencies[file]}) in dependencies` : 'not found in dependencies';
|
|
58
|
+
console.error(`patch ${patch.name} ${depmsg}`);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
if (!packageJson.bundledDependencies && bundledDependencies.length) {
|
|
63
|
+
delete packageJson.bundleDependencies;
|
|
64
|
+
packageJson.bundledDependencies = bundledDependencies;
|
|
65
|
+
console.error('renaming bundleDependencies to bundledDependencies');
|
|
66
|
+
changed = true;
|
|
67
|
+
}
|
|
68
|
+
if (changed) {
|
|
69
|
+
fs.writeFileSync('./package.json.new', JSON.stringify(packageJson, null, 2));
|
|
70
|
+
console.error('wrote package.json.new');
|
|
71
|
+
fs.renameSync('./package.json', './package.json.old');
|
|
72
|
+
console.error('moved package.json to package.json.old');
|
|
73
|
+
fs.renameSync('./package.json.new', './package.json');
|
|
74
|
+
console.error('moved package.json.new to package.json');
|
|
75
|
+
} else {
|
|
76
|
+
console.error('no changes\n');
|
|
77
|
+
process.exitCode = 1;
|
|
78
|
+
}
|
|
79
|
+
} catch (e) {
|
|
80
|
+
if (e) {
|
|
81
|
+
// caught error, exit with status 2 to signify abject failure
|
|
82
|
+
console.error(`\ncaught exception - ${e}\n`);
|
|
83
|
+
process.exitCode = 2;
|
|
84
|
+
} else {
|
|
85
|
+
// caught false, exit with status 1 to signify nothing done
|
|
86
|
+
process.exitCode = 1;
|
|
87
|
+
}
|
|
88
|
+
} finally {
|
|
89
|
+
console.error('done\n');
|
|
90
|
+
}
|