@itentialopensource/adapter-zscaler 0.6.6 → 0.6.7
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 +469 -1
- package/adapterBase.js +1 -1
- package/entities/.system/action.json +2 -2
- package/package.json +2 -2
- package/pronghorn.json +192 -0
- package/refs?service=git-upload-pack +0 -0
- package/report/updateReport1642619799800.json +95 -0
- package/test/integration/adapterTestIntegration.js +7 -1
- package/test/unit/adapterTestUnit.js +100 -1
- package/utils/basicGet.js +0 -17
- package/utils/modify.js +1 -1
- package/utils/patches2bundledDeps.js +90 -0
- package/utils/tbScript.js +4 -4
- package/utils/tbUtils.js +51 -6
- package/utils/troubleshootingAdapter.js +2 -26
package/CHANGELOG.md
CHANGED
package/adapter.js
CHANGED
|
@@ -85,7 +85,7 @@ class Zscaler extends AdapterBaseCl {
|
|
|
85
85
|
* @getWorkflowFunctions
|
|
86
86
|
*/
|
|
87
87
|
getWorkflowFunctions(inIgnore) {
|
|
88
|
-
let myIgnore = ['getObfuscatedKey'];
|
|
88
|
+
let myIgnore = ['hasEntities', 'hasDevices', 'getObfuscatedKey'];
|
|
89
89
|
if (!inIgnore && Array.isArray(inIgnore)) {
|
|
90
90
|
myIgnore = inIgnore;
|
|
91
91
|
} else if (!inIgnore && typeof inIgnore === 'string') {
|
|
@@ -249,6 +249,24 @@ class Zscaler extends AdapterBaseCl {
|
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
+
/**
|
|
253
|
+
* @summary moves entites into Mongo DB
|
|
254
|
+
*
|
|
255
|
+
* @function moveEntitiesToDB
|
|
256
|
+
* @param {getCallback} callback - a callback function to return the result (Generics)
|
|
257
|
+
* or the error
|
|
258
|
+
*/
|
|
259
|
+
moveEntitiesToDB(callback) {
|
|
260
|
+
const origin = `${this.id}-adapter-moveEntitiesToDB`;
|
|
261
|
+
log.trace(origin);
|
|
262
|
+
try {
|
|
263
|
+
return super.moveEntitiesToDB(callback);
|
|
264
|
+
} catch (err) {
|
|
265
|
+
log.error(`${origin}: ${err}`);
|
|
266
|
+
return callback(null, err);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
252
270
|
/**
|
|
253
271
|
* @summary Determines if this adapter supports the specific entity
|
|
254
272
|
*
|
|
@@ -528,6 +546,456 @@ class Zscaler extends AdapterBaseCl {
|
|
|
528
546
|
}
|
|
529
547
|
}
|
|
530
548
|
|
|
549
|
+
/* BROKER CALLS */
|
|
550
|
+
/**
|
|
551
|
+
* @summary Determines if this adapter supports any in a list of entities
|
|
552
|
+
*
|
|
553
|
+
* @function hasEntities
|
|
554
|
+
* @param {String} entityType - the entity type to check for
|
|
555
|
+
* @param {Array} entityList - the list of entities we are looking for
|
|
556
|
+
*
|
|
557
|
+
* @param {Callback} callback - A map where the entity is the key and the
|
|
558
|
+
* value is true or false
|
|
559
|
+
*/
|
|
560
|
+
hasEntities(entityType, entityList, callback) {
|
|
561
|
+
const origin = `${this.id}-adapter-hasEntities`;
|
|
562
|
+
log.trace(origin);
|
|
563
|
+
|
|
564
|
+
switch (entityType) {
|
|
565
|
+
case 'Device':
|
|
566
|
+
return this.hasDevices(entityList, callback);
|
|
567
|
+
default:
|
|
568
|
+
return callback(null, `${this.id} does not support entity ${entityType}`);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* @summary Helper method for hasEntities for the specific device case
|
|
574
|
+
*
|
|
575
|
+
* @param {Array} deviceList - array of unique device identifiers
|
|
576
|
+
* @param {Callback} callback - A map where the device is the key and the
|
|
577
|
+
* value is true or false
|
|
578
|
+
*/
|
|
579
|
+
hasDevices(deviceList, callback) {
|
|
580
|
+
const origin = `${this.id}-adapter-hasDevices`;
|
|
581
|
+
log.trace(origin);
|
|
582
|
+
|
|
583
|
+
const findings = deviceList.reduce((map, device) => {
|
|
584
|
+
// eslint-disable-next-line no-param-reassign
|
|
585
|
+
map[device] = false;
|
|
586
|
+
log.debug(`In reduce: ${JSON.stringify(map)}`);
|
|
587
|
+
return map;
|
|
588
|
+
}, {});
|
|
589
|
+
const apiCalls = deviceList.map((device) => new Promise((resolve) => {
|
|
590
|
+
this.getDevice(device, (result, error) => {
|
|
591
|
+
if (error) {
|
|
592
|
+
log.debug(`In map error: ${JSON.stringify(device)}`);
|
|
593
|
+
return resolve({ name: device, found: false });
|
|
594
|
+
}
|
|
595
|
+
log.debug(`In map: ${JSON.stringify(device)}`);
|
|
596
|
+
return resolve({ name: device, found: true });
|
|
597
|
+
});
|
|
598
|
+
}));
|
|
599
|
+
Promise.all(apiCalls).then((results) => {
|
|
600
|
+
results.forEach((device) => {
|
|
601
|
+
findings[device.name] = device.found;
|
|
602
|
+
});
|
|
603
|
+
log.debug(`FINDINGS: ${JSON.stringify(findings)}`);
|
|
604
|
+
return callback(findings);
|
|
605
|
+
}).catch((errors) => {
|
|
606
|
+
log.error('Unable to do device lookup.');
|
|
607
|
+
return callback(null, { code: 503, message: 'Unable to do device lookup.', error: errors });
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* @summary Get Appliance that match the deviceName
|
|
613
|
+
*
|
|
614
|
+
* @function getDevice
|
|
615
|
+
* @param {String} deviceName - the deviceName to find (required)
|
|
616
|
+
*
|
|
617
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
618
|
+
* (appliance) or the error
|
|
619
|
+
*/
|
|
620
|
+
getDevice(deviceName, callback) {
|
|
621
|
+
const meth = 'adapter-getDevice';
|
|
622
|
+
const origin = `${this.id}-${meth}`;
|
|
623
|
+
log.trace(origin);
|
|
624
|
+
|
|
625
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
626
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
627
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
628
|
+
return callback(null, errorObj);
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
632
|
+
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
|
633
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
|
634
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
635
|
+
return callback(null, errorObj);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
try {
|
|
639
|
+
// need to get the device so we can convert the deviceName to an id
|
|
640
|
+
// !! if we can do a lookup by name the getDevicesFiltered may not be necessary
|
|
641
|
+
const opts = {
|
|
642
|
+
filter: {
|
|
643
|
+
name: deviceName
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
|
647
|
+
// if we received an error or their is no response on the results return an error
|
|
648
|
+
if (ferr) {
|
|
649
|
+
return callback(null, ferr);
|
|
650
|
+
}
|
|
651
|
+
if (devs.list.length < 1) {
|
|
652
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
|
653
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
654
|
+
return callback(null, errorObj);
|
|
655
|
+
}
|
|
656
|
+
// get the uuid from the device
|
|
657
|
+
const { uuid } = devs.list[0];
|
|
658
|
+
|
|
659
|
+
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
660
|
+
// !! you can also replace with a specific call if that is easier
|
|
661
|
+
const uriPath = `/call/toget/device/${uuid}`;
|
|
662
|
+
return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
|
|
663
|
+
// if we received an error or their is no response on the results return an error
|
|
664
|
+
if (error) {
|
|
665
|
+
return callback(null, error);
|
|
666
|
+
}
|
|
667
|
+
if (!result.response || !result.response.applianceMo) {
|
|
668
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevice'], null, null, null);
|
|
669
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
670
|
+
return callback(null, errorObj);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
// return the response
|
|
674
|
+
// !! format the data we send back
|
|
675
|
+
// !! these fields are config manager fields you need to map to the data we receive
|
|
676
|
+
const thisDevice = result.response;
|
|
677
|
+
thisDevice.name = thisDevice.systemName;
|
|
678
|
+
thisDevice.ostype = `System-${thisDevice.systemType}`;
|
|
679
|
+
thisDevice.port = thisDevice.systemPort;
|
|
680
|
+
thisDevice.ipaddress = thisDevice.systemIP;
|
|
681
|
+
return callback(thisDevice);
|
|
682
|
+
});
|
|
683
|
+
});
|
|
684
|
+
} catch (ex) {
|
|
685
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
686
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
687
|
+
return callback(null, errorObj);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* @summary Get Appliances that match the filter
|
|
693
|
+
*
|
|
694
|
+
* @function getDevicesFiltered
|
|
695
|
+
* @param {Object} options - the data to use to filter the appliances (optional)
|
|
696
|
+
*
|
|
697
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
698
|
+
* (appliances) or the error
|
|
699
|
+
*/
|
|
700
|
+
getDevicesFiltered(options, callback) {
|
|
701
|
+
const meth = 'adapter-getDevicesFiltered';
|
|
702
|
+
const origin = `${this.id}-${meth}`;
|
|
703
|
+
log.trace(origin);
|
|
704
|
+
|
|
705
|
+
// verify the required fields have been provided
|
|
706
|
+
if (options === undefined || options === null || options === '' || options.length === 0) {
|
|
707
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['options'], null, null, null);
|
|
708
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
709
|
+
return callback(null, errorObj);
|
|
710
|
+
}
|
|
711
|
+
log.debug(`Device Filter Options: ${JSON.stringify(options)}`);
|
|
712
|
+
|
|
713
|
+
// TODO - get pagination working
|
|
714
|
+
// const nextToken = options.start;
|
|
715
|
+
// const maxResults = options.limit;
|
|
716
|
+
|
|
717
|
+
// set up the filter of Device Names
|
|
718
|
+
let filterName = [];
|
|
719
|
+
if (options && options.filter && options.filter.name) {
|
|
720
|
+
// when this hack is removed, remove the lint ignore above
|
|
721
|
+
if (Array.isArray(options.filter.name)) {
|
|
722
|
+
// eslint-disable-next-line prefer-destructuring
|
|
723
|
+
filterName = options.filter.name;
|
|
724
|
+
} else {
|
|
725
|
+
filterName = [options.filter.name];
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// TODO - get sort and order working
|
|
730
|
+
/*
|
|
731
|
+
if (options && options.sort) {
|
|
732
|
+
reqObj.uriOptions.sort = JSON.stringify(options.sort);
|
|
733
|
+
}
|
|
734
|
+
if (options && options.order) {
|
|
735
|
+
reqObj.uriOptions.order = options.order;
|
|
736
|
+
}
|
|
737
|
+
*/
|
|
738
|
+
try {
|
|
739
|
+
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
740
|
+
// !! you can also replace with a specific call if that is easier
|
|
741
|
+
const uriPath = '/call/toget/devices';
|
|
742
|
+
return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
|
|
743
|
+
// if we received an error or their is no response on the results return an error
|
|
744
|
+
if (error) {
|
|
745
|
+
return callback(null, error);
|
|
746
|
+
}
|
|
747
|
+
if (!result.response) {
|
|
748
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevicesFiltered'], null, null, null);
|
|
749
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
750
|
+
return callback(null, errorObj);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
// !! go through the response - may have to look for sub object
|
|
754
|
+
// handle an array of devices
|
|
755
|
+
if (Array.isArray(result.response)) {
|
|
756
|
+
const myDevices = [];
|
|
757
|
+
|
|
758
|
+
for (let d = 0; d < result.response.length; d += 1) {
|
|
759
|
+
// !! format the data we send back
|
|
760
|
+
// !! these fields are config manager fields you need to map to the data we receive
|
|
761
|
+
const thisDevice = result.response;
|
|
762
|
+
thisDevice.name = thisDevice.systemName;
|
|
763
|
+
thisDevice.ostype = `System-${thisDevice.systemType}`;
|
|
764
|
+
thisDevice.port = thisDevice.systemPort;
|
|
765
|
+
thisDevice.ipaddress = thisDevice.systemIP;
|
|
766
|
+
|
|
767
|
+
// if there is no filter - return the device
|
|
768
|
+
if (filterName.length === 0) {
|
|
769
|
+
myDevices.push(thisDevice);
|
|
770
|
+
} else {
|
|
771
|
+
// if we have to match a filter
|
|
772
|
+
let found = false;
|
|
773
|
+
for (let f = 0; f < filterName.length; f += 1) {
|
|
774
|
+
if (thisDevice.name.indexOf(filterName[f]) >= 0) {
|
|
775
|
+
found = true;
|
|
776
|
+
break;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
// matching device
|
|
780
|
+
if (found) {
|
|
781
|
+
myDevices.push(thisDevice);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
log.debug(`${origin}: Found #${myDevices.length} devices.`);
|
|
786
|
+
log.debug(`Devices: ${JSON.stringify(myDevices)}`);
|
|
787
|
+
return callback({ total: myDevices.length, list: myDevices });
|
|
788
|
+
}
|
|
789
|
+
// handle a single device response
|
|
790
|
+
// !! format the data we send back
|
|
791
|
+
// !! these fields are config manager fields you need to map to the data we receive
|
|
792
|
+
const thisDevice = result.response;
|
|
793
|
+
thisDevice.name = thisDevice.systemName;
|
|
794
|
+
thisDevice.ostype = `System-${thisDevice.systemType}`;
|
|
795
|
+
thisDevice.port = thisDevice.systemPort;
|
|
796
|
+
thisDevice.ipaddress = thisDevice.systemIP;
|
|
797
|
+
|
|
798
|
+
// if there is no filter - return the device
|
|
799
|
+
if (filterName.length === 0) {
|
|
800
|
+
log.debug(`${origin}: Found #1 device.`);
|
|
801
|
+
log.debug(`Device: ${JSON.stringify(thisDevice)}`);
|
|
802
|
+
return callback({ total: 1, list: [thisDevice] });
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
// if there is a filter need to check for matching device
|
|
806
|
+
let found = false;
|
|
807
|
+
for (let f = 0; f < filterName.length; f += 1) {
|
|
808
|
+
if (thisDevice.name.indexOf(filterName[f]) >= 0) {
|
|
809
|
+
found = true;
|
|
810
|
+
break;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
// matching device
|
|
814
|
+
if (found) {
|
|
815
|
+
log.debug(`${origin}: Found #1 device.`);
|
|
816
|
+
log.debug(`Device Found: ${JSON.stringify(thisDevice)}`);
|
|
817
|
+
return callback({ total: 1, list: [thisDevice] });
|
|
818
|
+
}
|
|
819
|
+
// not a matching device
|
|
820
|
+
log.debug(`${origin}: No matching device found.`);
|
|
821
|
+
return callback({ total: 0, list: [] });
|
|
822
|
+
});
|
|
823
|
+
} catch (ex) {
|
|
824
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
825
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
826
|
+
return callback(null, errorObj);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
/**
|
|
831
|
+
* @summary Gets the status for the provided appliance
|
|
832
|
+
*
|
|
833
|
+
* @function isAlive
|
|
834
|
+
* @param {String} deviceName - the deviceName of the appliance. (required)
|
|
835
|
+
*
|
|
836
|
+
* @param {configCallback} callback - callback function to return the result
|
|
837
|
+
* (appliance isAlive) or the error
|
|
838
|
+
*/
|
|
839
|
+
isAlive(deviceName, callback) {
|
|
840
|
+
const meth = 'adapter-isAlive';
|
|
841
|
+
const origin = `${this.id}-${meth}`;
|
|
842
|
+
log.trace(origin);
|
|
843
|
+
|
|
844
|
+
// verify the required fields have been provided
|
|
845
|
+
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
|
846
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
|
847
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
848
|
+
return callback(null, errorObj);
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
try {
|
|
852
|
+
// need to get the device so we can convert the deviceName to an id
|
|
853
|
+
// !! if we can do a lookup by name the getDevicesFiltered may not be necessary
|
|
854
|
+
const opts = {
|
|
855
|
+
filter: {
|
|
856
|
+
name: deviceName
|
|
857
|
+
}
|
|
858
|
+
};
|
|
859
|
+
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
|
860
|
+
// if we received an error or their is no response on the results return an error
|
|
861
|
+
if (ferr) {
|
|
862
|
+
return callback(null, ferr);
|
|
863
|
+
}
|
|
864
|
+
if (devs.list.length < 1) {
|
|
865
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
|
866
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
867
|
+
return callback(null, errorObj);
|
|
868
|
+
}
|
|
869
|
+
// get the uuid from the device
|
|
870
|
+
const { uuid } = devs.list[0];
|
|
871
|
+
|
|
872
|
+
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
873
|
+
// !! you can also replace with a specific call if that is easier
|
|
874
|
+
const uriPath = `/call/toget/status/${uuid}`;
|
|
875
|
+
return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
|
|
876
|
+
// if we received an error or their is no response on the results return an error
|
|
877
|
+
if (error) {
|
|
878
|
+
return callback(null, error);
|
|
879
|
+
}
|
|
880
|
+
// !! should update this to make sure we are checking for the appropriate object/field
|
|
881
|
+
if (!result.response || !result.response.returnObj || !Object.hasOwnProperty.call(result.response.returnObj, 'statusField')) {
|
|
882
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['isAlive'], null, null, null);
|
|
883
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
884
|
+
return callback(null, errorObj);
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
// !! return the response - Update to the appropriate object/field
|
|
888
|
+
return callback(!result.response.returnObj.statusField);
|
|
889
|
+
});
|
|
890
|
+
});
|
|
891
|
+
} catch (ex) {
|
|
892
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
893
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
894
|
+
return callback(null, errorObj);
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
/**
|
|
899
|
+
* @summary Gets a config for the provided Appliance
|
|
900
|
+
*
|
|
901
|
+
* @function getConfig
|
|
902
|
+
* @param {String} deviceName - the deviceName of the appliance. (required)
|
|
903
|
+
* @param {String} format - the desired format of the config. (optional)
|
|
904
|
+
*
|
|
905
|
+
* @param {configCallback} callback - callback function to return the result
|
|
906
|
+
* (appliance config) or the error
|
|
907
|
+
*/
|
|
908
|
+
getConfig(deviceName, format, callback) {
|
|
909
|
+
const meth = 'adapter-getConfig';
|
|
910
|
+
const origin = `${this.id}-${meth}`;
|
|
911
|
+
log.trace(origin);
|
|
912
|
+
|
|
913
|
+
// verify the required fields have been provided
|
|
914
|
+
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
|
915
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
|
916
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
917
|
+
return callback(null, errorObj);
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
try {
|
|
921
|
+
// need to get the device so we can convert the deviceName to an id
|
|
922
|
+
// !! if we can do a lookup by name the getDevicesFiltered may not be necessary
|
|
923
|
+
const opts = {
|
|
924
|
+
filter: {
|
|
925
|
+
name: deviceName
|
|
926
|
+
}
|
|
927
|
+
};
|
|
928
|
+
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
|
929
|
+
// if we received an error or their is no response on the results return an error
|
|
930
|
+
if (ferr) {
|
|
931
|
+
return callback(null, ferr);
|
|
932
|
+
}
|
|
933
|
+
if (devs.list.length < 1) {
|
|
934
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
|
935
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
936
|
+
return callback(null, errorObj);
|
|
937
|
+
}
|
|
938
|
+
// get the uuid from the device
|
|
939
|
+
const { uuid } = devs.list[0];
|
|
940
|
+
|
|
941
|
+
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
942
|
+
// !! you can also replace with a specific call if that is easier
|
|
943
|
+
const uriPath = `/call/toget/config/${uuid}`;
|
|
944
|
+
return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
|
|
945
|
+
// if we received an error or their is no response on the results return an error
|
|
946
|
+
if (error) {
|
|
947
|
+
return callback(null, error);
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
// return the result
|
|
951
|
+
const newResponse = {
|
|
952
|
+
response: JSON.stringify(result.response, null, 2)
|
|
953
|
+
};
|
|
954
|
+
return callback(newResponse);
|
|
955
|
+
});
|
|
956
|
+
});
|
|
957
|
+
} catch (ex) {
|
|
958
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
959
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
960
|
+
return callback(null, errorObj);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
/**
|
|
965
|
+
* @summary Gets the device count from the system
|
|
966
|
+
*
|
|
967
|
+
* @function getCount
|
|
968
|
+
*
|
|
969
|
+
* @param {getCallback} callback - callback function to return the result
|
|
970
|
+
* (count) or the error
|
|
971
|
+
*/
|
|
972
|
+
getCount(callback) {
|
|
973
|
+
const meth = 'adapter-getCount';
|
|
974
|
+
const origin = `${this.id}-${meth}`;
|
|
975
|
+
log.trace(origin);
|
|
976
|
+
|
|
977
|
+
// verify the required fields have been provided
|
|
978
|
+
|
|
979
|
+
try {
|
|
980
|
+
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
981
|
+
// !! you can also replace with a specific call if that is easier
|
|
982
|
+
const uriPath = '/call/toget/count';
|
|
983
|
+
return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
|
|
984
|
+
// if we received an error or their is no response on the results return an error
|
|
985
|
+
if (error) {
|
|
986
|
+
return callback(null, error);
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
// return the result
|
|
990
|
+
return callback({ count: result.response });
|
|
991
|
+
});
|
|
992
|
+
} catch (ex) {
|
|
993
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
994
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
995
|
+
return callback(null, errorObj);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
|
|
531
999
|
/**
|
|
532
1000
|
* @callback healthCallback
|
|
533
1001
|
* @param {Object} result - the result of the get request (contains an id and a status)
|
package/adapterBase.js
CHANGED
|
@@ -822,7 +822,7 @@ class AdapterBase extends EventEmitterCl {
|
|
|
822
822
|
*/
|
|
823
823
|
async runConnectivity(callback) {
|
|
824
824
|
try {
|
|
825
|
-
const { serviceItem } = await
|
|
825
|
+
const { serviceItem } = await tbUtils.getAdapterConfig();
|
|
826
826
|
const { host } = serviceItem.properties.properties;
|
|
827
827
|
const result = tbUtils.runConnectivity(host, false);
|
|
828
828
|
if (result.failCount > 0) {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"name": "healthcheck",
|
|
31
31
|
"protocol": "REST",
|
|
32
32
|
"method": "GET",
|
|
33
|
-
"entitypath": "{base_path}/{version}/
|
|
33
|
+
"entitypath": "{base_path}/{version}/authenticatedSession",
|
|
34
34
|
"requestSchema": "schema.json",
|
|
35
35
|
"responseSchema": "schema.json",
|
|
36
36
|
"timeout": 0,
|
|
@@ -48,4 +48,4 @@
|
|
|
48
48
|
]
|
|
49
49
|
}
|
|
50
50
|
]
|
|
51
|
-
}
|
|
51
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itentialopensource/adapter-zscaler",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
4
4
|
"description": "This adapter integrates with system Zscaler",
|
|
5
5
|
"main": "adapter.js",
|
|
6
6
|
"wizardVersion": "2.44.7",
|
|
7
|
-
"engineVersion": "1.59.
|
|
7
|
+
"engineVersion": "1.59.55",
|
|
8
8
|
"adapterType": "http",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"artifactize": "npm i && node utils/packModificationScript.js",
|
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": "getAuthenticatedSession",
|
|
391
583
|
"summary": "Checks if there is an authenticated session",
|
|
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": 65
|
|
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": 2357
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"owner": "unitTestJS",
|
|
56
|
+
"description": "Number of unit tests",
|
|
57
|
+
"value": 130
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"owner": "integrationTestJS",
|
|
61
|
+
"description": "Number of lines of code in integration tests",
|
|
62
|
+
"value": 2130
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"owner": "integrationTestJS",
|
|
66
|
+
"description": "Number of integration tests",
|
|
67
|
+
"value": 62
|
|
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": 5516
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"owner": "Overall",
|
|
86
|
+
"description": "Total Tests",
|
|
87
|
+
"value": 192
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"owner": "Overall",
|
|
91
|
+
"description": "Total Files",
|
|
92
|
+
"value": 6
|
|
93
|
+
}
|
|
94
|
+
]
|
|
95
|
+
}
|
|
@@ -13,7 +13,10 @@ const winston = require('winston');
|
|
|
13
13
|
const { expect } = require('chai');
|
|
14
14
|
const { use } = require('chai');
|
|
15
15
|
const td = require('testdouble');
|
|
16
|
+
const util = require('util');
|
|
17
|
+
const pronghorn = require('../../pronghorn.json');
|
|
16
18
|
|
|
19
|
+
pronghorn.methodsByName = pronghorn.methods.reduce((result, meth) => ({ ...result, [meth.name]: meth }), {});
|
|
17
20
|
const anything = td.matchers.anything();
|
|
18
21
|
|
|
19
22
|
// stub and attemptTimeout are used throughout the code so set them here
|
|
@@ -63,7 +66,10 @@ global.pronghornProps = {
|
|
|
63
66
|
invalid_token_error: 401,
|
|
64
67
|
auth_field: 'header.headers.Authorization',
|
|
65
68
|
auth_field_format: 'Basic {b64}{username}:{password}{/b64}',
|
|
66
|
-
auth_logging: false
|
|
69
|
+
auth_logging: false,
|
|
70
|
+
client_id: '',
|
|
71
|
+
client_secret: '',
|
|
72
|
+
grant_type: ''
|
|
67
73
|
},
|
|
68
74
|
healthcheck: {
|
|
69
75
|
type: 'startup',
|
|
@@ -65,7 +65,10 @@ global.pronghornProps = {
|
|
|
65
65
|
invalid_token_error: 401,
|
|
66
66
|
auth_field: 'header.headers.Authorization',
|
|
67
67
|
auth_field_format: 'Basic {b64}{username}:{password}{/b64}',
|
|
68
|
-
auth_logging: false
|
|
68
|
+
auth_logging: false,
|
|
69
|
+
client_id: '',
|
|
70
|
+
client_secret: '',
|
|
71
|
+
grant_type: ''
|
|
69
72
|
},
|
|
70
73
|
healthcheck: {
|
|
71
74
|
type: 'startup',
|
|
@@ -1129,6 +1132,18 @@ describe('[unit] Zscaler Adapter Test', () => {
|
|
|
1129
1132
|
});
|
|
1130
1133
|
});
|
|
1131
1134
|
|
|
1135
|
+
describe('#moveEntitiesToDB', () => {
|
|
1136
|
+
it('should have a moveEntitiesToDB function', (done) => {
|
|
1137
|
+
try {
|
|
1138
|
+
assert.equal(true, typeof a.moveEntitiesToDB === 'function');
|
|
1139
|
+
done();
|
|
1140
|
+
} catch (error) {
|
|
1141
|
+
log.error(`Test Failure: ${error}`);
|
|
1142
|
+
done(error);
|
|
1143
|
+
}
|
|
1144
|
+
});
|
|
1145
|
+
});
|
|
1146
|
+
|
|
1132
1147
|
describe('#checkActionFiles', () => {
|
|
1133
1148
|
it('should have a checkActionFiles function', (done) => {
|
|
1134
1149
|
try {
|
|
@@ -1258,6 +1273,90 @@ describe('[unit] Zscaler Adapter Test', () => {
|
|
|
1258
1273
|
// }).timeout(attemptTimeout);
|
|
1259
1274
|
// });
|
|
1260
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
|
+
|
|
1261
1360
|
/*
|
|
1262
1361
|
-----------------------------------------------------------------------
|
|
1263
1362
|
-----------------------------------------------------------------------
|
package/utils/basicGet.js
CHANGED
|
@@ -6,11 +6,8 @@
|
|
|
6
6
|
/* eslint import/no-unresolved: warn */
|
|
7
7
|
/* eslint import/no-dynamic-require: warn */
|
|
8
8
|
|
|
9
|
-
const path = require('path');
|
|
10
9
|
const winston = require('winston');
|
|
11
10
|
|
|
12
|
-
const utils = require(path.join(__dirname, 'tbUtils'));
|
|
13
|
-
|
|
14
11
|
const logLevel = 'none';
|
|
15
12
|
const myCustomLevels = {
|
|
16
13
|
levels: {
|
|
@@ -47,20 +44,6 @@ const basicGet = {
|
|
|
47
44
|
adapter.id,
|
|
48
45
|
adapterProps
|
|
49
46
|
);
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* @summary connect to mongodb
|
|
54
|
-
*
|
|
55
|
-
* @function connect
|
|
56
|
-
* @param {Object} properties - pronghornProps
|
|
57
|
-
*/
|
|
58
|
-
connect: async function connect(properties) {
|
|
59
|
-
// Connect to Mongo
|
|
60
|
-
const { MongoDBConnection } = require(path.join(utils.getDirname(), '../../../', '@itential/database'));
|
|
61
|
-
const connection = new MongoDBConnection(properties.mongoProps);
|
|
62
|
-
const database = await connection.connect(true);
|
|
63
|
-
return database;
|
|
64
47
|
}
|
|
65
48
|
};
|
|
66
49
|
|
package/utils/modify.js
CHANGED
|
@@ -3,7 +3,7 @@ const Ajv = require('ajv');
|
|
|
3
3
|
const rls = require('readline-sync');
|
|
4
4
|
const { execSync } = require('child_process');
|
|
5
5
|
const { existsSync } = require('fs-extra');
|
|
6
|
-
const { getAdapterConfig } = require('./
|
|
6
|
+
const { getAdapterConfig } = require('./tbUtils');
|
|
7
7
|
const { name } = require('../package.json');
|
|
8
8
|
const propertiesSchema = require('../propertiesSchema.json');
|
|
9
9
|
|
|
@@ -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
|
+
}
|
package/utils/tbScript.js
CHANGED
|
@@ -17,11 +17,11 @@ const sampleProperties = require('../sampleProperties.json');
|
|
|
17
17
|
const adapterPronghorn = require('../pronghorn.json');
|
|
18
18
|
const { addAuthInfo } = require('./addAuth');
|
|
19
19
|
|
|
20
|
-
const { troubleshoot,
|
|
20
|
+
const { troubleshoot, offline } = require('./troubleshootingAdapter');
|
|
21
21
|
|
|
22
22
|
const main = async (command) => {
|
|
23
23
|
const dirname = utils.getDirname();
|
|
24
|
-
const iapDir = path.join(dirname, '
|
|
24
|
+
const iapDir = path.join(dirname, '../../../');
|
|
25
25
|
if (!utils.withinIAP(iapDir)) {
|
|
26
26
|
if (command === 'install') {
|
|
27
27
|
console.log('Not currently in IAP directory - installation not possible');
|
|
@@ -48,7 +48,7 @@ const main = async (command) => {
|
|
|
48
48
|
if (command === undefined) {
|
|
49
49
|
await troubleshoot({}, true, true);
|
|
50
50
|
} else if (command === 'install') {
|
|
51
|
-
const { database, serviceItem, pronghornProps } = await getAdapterConfig();
|
|
51
|
+
const { database, serviceItem, pronghornProps } = await utils.getAdapterConfig();
|
|
52
52
|
const filter = { id: pronghornProps.id };
|
|
53
53
|
const profileItem = await database.collection(utils.IAP_PROFILES_COLLECTION).findOne(filter);
|
|
54
54
|
if (!profileItem) {
|
|
@@ -101,7 +101,7 @@ const main = async (command) => {
|
|
|
101
101
|
process.exit(0);
|
|
102
102
|
}
|
|
103
103
|
} else if (['healthcheck', 'basicget', 'connectivity'].includes(command)) {
|
|
104
|
-
const { serviceItem } = await getAdapterConfig();
|
|
104
|
+
const { serviceItem } = await utils.getAdapterConfig();
|
|
105
105
|
if (serviceItem) {
|
|
106
106
|
const adapter = serviceItem;
|
|
107
107
|
const a = basicGet.getAdapterInstance(adapter);
|
package/utils/tbUtils.js
CHANGED
|
@@ -100,8 +100,8 @@ module.exports = {
|
|
|
100
100
|
*
|
|
101
101
|
* @function decryptProperties
|
|
102
102
|
*/
|
|
103
|
-
decryptProperties: (props,
|
|
104
|
-
const propertyEncryptionClassPath = path.join(
|
|
103
|
+
decryptProperties: (props, iapDir, discovery) => {
|
|
104
|
+
const propertyEncryptionClassPath = path.join(iapDir, 'node_modules/@itential/pronghorn-core/core/PropertyEncryption.js');
|
|
105
105
|
const isEncrypted = props.pathProps.encrypted;
|
|
106
106
|
const PropertyEncryption = discovery.require(propertyEncryptionClassPath, isEncrypted);
|
|
107
107
|
const propertyEncryption = new PropertyEncryption({
|
|
@@ -177,12 +177,12 @@ module.exports = {
|
|
|
177
177
|
verifyInstallationDir: (dirname, name) => {
|
|
178
178
|
const pathArray = dirname.split(path.sep);
|
|
179
179
|
const expectedPath = `node_modules/${name}`;
|
|
180
|
-
const currentPath = pathArray.slice(pathArray.length -
|
|
180
|
+
const currentPath = pathArray.slice(pathArray.length - 3, pathArray.length).join('/');
|
|
181
181
|
if (currentPath.trim() !== expectedPath.trim()) {
|
|
182
|
-
throw new Error(`adapter should be installed under ${expectedPath}`);
|
|
182
|
+
throw new Error(`adapter should be installed under ${expectedPath} but is installed under ${currentPath}`);
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
const serverFile = path.join(dirname, '
|
|
185
|
+
const serverFile = path.join(dirname, '../../../', 'server.js');
|
|
186
186
|
if (!fs.existsSync(serverFile)) {
|
|
187
187
|
throw new Error(`adapter should be installed under IAP/${expectedPath}`);
|
|
188
188
|
}
|
|
@@ -339,6 +339,37 @@ module.exports = {
|
|
|
339
339
|
return adapter;
|
|
340
340
|
},
|
|
341
341
|
|
|
342
|
+
getPronghornProps: function getPronghornProps(iapDir) {
|
|
343
|
+
console.log('Retrieving properties.json file...');
|
|
344
|
+
const rawProps = require(path.join(iapDir, 'properties.json'));
|
|
345
|
+
console.log('Decrypting properties...');
|
|
346
|
+
const { Discovery } = require(path.join(iapDir, 'node_modules/@itential/itential-utils'));
|
|
347
|
+
const discovery = new Discovery();
|
|
348
|
+
const pronghornProps = this.decryptProperties(rawProps, iapDir, discovery);
|
|
349
|
+
console.log('Found properties.\n');
|
|
350
|
+
return pronghornProps;
|
|
351
|
+
},
|
|
352
|
+
|
|
353
|
+
// get database connection and existing adapter config
|
|
354
|
+
getAdapterConfig: async function getAdapterConfig() {
|
|
355
|
+
const newDirname = this.getDirname();
|
|
356
|
+
let iapDir;
|
|
357
|
+
if (this.withinIAP(newDirname)) { // when this script is called from IAP
|
|
358
|
+
iapDir = newDirname;
|
|
359
|
+
} else {
|
|
360
|
+
iapDir = path.join(this.getDirname(), 'utils', '../../../../');
|
|
361
|
+
}
|
|
362
|
+
const pronghornProps = this.getPronghornProps(iapDir);
|
|
363
|
+
console.log('Connecting to Database...');
|
|
364
|
+
const database = await this.connect(iapDir, pronghornProps);
|
|
365
|
+
console.log('Connection established.');
|
|
366
|
+
const { name } = require(path.join(__dirname, '..', 'package.json'));
|
|
367
|
+
const serviceItem = await database.collection(this.SERVICE_CONFIGS_COLLECTION).findOne(
|
|
368
|
+
{ model: name }
|
|
369
|
+
);
|
|
370
|
+
return { database, serviceItem, pronghornProps };
|
|
371
|
+
},
|
|
372
|
+
|
|
342
373
|
/**
|
|
343
374
|
* @summary return async healthcheck result as a Promise
|
|
344
375
|
*
|
|
@@ -400,7 +431,21 @@ module.exports = {
|
|
|
400
431
|
return __dirname;
|
|
401
432
|
}
|
|
402
433
|
const { stdout } = this.systemSync('pwd', true);
|
|
403
|
-
return
|
|
434
|
+
return stdout.trim();
|
|
435
|
+
},
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* @summary connect to mongodb
|
|
439
|
+
*
|
|
440
|
+
* @function connect
|
|
441
|
+
* @param {Object} properties - pronghornProps
|
|
442
|
+
*/
|
|
443
|
+
connect: async function connect(iapDir, properties) {
|
|
444
|
+
// Connect to Mongo
|
|
445
|
+
const { MongoDBConnection } = require(path.join(iapDir, 'node_modules/@itential/database'));
|
|
446
|
+
const connection = new MongoDBConnection(properties.mongoProps);
|
|
447
|
+
const database = await connection.connect(true);
|
|
448
|
+
return database;
|
|
404
449
|
}
|
|
405
450
|
|
|
406
451
|
};
|
|
@@ -117,30 +117,6 @@ const VerifyHealthCheckEndpoint = (serviceItem, props, scriptFlag) => {
|
|
|
117
117
|
return { result, updatedAdapter };
|
|
118
118
|
};
|
|
119
119
|
|
|
120
|
-
const getPronghornProps = (iapDir) => {
|
|
121
|
-
console.log('Retrieving properties.json file...');
|
|
122
|
-
const rawProps = require(path.join(iapDir, 'properties.json'));
|
|
123
|
-
console.log('Decrypting properties...');
|
|
124
|
-
const { Discovery } = require(path.join(iapDir, 'node_modules/@itential/itential-utils'));
|
|
125
|
-
const discovery = new Discovery();
|
|
126
|
-
const pronghornProps = utils.decryptProperties(rawProps, utils.getDirname(), discovery);
|
|
127
|
-
console.log('Found properties.\n');
|
|
128
|
-
return pronghornProps;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
// get database connection and existing adapter config
|
|
132
|
-
const getAdapterConfig = async () => {
|
|
133
|
-
const iapDir = path.join(utils.getDirname(), '../../../../');
|
|
134
|
-
const pronghornProps = getPronghornProps(iapDir);
|
|
135
|
-
console.log('Connecting to Database...');
|
|
136
|
-
const database = await basicGet.connect(pronghornProps);
|
|
137
|
-
console.log('Connection established.');
|
|
138
|
-
const serviceItem = await database.collection(utils.SERVICE_CONFIGS_COLLECTION).findOne(
|
|
139
|
-
{ model: name }
|
|
140
|
-
);
|
|
141
|
-
return { database, serviceItem, pronghornProps };
|
|
142
|
-
};
|
|
143
|
-
|
|
144
120
|
const offline = async () => {
|
|
145
121
|
console.log('Start offline troubleshooting');
|
|
146
122
|
const { updatedAdapter } = VerifyHealthCheckEndpoint({ properties: sampleProperties }, {}, true);
|
|
@@ -159,7 +135,7 @@ const offline = async () => {
|
|
|
159
135
|
|
|
160
136
|
const troubleshoot = async (props, scriptFlag, persistFlag, adapter) => {
|
|
161
137
|
// get database connection and existing adapter config
|
|
162
|
-
const { database, serviceItem } = await getAdapterConfig();
|
|
138
|
+
const { database, serviceItem } = await utils.getAdapterConfig();
|
|
163
139
|
// where troubleshoot should start
|
|
164
140
|
if (serviceItem) {
|
|
165
141
|
if (!scriptFlag || rls.keyInYN(`Start verifying the connection and authentication properties for ${name}?`)) {
|
|
@@ -211,4 +187,4 @@ const troubleshoot = async (props, scriptFlag, persistFlag, adapter) => {
|
|
|
211
187
|
return null;
|
|
212
188
|
};
|
|
213
189
|
|
|
214
|
-
module.exports = { troubleshoot,
|
|
190
|
+
module.exports = { troubleshoot, offline };
|