@contrail/cli 1.0.71 → 2.0.1

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 (270) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1034 -5
  3. package/bin/dev +17 -0
  4. package/bin/dev.cmd +3 -0
  5. package/bin/run +5 -0
  6. package/bin/run.cmd +3 -0
  7. package/{lib → dist}/api/apps.d.ts +13 -13
  8. package/dist/api/apps.js +96 -0
  9. package/{lib → dist}/api/event-workflow-action-definition.d.ts +1 -1
  10. package/dist/api/event-workflow-action-definition.js +11 -0
  11. package/{lib → dist}/api/event-workflow-template-definition.d.ts +6 -6
  12. package/dist/api/event-workflow-template-definition.js +26 -0
  13. package/{lib → dist}/api/event-workflow-templates.d.ts +7 -7
  14. package/dist/api/event-workflow-templates.js +32 -0
  15. package/dist/api/types.d.ts +7 -0
  16. package/dist/api/types.js +52 -0
  17. package/{lib → dist}/auth/auth.d.ts +9 -9
  18. package/dist/auth/auth.js +6 -0
  19. package/{lib → dist}/auth/login.d.ts +2 -2
  20. package/{lib → dist}/auth/login.js +146 -141
  21. package/dist/commands/app/create.d.ts +6 -0
  22. package/dist/commands/app/create.js +15 -0
  23. package/dist/commands/app/delete.d.ts +7 -0
  24. package/dist/commands/app/delete.js +38 -0
  25. package/dist/commands/app/install.d.ts +11 -0
  26. package/dist/commands/app/install.js +117 -0
  27. package/dist/commands/app/publish.d.ts +7 -0
  28. package/dist/commands/app/publish.js +45 -0
  29. package/dist/commands/app/uninstall.d.ts +10 -0
  30. package/dist/commands/app/uninstall.js +58 -0
  31. package/dist/commands/app/upgrade.d.ts +11 -0
  32. package/dist/commands/app/upgrade.js +79 -0
  33. package/dist/commands/colors/deleteAll.d.ts +6 -0
  34. package/dist/commands/colors/deleteAll.js +30 -0
  35. package/dist/commands/colors/load.d.ts +6 -0
  36. package/dist/commands/colors/load.js +29 -0
  37. package/dist/commands/config/list.d.ts +6 -0
  38. package/dist/commands/config/list.js +15 -0
  39. package/dist/commands/config/remove.d.ts +14 -0
  40. package/dist/commands/config/remove.js +26 -0
  41. package/dist/commands/config/set.d.ts +13 -0
  42. package/dist/commands/config/set.js +29 -0
  43. package/dist/commands/loader-process/load.d.ts +9 -0
  44. package/dist/commands/loader-process/load.js +33 -0
  45. package/dist/commands/loader-process/upload-and-load.d.ts +10 -0
  46. package/dist/commands/loader-process/upload-and-load.js +35 -0
  47. package/dist/commands/projects/export.d.ts +10 -0
  48. package/dist/commands/projects/export.js +34 -0
  49. package/dist/commands/projects/list.d.ts +6 -0
  50. package/dist/commands/projects/list.js +34 -0
  51. package/dist/commands/projects/load.d.ts +9 -0
  52. package/{lib/projects/project-uploader.js → dist/commands/projects/load.js} +106 -105
  53. package/dist/commands/types/exportOptionSetHierarchies.d.ts +7 -0
  54. package/{lib/types/option-set-hierarchy-exporter.js → dist/commands/types/exportOptionSetHierarchies.js} +130 -113
  55. package/{lib/types/types-extractor.d.ts → dist/commands/types/getAll.d.ts} +29 -27
  56. package/{lib/types/types-extractor.js → dist/commands/types/getAll.js} +267 -318
  57. package/dist/commands/types/loadAll.d.ts +7 -0
  58. package/dist/commands/types/loadAll.js +41 -0
  59. package/dist/commands/types/mergeOptionSets.d.ts +9 -0
  60. package/{lib/types/option-set-merger.js → dist/commands/types/mergeOptionSets.js} +114 -105
  61. package/dist/commands/types/mergeTypeProperties.d.ts +11 -0
  62. package/dist/commands/types/mergeTypeProperties.js +89 -0
  63. package/dist/commands/types/parseOptionSetsHierarchyLocalFile.d.ts +10 -0
  64. package/dist/commands/types/parseOptionSetsHierarchyLocalFile.js +112 -0
  65. package/dist/commands/types/parseOptionSetsLocalFiles.d.ts +14 -0
  66. package/dist/commands/types/parseOptionSetsLocalFiles.js +153 -0
  67. package/dist/commands/types/parseOptionSetsToFolderStructure.d.ts +10 -0
  68. package/dist/commands/types/parseOptionSetsToFolderStructure.js +104 -0
  69. package/dist/commands/types/parseTypesFromFiles.d.ts +10 -0
  70. package/dist/commands/types/parseTypesFromFiles.js +34 -0
  71. package/dist/commands/types/parseTypesFromLocalFiles.d.ts +10 -0
  72. package/dist/commands/types/parseTypesFromLocalFiles.js +34 -0
  73. package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.d.ts +11 -0
  74. package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.js +36 -0
  75. package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.d.ts +10 -0
  76. package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.js +35 -0
  77. package/dist/commands/types/uploadOptionSetHierarchies.d.ts +7 -0
  78. package/{lib/types/option-set-hierarchy-uploader.js → dist/commands/types/uploadOptionSetHierarchies.js} +130 -113
  79. package/dist/commands/types/uploadOptionSets.d.ts +7 -0
  80. package/{lib/types/option-set-uploader.js → dist/commands/types/uploadOptionSets.js} +115 -98
  81. package/dist/commands/types/uploadOptionSetsHierarchyLocalFile.d.ts +11 -0
  82. package/{lib/types/option-set-hierarchy-parser.js → dist/commands/types/uploadOptionSetsHierarchyLocalFile.js} +128 -140
  83. package/dist/commands/types/uploadRuleSets.d.ts +7 -0
  84. package/{lib/types/rule-set-uploader.js → dist/commands/types/uploadRuleSets.js} +189 -172
  85. package/dist/commands/types/uploadTypePropertyPolicies.d.ts +7 -0
  86. package/{lib/types/type-property-policy-uploader.js → dist/commands/types/uploadTypePropertyPolicies.js} +195 -178
  87. package/dist/commands/types/uploadUsageInfo.d.ts +7 -0
  88. package/{lib/types/usage-info-uploader.js → dist/commands/types/uploadUsageInfo.js} +149 -132
  89. package/dist/commands/users/export.d.ts +9 -0
  90. package/dist/commands/users/export.js +60 -0
  91. package/dist/commands/users/upload.d.ts +9 -0
  92. package/dist/commands/users/upload.js +65 -0
  93. package/dist/commands/workflow-template-definitions/install.d.ts +6 -0
  94. package/dist/commands/workflow-template-definitions/install.js +17 -0
  95. package/dist/commands/workflow-template-definitions/list.d.ts +6 -0
  96. package/dist/commands/workflow-template-definitions/list.js +17 -0
  97. package/dist/commands/workflow-templates/delete.d.ts +6 -0
  98. package/dist/commands/workflow-templates/delete.js +17 -0
  99. package/dist/commands/workflow-templates/list.d.ts +6 -0
  100. package/dist/commands/workflow-templates/list.js +17 -0
  101. package/dist/commands/workflow-templates/load.d.ts +9 -0
  102. package/dist/commands/workflow-templates/load.js +21 -0
  103. package/{lib → dist}/common.d.ts +1 -1
  104. package/dist/common.js +9 -0
  105. package/{lib/apps/deploy-app → dist/helpers/app}/actions-deployer.d.ts +11 -11
  106. package/{lib/apps/deploy-app → dist/helpers/app}/actions-deployer.js +122 -114
  107. package/{lib/apps/deploy-app → dist/helpers/app}/app-deployer.d.ts +8 -8
  108. package/{lib/apps/deploy-app → dist/helpers/app}/app-deployer.js +98 -93
  109. package/{lib/apps/deploy-app → dist/helpers/app}/app-template-parsers.d.ts +7 -7
  110. package/{lib/apps/deploy-app → dist/helpers/app}/app-template-parsers.js +43 -38
  111. package/dist/helpers/app/load-app-config.d.ts +1 -0
  112. package/dist/helpers/app/load-app-config.js +18 -0
  113. package/dist/helpers/app/setup-template.d.ts +1 -0
  114. package/dist/helpers/app/setup-template.js +38 -0
  115. package/dist/helpers/colors/helpers.d.ts +4 -0
  116. package/dist/helpers/colors/helpers.js +74 -0
  117. package/{lib → dist/helpers}/config/config.d.ts +6 -6
  118. package/dist/helpers/config/config.js +76 -0
  119. package/dist/helpers/loader-process/helpers.d.ts +2 -0
  120. package/{lib/loader-process/loader-process.js → dist/helpers/loader-process/helpers.js} +98 -120
  121. package/dist/helpers/projects/helpers.d.ts +2 -0
  122. package/{lib/projects/project-exporter.js → dist/helpers/projects/helpers.js} +165 -187
  123. package/{lib → dist/helpers}/types/csv-parser.d.ts +1 -1
  124. package/{lib → dist/helpers}/types/csv-parser.js +56 -51
  125. package/dist/helpers/types/type-extractor.d.ts +1 -0
  126. package/dist/helpers/types/type-extractor.js +32 -0
  127. package/dist/helpers/types/type-parser.d.ts +4 -0
  128. package/dist/helpers/types/type-parser.js +118 -0
  129. package/{lib/types/types-uploader.d.ts → dist/helpers/types/type-uploader.d.ts} +1 -1
  130. package/{lib/types/types-uploader.js → dist/helpers/types/type-uploader.js} +244 -239
  131. package/{lib → dist/helpers}/workflow-template-definitions/workflow-template-definition-deployer.d.ts +12 -12
  132. package/{lib → dist/helpers}/workflow-template-definitions/workflow-template-definition-deployer.js +156 -151
  133. package/{lib/workflow-templates/local-workflow-template-deployer.d.ts → dist/helpers/workflow-templates/helper.d.ts} +17 -11
  134. package/dist/helpers/workflow-templates/helper.js +166 -0
  135. package/dist/index.d.ts +1 -0
  136. package/dist/index.js +5 -0
  137. package/{lib → dist}/interfaces.d.ts +323 -191
  138. package/dist/interfaces.js +63 -0
  139. package/{templates → dist/templates}/typescript/Dockerfile +15 -15
  140. package/{templates → dist/templates}/typescript/README.md +10 -10
  141. package/{templates → dist/templates}/typescript/app.yml +49 -49
  142. package/{templates → dist/templates}/typescript/docker_deploy.bat +1 -1
  143. package/{templates → dist/templates}/typescript/package.json +54 -54
  144. package/{templates → dist/templates}/typescript/src/actions/logItem.ts +25 -25
  145. package/{templates → dist/templates}/typescript/src/framework/action-dispatcher.ts +89 -89
  146. package/{templates → dist/templates}/typescript/src/framework/app-config.ts +26 -26
  147. package/{templates → dist/templates}/typescript/src/framework/handler.ts +11 -11
  148. package/{templates → dist/templates}/typescript/src/framework/index.ts +2 -2
  149. package/{templates → dist/templates}/typescript/src/framework/interfaces.ts +32 -32
  150. package/{templates → dist/templates}/typescript/src/framework/logger.ts +21 -21
  151. package/{templates → dist/templates}/typescript/src/framework/mock-server.ts +31 -31
  152. package/{templates → dist/templates}/typescript/tsconfig.json +28 -28
  153. package/oclif.manifest.json +821 -0
  154. package/package.json +116 -72
  155. package/.eslintrc.js +0 -53
  156. package/.vscode/settings.json +0 -6
  157. package/bin/init +0 -4
  158. package/lib/api/apps.js +0 -85
  159. package/lib/api/event-workflow-action-definition.js +0 -7
  160. package/lib/api/event-workflow-template-definition.js +0 -20
  161. package/lib/api/event-workflow-templates.js +0 -25
  162. package/lib/apps/create-app/create.d.ts +0 -1
  163. package/lib/apps/create-app/create.js +0 -60
  164. package/lib/apps/create-app/setup-template.d.ts +0 -1
  165. package/lib/apps/create-app/setup-template.js +0 -34
  166. package/lib/apps/deploy-app/deploy.d.ts +0 -2
  167. package/lib/apps/deploy-app/deploy.js +0 -58
  168. package/lib/apps/install-app/app-installer.d.ts +0 -2
  169. package/lib/apps/install-app/app-installer.js +0 -120
  170. package/lib/apps/upgrade-app/app-upgrader.d.ts +0 -3
  171. package/lib/apps/upgrade-app/app-upgrader.js +0 -126
  172. package/lib/auth/auth.js +0 -2
  173. package/lib/cli.d.ts +0 -5
  174. package/lib/cli.js +0 -524
  175. package/lib/colors/color-loader.d.ts +0 -2
  176. package/lib/colors/color-loader.js +0 -96
  177. package/lib/common.js +0 -5
  178. package/lib/config/config.js +0 -70
  179. package/lib/config/configCommands.d.ts +0 -3
  180. package/lib/config/configCommands.js +0 -34
  181. package/lib/interfaces.js +0 -25
  182. package/lib/loader-process/loader-process.d.ts +0 -2
  183. package/lib/projects/interfaces.d.ts +0 -77
  184. package/lib/projects/interfaces.js +0 -23
  185. package/lib/projects/project-exporter.d.ts +0 -2
  186. package/lib/projects/project-uploader.d.ts +0 -1
  187. package/lib/types/allUploader.d.ts +0 -1
  188. package/lib/types/allUploader.js +0 -24
  189. package/lib/types/interfaces.d.ts +0 -55
  190. package/lib/types/interfaces.js +0 -1
  191. package/lib/types/option-set-hierarchy-exporter.d.ts +0 -1
  192. package/lib/types/option-set-hierarchy-parser.d.ts +0 -2
  193. package/lib/types/option-set-hierarchy-uploader.d.ts +0 -1
  194. package/lib/types/option-set-merger.d.ts +0 -1
  195. package/lib/types/option-set-parser.d.ts +0 -3
  196. package/lib/types/option-set-parser.js +0 -140
  197. package/lib/types/option-set-uploader.d.ts +0 -1
  198. package/lib/types/parse-types.d.ts +0 -4
  199. package/lib/types/parse-types.js +0 -189
  200. package/lib/types/rule-set-uploader.d.ts +0 -1
  201. package/lib/types/type-property-policy-uploader.d.ts +0 -1
  202. package/lib/types/types-properties-merger.d.ts +0 -1
  203. package/lib/types/types-properties-merger.js +0 -75
  204. package/lib/types/usage-info-uploader.d.ts +0 -1
  205. package/lib/users/user-exporter.d.ts +0 -1
  206. package/lib/users/user-exporter.js +0 -41
  207. package/lib/users/user-uploader.d.ts +0 -1
  208. package/lib/users/user-uploader.js +0 -45
  209. package/lib/workflow-template-definitions/workflow-template-definition-commands.d.ts +0 -2
  210. package/lib/workflow-template-definitions/workflow-template-definition-commands.js +0 -10
  211. package/lib/workflow-templates/local-workflow-template-deployer.js +0 -102
  212. package/lib/workflow-templates/workflow-template-commands.d.ts +0 -4
  213. package/lib/workflow-templates/workflow-template-commands.js +0 -51
  214. package/lib/workflow-templates/workflow-template-deployer.d.ts +0 -4
  215. package/lib/workflow-templates/workflow-template-deployer.js +0 -26
  216. package/publish.bat +0 -5
  217. package/publish.sh +0 -5
  218. package/src/api/apps.ts +0 -97
  219. package/src/api/event-workflow-action-definition.ts +0 -8
  220. package/src/api/event-workflow-template-definition.ts +0 -23
  221. package/src/api/event-workflow-templates.ts +0 -29
  222. package/src/apps/create-app/create.ts +0 -74
  223. package/src/apps/create-app/setup-template.ts +0 -38
  224. package/src/apps/deploy-app/actions-deployer.ts +0 -140
  225. package/src/apps/deploy-app/app-deployer.ts +0 -105
  226. package/src/apps/deploy-app/app-template-parsers.ts +0 -44
  227. package/src/apps/deploy-app/deploy.ts +0 -66
  228. package/src/apps/install-app/app-installer.ts +0 -126
  229. package/src/apps/upgrade-app/app-upgrader.ts +0 -132
  230. package/src/auth/auth.ts +0 -10
  231. package/src/auth/login.ts +0 -155
  232. package/src/cli.ts +0 -540
  233. package/src/colors/color-loader.ts +0 -112
  234. package/src/colors/colors.csv +0 -866
  235. package/src/common.ts +0 -5
  236. package/src/config/config.ts +0 -74
  237. package/src/config/configCommands.ts +0 -38
  238. package/src/interfaces.ts +0 -200
  239. package/src/loader-process/loader-process.ts +0 -152
  240. package/src/projects/interfaces.ts +0 -73
  241. package/src/projects/project-exporter.ts +0 -225
  242. package/src/projects/project-uploader.ts +0 -131
  243. package/src/types/allUploader.ts +0 -28
  244. package/src/types/csv-parser.ts +0 -59
  245. package/src/types/interfaces.ts +0 -58
  246. package/src/types/option-set-hierarchy-exporter.ts +0 -125
  247. package/src/types/option-set-hierarchy-parser.ts +0 -169
  248. package/src/types/option-set-hierarchy-uploader.ts +0 -122
  249. package/src/types/option-set-merger.ts +0 -124
  250. package/src/types/option-set-parser.ts +0 -166
  251. package/src/types/option-set-uploader.ts +0 -108
  252. package/src/types/parse-types.ts +0 -227
  253. package/src/types/rule-set-uploader.ts +0 -187
  254. package/src/types/type-property-policy-uploader.ts +0 -192
  255. package/src/types/types-extractor.ts +0 -369
  256. package/src/types/types-properties-merger.ts +0 -90
  257. package/src/types/types-uploader.ts +0 -271
  258. package/src/types/usage-info-uploader.ts +0 -139
  259. package/src/users/user-exporter.ts +0 -52
  260. package/src/users/user-uploader.ts +0 -58
  261. package/src/workflow-template-definitions/workflow-template-definition-commands.ts +0 -13
  262. package/src/workflow-template-definitions/workflow-template-definition-deployer.ts +0 -184
  263. package/src/workflow-templates/local-workflow-template-deployer.ts +0 -126
  264. package/src/workflow-templates/workflow-template-commands.ts +0 -59
  265. package/src/workflow-templates/workflow-template-deployer.ts +0 -30
  266. package/templates/javascript/actions/example/action.js +0 -38
  267. package/templates/javascript/app.yml +0 -53
  268. package/templates/javascript/package.json +0 -23
  269. package/templates/typescript/package-lock.json +0 -14
  270. package/tsconfig.json +0 -32
@@ -1,140 +0,0 @@
1
- import { Entities } from '@contrail/sdk';
2
- import chalk from 'chalk';
3
- import { App, AppDeclaration, AppActionDeclaration, EventWorkflowActionDefinition } from '../../interfaces';
4
- import { ConfigPropertiesParser } from './app-template-parsers';
5
- import { getSeparatorByPlatform } from '../../common';
6
-
7
- import fs from 'fs';
8
-
9
- export async function getActionsForApp(app: App) {
10
- return await new Entities().get({
11
- entityName: 'event-workflow-action-definition',
12
- criteria: { ownerKey: `app:${app.id}` },
13
- });
14
- }
15
-
16
- export function getActionDeclarationIdentifier(actionKey, app: App) {
17
- return app.identifier + ':' + actionKey;
18
- }
19
-
20
- export async function deleteAction(actionId): Promise<any> {
21
- return await new Entities().delete({ entityName: 'event-workflow-action-definition', id: actionId });
22
- }
23
-
24
- export class ActionsDeployer {
25
-
26
- async deployActions(appDeclaration: AppDeclaration, app: App) {
27
-
28
- // FETCH ALL ACTIONS FROM THE API.
29
- const existingActions = await getActionsForApp(app);
30
-
31
- // UPSERT / DELETE BASED ON ACTION IDENTIFIER
32
- console.log('%s \tDeploying actions.', chalk.yellow.bold('ACTION'));
33
- let appActionIdentifiers = [];
34
- if (appDeclaration.actions) {
35
- const localActionKeys = Object.keys(appDeclaration.actions);
36
- appActionIdentifiers = localActionKeys.map(x => getActionDeclarationIdentifier(x, app));
37
- if (localActionKeys?.length > 0) {
38
- for (const actionKey of localActionKeys) {
39
- await this.deployAction(actionKey, appDeclaration.actions[actionKey], app, existingActions);
40
- }
41
- }
42
- }
43
- const toDelete = existingActions.filter(x => !appActionIdentifiers.includes(x.identifier));
44
- for (const action of toDelete) {
45
- console.log(`%s \tDeleting action: ${action.identifier}`, chalk.yellow.bold('ACTION'));
46
- await deleteAction(action.id);
47
- }
48
- }
49
-
50
- async deployAction(actionKey: string, actionDeclaration: AppActionDeclaration, app: App, existingActions: Array<any>) {
51
- console.log(`%s \tDeploying action: ${actionKey}`, chalk.yellow.bold('ACTION'));
52
-
53
- const identifier = getActionDeclarationIdentifier(actionKey, app);
54
- const existingDefinition = existingActions.find(ad => ad.identifier === identifier);
55
-
56
- if (!existingDefinition) {
57
- await this.createNewActionDefinition(actionKey, actionDeclaration, app);
58
- } else {
59
- await this.updateActionDefinition(existingDefinition, actionDeclaration, app);
60
- }
61
- }
62
-
63
- private async createNewActionDefinition(actionKey: string, actionDeclaration: AppActionDeclaration, app: App) {
64
- let configProperties;
65
- if (actionDeclaration?.actionConfiguration) {
66
- configProperties = ConfigPropertiesParser.getConfigProperties(actionDeclaration.actionConfiguration);
67
- }
68
- const newObject: EventWorkflowActionDefinition = {
69
- identifier: getActionDeclarationIdentifier(actionKey, app),
70
- name: actionDeclaration.name,
71
- ownerKey: `app:${app.id}`,
72
- public: 'public' in actionDeclaration ? actionDeclaration.public : app.public,
73
- configProperties,
74
- async: actionDeclaration.async,
75
- };
76
-
77
- const functionString = await this.getFunction(actionDeclaration);
78
- if (functionString) {
79
- newObject.executeFunctionString = functionString;
80
- }
81
-
82
- const actionDefinition = await new Entities().create({
83
- entityName: 'event-workflow-action-definition',
84
- object: newObject,
85
- });
86
-
87
- console.log(`%s Created new action definition: ${actionKey}`, chalk.yellow.bold('APP'));
88
-
89
- return actionDefinition;
90
- }
91
-
92
- private async updateActionDefinition(existingActionDefinition: EventWorkflowActionDefinition, actionDeclaration: AppActionDeclaration, app: App) {
93
-
94
- let configProperties;
95
- if (actionDeclaration?.actionConfiguration) {
96
- configProperties = ConfigPropertiesParser.getConfigProperties(actionDeclaration.actionConfiguration);
97
- }
98
- else if (!actionDeclaration?.actionConfiguration && existingActionDefinition.configProperties) {
99
- configProperties = null;
100
- }
101
-
102
- const updates: EventWorkflowActionDefinition = {
103
- name: actionDeclaration.name,
104
- public: 'public' in actionDeclaration ? actionDeclaration.public : app.public,
105
- configProperties,
106
- async: actionDeclaration.async,
107
- };
108
-
109
- const functionString = await this.getFunction(actionDeclaration);
110
- if (functionString) {
111
- updates.executeFunctionString = functionString;
112
- }
113
-
114
- const actionDefinition = await new Entities().update({
115
- entityName: 'event-workflow-action-definition',
116
- id: existingActionDefinition.id,
117
- object: updates,
118
- });
119
-
120
- console.log(`%s Updated existing action definition: ${actionDefinition.identifier}`, chalk.yellow.bold('APP'));
121
-
122
- return actionDefinition;
123
- }
124
-
125
- async getFunction(actionDeclaration: AppActionDeclaration): Promise<string> {
126
- if (!actionDeclaration.handler) {
127
- return;
128
- }
129
-
130
- if (!actionDeclaration.handler.endsWith('.js')) {
131
- throw new Error('Action handler must be a .js file.');
132
- }
133
- const CURRENT_DIR = process.cwd();
134
- const separator = getSeparatorByPlatform();
135
-
136
- const functionLocation = CURRENT_DIR + separator + actionDeclaration.handler;
137
- const content = fs.readFileSync(functionLocation);
138
- return content.toString();
139
- }
140
- }
@@ -1,105 +0,0 @@
1
- import { Entities } from '@contrail/sdk';
2
- import chalk from 'chalk';
3
- import { Auth } from '../../auth/auth';
4
- import { ActionsDeployer, getActionsForApp, deleteAction } from './actions-deployer';
5
- import { App, AppDeclaration } from '../../interfaces';
6
- import { TriggerKeyDefinitionParser, ConfigPropertiesParser } from './app-template-parsers';
7
- import { WorkflowTemplateDefinitionDeployer } from '../../workflow-template-definitions/workflow-template-definition-deployer';
8
- import { getAllAvailableApps } from '../../api/apps';
9
-
10
- export class AppDeployer {
11
- public async deploy(appDeclaration: AppDeclaration) {
12
- let app = await this.getExistingApp(appDeclaration);
13
- if (!app) {
14
- console.log('%s Creating new app.', chalk.yellow.bold('APP'));
15
- app = await this.createNewApp(appDeclaration);
16
- } else {
17
- console.log('%s Updating existing app.', chalk.yellow.bold('APP'));
18
- app = await this.updateExistingApp(appDeclaration, app);
19
- }
20
- await new ActionsDeployer().deployActions(appDeclaration, app);
21
- await new WorkflowTemplateDefinitionDeployer().deployWorkflowTemplateDefinitions(appDeclaration, app);
22
- }
23
-
24
- public async getExistingApp(appDeclaration: AppDeclaration): Promise<App> {
25
- const orgId = Auth.config.orgId;
26
- const apps = await getAllAvailableApps({orgId});
27
- return apps.find(app => app.identifier === appDeclaration.appIdentifier);
28
- }
29
-
30
- private async createNewApp(appDeclaration: AppDeclaration) {
31
-
32
- let configProperties;
33
- if (appDeclaration?.appConfiguration) {
34
- configProperties = ConfigPropertiesParser.getConfigProperties(appDeclaration.appConfiguration);
35
- }
36
-
37
- let triggerKeyDefinitions;
38
- if (appDeclaration?.triggers) {
39
- triggerKeyDefinitions = TriggerKeyDefinitionParser.buildTriggersArray(appDeclaration);
40
- }
41
-
42
- const newApp = {
43
- identifier: appDeclaration.appIdentifier,
44
- name: appDeclaration.appName,
45
- public: appDeclaration.visibility === 'public',
46
- description: appDeclaration.appDescription,
47
- publisher: appDeclaration.publisher,
48
- thumbnail: appDeclaration.thumbnail,
49
- eventWorkflowTriggerKeyMapping: appDeclaration.eventWorkflowTriggerKeyMapping,
50
- keywords: appDeclaration.keywords,
51
- configProperties,
52
- triggerKeyDefinitions,
53
- dockerImageRef: appDeclaration.dockerImageRef,
54
- };
55
- const app = await new Entities().create({ entityName: 'app', object: newApp });
56
- console.log(`%s Created new app: ${app.name}`, chalk.yellow.bold('APP'));
57
- return app;
58
- }
59
-
60
- public async updateExistingApp(appDeclaration: AppDeclaration, existingApp) {
61
-
62
- let configProperties;
63
- if (appDeclaration?.appConfiguration) {
64
- configProperties = ConfigPropertiesParser.getConfigProperties(appDeclaration.appConfiguration);
65
- }
66
-
67
- let triggerKeyDefinitions;
68
- if (appDeclaration?.triggers) {
69
- triggerKeyDefinitions = TriggerKeyDefinitionParser.buildTriggersArray(appDeclaration);
70
- }
71
-
72
- const updates = {
73
- name: appDeclaration.appName,
74
- public: appDeclaration.visibility === 'public',
75
- description: appDeclaration.appDescription,
76
- publisher: appDeclaration.publisher,
77
- thumbnail: appDeclaration.thumbnail,
78
- eventWorkflowTriggerKeyMapping: appDeclaration.eventWorkflowTriggerKeyMapping,
79
- keywords: appDeclaration.keywords,
80
- configProperties,
81
- triggerKeyDefinitions,
82
- dockerImageRef: appDeclaration.dockerImageRef,
83
- };
84
- const app = await new Entities().update({ entityName: 'app', id: existingApp.id, object: updates });
85
- console.log(`%s Updated app: ${app.name}`, chalk.yellow.bold('APP'));
86
- return app;
87
- }
88
-
89
- public async remove(appDeclaration: AppDeclaration) {
90
- let app = await this.getExistingApp(appDeclaration);
91
- if (app) {
92
- const actions = await getActionsForApp(app);
93
- for(const action of actions)
94
- {
95
- console.log(`%s Deleting action: ${action.identifier}`, chalk.yellow.bold('APP'));
96
- await deleteAction(action.id);
97
- }
98
- app = await new Entities().delete({ entityName: 'app', id: app.id });
99
- console.log(`%s Deleted app: ${app.name}`, chalk.yellow.bold('APP'));
100
- } else {
101
- throw new Error('App not found.');
102
- }
103
- }
104
-
105
- }
@@ -1,44 +0,0 @@
1
- import { AppDeclaration, TriggerKeyDefinition, ConfigPropertyElements } from '../../interfaces';
2
-
3
- export class TriggerKeyDefinitionParser {
4
- public static buildTriggersArray(appDeclaration: AppDeclaration): Array<TriggerKeyDefinition> {
5
- const triggers: Array<TriggerKeyDefinition> = [];
6
-
7
- for (const triggerName of Object.keys(appDeclaration.triggers)) {
8
- const triggerDeclaration = appDeclaration.triggers[triggerName];
9
-
10
- const triggerDefinition = {
11
- triggerKey: triggerDeclaration.external ? `${appDeclaration.appIdentifier}:${triggerDeclaration.key}` : triggerDeclaration.key,
12
- name: triggerDeclaration.name,
13
- external: triggerDeclaration.external,
14
- description: triggerDeclaration.description,
15
- };
16
- if (!triggerDefinition.triggerKey || !triggerDefinition.name) {
17
- throw new Error('Illegal trigger declaration: must have key and name');
18
- }
19
- triggers.push(triggerDefinition);
20
-
21
- }
22
- return triggers;
23
- }
24
- }
25
-
26
- export class ConfigPropertiesParser {
27
- public static getConfigProperties(configPropertyElements: ConfigPropertyElements) {
28
- const appConfiguration = [];
29
- for (const configKey of Object.keys(configPropertyElements)) {
30
- const declaration = configPropertyElements[configKey];
31
- const config: any = {
32
- label: declaration.label,
33
- slug: configKey,
34
- propertyType: declaration.propertyType, // TODO should support options
35
- dynamic: declaration?.dynamic || false,
36
- };
37
- if (declaration.options) {
38
- config.options = declaration.options;
39
- }
40
- appConfiguration.push(config);
41
- }
42
- return appConfiguration;
43
- }
44
- }
@@ -1,66 +0,0 @@
1
- import chalk from 'chalk';
2
- import fs from 'fs';
3
- import { authUser } from '../../auth/login';
4
- import { AppDeployer } from './app-deployer';
5
- import { AppDeclaration } from '../../interfaces';
6
- import { getSeparatorByPlatform } from '../../common';
7
- const yaml = require('js-yaml');
8
-
9
- function loadAppConfig(){
10
- const TARGET_DIR = process.cwd();
11
- try {
12
- const separator = getSeparatorByPlatform();
13
- const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + 'app.yml', 'utf8'));
14
- console.log(doc);
15
- return doc;
16
- } catch (e) {
17
- throw new Error(`ERROR PARSING YAML: ${e}`);
18
- }
19
- }
20
-
21
- export async function deployApp(args) {
22
- let appDeclaration: AppDeclaration;
23
- try {
24
- appDeclaration = loadAppConfig();
25
- }
26
- catch (e) {
27
- console.log(`%s Application Deployment Failed. ${e}`, chalk.red.bold('FAIL'));
28
- return;
29
- }
30
-
31
- console.log(`%s Deploying Application. ${appDeclaration.appIdentifier}`, chalk.blue.bold('START'));
32
- try {
33
- await authUser();
34
- await new AppDeployer().deploy(appDeclaration);
35
- }
36
- catch (e) {
37
- console.log(`%s Application Deployment Failed. ${e}`, chalk.red.bold('FAIL'));
38
- return;
39
- }
40
-
41
- console.log('%s Deployment Complete.', chalk.green.bold('COMPLETE'));
42
- }
43
-
44
- export async function removeApp(args) {
45
- let appDeclaration: AppDeclaration;
46
- try {
47
- appDeclaration = loadAppConfig();
48
- }
49
- catch (e) {
50
- console.log(`%s Application Removal Failed. ${e}`, chalk.red.bold('FAIL'));
51
- return;
52
- }
53
-
54
- console.log(`%s Removing Application. ${appDeclaration.appIdentifier}`, chalk.blue.bold('START'));
55
-
56
- try {
57
- await authUser();
58
- await new AppDeployer().remove(appDeclaration);
59
- }
60
- catch (e) {
61
- console.log(`%s Application Removal Failed. ${e}`, chalk.red.bold('FAIL'));
62
- return;
63
- }
64
-
65
- console.log('%s Application Removal Complete.', chalk.green.bold('COMPLETE'));
66
- }
@@ -1,126 +0,0 @@
1
- import inquirer from 'inquirer';
2
- import chalk from 'chalk';
3
- import { Entities } from '@contrail/sdk';
4
- import { authUser } from '../../auth/login';
5
- import { deleteAppOrg, getAvailableApps, getInstalledApps, getWorkflowTemplateDefinitionsForApp, installAppToOrg } from '../../api/apps';
6
- import { App } from '../../interfaces';
7
- import { WorkflowTemplateDefinitionDeployer } from '../../workflow-template-definitions/workflow-template-definition-deployer';
8
-
9
- async function getConfigProperties(app) {
10
- const config = {};
11
- for (const key of Object.keys(app.configProperties)) {
12
- const slug = app.configProperties[key]['slug'];
13
- const name = app.configProperties[key]['label'];
14
- const type = app.configProperties[key]['propertyType'];
15
- const questions = [];
16
- questions.push({
17
- type: 'input',
18
- name: 'configAnswer',
19
- message: `[App config] ${name} (${type}):`,
20
- });
21
- const answers = await inquirer.prompt(questions);
22
- config[slug] = answers.configAnswer;
23
- }
24
- return config;
25
- }
26
- export async function uninstallApp() {
27
- await authUser();
28
- const installedApps = await getInstalledApps();
29
- const answers = await inquirer.prompt([{
30
- type: 'list',
31
- name: 'appIdentifier',
32
- message: 'Which app would you like to uninstall?',
33
- choices: installedApps.map(x => x.app.identifier)
34
- }]);
35
- const appToDelete = installedApps.find(x => x.app.identifier === answers.appIdentifier);
36
- console.log('%s Uninstalling app', chalk.green.bold('APP INSTALLATION'));
37
- await deleteAppOrg(appToDelete.id);
38
- // eslint-disable-next-line no-constant-condition
39
- while (true) {
40
- await delay(1000);
41
- try {
42
- const appStillDeleting = await new Entities().get({ entityName: 'app-org', id: appToDelete.id });
43
- if (!appStillDeleting) {
44
- break;
45
- }
46
- process.stdout.write('.');
47
- } catch (e) {
48
- console.log('Error is:', e);
49
- break;
50
- }
51
- }
52
- console.log('%s App Uninstalled', chalk.green.bold('APP INSTALLATION'));
53
- }
54
-
55
- export async function installApp() {
56
- await authUser();
57
- const apps: App[] = await getAvailableApps();
58
- if (!apps.length) {
59
- throw new Error('No apps are available to install...');
60
- }
61
- const installedApps = await getInstalledApps();
62
- const installedAppsIds = installedApps.map(x => x.app.id);
63
- const installableApps = apps.filter(x => !installedAppsIds.includes(x.id));
64
- console.log(chalk.yellow.bold('Installed Apps:'));
65
- for (const appOrg of installedApps) {
66
- console.log(chalk.yellow.bold(`${appOrg.app.name}: ${appOrg.app.identifier}`));
67
- }
68
- const questions = [];
69
- questions.push({
70
- type: 'list',
71
- name: 'appIdentifier',
72
- message: 'Which app would you like to install?',
73
- choices: installableApps.map(x => x.identifier)
74
- });
75
- let answers = await inquirer.prompt(questions);
76
- const app = installableApps.find(x => x.identifier === answers.appIdentifier);
77
- let configProperties: any;
78
- if (app.configProperties) {
79
- configProperties = await getConfigProperties(app);
80
- }
81
- console.log('%s Installing apps', chalk.green.bold('APP INSTALLATION'));
82
-
83
- const appOrg = await installAppToOrg(app, configProperties);
84
- // eslint-disable-next-line no-constant-condition
85
- while (true) {
86
- await delay(1000);
87
- try {
88
- const installingApp = await new Entities().get({ entityName: 'app-org', id: appOrg.id });
89
- if (installingApp.status === 'READY') {
90
- console.log('%s App installed', chalk.green.bold('APP INSTALLATION'));
91
- break;
92
- }
93
- if (installingApp.status === 'FAILED_INSTALLING') {
94
- console.log('%s App installation failed', chalk.red.bold('APP INSTALLATION'));
95
- return;
96
- }
97
- process.stdout.write('.');
98
- } catch (e) {
99
- console.log('%s App installation failed', chalk.red.bold('APP INSTALLATION'));
100
- console.log('Error is:', e);
101
- return;
102
- }
103
- }
104
-
105
- const workflowTemplateDefinitions = await getWorkflowTemplateDefinitionsForApp({ appId: app.id });
106
- if (!workflowTemplateDefinitions.length) {
107
- return;
108
- }
109
- answers = await inquirer.prompt([{
110
- type: 'confirm',
111
- name: 'shouldInstallWorkflows',
112
- message: 'Would you like to install the Workflows associated with this app?',
113
- default: false
114
- }]);
115
-
116
- if (!answers.shouldInstallWorkflows) {
117
- console.log('%s Not installing associated app workflows', chalk.yellow.bold('APP INSTALLATION'));
118
- return;
119
- }
120
-
121
- new WorkflowTemplateDefinitionDeployer().installWorkflowTemplateDefinitions(workflowTemplateDefinitions);
122
- }
123
-
124
- function delay(ms: number) {
125
- return new Promise(resolve => setTimeout(resolve, ms));
126
- }
@@ -1,132 +0,0 @@
1
- import inquirer from 'inquirer';
2
- import chalk from 'chalk';
3
- import { Entities } from '@contrail/sdk';
4
- import { authUser } from '../../auth/login';
5
- import { deleteAppOrg, getAppVersions, getAvailableApps, getInstalledApps, installAppToOrg, upgradeAppVersion } from '../../api/apps';
6
-
7
- async function getConfigProperties(app) {
8
- const config = {};
9
- for (const key of Object.keys(app.configProperties)) {
10
- const slug = app.configProperties[key]['slug'];
11
- const name = app.configProperties[key]['label'];
12
- const type = app.configProperties[key]['propertyType'];
13
- const questions = [];
14
- questions.push({
15
- type: 'input',
16
- name: 'configAnswer',
17
- message: `[App config] ${name} (${type}):`,
18
- });
19
- const answers = await inquirer.prompt(questions);
20
- config[slug] = answers.configAnswer;
21
- }
22
- return config;
23
- }
24
-
25
- export async function uninstallApp() {
26
- await authUser();
27
- const installedApps = await getInstalledApps();
28
- const answers = await inquirer.prompt([{
29
- type: 'list',
30
- name: 'appIdentifier',
31
- message: 'Which app would you like to uninstall?',
32
- choices: installedApps.map(x => x.app.identifier)
33
- }]);
34
- const appToDelete = installedApps.find(x => x.app.identifier === answers.appIdentifier);
35
- console.log('%s Uninstalling app', chalk.green.bold('APP INSTALLATION'));
36
- await deleteAppOrg(appToDelete.id);
37
- // eslint-disable-next-line no-constant-condition
38
- while (true) {
39
- await delay(1000);
40
- try {
41
- const appStillDeleting = await new Entities().get({ entityName: 'app-org', id: appToDelete.id });
42
- if (!appStillDeleting) {
43
- break;
44
- }
45
- process.stdout.write('.');
46
- } catch (e) {
47
- console.log('Error is:', e);
48
- break;
49
- }
50
- }
51
- console.log('%s App Uninstalled', chalk.green.bold('APP INSTALLATION'));
52
- }
53
-
54
- export async function upgradeApp() {
55
- await authUser();
56
- const allApps = await getAvailableApps();
57
- const installedApps = await getInstalledApps();
58
- let answers = await inquirer.prompt([{
59
- type: 'list',
60
- name: 'appIdentifier',
61
- message: 'Which app would you like to upgrade?',
62
- choices: installedApps.map(x => x.app.identifier)
63
- }]);
64
- const appOrgToUpgrade = installedApps.find(x => x.app.identifier === answers.appIdentifier);
65
- const appToUpgrade = allApps.find(x => x.identifier === answers.appIdentifier);
66
- const versions = await getAppVersions(appToUpgrade);
67
- answers = await inquirer.prompt([{
68
- type: 'list',
69
- name: 'appVersion',
70
- message: 'Which app version would you like to upgrade to?',
71
- choices: versions.map(x => {
72
- const number = x.versionNumber.toString().padStart(4, '0');
73
- const name = x.id === appOrgToUpgrade.appVersionId ? `${number} (${x.createdOn}) (current)` : `${number} (${x.createdOn})`;
74
- return {
75
- value: x.id, name
76
- };
77
- }).sort((x, y) => { return x.name > y.name ? -1 : 1; })
78
- }]);
79
-
80
- console.log(`%s Upgrading app to version ${answers.appVersion}`, chalk.green.bold('APP INSTALLATION'));
81
- await upgradeAppVersion(appOrgToUpgrade, answers.appVersion);
82
- // eslint-disable-next-line no-constant-condition
83
- while (true) {
84
- await delay(1000);
85
- const appStillUpgrading = await new Entities().get({ entityName: 'app-org', id: appOrgToUpgrade.id });
86
- if (appStillUpgrading.status === 'READY') {
87
- console.log('%s App Upgraded', chalk.green.bold('APP INSTALLATION'));
88
- return;
89
- }
90
- if (appStillUpgrading.status === 'FAILED_INSTALLING') {
91
- console.log('%s App Upgrade FAILED!', chalk.red.bold('APP INSTALLATION'));
92
- return;
93
- }
94
- console.log('checking app status...');
95
- }
96
- }
97
-
98
- export async function installApp() {
99
- await authUser();
100
- const apps = await getAvailableApps();
101
- if (!apps.length) {
102
- throw new Error('No apps are available to install...');
103
- }
104
- const installedApps = await getInstalledApps();
105
- const installedAppsIds = installedApps.map(x => x.app.id);
106
- const installableApps = apps.filter(x => !installedAppsIds.includes(x.id));
107
- console.log(chalk.yellow.bold('Installed Apps:'));
108
- for (const appOrg of installedApps) {
109
- console.log(chalk.yellow.bold(`${appOrg.app.name}: ${appOrg.app.identifier}`));
110
- }
111
- const questions = [];
112
- questions.push({
113
- type: 'list',
114
- name: 'appIdentifier',
115
- message: 'Which app would you like to install?',
116
- choices: installableApps.map(x => x.identifier)
117
- });
118
- const answers = await inquirer.prompt(questions);
119
- const app = installableApps.find(x => x.identifier === answers.appIdentifier);
120
- let configProperties: any;
121
- if (app.configProperties) {
122
- configProperties = await getConfigProperties(app);
123
- }
124
- console.log('%s Installing apps', chalk.green.bold('APP INSTALLATION'));
125
-
126
- await installAppToOrg(app, configProperties);
127
- console.log('%s App installed', chalk.green.bold('APP INSTALLATION'));
128
- }
129
-
130
- function delay(ms: number) {
131
- return new Promise(resolve => setTimeout(resolve, ms));
132
- }
package/src/auth/auth.ts DELETED
@@ -1,10 +0,0 @@
1
- export interface AuthContext {
2
- apiUserToken: string;
3
- apiGateway?: string;
4
- orgSlug?: string;
5
- orgId?: string;
6
- }
7
-
8
- export class Auth {
9
- public static config: AuthContext;
10
- }