@itentialopensource/adapter-jira 1.7.4 → 1.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/AUTH.md +39 -0
  2. package/BROKER.md +199 -0
  3. package/CALLS.md +9587 -0
  4. package/CHANGELOG.md +16 -0
  5. package/CODE_OF_CONDUCT.md +12 -17
  6. package/CONTRIBUTING.md +88 -74
  7. package/ENHANCE.md +69 -0
  8. package/PROPERTIES.md +641 -0
  9. package/README.md +225 -502
  10. package/SUMMARY.md +9 -0
  11. package/SYSTEMINFO.md +11 -0
  12. package/TROUBLESHOOT.md +47 -0
  13. package/adapter.js +10821 -59
  14. package/adapterBase.js +1030 -248
  15. package/entities/.generic/action.json +110 -5
  16. package/entities/.generic/schema.json +6 -1
  17. package/entities/Avatars/action.json +63 -0
  18. package/entities/Avatars/schema.json +4 -1
  19. package/entities/Dashboards/action.json +80 -0
  20. package/entities/Dashboards/mockdatafiles/copyDashboard-default.json +13 -0
  21. package/entities/Dashboards/mockdatafiles/createDashboard-default.json +13 -0
  22. package/entities/Dashboards/mockdatafiles/updateDashboard-default.json +13 -0
  23. package/entities/Dashboards/schema.json +5 -1
  24. package/entities/Groups/action.json +21 -0
  25. package/entities/Groups/mockdatafiles/bulkGetGroups-default.json +16 -0
  26. package/entities/Groups/schema.json +2 -1
  27. package/entities/InstanceInformation/action.json +25 -0
  28. package/entities/InstanceInformation/mockdatafiles/getLicense-default.json +20 -0
  29. package/entities/InstanceInformation/schema.json +19 -0
  30. package/entities/IssueCustomFieldConfigurationApps/action.json +45 -0
  31. package/entities/IssueCustomFieldConfigurationApps/mockdatafiles/getCustomFieldConfiguration-default.json +34 -0
  32. package/entities/IssueCustomFieldConfigurationApps/schema.json +20 -0
  33. package/entities/IssueCustomFieldContexts/action.json +268 -0
  34. package/entities/IssueCustomFieldContexts/mockdatafiles/createCustomFieldContext-default.json +9 -0
  35. package/entities/IssueCustomFieldContexts/mockdatafiles/getContextsForField-default.json +22 -0
  36. package/entities/IssueCustomFieldContexts/mockdatafiles/getCustomFieldContextsForProjectsAndIssueTypes-default.json +23 -0
  37. package/entities/IssueCustomFieldContexts/mockdatafiles/getDefaultValues-default.json +22 -0
  38. package/entities/IssueCustomFieldContexts/mockdatafiles/getIssueTypeMappingsForContexts-default.json +20 -0
  39. package/entities/IssueCustomFieldContexts/mockdatafiles/getProjectContextMapping-default.json +16 -0
  40. package/entities/IssueCustomFieldContexts/schema.json +31 -0
  41. package/entities/IssueCustomFieldOptions/action.json +105 -0
  42. package/entities/IssueCustomFieldOptions/mockdatafiles/createCustomFieldOption-default.json +20 -0
  43. package/entities/IssueCustomFieldOptions/mockdatafiles/getOptionsForContext-default.json +26 -0
  44. package/entities/IssueCustomFieldOptions/mockdatafiles/updateCustomFieldOption-default.json +19 -0
  45. package/entities/IssueCustomFieldOptions/schema.json +23 -0
  46. package/entities/IssueCustomFieldValuesApps/action.json +44 -0
  47. package/entities/IssueCustomFieldValuesApps/schema.json +20 -0
  48. package/entities/IssueFieldConfigurations/action.json +309 -0
  49. package/entities/IssueFieldConfigurations/mockdatafiles/createFieldConfiguration-default.json +5 -0
  50. package/entities/IssueFieldConfigurations/mockdatafiles/createFieldConfigurationScheme-default.json +5 -0
  51. package/entities/IssueFieldConfigurations/mockdatafiles/getAllFieldConfigurationSchemes-default.json +23 -0
  52. package/entities/IssueFieldConfigurations/mockdatafiles/getAllFieldConfigurations-default.json +19 -0
  53. package/entities/IssueFieldConfigurations/mockdatafiles/getFieldConfigurationItems-default.json +19 -0
  54. package/entities/IssueFieldConfigurations/mockdatafiles/getFieldConfigurationSchemeMappings-default.json +33 -0
  55. package/entities/IssueFieldConfigurations/mockdatafiles/getFieldConfigurationSchemeProjectMapping-default.json +26 -0
  56. package/entities/IssueFieldConfigurations/schema.json +33 -0
  57. package/entities/IssueTypeSchemes/action.json +207 -0
  58. package/entities/IssueTypeSchemes/mockdatafiles/createIssueTypeScheme-default.json +3 -0
  59. package/entities/IssueTypeSchemes/mockdatafiles/getAllIssueTypeSchemes-default.json +26 -0
  60. package/entities/IssueTypeSchemes/mockdatafiles/getIssueTypeSchemeForProjects-default.json +44 -0
  61. package/entities/IssueTypeSchemes/mockdatafiles/getIssueTypeSchemesMapping-default.json +24 -0
  62. package/entities/IssueTypeSchemes/schema.json +28 -0
  63. package/entities/IssueTypeScreenSchemes/action.json +228 -0
  64. package/entities/IssueTypeScreenSchemes/mockdatafiles/createIssueTypeScreenScheme-default.json +3 -0
  65. package/entities/IssueTypeScreenSchemes/mockdatafiles/getIssueTypeScreenSchemeMappings-default.json +28 -0
  66. package/entities/IssueTypeScreenSchemes/mockdatafiles/getIssueTypeScreenSchemeProjectAssociations-default.json +19 -0
  67. package/entities/IssueTypeScreenSchemes/mockdatafiles/getIssueTypeScreenSchemes-default.json +18 -0
  68. package/entities/IssueTypeScreenSchemes/mockdatafiles/getProjectsForIssueTypeScreenScheme-default.json +27 -0
  69. package/entities/IssueTypeScreenSchemes/schema.json +29 -0
  70. package/entities/Issueattachments/action.json +42 -0
  71. package/entities/Issueattachments/schema.json +3 -1
  72. package/entities/Issuefields/action.json +122 -0
  73. package/entities/Issuefields/mockdatafiles/getContextsForFieldDeprecated-default.json +12 -0
  74. package/entities/Issuefields/mockdatafiles/getFieldsPaginated-default.json +46 -0
  75. package/entities/Issuefields/schema.json +7 -1
  76. package/entities/Issueproperties/action.json +40 -0
  77. package/entities/Issueproperties/schema.json +3 -1
  78. package/entities/Issues/action.json +45 -0
  79. package/entities/Issues/mockdatafiles/getChangeLogsByIds-default.json +65 -0
  80. package/entities/Issues/mockdatafiles/getEvents-default.json +10 -0
  81. package/entities/Issues/schema.json +20 -0
  82. package/entities/Issuesearch/action.json +20 -0
  83. package/entities/Issuesearch/mockdatafiles/matchIssues-default.json +29 -0
  84. package/entities/Issuesearch/schema.json +2 -1
  85. package/entities/Issuesecuritylevel/action.json +21 -0
  86. package/entities/Issuesecuritylevel/mockdatafiles/getIssueSecurityLevelMembers-default.json +46 -0
  87. package/entities/Issuesecuritylevel/schema.json +2 -1
  88. package/entities/Issuetypes/action.json +21 -0
  89. package/entities/Issuetypes/mockdatafiles/getIssueTypesForProject-default.json +39 -0
  90. package/entities/Issuetypes/schema.json +2 -1
  91. package/entities/Issuewatchers/action.json +20 -0
  92. package/entities/Issuewatchers/mockdatafiles/getIsWatchingIssueBulk-default.json +7 -0
  93. package/entities/Issuewatchers/schema.json +2 -1
  94. package/entities/JQL/action.json +40 -0
  95. package/entities/JQL/mockdatafiles/getAutoCompletePost-default.json +89 -0
  96. package/entities/JQL/mockdatafiles/parseJqlQueries-default.json +119 -0
  97. package/entities/JQL/schema.json +3 -1
  98. package/entities/Jiraexpressions/action.json +20 -0
  99. package/entities/Jiraexpressions/mockdatafiles/analyseExpression-default.json +47 -0
  100. package/entities/Jiraexpressions/schema.json +2 -1
  101. package/entities/Labels/action.json +25 -0
  102. package/entities/Labels/mockdatafiles/getAllLabels-default.json +10 -0
  103. package/entities/Labels/schema.json +19 -0
  104. package/entities/ProjectEmail/action.json +45 -0
  105. package/entities/ProjectEmail/mockdatafiles/getProjectEmail-default.json +6 -0
  106. package/entities/ProjectEmail/schema.json +20 -0
  107. package/entities/ProjectFeatures/action.json +45 -0
  108. package/entities/ProjectFeatures/mockdatafiles/getFeaturesForProject-default.json +24 -0
  109. package/entities/ProjectFeatures/mockdatafiles/toggleFeatureForProject-default.json +24 -0
  110. package/entities/ProjectFeatures/schema.json +20 -0
  111. package/entities/Projects/action.json +102 -0
  112. package/entities/Projects/mockdatafiles/getHierarchy-default.json +50 -0
  113. package/entities/Projects/mockdatafiles/getRecent-default.json +50 -0
  114. package/entities/Projects/mockdatafiles/restore-default.json +139 -0
  115. package/entities/Projects/schema.json +6 -1
  116. package/entities/Projecttypes/action.json +21 -0
  117. package/entities/Projecttypes/mockdatafiles/getAllAccessibleProjectTypes-default.json +16 -0
  118. package/entities/Projecttypes/schema.json +2 -1
  119. package/entities/ScreenSchemes/action.json +85 -0
  120. package/entities/ScreenSchemes/mockdatafiles/createScreenScheme-default.json +3 -0
  121. package/entities/ScreenSchemes/mockdatafiles/getScreenSchemes-default.json +28 -0
  122. package/entities/ScreenSchemes/schema.json +22 -0
  123. package/entities/Screens/action.json +81 -0
  124. package/entities/Screens/mockdatafiles/createScreen-default.json +5 -0
  125. package/entities/Screens/mockdatafiles/getScreensForField-default.json +17 -0
  126. package/entities/Screens/mockdatafiles/updateScreen-default.json +5 -0
  127. package/entities/Screens/schema.json +5 -1
  128. package/entities/Users/action.json +84 -0
  129. package/entities/Users/mockdatafiles/getAllUsers-default.json +32 -0
  130. package/entities/Users/mockdatafiles/getAllUsersDefault-default.json +32 -0
  131. package/entities/Users/mockdatafiles/getUserEmail-default.json +1 -0
  132. package/entities/Users/schema.json +5 -1
  133. package/entities/Webhooks/action.json +106 -0
  134. package/entities/Webhooks/mockdatafiles/getDynamicWebhooksForApp-default.json +40 -0
  135. package/entities/Webhooks/mockdatafiles/getFailedWebhooks-default.json +17 -0
  136. package/entities/Webhooks/mockdatafiles/refreshWebhooks-default.json +3 -0
  137. package/entities/Webhooks/mockdatafiles/registerDynamicWebhooks-default.json +15 -0
  138. package/entities/Webhooks/schema.json +23 -0
  139. package/entities/WorkflowSchemeProjectAssociations/action.json +45 -0
  140. package/entities/WorkflowSchemeProjectAssociations/mockdatafiles/getWorkflowSchemeProjectAssociations-default.json +21 -0
  141. package/entities/WorkflowSchemeProjectAssociations/schema.json +20 -0
  142. package/entities/WorkflowTransitionRules/action.json +65 -0
  143. package/entities/WorkflowTransitionRules/mockdatafiles/deleteWorkflowTransitionRuleConfigurations-default.json +34 -0
  144. package/entities/WorkflowTransitionRules/mockdatafiles/getWorkflowTransitionRuleConfigurations-default.json +56 -0
  145. package/entities/WorkflowTransitionRules/mockdatafiles/updateWorkflowTransitionRuleConfigurations-default.json +34 -0
  146. package/entities/WorkflowTransitionRules/schema.json +21 -0
  147. package/entities/Workflows/action.json +61 -0
  148. package/entities/Workflows/mockdatafiles/createWorkflow-default.json +4 -0
  149. package/entities/Workflows/mockdatafiles/getWorkflowsPaginated-default.json +140 -0
  150. package/entities/Workflows/schema.json +4 -1
  151. package/entities/Workflowschemedrafts/action.json +20 -0
  152. package/entities/Workflowschemedrafts/schema.json +2 -1
  153. package/entities/Workflowschemes/action.json +21 -0
  154. package/entities/Workflowschemes/mockdatafiles/getAllWorkflowSchemes-default.json +30 -0
  155. package/entities/Workflowschemes/schema.json +2 -1
  156. package/error.json +12 -0
  157. package/package.json +21 -13
  158. package/pronghorn.json +33339 -5948
  159. package/propertiesDecorators.json +14 -0
  160. package/propertiesSchema.json +436 -0
  161. package/refs?service=git-upload-pack +0 -0
  162. package/report/adapterInfo.json +10 -0
  163. package/report/updateReport1659707107792.json +120 -0
  164. package/sampleProperties.json +95 -3
  165. package/test/integration/adapterTestBasicGet.js +2 -2
  166. package/test/integration/adapterTestIntegration.js +3633 -106
  167. package/test/unit/adapterBaseTestUnit.js +35 -27
  168. package/test/unit/adapterTestUnit.js +4767 -115
  169. package/utils/adapterInfo.js +206 -0
  170. package/utils/addAuth.js +94 -0
  171. package/utils/basicGet.js +1 -14
  172. package/utils/entitiesToDB.js +179 -0
  173. package/utils/methodDocumentor.js +225 -0
  174. package/utils/modify.js +1 -1
  175. package/utils/packModificationScript.js +1 -1
  176. package/utils/patches2bundledDeps.js +90 -0
  177. package/utils/pre-commit.sh +5 -0
  178. package/utils/removeHooks.js +20 -0
  179. package/utils/tbScript.js +43 -22
  180. package/utils/tbUtils.js +126 -29
  181. package/utils/testRunner.js +16 -16
  182. package/utils/troubleshootingAdapter.js +2 -26
  183. package/versions.json +142 -0
@@ -0,0 +1,206 @@
1
+ #!/usr/bin/env node
2
+ /* @copyright Itential, LLC 2019 */
3
+ /* eslint global-require:warn */
4
+ /* eslint import/no-dynamic-require:warn */
5
+ /* eslint prefer-destructuring:warn */
6
+
7
+ const fs = require('fs-extra');
8
+ const path = require('path');
9
+
10
+ /**
11
+ * This script will determine the information about the adapter and store
12
+ * it into a file in the adapter.
13
+ */
14
+
15
+ /**
16
+ * get adapter information
17
+ */
18
+ function adapterInfo() {
19
+ // set the base pase of the adapter - tool shoud be one level up in utils
20
+ let adaptdir = __dirname;
21
+ const infoRes = {};
22
+
23
+ if (adaptdir.endsWith('/utils')) {
24
+ adaptdir = adaptdir.substring(0, adaptdir.length - 6);
25
+ }
26
+ const pack = require(`${adaptdir}/package.json`);
27
+ infoRes.version = pack.version;
28
+
29
+ let configCount = 0;
30
+ if (fs.existsSync(`${adaptdir}/pronghorn.json`)) {
31
+ const cFile = fs.readFileSync(`${adaptdir}/pronghorn.json`, 'utf8');
32
+ configCount += cFile.split('\n').length;
33
+ } else {
34
+ console.log('Missing - pronghorn.json');
35
+ }
36
+ if (fs.existsSync(`${adaptdir}/propertiesSchema.json`)) {
37
+ const cFile = fs.readFileSync(`${adaptdir}/propertiesSchema.json`, 'utf8');
38
+ configCount += cFile.split('\n').length;
39
+ } else {
40
+ console.log('Missing - propertiesSchema.json');
41
+ }
42
+ if (fs.existsSync(`${adaptdir}/error.json`)) {
43
+ const cFile = fs.readFileSync(`${adaptdir}/error.json`, 'utf8');
44
+ configCount += cFile.split('\n').length;
45
+ } else {
46
+ console.log('Missing - error.json');
47
+ }
48
+ const entitydir = path.join(adaptdir, '/entities');
49
+ if (fs.existsSync(entitydir) && fs.statSync(entitydir).isDirectory()) {
50
+ const entities = fs.readdirSync(entitydir);
51
+ // need to go through each entity in the entities directory
52
+ for (let e = 0; e < entities.length; e += 1) {
53
+ if (fs.statSync(`${entitydir}/${entities[e]}`).isDirectory()) {
54
+ const cfiles = fs.readdirSync(entitydir);
55
+ for (let c = 0; c < cfiles.length; c += 1) {
56
+ if (cfiles[c].endsWith('.json')) {
57
+ const ccFile = fs.readFileSync(`${entitydir}/${entities[e]}/${cfiles[c]}`, 'utf8');
58
+ configCount += ccFile.split('\n').length;
59
+ }
60
+ }
61
+ }
62
+ }
63
+ } else {
64
+ console.log('Could not find the entities directory');
65
+ }
66
+ infoRes.configLines = configCount;
67
+
68
+ let scodeCount = 0;
69
+ if (fs.existsSync(`${adaptdir}/utils/artifactize.js`)) {
70
+ const sFile = fs.readFileSync(`${adaptdir}/utils/artifactize.js`, 'utf8');
71
+ scodeCount += sFile.split('\n').length;
72
+ } else {
73
+ console.log('Missing - utils/artifactize.js');
74
+ }
75
+ if (fs.existsSync(`${adaptdir}/utils/basicGet.js`)) {
76
+ const sFile = fs.readFileSync(`${adaptdir}/utils/basicGet.js`, 'utf8');
77
+ scodeCount += sFile.split('\n').length;
78
+ } else {
79
+ console.log('Missing - utils/basicGet.js');
80
+ }
81
+ if (fs.existsSync(`${adaptdir}/utils/checkMigrate.js`)) {
82
+ const sFile = fs.readFileSync(`${adaptdir}/utils/checkMigrate.js`, 'utf8');
83
+ scodeCount += sFile.split('\n').length;
84
+ } else {
85
+ console.log('Missing - utils/checkMigrate.js');
86
+ }
87
+ if (fs.existsSync(`${adaptdir}/utils/findPath.js`)) {
88
+ const sFile = fs.readFileSync(`${adaptdir}/utils/findPath.js`, 'utf8');
89
+ scodeCount += sFile.split('\n').length;
90
+ } else {
91
+ console.log('Missing - utils/findPath.js');
92
+ }
93
+ if (fs.existsSync(`${adaptdir}/utils/modify.js`)) {
94
+ const sFile = fs.readFileSync(`${adaptdir}/utils/modify.js`, 'utf8');
95
+ scodeCount += sFile.split('\n').length;
96
+ } else {
97
+ console.log('Missing - utils/modify.js');
98
+ }
99
+ if (fs.existsSync(`${adaptdir}/utils/packModificationScript.js`)) {
100
+ const sFile = fs.readFileSync(`${adaptdir}/utils/packModificationScript.js`, 'utf8');
101
+ scodeCount += sFile.split('\n').length;
102
+ } else {
103
+ console.log('Missing - utils/packModificationScript.js');
104
+ }
105
+ if (fs.existsSync(`${adaptdir}/utils/setup.js`)) {
106
+ const sFile = fs.readFileSync(`${adaptdir}/utils/setup.js`, 'utf8');
107
+ scodeCount += sFile.split('\n').length;
108
+ } else {
109
+ console.log('Missing - utils/setup.js');
110
+ }
111
+ if (fs.existsSync(`${adaptdir}/utils/tbScript.js`)) {
112
+ const sFile = fs.readFileSync(`${adaptdir}/utils/tbScript.js`, 'utf8');
113
+ scodeCount += sFile.split('\n').length;
114
+ } else {
115
+ console.log('Missing - utils/tbScript.js');
116
+ }
117
+ if (fs.existsSync(`${adaptdir}/utils/tbUtils.js`)) {
118
+ const sFile = fs.readFileSync(`${adaptdir}/utils/tbUtils.js`, 'utf8');
119
+ scodeCount += sFile.split('\n').length;
120
+ } else {
121
+ console.log('Missing - utils/tbUtils.js');
122
+ }
123
+ if (fs.existsSync(`${adaptdir}/utils/testRunner.js`)) {
124
+ const sFile = fs.readFileSync(`${adaptdir}/utils/testRunner.js`, 'utf8');
125
+ scodeCount += sFile.split('\n').length;
126
+ } else {
127
+ console.log('Missing - utils/testRunner.js');
128
+ }
129
+ if (fs.existsSync(`${adaptdir}/utils/troubleshootingAdapter.js`)) {
130
+ const sFile = fs.readFileSync(`${adaptdir}/utils/troubleshootingAdapter.js`, 'utf8');
131
+ scodeCount += sFile.split('\n').length;
132
+ } else {
133
+ console.log('Missing - utils/troubleshootingAdapter.js');
134
+ }
135
+ infoRes.scriptLines = scodeCount;
136
+
137
+ let codeCount = 0;
138
+ if (fs.existsSync(`${adaptdir}/adapter.js`)) {
139
+ const aFile = fs.readFileSync(`${adaptdir}/adapter.js`, 'utf8');
140
+ codeCount += aFile.split('\n').length;
141
+ } else {
142
+ console.log('Missing - utils/adapter.js');
143
+ }
144
+ if (fs.existsSync(`${adaptdir}/adapterBase.js`)) {
145
+ const aFile = fs.readFileSync(`${adaptdir}/adapterBase.js`, 'utf8');
146
+ codeCount += aFile.split('\n').length;
147
+ } else {
148
+ console.log('Missing - utils/adapterBase.js');
149
+ }
150
+ infoRes.codeLines = codeCount;
151
+
152
+ let tcodeCount = 0;
153
+ let ttestCount = 0;
154
+ if (fs.existsSync(`${adaptdir}/test/integration/adapterTestBasicGet.js`)) {
155
+ const tFile = fs.readFileSync(`${adaptdir}/test/integration/adapterTestBasicGet.js`, 'utf8');
156
+ tcodeCount += tFile.split('\n').length;
157
+ ttestCount += tFile.split('it(\'').length;
158
+ } else {
159
+ console.log('Missing - test/integration/adapterTestBasicGet.js');
160
+ }
161
+ if (fs.existsSync(`${adaptdir}/test/integration/adapterTestConnectivity.js`)) {
162
+ const tFile = fs.readFileSync(`${adaptdir}/test/integration/adapterTestConnectivity.js`, 'utf8');
163
+ tcodeCount += tFile.split('\n').length;
164
+ ttestCount += tFile.split('it(\'').length;
165
+ } else {
166
+ console.log('Missing - test/integration/adapterTestConnectivity.js');
167
+ }
168
+ if (fs.existsSync(`${adaptdir}/test/integration/adapterTestIntegration.js`)) {
169
+ const tFile = fs.readFileSync(`${adaptdir}/test/integration/adapterTestIntegration.js`, 'utf8');
170
+ tcodeCount += tFile.split('\n').length;
171
+ ttestCount += tFile.split('it(\'').length;
172
+ } else {
173
+ console.log('Missing - test/integration/adapterTestIntegration.js');
174
+ }
175
+ if (fs.existsSync(`${adaptdir}/test/unit/adapterBaseTestUnit.js`)) {
176
+ const tFile = fs.readFileSync(`${adaptdir}/test/unit/adapterBaseTestUnit.js`, 'utf8');
177
+ tcodeCount += tFile.split('\n').length;
178
+ ttestCount += tFile.split('it(\'').length;
179
+ } else {
180
+ console.log('Missing - test/unit/adapterBaseTestUnit.js');
181
+ }
182
+ if (fs.existsSync(`${adaptdir}/test/unit/adapterTestUnit.js`)) {
183
+ const tFile = fs.readFileSync(`${adaptdir}/test/unit/adapterTestUnit.js`, 'utf8');
184
+ tcodeCount += tFile.split('\n').length;
185
+ ttestCount += tFile.split('it(\'').length;
186
+ } else {
187
+ console.log('Missing - test/unit/adapterTestUnit.js');
188
+ }
189
+ infoRes.testLines = tcodeCount;
190
+ infoRes.testCases = ttestCount;
191
+ infoRes.totalCodeLines = scodeCount + codeCount + tcodeCount;
192
+
193
+ if (fs.existsSync(`${adaptdir}/pronghorn.json`)) {
194
+ // Read the entity schema from the file system
195
+ const phFile = path.join(adaptdir, '/pronghorn.json');
196
+ const prong = require(phFile);
197
+ infoRes.wfTasks = prong.methods.length;
198
+ } else {
199
+ console.log('Missing - pronghorn.json');
200
+ }
201
+
202
+ console.log(JSON.stringify(infoRes));
203
+ fs.writeFileSync(`${adaptdir}/report/adapterInfo.json`, JSON.stringify(infoRes, null, 2));
204
+ }
205
+
206
+ adapterInfo();
@@ -0,0 +1,94 @@
1
+ /* eslint-disable no-plusplus */
2
+ /* eslint global-require: warn */
3
+ /* eslint import/no-dynamic-require: warn */
4
+
5
+ const rls = require('readline-sync');
6
+ const path = require('path');
7
+ const fs = require('fs');
8
+
9
+ function getQuestions(props, obj) {
10
+ const questions = props.map((p) => `${p}: ${(obj[p] !== undefined) ? `(${obj[p]})` : ''} `);
11
+ return questions;
12
+ }
13
+
14
+ // function outputs each property for user to edit/confirm
15
+ // props are the fields that need to be changed depending on what the user selects
16
+ // obj is the JSON object that's being updated
17
+ function confirm(props, obj) {
18
+ // create array of questions
19
+ const updatedObj = obj;
20
+ getQuestions(props, obj).forEach((q) => {
21
+ const answer = rls.question(q);
22
+ // only update the field if the answer is NOT and empty string
23
+ if (answer) {
24
+ updatedObj[q.split(':')[0].trim()] = answer;
25
+ }
26
+ });
27
+ return updatedObj;
28
+ }
29
+
30
+ const updateBasicAuth = (auth) => {
31
+ const propsToUpdate = ['username', 'password', 'auth_field', 'auth_field_format'];
32
+ return confirm(propsToUpdate, auth);
33
+ };
34
+
35
+ const updateStaticTokenAuth = (auth) => {
36
+ const propsToUpdate = ['token', 'auth_field', 'auth_field_format'];
37
+ return confirm(propsToUpdate, auth);
38
+ };
39
+
40
+ function updateTokenSchemas(user, pw, token) {
41
+ let schemaPath = path.join(__dirname, '..', 'entities/.system/schemaTokenReq.json');
42
+ const reqSchema = require(schemaPath);
43
+ reqSchema.properties.username.external_name = user;
44
+ reqSchema.properties.password.external_name = pw;
45
+ fs.writeFileSync(schemaPath, JSON.stringify(reqSchema, null, 2));
46
+ schemaPath = path.join(__dirname, '..', 'entities/.system/schemaTokenResp.json');
47
+ const respSchema = require(schemaPath);
48
+ respSchema.properties.token.external_name = token;
49
+ fs.writeFileSync(schemaPath, JSON.stringify(respSchema, null, 2));
50
+ }
51
+
52
+ function updateRequestToken(auth) {
53
+ const propsToUpdate = [
54
+ 'username',
55
+ 'password',
56
+ 'auth_field',
57
+ 'auth_field_format',
58
+ 'token_user_field',
59
+ 'token_password_field',
60
+ 'token_result_field',
61
+ 'token_URI_path'
62
+ ];
63
+ const newAuth = confirm(propsToUpdate, auth);
64
+ updateTokenSchemas(newAuth.token_user_field, newAuth.token_password_field, newAuth.token_result_field);
65
+
66
+ return newAuth;
67
+ }
68
+
69
+ // prompt users to pick an auth method from the list above
70
+ const addAuthInfo = (props) => {
71
+ const authOptions = [
72
+ 'basic user_password',
73
+ 'static_token',
74
+ 'request_token',
75
+ 'no_authentication'
76
+ ];
77
+ const newProps = confirm(['host', 'port', 'base_path'], props);
78
+
79
+ const newAuthMethod = authOptions[rls.keyInSelect(authOptions, 'Which authentication method?')];
80
+ newProps.authentication.auth_method = newAuthMethod;
81
+
82
+ if (newAuthMethod === 'basic user_password') {
83
+ newProps.authentication = updateBasicAuth(newProps.authentication);
84
+ } else if (newAuthMethod === 'static_token') {
85
+ newProps.authentication = updateStaticTokenAuth(newProps.authentication);
86
+ } else if (newAuthMethod === 'request_token') {
87
+ newProps.authentication = updateRequestToken(newProps.authentication);
88
+ }
89
+ console.log('Connectivity and authentication properties have been configured');
90
+ console.log('If you want to make changes, rerun this script to reinstall the adapter');
91
+ return newProps;
92
+ };
93
+
94
+ module.exports = { addAuthInfo };
package/utils/basicGet.js CHANGED
@@ -4,6 +4,7 @@
4
4
  /* eslint import/no-extraneous-dependencies: warn */
5
5
  /* eslint global-require: warn */
6
6
  /* eslint import/no-unresolved: warn */
7
+ /* eslint import/no-dynamic-require: warn */
7
8
 
8
9
  const winston = require('winston');
9
10
 
@@ -43,20 +44,6 @@ const basicGet = {
43
44
  adapter.id,
44
45
  adapterProps
45
46
  );
46
- },
47
-
48
- /**
49
- * @summary connect to mongodb
50
- *
51
- * @function connect
52
- * @param {Object} properties - pronghornProps
53
- */
54
- connect: async function connect(properties) {
55
- // Connect to Mongo
56
- const { MongoDBConnection } = require('@itential/database');
57
- const connection = new MongoDBConnection(properties.mongoProps);
58
- const database = await connection.connect(true);
59
- return database;
60
47
  }
61
48
  };
62
49
 
@@ -0,0 +1,179 @@
1
+ /* @copyright Itential, LLC 2021 */
2
+
3
+ // Set globals
4
+ /* global log */
5
+
6
+ /* eslint import/no-dynamic-require: warn */
7
+ /* eslint global-require: warn */
8
+ /* eslint no-unused-vars: warn */
9
+ /* eslint import/no-unresolved: warn */
10
+
11
+ /**
12
+ * This script is used to read through an adapter's entities files
13
+ * and then creates documents and enters them into the IAP mongodb
14
+ */
15
+
16
+ const fs = require('fs');
17
+ const path = require('path');
18
+ const utils = require('./tbUtils');
19
+
20
+ // get the pronghorn database information
21
+ const getPronghornProps = async (iapDir) => {
22
+ log.trace('Retrieving properties.json file...');
23
+ const rawProps = require(path.join(iapDir, 'properties.json'));
24
+ log.trace('Decrypting properties...');
25
+ const { PropertyEncryption } = require('@itential/itential-utils');
26
+ const propertyEncryption = new PropertyEncryption();
27
+ const pronghornProps = await propertyEncryption.decryptProps(rawProps);
28
+ log.trace('Found properties.\n');
29
+ return pronghornProps;
30
+ };
31
+
32
+ /**
33
+ * Function used to take a file path to a entity directory and build
34
+ * a document that corresponds to the entity files.
35
+ */
36
+ const buildDoc = (pathstring) => {
37
+ let files = fs.readdirSync(pathstring);
38
+
39
+ // load the mockdatafiles
40
+ const mockdatafiles = {};
41
+ if (files.includes('mockdatafiles') && fs.lstatSync(`${pathstring}/mockdatafiles`).isDirectory()) {
42
+ fs.readdirSync(`${pathstring}/mockdatafiles`).forEach((file) => {
43
+ if (file.split('.').pop() === 'json') {
44
+ const mockpath = `${pathstring}/mockdatafiles/${file}`;
45
+ const data = JSON.parse(fs.readFileSync(mockpath));
46
+ mockdatafiles[mockpath.split('/').pop()] = data;
47
+ }
48
+ });
49
+ }
50
+
51
+ // load the action data
52
+ let actions;
53
+ if (files.includes('action.json')) {
54
+ actions = JSON.parse(fs.readFileSync(`${pathstring}/action.json`));
55
+ }
56
+
57
+ // Load schema.json and other schemas in remaining json files
58
+ files = files.filter((f) => (f !== 'action.json') && f.endsWith('.json'));
59
+ const schema = [];
60
+ files.forEach((file) => {
61
+ const data = JSON.parse(fs.readFileSync(`${pathstring}/${file}`));
62
+ schema.push({
63
+ name: file,
64
+ schema: data
65
+ });
66
+ });
67
+
68
+ // return the data
69
+ return {
70
+ actions: actions.actions,
71
+ schema,
72
+ mockdatafiles
73
+ };
74
+ };
75
+
76
+ /**
77
+ * Function used to get the database from the options or a provided directory
78
+ */
79
+ const optionsHandler = (options) => {
80
+ // if the database properties were provided in the options - return them
81
+ if (options.pronghornProps) {
82
+ if (typeof options.pronghornProps === 'string') {
83
+ return JSON.parse(options.pronghornProps);
84
+ }
85
+ return new Promise((resolve, reject) => resolve(options.pronghornProps));
86
+ }
87
+
88
+ // if the directory was provided, get the pronghorn props from the directory
89
+ if (options.iapDir) {
90
+ return getPronghornProps(options.iapDir);
91
+ }
92
+
93
+ // if nothing was provided, error
94
+ return new Promise((resolve, reject) => reject(new Error('Neither pronghornProps nor iapDir defined in options!')));
95
+ };
96
+
97
+ /**
98
+ * Function used to put the adapter configuration into the provided database
99
+ */
100
+ const moveEntitiesToDB = async (targetPath, options) => {
101
+ // set local variables
102
+ let myOpts = options;
103
+ let myPath = targetPath;
104
+
105
+ // if we got a string parse into a JSON object
106
+ if (typeof myOpts === 'string') {
107
+ myOpts = JSON.parse(myOpts);
108
+ }
109
+
110
+ // if there is no target collection - set the collection to the default
111
+ if (!myOpts.targetCollection) {
112
+ myOpts.targetCollection = 'adapter_configs';
113
+ }
114
+
115
+ // if there is no id error since we need an id for the entities
116
+ if (!myOpts.id) {
117
+ throw new Error('Adapter ID required!');
118
+ }
119
+
120
+ // get the pronghorn database properties
121
+ return optionsHandler(options).then(async (currentProps) => {
122
+ // Check valid filepath provided
123
+ if (!myPath) {
124
+ // if no path use the current directory without the utils
125
+ myPath = path.join(__dirname, '../');
126
+ } else if (myPath.slice(-1) === '/') {
127
+ myPath = myPath.slice(0, -1);
128
+ }
129
+
130
+ // verify set the entity path
131
+ const entitiesPath = `${myPath}/entities`;
132
+ if (!fs.existsSync(entitiesPath)) {
133
+ throw new Error(`Entities path does not exist in filesystem: ${entitiesPath}`);
134
+ } else {
135
+ log.trace('Target found on filesystem');
136
+ }
137
+
138
+ // Get adapter details
139
+ if (!fs.existsSync(`${myPath}/pronghorn.json`)) {
140
+ throw new Error(`pronghorn.json does not exist in path: ${myPath}`);
141
+ } else {
142
+ log.trace('pronghorn.json found on filesystem');
143
+ }
144
+ const adapterData = JSON.parse(fs.readFileSync(`${myPath}/pronghorn.json`));
145
+
146
+ // Load files from the filesystem
147
+ const docs = [];
148
+ const entities = fs.readdirSync(entitiesPath);
149
+ entities.forEach((entity) => {
150
+ const entityPath = `${entitiesPath}/${entity}`;
151
+ const isDir = fs.lstatSync(entitiesPath).isDirectory();
152
+
153
+ // Build doc for entity
154
+ if (isDir) {
155
+ let doc = buildDoc(entityPath);
156
+ doc = {
157
+ id: myOpts.id,
158
+ type: adapterData.id,
159
+ entity,
160
+ ...doc
161
+ };
162
+ docs.push(doc);
163
+ }
164
+ });
165
+
166
+ // Upload documents to db collection
167
+ const iapDir = utils.getIAPHome();
168
+ const db = await utils.connect(iapDir, currentProps).catch((err) => { console.error(err); throw err; });
169
+ if (!db) {
170
+ console.error('Error occured when connectiong to database', currentProps);
171
+ throw new Error('Database not found');
172
+ }
173
+ const collection = db.collection(myOpts.targetCollection);
174
+ const res = await collection.insertMany(docs, { checkKeys: false }).catch((err) => { console.error(err); throw err; });
175
+ return res;
176
+ });
177
+ };
178
+
179
+ module.exports = { moveEntitiesToDB };