@itentialopensource/adapter-bitbucket 0.3.4 → 0.3.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/adapter.js CHANGED
@@ -85,7 +85,7 @@ class Bitbucket extends AdapterBaseCl {
85
85
  * @getWorkflowFunctions
86
86
  */
87
87
  getWorkflowFunctions(inIgnore) {
88
- let myIgnore = [];
88
+ let myIgnore = ['hasEntities', 'hasDevices'];
89
89
  if (!inIgnore && Array.isArray(inIgnore)) {
90
90
  myIgnore = inIgnore;
91
91
  } else if (!inIgnore && typeof inIgnore === 'string') {
@@ -249,6 +249,24 @@ class Bitbucket 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 Bitbucket 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)
@@ -1783,12 +2251,12 @@ surrounded by curly-braces, for example: `{repository UUID}`.
1783
2251
  const bodyVars = body;
1784
2252
  // 'MIME-Version': 1.0,
1785
2253
  // 'Content-Transfer-Encoding': '7bit',
1786
- const addlHeaders = {
1787
- 'Content-Type': 'application/x-www-form-urlencoded',
1788
- 'Content-ID': filename,
1789
- 'Content-Disposition': `attachment; filename="${filename}"`
1790
- };
1791
-
2254
+ const addlHeaders = {};
2255
+ if (filename) {
2256
+ addlHeaders['Content-Type'] = 'application/x-www-form-urlencoded';
2257
+ addlHeaders['Content-ID'] = filename;
2258
+ addlHeaders['Content-Disposition'] = `attachment; filename="${filename}"`;
2259
+ }
1792
2260
  if (attribute) {
1793
2261
  addlHeaders['Content-Disposition'] += `; x-attributes:${attribute}`;
1794
2262
  }
@@ -1836,6 +2304,107 @@ surrounded by curly-braces, for example: `{repository UUID}`.
1836
2304
  }
1837
2305
  }
1838
2306
 
2307
+ /**
2308
+ * @summary This endpoint is used to create new commits in the repository by uploading files.
2309
+ * @function CreateACommitByUploadingAFile
2310
+ * @param {string} username - This can either be the username or the UUID of the user, surrounded by curly-braces, for example: `{user UUID}`.
2311
+ * @param {string} repoSlug - This can either be the repository slug or the UUID of the repository, surrounded by curly-braces, for example: `{repository UUID}`.
2312
+ * @param {string} message - The commit message. When omitted, Bitbucket uses a canned string.
2313
+ * @param {string} author - The raw string to be used as the new commit's author.
2314
+ * @param {string} parents - A comma-separated list of SHA1s of the commits that should be the parents of the newly created commit.
2315
+ * @param {object} files - Optional field that declares the files that the request is manipulating. ex. {"path/to/file.txt":"Contents of File"}
2316
+ * @param {string} branch - The name of the branch that the new commit should be created on. When omitted, the commit will be created on top of the main branch and will become the main branch's new head.
2317
+ * @param {getCallback} callback - a callback function to return the result
2318
+ */
2319
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
2320
+ CreateACommitByUploadingAFile(username, repoSlug, message, author, parents, files, branch, callback) {
2321
+ const meth = 'adapter-CreateACommitByUploadingAFile';
2322
+ const origin = `${this.id}-${meth}`;
2323
+ log.trace(origin);
2324
+
2325
+ if (this.suspended && this.suspendMode === 'error') {
2326
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
2327
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2328
+ return callback(null, errorObj);
2329
+ }
2330
+
2331
+ /* HERE IS WHERE YOU VALIDATE DATA */
2332
+ if (username === undefined || username === null || username === '') {
2333
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['username'], null, null, null);
2334
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2335
+ return callback(null, errorObj);
2336
+ }
2337
+ if (repoSlug === undefined || repoSlug === null || repoSlug === '') {
2338
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['repoSlug'], null, null, null);
2339
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2340
+ return callback(null, errorObj);
2341
+ }
2342
+ // Build request body
2343
+ let body = {};
2344
+ if (message !== undefined || message !== null || message !== '') {
2345
+ body.message = message;
2346
+ }
2347
+ if (author !== undefined || author !== null || author !== '') {
2348
+ body.author = author;
2349
+ }
2350
+ if (parents !== undefined || parents !== null || parents !== '') {
2351
+ body.parents = parents;
2352
+ }
2353
+ if (branch !== undefined || branch !== null || branch !== '') {
2354
+ body.branch = branch;
2355
+ }
2356
+ if (files !== undefined || files !== null || files !== '') {
2357
+ body = Object.assign(body, files);
2358
+ }
2359
+
2360
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
2361
+ const queryParamsAvailable = {};
2362
+ const queryParams = {};
2363
+ const pathVars = [username, repoSlug];
2364
+ const bodyVars = body;
2365
+
2366
+ // loop in template. long callback arg name to avoid identifier conflicts
2367
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
2368
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
2369
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
2370
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
2371
+ }
2372
+ });
2373
+
2374
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
2375
+ const reqObj = {
2376
+ payload: bodyVars,
2377
+ uriPathVars: pathVars,
2378
+ uriQuery: queryParams
2379
+ };
2380
+
2381
+ try {
2382
+ // Make the call -
2383
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
2384
+ return this.requestHandlerInst.identifyRequest('Repositories', 'CreateACommitByUploadingAFile', reqObj, true, (irReturnData, irReturnError) => {
2385
+ // if we received an error or their is no response on the results
2386
+ // return an error
2387
+ if (irReturnError) {
2388
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
2389
+ return callback(null, irReturnError);
2390
+ }
2391
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
2392
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['CreateACommitByUploadingAFile'], null, null, null);
2393
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2394
+ return callback(null, errorObj);
2395
+ }
2396
+
2397
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
2398
+ // return the response
2399
+ return callback(irReturnData, null);
2400
+ });
2401
+ } catch (ex) {
2402
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
2403
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2404
+ return callback(null, errorObj);
2405
+ }
2406
+ }
2407
+
1839
2408
  /**
1840
2409
  * @summary Updates the specified webhook subscription.
1841
2410
  The following properties can be mutated:
@@ -13114,7 +13683,7 @@ This endpoint supports (and encourages!) the use of [HTTP Range requests](https:
13114
13683
  /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
13115
13684
  const queryParamsAvailable = {};
13116
13685
  const queryParams = {};
13117
- const pathVars = [username, name, repoSlug];
13686
+ const pathVars = [username, repoSlug, name];
13118
13687
  const bodyVars = {};
13119
13688
 
13120
13689
  // loop in template. long callback arg name to avoid identifier conflicts
package/adapterBase.js CHANGED
@@ -22,6 +22,7 @@ const AjvCl = require('ajv');
22
22
  const PropUtilCl = require('@itentialopensource/adapter-utils').PropertyUtility;
23
23
  const RequestHandlerCl = require('@itentialopensource/adapter-utils').RequestHandler;
24
24
 
25
+ const entitiesToDB = require(path.join(__dirname, 'utils/entitiesToDB'));
25
26
  const troubleshootingAdapter = require(path.join(__dirname, 'utils/troubleshootingAdapter'));
26
27
  const tbUtils = require(path.join(__dirname, 'utils/tbUtils'));
27
28
 
@@ -659,7 +660,7 @@ class AdapterBase extends EventEmitterCl {
659
660
  }
660
661
 
661
662
  // make sure the entities directory exists
662
- const entitydir = path.join(__dirname, '../entities');
663
+ const entitydir = path.join(__dirname, 'entities');
663
664
  if (!fs.statSync(entitydir).isDirectory()) {
664
665
  log.error('Could not find the entities directory');
665
666
  result.found = false;
@@ -687,7 +688,7 @@ class AdapterBase extends EventEmitterCl {
687
688
  log.info(` method: ${actions.actions[a].method} path: ${actions.actions[a].entitypath}`);
688
689
  const fitem = {
689
690
  entity: entities[e],
690
- action: actions[a].name,
691
+ action: actions.actions[a].name,
691
692
  method: actions.actions[a].method,
692
693
  path: actions.actions[a].entitypath
693
694
  };
@@ -821,7 +822,7 @@ class AdapterBase extends EventEmitterCl {
821
822
  */
822
823
  async runConnectivity(callback) {
823
824
  try {
824
- const { serviceItem } = await troubleshootingAdapter.getAdapterConfig();
825
+ const { serviceItem } = await tbUtils.getAdapterConfig();
825
826
  const { host } = serviceItem.properties.properties;
826
827
  const result = tbUtils.runConnectivity(host, false);
827
828
  if (result.failCount > 0) {
@@ -1001,6 +1002,27 @@ class AdapterBase extends EventEmitterCl {
1001
1002
  return [];
1002
1003
  }
1003
1004
  }
1005
+
1006
+ /**
1007
+ * @summary moves entities to mongo database
1008
+ *
1009
+ * @function moveEntitiesToDB
1010
+ *
1011
+ * @return {Callback} - containing the response from the mongo transaction
1012
+ */
1013
+ moveEntitiesToDB(callback) {
1014
+ const meth = 'adapterBase-moveEntitiesToDB';
1015
+ const origin = `${this.id}-${meth}`;
1016
+ log.trace(origin);
1017
+
1018
+ try {
1019
+ return callback(entitiesToDB.moveEntitiesToDB(__dirname, { pronghornProps: this.allProps, id: this.id }), null);
1020
+ } catch (err) {
1021
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, err);
1022
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1023
+ return callback(null, errorObj);
1024
+ }
1025
+ }
1004
1026
  }
1005
1027
 
1006
1028
  module.exports = AdapterBase;