@contrail/cli 1.0.70 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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/index.ts +2 -2
  148. package/{templates → dist/templates}/typescript/src/framework/interfaces.ts +32 -32
  149. package/{templates → dist/templates}/typescript/tsconfig.json +28 -28
  150. package/oclif.manifest.json +821 -0
  151. package/package.json +116 -72
  152. package/.eslintrc.js +0 -53
  153. package/.vscode/settings.json +0 -6
  154. package/bin/init +0 -4
  155. package/lib/api/apps.js +0 -85
  156. package/lib/api/event-workflow-action-definition.js +0 -7
  157. package/lib/api/event-workflow-template-definition.js +0 -20
  158. package/lib/api/event-workflow-templates.js +0 -25
  159. package/lib/apps/create-app/create.d.ts +0 -1
  160. package/lib/apps/create-app/create.js +0 -60
  161. package/lib/apps/create-app/setup-template.d.ts +0 -1
  162. package/lib/apps/create-app/setup-template.js +0 -34
  163. package/lib/apps/deploy-app/deploy.d.ts +0 -2
  164. package/lib/apps/deploy-app/deploy.js +0 -58
  165. package/lib/apps/install-app/app-installer.d.ts +0 -2
  166. package/lib/apps/install-app/app-installer.js +0 -120
  167. package/lib/apps/upgrade-app/app-upgrader.d.ts +0 -3
  168. package/lib/apps/upgrade-app/app-upgrader.js +0 -126
  169. package/lib/auth/auth.js +0 -2
  170. package/lib/cli.d.ts +0 -5
  171. package/lib/cli.js +0 -524
  172. package/lib/colors/color-loader.d.ts +0 -2
  173. package/lib/colors/color-loader.js +0 -96
  174. package/lib/common.js +0 -5
  175. package/lib/config/config.js +0 -70
  176. package/lib/config/configCommands.d.ts +0 -3
  177. package/lib/config/configCommands.js +0 -34
  178. package/lib/interfaces.js +0 -25
  179. package/lib/loader-process/loader-process.d.ts +0 -2
  180. package/lib/projects/interfaces.d.ts +0 -77
  181. package/lib/projects/interfaces.js +0 -23
  182. package/lib/projects/project-exporter.d.ts +0 -2
  183. package/lib/projects/project-uploader.d.ts +0 -1
  184. package/lib/types/allUploader.d.ts +0 -1
  185. package/lib/types/allUploader.js +0 -24
  186. package/lib/types/interfaces.d.ts +0 -55
  187. package/lib/types/interfaces.js +0 -1
  188. package/lib/types/option-set-hierarchy-exporter.d.ts +0 -1
  189. package/lib/types/option-set-hierarchy-parser.d.ts +0 -2
  190. package/lib/types/option-set-hierarchy-uploader.d.ts +0 -1
  191. package/lib/types/option-set-merger.d.ts +0 -1
  192. package/lib/types/option-set-parser.d.ts +0 -3
  193. package/lib/types/option-set-parser.js +0 -140
  194. package/lib/types/option-set-uploader.d.ts +0 -1
  195. package/lib/types/parse-types.d.ts +0 -4
  196. package/lib/types/parse-types.js +0 -189
  197. package/lib/types/rule-set-uploader.d.ts +0 -1
  198. package/lib/types/type-property-policy-uploader.d.ts +0 -1
  199. package/lib/types/types-properties-merger.d.ts +0 -1
  200. package/lib/types/types-properties-merger.js +0 -75
  201. package/lib/types/usage-info-uploader.d.ts +0 -1
  202. package/lib/users/user-exporter.d.ts +0 -1
  203. package/lib/users/user-exporter.js +0 -41
  204. package/lib/users/user-uploader.d.ts +0 -1
  205. package/lib/users/user-uploader.js +0 -45
  206. package/lib/workflow-template-definitions/workflow-template-definition-commands.d.ts +0 -2
  207. package/lib/workflow-template-definitions/workflow-template-definition-commands.js +0 -10
  208. package/lib/workflow-templates/local-workflow-template-deployer.js +0 -102
  209. package/lib/workflow-templates/workflow-template-commands.d.ts +0 -4
  210. package/lib/workflow-templates/workflow-template-commands.js +0 -51
  211. package/lib/workflow-templates/workflow-template-deployer.d.ts +0 -4
  212. package/lib/workflow-templates/workflow-template-deployer.js +0 -26
  213. package/publish.bat +0 -5
  214. package/publish.sh +0 -5
  215. package/src/api/apps.ts +0 -97
  216. package/src/api/event-workflow-action-definition.ts +0 -8
  217. package/src/api/event-workflow-template-definition.ts +0 -23
  218. package/src/api/event-workflow-templates.ts +0 -29
  219. package/src/apps/create-app/create.ts +0 -74
  220. package/src/apps/create-app/setup-template.ts +0 -38
  221. package/src/apps/deploy-app/actions-deployer.ts +0 -140
  222. package/src/apps/deploy-app/app-deployer.ts +0 -105
  223. package/src/apps/deploy-app/app-template-parsers.ts +0 -44
  224. package/src/apps/deploy-app/deploy.ts +0 -66
  225. package/src/apps/install-app/app-installer.ts +0 -126
  226. package/src/apps/upgrade-app/app-upgrader.ts +0 -132
  227. package/src/auth/auth.ts +0 -10
  228. package/src/auth/login.ts +0 -155
  229. package/src/cli.ts +0 -540
  230. package/src/colors/color-loader.ts +0 -112
  231. package/src/colors/colors.csv +0 -866
  232. package/src/common.ts +0 -5
  233. package/src/config/config.ts +0 -74
  234. package/src/config/configCommands.ts +0 -38
  235. package/src/interfaces.ts +0 -200
  236. package/src/loader-process/loader-process.ts +0 -152
  237. package/src/projects/interfaces.ts +0 -73
  238. package/src/projects/project-exporter.ts +0 -225
  239. package/src/projects/project-uploader.ts +0 -131
  240. package/src/types/allUploader.ts +0 -28
  241. package/src/types/csv-parser.ts +0 -59
  242. package/src/types/interfaces.ts +0 -58
  243. package/src/types/option-set-hierarchy-exporter.ts +0 -125
  244. package/src/types/option-set-hierarchy-parser.ts +0 -169
  245. package/src/types/option-set-hierarchy-uploader.ts +0 -122
  246. package/src/types/option-set-merger.ts +0 -124
  247. package/src/types/option-set-parser.ts +0 -166
  248. package/src/types/option-set-uploader.ts +0 -108
  249. package/src/types/parse-types.ts +0 -227
  250. package/src/types/rule-set-uploader.ts +0 -187
  251. package/src/types/type-property-policy-uploader.ts +0 -192
  252. package/src/types/types-extractor.ts +0 -369
  253. package/src/types/types-properties-merger.ts +0 -90
  254. package/src/types/types-uploader.ts +0 -271
  255. package/src/types/usage-info-uploader.ts +0 -139
  256. package/src/users/user-exporter.ts +0 -52
  257. package/src/users/user-uploader.ts +0 -58
  258. package/src/workflow-template-definitions/workflow-template-definition-commands.ts +0 -13
  259. package/src/workflow-template-definitions/workflow-template-definition-deployer.ts +0 -184
  260. package/src/workflow-templates/local-workflow-template-deployer.ts +0 -126
  261. package/src/workflow-templates/workflow-template-commands.ts +0 -59
  262. package/src/workflow-templates/workflow-template-deployer.ts +0 -30
  263. package/templates/javascript/actions/example/action.js +0 -38
  264. package/templates/javascript/app.yml +0 -53
  265. package/templates/javascript/package.json +0 -23
  266. package/templates/typescript/package-lock.json +0 -14
  267. package/tsconfig.json +0 -32
  268. /package/{templates → dist/templates}/typescript/src/framework/handler.ts +0 -0
  269. /package/{templates → dist/templates}/typescript/src/framework/logger.ts +0 -0
  270. /package/{templates → dist/templates}/typescript/src/framework/mock-server.ts +0 -0
@@ -1,178 +1,195 @@
1
- import { Entities } from '@contrail/sdk';
2
- import fs from 'fs';
3
- import * as path from 'path';
4
- import { authUser } from '../auth/login';
5
- import chalk from 'chalk';
6
- import { getTypes } from './types-extractor';
7
- const yaml = require('js-yaml');
8
- export async function uploadTypePropertyPolicies(args) {
9
- try {
10
- await authUser();
11
- console.log('%s Uploading', chalk.yellow.bold('TYPE PROPERTY POLICY'));
12
- const [reducedTypePropertyPolicies, reducedTypePropertyPolicyLinks] = await loadTPPolicies();
13
- await uploadTPPolicyObjects(reducedTypePropertyPolicies);
14
- await uploadTypePropertyPolicyLinks(reducedTypePropertyPolicyLinks);
15
- console.log('%s Uploaded', chalk.yellow.bold('TYPE PROPERTY POLICY'));
16
- }
17
- catch (e) {
18
- console.log(`%s Type Property Policy Upload Failed. ${e}`, chalk.red.bold('FAIL'));
19
- return;
20
- }
21
- console.log('%s Type Property Policy Upload Complete.', chalk.green.bold('COMPLETE'));
22
- }
23
- function loadTPPolicies() {
24
- const tpps = [];
25
- let tppLinks = [];
26
- const TARGET_DIR = process.cwd();
27
- try {
28
- const files = fs.readdirSync(path.join(TARGET_DIR, 'type-property-policies'));
29
- for (const file of files) {
30
- tpps.push(yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'type-property-policies', file), 'utf8')));
31
- }
32
- tppLinks = yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'type-property-policy-links.yml'), 'utf8'));
33
- return [tpps, tppLinks];
34
- }
35
- catch (e) {
36
- throw new Error(`ERROR PARSING YAML: ${e}`);
37
- }
38
- }
39
- async function uploadTPPolicyObjects(reducedTypePropertyPolicies) {
40
- const currentTPPolicies = await new Entities().get({
41
- entityName: 'type-property-policy',
42
- });
43
- const currentTPPByLabel = {};
44
- for (const currentTPP of currentTPPolicies) {
45
- currentTPPByLabel[currentTPP.label] = currentTPP;
46
- }
47
- const loadedTPPByName = {};
48
- for (const loadedTPP of reducedTypePropertyPolicies) {
49
- loadedTPPByName[loadedTPP.label] = loadedTPP;
50
- }
51
- console.debug('current tp policy:', currentTPPolicies);
52
- console.debug('reduced tp policy:', reducedTypePropertyPolicies);
53
- for (const [label, loadedTPP] of Object.entries(loadedTPPByName)) {
54
- try {
55
- const found = currentTPPByLabel[label];
56
- if (!found) {
57
- console.log('Creating: ', label);
58
- await new Entities().create({
59
- entityName: 'type-property-policy',
60
- object: loadedTPP
61
- });
62
- }
63
- else {
64
- console.log('Updating: ', label);
65
- await new Entities().update({
66
- entityName: 'type-property-policy',
67
- id: found.id,
68
- object: loadedTPP,
69
- });
70
- }
71
- }
72
- catch (err) {
73
- throw new Error(`Error Uploading Type Property Policy: ${err}`);
74
- }
75
- }
76
- for (const [label, currentTPP] of Object.entries(currentTPPByLabel)) {
77
- try {
78
- const found = loadedTPPByName[label];
79
- if (!found) {
80
- console.log('Deleting: ', label);
81
- await new Entities().delete({
82
- entityName: 'type-property-policy',
83
- id: currentTPP['id'],
84
- });
85
- }
86
- }
87
- catch (err) {
88
- throw new Error(`Error Type Property Policy: ${err}`);
89
- }
90
- }
91
- }
92
- async function uploadTypePropertyPolicyLinks(reducedTypePropertyPolicyLinks) {
93
- const typesWithProperties = await getTypes();
94
- const typeProperties = typesWithProperties
95
- .filter(t => !!t.typeProperties)
96
- .map(t => t.typeProperties)
97
- .reduce((a, b) => a.concat(b));
98
- const currentTPPs = await new Entities().get({
99
- entityName: 'type-property-policy',
100
- });
101
- const currentTPPLinks = await new Entities().get({
102
- entityName: 'type-property-policy-link',
103
- });
104
- const currentLinksHashes = {};
105
- for (const currentLink of currentTPPLinks) {
106
- const foundTypeProperty = typeProperties.find(tp => tp.id === currentLink.typePropertyId);
107
- const foundTPP = currentTPPs.find(tpp => tpp.id === currentLink.typePropertyPolicyId);
108
- if (!foundTypeProperty || !foundTPP) {
109
- console.log('skipping unhashable, invalid policy link:', currentLink);
110
- }
111
- const hash = `${foundTypeProperty.slug}|${foundTPP.label}`;
112
- currentLinksHashes[hash] = currentLink;
113
- }
114
- const reducedLinksByHashes = {};
115
- for (const loadedLink of reducedTypePropertyPolicyLinks) {
116
- const hash = `${loadedLink.typePropertySlug}|${loadedLink.typePropertyPolicyLabel}`;
117
- reducedLinksByHashes[hash] = loadedLink;
118
- }
119
- console.debug('current type property policy links:', currentLinksHashes);
120
- console.debug('reduced type property policy links:', reducedLinksByHashes);
121
- for (const loadedTPPLink of reducedTypePropertyPolicyLinks) {
122
- try {
123
- const found = currentLinksHashes[`${loadedTPPLink.typePropertySlug}|${loadedTPPLink.typePropertyPolicyLabel}`];
124
- if (!found) {
125
- if (!transformReducedLink(loadedTPPLink, typeProperties, currentTPPs)) {
126
- continue;
127
- }
128
- console.log('Creating: ', loadedTPPLink);
129
- await new Entities().create({
130
- entityName: 'type-property-policy-link',
131
- object: {
132
- typePropertyPolicyId: loadedTPPLink.typePropertyPolicyId,
133
- typePropertyId: loadedTPPLink.typePropertyId,
134
- },
135
- });
136
- }
137
- else {
138
- if (!transformReducedLink(loadedTPPLink, typeProperties, currentTPPs)) {
139
- continue;
140
- }
141
- console.log('skipping existing link: ', loadedTPPLink);
142
- }
143
- }
144
- catch (err) {
145
- throw new Error(`Error Uploading type property policy links: ${err}`);
146
- }
147
- }
148
- for (const [currentLinkHash, currentLink] of Object.entries(currentLinksHashes)) {
149
- try {
150
- const found = reducedLinksByHashes[currentLinkHash];
151
- if (!found) {
152
- console.log('Deleting: ', currentLinkHash);
153
- await new Entities().delete({
154
- entityName: 'type-property-policy-link',
155
- id: currentLink['id'],
156
- });
157
- }
158
- }
159
- catch (err) {
160
- throw new Error(`Error Deleting rule set link: ${err}`);
161
- }
162
- }
163
- }
164
- function transformReducedLink(TPPLink, typeProperties, typePropertyPolicies) {
165
- const foundTP = typeProperties.find(tp => tp.slug === TPPLink.typePropertySlug);
166
- if (!foundTP) {
167
- console.error('Could not find type property with label', TPPLink.typePropertySlug);
168
- return false;
169
- }
170
- TPPLink.typePropertyId = foundTP.id;
171
- const foundTPP = typePropertyPolicies.find(tpp => tpp.label === TPPLink.typePropertyPolicyLabel);
172
- if (!foundTPP) {
173
- console.error('Could not find type property policy with label', TPPLink.typePropertyPolicyLabel);
174
- return false;
175
- }
176
- TPPLink.typePropertyPolicyId = foundTPP.id;
177
- return true;
178
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uploadTypePropertyPolicies = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const sdk_1 = require("@contrail/sdk");
6
+ const fs_1 = tslib_1.__importDefault(require("fs"));
7
+ const path = tslib_1.__importStar(require("path"));
8
+ const login_1 = require("../../auth/login");
9
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
10
+ const core_1 = require("@oclif/core");
11
+ const type_extractor_1 = require("../../helpers/types/type-extractor");
12
+ const yaml = require('js-yaml');
13
+ class UploadTypePropertyPolicies extends core_1.Command {
14
+ async run() {
15
+ return await uploadTypePropertyPolicies();
16
+ }
17
+ }
18
+ exports.default = UploadTypePropertyPolicies;
19
+ UploadTypePropertyPolicies.description = 'Upload type property policies';
20
+ UploadTypePropertyPolicies.examples = [
21
+ `$ contrail types uploadTypePropertyPolicies
22
+ `,
23
+ ];
24
+ async function uploadTypePropertyPolicies() {
25
+ try {
26
+ await (0, login_1.authUser)();
27
+ console.log('%s Uploading', chalk_1.default.yellow.bold('TYPE PROPERTY POLICY'));
28
+ const [reducedTypePropertyPolicies, reducedTypePropertyPolicyLinks] = await loadTPPolicies();
29
+ await uploadTPPolicyObjects(reducedTypePropertyPolicies);
30
+ await uploadTypePropertyPolicyLinks(reducedTypePropertyPolicyLinks);
31
+ console.log('%s Uploaded', chalk_1.default.yellow.bold('TYPE PROPERTY POLICY'));
32
+ }
33
+ catch (e) {
34
+ console.log(`%s Type Property Policy Upload Failed. ${e}`, chalk_1.default.red.bold('FAIL'));
35
+ return;
36
+ }
37
+ console.log('%s Type Property Policy Upload Complete.', chalk_1.default.green.bold('COMPLETE'));
38
+ }
39
+ exports.uploadTypePropertyPolicies = uploadTypePropertyPolicies;
40
+ function loadTPPolicies() {
41
+ const tpps = [];
42
+ let tppLinks = [];
43
+ const TARGET_DIR = process.cwd();
44
+ try {
45
+ const files = fs_1.default.readdirSync(path.join(TARGET_DIR, 'type-property-policies'));
46
+ for (const file of files) {
47
+ tpps.push(yaml.load(fs_1.default.readFileSync(path.join(TARGET_DIR, 'type-property-policies', file), 'utf8')));
48
+ }
49
+ tppLinks = yaml.load(fs_1.default.readFileSync(path.join(TARGET_DIR, 'type-property-policy-links.yml'), 'utf8'));
50
+ return [tpps, tppLinks];
51
+ }
52
+ catch (e) {
53
+ throw new Error(`ERROR PARSING YAML: ${e}`);
54
+ }
55
+ }
56
+ async function uploadTPPolicyObjects(reducedTypePropertyPolicies) {
57
+ const currentTPPolicies = await new sdk_1.Entities().get({
58
+ entityName: 'type-property-policy',
59
+ });
60
+ const currentTPPByLabel = {};
61
+ for (const currentTPP of currentTPPolicies) {
62
+ currentTPPByLabel[currentTPP.label] = currentTPP;
63
+ }
64
+ const loadedTPPByName = {};
65
+ for (const loadedTPP of reducedTypePropertyPolicies) {
66
+ loadedTPPByName[loadedTPP.label] = loadedTPP;
67
+ }
68
+ console.debug('current tp policy:', currentTPPolicies);
69
+ console.debug('reduced tp policy:', reducedTypePropertyPolicies);
70
+ for (const [label, loadedTPP] of Object.entries(loadedTPPByName)) {
71
+ try {
72
+ const found = currentTPPByLabel[label];
73
+ if (!found) {
74
+ console.log('Creating: ', label);
75
+ await new sdk_1.Entities().create({
76
+ entityName: 'type-property-policy',
77
+ object: loadedTPP
78
+ });
79
+ }
80
+ else {
81
+ console.log('Updating: ', label);
82
+ await new sdk_1.Entities().update({
83
+ entityName: 'type-property-policy',
84
+ id: found.id,
85
+ object: loadedTPP,
86
+ });
87
+ }
88
+ }
89
+ catch (err) {
90
+ throw new Error(`Error Uploading Type Property Policy: ${err}`);
91
+ }
92
+ }
93
+ for (const [label, currentTPP] of Object.entries(currentTPPByLabel)) {
94
+ try {
95
+ const found = loadedTPPByName[label];
96
+ if (!found) {
97
+ console.log('Deleting: ', label);
98
+ await new sdk_1.Entities().delete({
99
+ entityName: 'type-property-policy',
100
+ id: currentTPP['id'],
101
+ });
102
+ }
103
+ }
104
+ catch (err) {
105
+ throw new Error(`Error Type Property Policy: ${err}`);
106
+ }
107
+ }
108
+ }
109
+ async function uploadTypePropertyPolicyLinks(reducedTypePropertyPolicyLinks) {
110
+ const typesWithProperties = await (0, type_extractor_1.getTypes)();
111
+ const typeProperties = typesWithProperties
112
+ .filter(t => !!t.typeProperties)
113
+ .map(t => t.typeProperties)
114
+ .reduce((a, b) => a.concat(b));
115
+ const currentTPPs = await new sdk_1.Entities().get({
116
+ entityName: 'type-property-policy',
117
+ });
118
+ const currentTPPLinks = await new sdk_1.Entities().get({
119
+ entityName: 'type-property-policy-link',
120
+ });
121
+ const currentLinksHashes = {};
122
+ for (const currentLink of currentTPPLinks) {
123
+ const foundTypeProperty = typeProperties.find(tp => tp.id === currentLink.typePropertyId);
124
+ const foundTPP = currentTPPs.find(tpp => tpp.id === currentLink.typePropertyPolicyId);
125
+ if (!foundTypeProperty || !foundTPP) {
126
+ console.log('skipping unhashable, invalid policy link:', currentLink);
127
+ }
128
+ const hash = `${foundTypeProperty.slug}|${foundTPP.label}`;
129
+ currentLinksHashes[hash] = currentLink;
130
+ }
131
+ const reducedLinksByHashes = {};
132
+ for (const loadedLink of reducedTypePropertyPolicyLinks) {
133
+ const hash = `${loadedLink.typePropertySlug}|${loadedLink.typePropertyPolicyLabel}`;
134
+ reducedLinksByHashes[hash] = loadedLink;
135
+ }
136
+ console.debug('current type property policy links:', currentLinksHashes);
137
+ console.debug('reduced type property policy links:', reducedLinksByHashes);
138
+ for (const loadedTPPLink of reducedTypePropertyPolicyLinks) {
139
+ try {
140
+ const found = currentLinksHashes[`${loadedTPPLink.typePropertySlug}|${loadedTPPLink.typePropertyPolicyLabel}`];
141
+ if (!found) {
142
+ if (!transformReducedLink(loadedTPPLink, typeProperties, currentTPPs)) {
143
+ continue;
144
+ }
145
+ console.log('Creating: ', loadedTPPLink);
146
+ await new sdk_1.Entities().create({
147
+ entityName: 'type-property-policy-link',
148
+ object: {
149
+ typePropertyPolicyId: loadedTPPLink.typePropertyPolicyId,
150
+ typePropertyId: loadedTPPLink.typePropertyId,
151
+ },
152
+ });
153
+ }
154
+ else {
155
+ if (!transformReducedLink(loadedTPPLink, typeProperties, currentTPPs)) {
156
+ continue;
157
+ }
158
+ console.log('skipping existing link: ', loadedTPPLink);
159
+ }
160
+ }
161
+ catch (err) {
162
+ throw new Error(`Error Uploading type property policy links: ${err}`);
163
+ }
164
+ }
165
+ for (const [currentLinkHash, currentLink] of Object.entries(currentLinksHashes)) {
166
+ try {
167
+ const found = reducedLinksByHashes[currentLinkHash];
168
+ if (!found) {
169
+ console.log('Deleting: ', currentLinkHash);
170
+ await new sdk_1.Entities().delete({
171
+ entityName: 'type-property-policy-link',
172
+ id: currentLink['id'],
173
+ });
174
+ }
175
+ }
176
+ catch (err) {
177
+ throw new Error(`Error Deleting rule set link: ${err}`);
178
+ }
179
+ }
180
+ }
181
+ function transformReducedLink(TPPLink, typeProperties, typePropertyPolicies) {
182
+ const foundTP = typeProperties.find(tp => tp.slug === TPPLink.typePropertySlug);
183
+ if (!foundTP) {
184
+ console.error('Could not find type property with label', TPPLink.typePropertySlug);
185
+ return false;
186
+ }
187
+ TPPLink.typePropertyId = foundTP.id;
188
+ const foundTPP = typePropertyPolicies.find(tpp => tpp.label === TPPLink.typePropertyPolicyLabel);
189
+ if (!foundTPP) {
190
+ console.error('Could not find type property policy with label', TPPLink.typePropertyPolicyLabel);
191
+ return false;
192
+ }
193
+ TPPLink.typePropertyPolicyId = foundTPP.id;
194
+ return true;
195
+ }
@@ -0,0 +1,7 @@
1
+ import { Command } from '@oclif/core';
2
+ export default class UploadUsageInfo extends Command {
3
+ static description: string;
4
+ static examples: string[];
5
+ run(): Promise<void>;
6
+ }
7
+ export declare function uploadUsageInfo(): Promise<void>;