@contrail/cli 3.4.1 → 3.4.2-alpha.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 (235) hide show
  1. package/README.md +5 -4
  2. package/bin/dev +0 -0
  3. package/bin/run +0 -0
  4. package/dist/__mocks__/@contrail/sdk.d.ts +123 -123
  5. package/dist/__mocks__/@contrail/sdk.js +716 -716
  6. package/dist/api/app-extension-deployments.d.ts +2 -2
  7. package/dist/api/app-extension-deployments.js +11 -11
  8. package/dist/api/app-extension-packages.d.ts +2 -2
  9. package/dist/api/app-extension-packages.js +11 -11
  10. package/dist/api/apps.d.ts +10 -10
  11. package/dist/api/apps.js +63 -63
  12. package/dist/api/event-workflow-action-definition.d.ts +3 -3
  13. package/dist/api/event-workflow-action-definition.js +18 -18
  14. package/dist/api/event-workflow-template-definition.d.ts +7 -7
  15. package/dist/api/event-workflow-template-definition.js +26 -26
  16. package/dist/api/event-workflow-templates.d.ts +8 -8
  17. package/dist/api/event-workflow-templates.js +32 -32
  18. package/dist/api/schedules.d.ts +7 -7
  19. package/dist/api/schedules.js +32 -32
  20. package/dist/api/types.d.ts +11 -11
  21. package/dist/api/types.js +79 -79
  22. package/dist/api/users.d.ts +2 -2
  23. package/dist/api/users.js +18 -18
  24. package/dist/api/webhooks.d.ts +4 -4
  25. package/dist/api/webhooks.js +16 -16
  26. package/dist/auth/login.d.ts +3 -3
  27. package/dist/auth/login.js +221 -221
  28. package/dist/auth/login.spec.d.ts +1 -1
  29. package/dist/auth/login.spec.js +10 -10
  30. package/dist/baseFlags.d.ts +10 -10
  31. package/dist/baseFlags.js +25 -25
  32. package/dist/basecommand.d.ts +15 -15
  33. package/dist/basecommand.js +83 -83
  34. package/dist/commands/app/create.d.ts +10 -10
  35. package/dist/commands/app/create.js +96 -96
  36. package/dist/commands/app/delete.d.ts +11 -11
  37. package/dist/commands/app/delete.js +40 -40
  38. package/dist/commands/app/extension/deploy.d.ts +18 -18
  39. package/dist/commands/app/extension/deploy.js +127 -127
  40. package/dist/commands/app/extension/deployment/list.d.ts +14 -14
  41. package/dist/commands/app/extension/deployment/list.js +82 -82
  42. package/dist/commands/app/getApiKey.d.ts +11 -11
  43. package/dist/commands/app/getApiKey.js +49 -49
  44. package/dist/commands/app/init.d.ts +10 -10
  45. package/dist/commands/app/init.js +67 -67
  46. package/dist/commands/app/install.d.ts +13 -13
  47. package/dist/commands/app/install.js +135 -135
  48. package/dist/commands/app/publish.d.ts +14 -14
  49. package/dist/commands/app/publish.js +69 -69
  50. package/dist/commands/app/uninstall.d.ts +12 -12
  51. package/dist/commands/app/uninstall.js +68 -68
  52. package/dist/commands/app/upgrade.d.ts +14 -14
  53. package/dist/commands/app/upgrade.js +108 -108
  54. package/dist/commands/app/version/major.d.ts +11 -11
  55. package/dist/commands/app/version/major.js +39 -39
  56. package/dist/commands/app/version/minor.d.ts +11 -11
  57. package/dist/commands/app/version/minor.js +39 -39
  58. package/dist/commands/app/version/patch.d.ts +11 -11
  59. package/dist/commands/app/version/patch.js +39 -39
  60. package/dist/commands/config/create.d.ts +12 -12
  61. package/dist/commands/config/create.js +27 -27
  62. package/dist/commands/config/describe.d.ts +14 -14
  63. package/dist/commands/config/describe.js +46 -46
  64. package/dist/commands/config/list.d.ts +11 -11
  65. package/dist/commands/config/list.js +38 -38
  66. package/dist/commands/config/set.d.ts +16 -16
  67. package/dist/commands/config/set.js +46 -46
  68. package/dist/commands/config/use.d.ts +14 -14
  69. package/dist/commands/config/use.js +47 -47
  70. package/dist/commands/file/upload.d.ts +15 -15
  71. package/dist/commands/file/upload.js +69 -69
  72. package/dist/commands/groups/export.d.ts +14 -14
  73. package/dist/commands/groups/export.js +103 -103
  74. package/dist/commands/groups/import.d.ts +14 -14
  75. package/dist/commands/groups/import.js +190 -190
  76. package/dist/commands/instance/export.d.ts +12 -12
  77. package/dist/commands/instance/export.js +36 -36
  78. package/dist/commands/instance/import.d.ts +11 -11
  79. package/dist/commands/instance/import.js +34 -34
  80. package/dist/commands/load/colors.d.ts +14 -14
  81. package/dist/commands/load/colors.js +53 -53
  82. package/dist/commands/load/custom-entity.d.ts +14 -14
  83. package/dist/commands/load/custom-entity.js +55 -55
  84. package/dist/commands/load/line-sheet.d.ts +14 -14
  85. package/dist/commands/load/line-sheet.js +55 -55
  86. package/dist/commands/load/upload-and-load.d.ts +14 -14
  87. package/dist/commands/load/upload-and-load.js +46 -46
  88. package/dist/commands/projects/export.d.ts +13 -13
  89. package/dist/commands/projects/export.js +35 -35
  90. package/dist/commands/projects/list.d.ts +10 -10
  91. package/dist/commands/projects/list.js +36 -36
  92. package/dist/commands/projects/load.d.ts +25 -25
  93. package/dist/commands/projects/load.js +198 -198
  94. package/dist/commands/types/exportOptionSetHierarchies.d.ts +11 -11
  95. package/dist/commands/types/exportOptionSetHierarchies.js +133 -133
  96. package/dist/commands/types/getAll.d.ts +21 -21
  97. package/dist/commands/types/getAll.js +180 -180
  98. package/dist/commands/types/getOptionSets.d.ts +16 -16
  99. package/dist/commands/types/getOptionSets.js +170 -170
  100. package/dist/commands/types/loadAll.d.ts +12 -12
  101. package/dist/commands/types/loadAll.js +55 -55
  102. package/dist/commands/types/mergeOptionSets.d.ts +13 -13
  103. package/dist/commands/types/mergeOptionSets.js +116 -119
  104. package/dist/commands/types/mergeTypeProperties.d.ts +15 -15
  105. package/dist/commands/types/mergeTypeProperties.js +95 -95
  106. package/dist/commands/types/parseOptionSetsHierarchyLocalFile.d.ts +14 -14
  107. package/dist/commands/types/parseOptionSetsHierarchyLocalFile.js +133 -133
  108. package/dist/commands/types/parseOptionSetsHierarchyValuesToKeysLocalFile.d.ts +14 -14
  109. package/dist/commands/types/parseOptionSetsHierarchyValuesToKeysLocalFile.js +102 -102
  110. package/dist/commands/types/parseOptionSetsLocalFiles.d.ts +39 -39
  111. package/dist/commands/types/parseOptionSetsLocalFiles.js +229 -229
  112. package/dist/commands/types/parseOptionSetsToFolderStructure.d.ts +13 -13
  113. package/dist/commands/types/parseOptionSetsToFolderStructure.js +68 -68
  114. package/dist/commands/types/parseTypesFromFiles.d.ts +14 -14
  115. package/dist/commands/types/parseTypesFromFiles.js +40 -40
  116. package/dist/commands/types/parseTypesFromLocalFiles.d.ts +14 -14
  117. package/dist/commands/types/parseTypesFromLocalFiles.js +37 -37
  118. package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.d.ts +15 -15
  119. package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.js +39 -39
  120. package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.d.ts +14 -14
  121. package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.js +38 -38
  122. package/dist/commands/types/uploadOptionSetHierarchies.d.ts +12 -12
  123. package/dist/commands/types/uploadOptionSetHierarchies.js +257 -257
  124. package/dist/commands/types/uploadOptionSets.d.ts +13 -13
  125. package/dist/commands/types/uploadOptionSets.js +155 -155
  126. package/dist/commands/types/uploadOptionSetsHierarchyLocalFile.d.ts +15 -15
  127. package/dist/commands/types/uploadOptionSetsHierarchyLocalFile.js +135 -135
  128. package/dist/commands/types/uploadRuleSets.d.ts +12 -12
  129. package/dist/commands/types/uploadRuleSets.js +197 -197
  130. package/dist/commands/types/uploadTypePolicies.d.ts +12 -12
  131. package/dist/commands/types/uploadTypePolicies.js +233 -233
  132. package/dist/commands/types/uploadTypePropertyPolicies.d.ts +13 -13
  133. package/dist/commands/types/uploadTypePropertyPolicies.js +286 -286
  134. package/dist/commands/types/uploadTypes.d.ts +13 -13
  135. package/dist/commands/types/uploadTypes.js +35 -35
  136. package/dist/commands/types/uploadUsageInfo.d.ts +12 -12
  137. package/dist/commands/types/uploadUsageInfo.js +172 -172
  138. package/dist/commands/users/export.d.ts +14 -14
  139. package/dist/commands/users/export.js +76 -76
  140. package/dist/commands/users/import.d.ts +14 -14
  141. package/dist/commands/users/import.js +68 -68
  142. package/dist/commands/webhooks/create.d.ts +11 -11
  143. package/dist/commands/webhooks/create.js +25 -25
  144. package/dist/commands/webhooks/delete.d.ts +14 -14
  145. package/dist/commands/webhooks/delete.js +53 -53
  146. package/dist/commands/webhooks/getWebhookTrigger.d.ts +13 -13
  147. package/dist/commands/webhooks/getWebhookTrigger.js +40 -40
  148. package/dist/commands/webhooks/list.d.ts +12 -12
  149. package/dist/commands/webhooks/list.js +31 -31
  150. package/dist/commands/workflow-template-definitions/install.d.ts +10 -10
  151. package/dist/commands/workflow-template-definitions/install.js +19 -19
  152. package/dist/commands/workflow-template-definitions/list.d.ts +10 -10
  153. package/dist/commands/workflow-template-definitions/list.js +19 -19
  154. package/dist/commands/workflow-templates/delete.d.ts +10 -10
  155. package/dist/commands/workflow-templates/delete.js +19 -19
  156. package/dist/commands/workflow-templates/export.d.ts +14 -14
  157. package/dist/commands/workflow-templates/export.js +78 -78
  158. package/dist/commands/workflow-templates/list.d.ts +10 -10
  159. package/dist/commands/workflow-templates/list.js +19 -19
  160. package/dist/commands/workflow-templates/load.d.ts +13 -13
  161. package/dist/commands/workflow-templates/load.js +26 -26
  162. package/dist/common.d.ts +4 -4
  163. package/dist/common.js +18 -18
  164. package/dist/helpers/app/actions-deployer.d.ts +11 -11
  165. package/dist/helpers/app/actions-deployer.js +123 -123
  166. package/dist/helpers/app/app-config-validators.d.ts +22 -22
  167. package/dist/helpers/app/app-config-validators.js +100 -100
  168. package/dist/helpers/app/app-config-validators.spec.d.ts +1 -1
  169. package/dist/helpers/app/app-config-validators.spec.js +310 -310
  170. package/dist/helpers/app/app-deployer.d.ts +12 -12
  171. package/dist/helpers/app/app-deployer.js +278 -278
  172. package/dist/helpers/app/app-template-parsers.d.ts +14 -14
  173. package/dist/helpers/app/app-template-parsers.js +106 -106
  174. package/dist/helpers/app/extension-package-deployer.d.ts +7 -7
  175. package/dist/helpers/app/extension-package-deployer.js +175 -175
  176. package/dist/helpers/app/extensions-deployer.d.ts +9 -9
  177. package/dist/helpers/app/extensions-deployer.js +95 -93
  178. package/dist/helpers/app/load-app-config.d.ts +4 -4
  179. package/dist/helpers/app/load-app-config.js +22 -22
  180. package/dist/helpers/app/metadata-extractor.d.ts +1 -1
  181. package/dist/helpers/app/metadata-extractor.js +100 -100
  182. package/dist/helpers/app/setup-template.d.ts +8 -8
  183. package/dist/helpers/app/setup-template.js +48 -48
  184. package/dist/helpers/app/update-app-config.d.ts +2 -2
  185. package/dist/helpers/app/update-app-config.js +20 -20
  186. package/dist/helpers/app/upgrade-version.d.ts +16 -16
  187. package/dist/helpers/app/upgrade-version.js +37 -37
  188. package/dist/helpers/app/upgrade-version.spec.d.ts +1 -1
  189. package/dist/helpers/app/upgrade-version.spec.js +33 -33
  190. package/dist/helpers/colors/helpers.d.ts +12 -12
  191. package/dist/helpers/colors/helpers.js +84 -84
  192. package/dist/helpers/config/config.d.ts +16 -16
  193. package/dist/helpers/config/config.js +223 -223
  194. package/dist/helpers/file-helpers.d.ts +2 -2
  195. package/dist/helpers/file-helpers.js +36 -36
  196. package/dist/helpers/load/helpers.d.ts +20 -20
  197. package/dist/helpers/load/helpers.js +141 -141
  198. package/dist/helpers/load/helpers.spec.d.ts +1 -1
  199. package/dist/helpers/load/helpers.spec.js +62 -62
  200. package/dist/helpers/load/validators.d.ts +14 -14
  201. package/dist/helpers/load/validators.js +182 -182
  202. package/dist/helpers/load/validators.spec.d.ts +1 -1
  203. package/dist/helpers/load/validators.spec.js +450 -450
  204. package/dist/helpers/projects/helpers.d.ts +3 -3
  205. package/dist/helpers/projects/helpers.js +167 -167
  206. package/dist/helpers/types/csv-parser.d.ts +1 -1
  207. package/dist/helpers/types/csv-parser.js +59 -59
  208. package/dist/helpers/types/option-set-helper.d.ts +9 -0
  209. package/dist/helpers/types/option-set-helper.js +48 -0
  210. package/dist/helpers/types/option-set-helper.spec.d.ts +1 -0
  211. package/dist/helpers/types/option-set-helper.spec.js +69 -0
  212. package/dist/helpers/types/parseOptionSetsLocalFiles.spec.d.ts +1 -1
  213. package/dist/helpers/types/parseOptionSetsLocalFiles.spec.js +285 -285
  214. package/dist/helpers/types/type-extractor.d.ts +1 -1
  215. package/dist/helpers/types/type-extractor.js +36 -36
  216. package/dist/helpers/types/type-parser.d.ts +4 -4
  217. package/dist/helpers/types/type-parser.js +119 -119
  218. package/dist/helpers/types/type-uploader.d.ts +20 -20
  219. package/dist/helpers/types/type-uploader.js +336 -336
  220. package/dist/helpers/types/type-uploader.spec.d.ts +1 -1
  221. package/dist/helpers/types/type-uploader.spec.js +266 -266
  222. package/dist/helpers/types/uploadOptionSets.spec.d.ts +1 -1
  223. package/dist/helpers/types/uploadOptionSets.spec.js +19 -19
  224. package/dist/helpers/workflow-template-definitions/workflow-template-definition-deployer.d.ts +12 -12
  225. package/dist/helpers/workflow-template-definitions/workflow-template-definition-deployer.js +158 -158
  226. package/dist/helpers/workflow-templates/helper.d.ts +20 -20
  227. package/dist/helpers/workflow-templates/helper.js +285 -285
  228. package/dist/index.d.ts +1 -1
  229. package/dist/index.js +5 -5
  230. package/dist/interfaces.d.ts +445 -444
  231. package/dist/interfaces.js +163 -163
  232. package/dist/logger.d.ts +3 -3
  233. package/dist/logger.js +33 -33
  234. package/oclif.manifest.json +3 -3
  235. package/package.json +1 -1
@@ -1,287 +1,287 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findAllOccurrences = 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 users_1 = require("../../api/users");
13
- const basecommand_1 = require("../../basecommand");
14
- const logger_1 = tslib_1.__importDefault(require("../../logger"));
15
- const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
16
- const _ = tslib_1.__importStar(require("lodash"));
17
- class UploadTypePropertyPolicies extends basecommand_1.BaseCommand {
18
- static description = 'Upload type property policies';
19
- static examples = [
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findAllOccurrences = 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 users_1 = require("../../api/users");
13
+ const basecommand_1 = require("../../basecommand");
14
+ const logger_1 = tslib_1.__importDefault(require("../../logger"));
15
+ const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
16
+ const _ = tslib_1.__importStar(require("lodash"));
17
+ class UploadTypePropertyPolicies extends basecommand_1.BaseCommand {
18
+ static description = 'Upload type property policies';
19
+ static examples = [
20
20
  `$ contrail types uploadTypePropertyPolicies
21
- `,
22
- ];
23
- static flags = {
24
- ...basecommand_1.BaseCommand.baseFlags,
25
- dir: core_1.Flags.string({
26
- char: 'd',
27
- description: 'The directory from which to export the type property policy data. Defaults to the current directory. The type property policy data will be loaded from $dir/type-property-policies/*.yml',
28
- required: false,
29
- default: '.',
30
- }),
31
- };
32
- async run() {
33
- return await uploadTypePropertyPolicies(this.flags.dir);
34
- }
35
- }
36
- exports.default = UploadTypePropertyPolicies;
37
- async function uploadTypePropertyPolicies(dir) {
38
- try {
39
- await (0, login_1.authUser)();
40
- logger_1.default.info(`${chalk_1.default.yellow.bold('TYPE PROPERTY POLICY')} Uploading`);
41
- const [reducedTypePropertyPolicies, reducedTypePropertyPolicyLinks] = await loadTPPolicies(dir);
42
- await uploadTPPolicyObjects(reducedTypePropertyPolicies);
43
- await uploadTypePropertyPolicyLinks(reducedTypePropertyPolicyLinks);
44
- logger_1.default.info(`${chalk_1.default.yellow.bold('TYPE PROPERTY POLICY')} Uploaded`);
45
- }
46
- catch (e) {
47
- logger_1.default.info(`${chalk_1.default.red.bold('FAIL')} Type Property Policy Upload Failed . ${e}`);
48
- //TODO make this only print if a debug flag is set
49
- console.trace(e);
50
- return;
51
- }
52
- logger_1.default.info(`${chalk_1.default.green.bold('COMPLETE')} Type Property Policy Upload Complete.`);
53
- }
54
- exports.uploadTypePropertyPolicies = uploadTypePropertyPolicies;
55
- function loadTPPolicies(fromDir) {
56
- const tpps = [];
57
- let tppLinks = [];
58
- const dir = path.join(fromDir, 'type-property-policies');
59
- try {
60
- const files = fs_1.default.readdirSync(dir);
61
- for (const file of files) {
62
- tpps.push(js_yaml_1.default.load(fs_1.default.readFileSync(path.join(dir, file), 'utf8')));
63
- }
64
- tppLinks = js_yaml_1.default.load(fs_1.default.readFileSync(path.join(fromDir, 'type-property-policy-links.yml'), 'utf8'));
65
- return [tpps, tppLinks];
66
- }
67
- catch (e) {
68
- throw new Error(`ERROR PARSING YAML: ${e}`);
69
- }
70
- }
71
- async function uploadTPPolicyObjects(reducedTypePropertyPolicies) {
72
- const orgUsers = await (0, users_1.getUserOrgs)();
73
- const groups = await (0, users_1.getGroups)();
74
- function fillPrincipal(statement) {
75
- const principal = statement?.principal;
76
- if (!principal) {
77
- logger_1.default.warn(`skipping bad statement principal ${statement?.principal}`);
78
- return statement;
79
- }
80
- const [type, identifier] = principal.split(':');
81
- if (!type || !identifier) {
82
- logger_1.default.warn(`skipping bad statement principal ${statement?.principal}`);
83
- return statement;
84
- }
85
- if (type === 'group') {
86
- const group = groups.find((x) => x.name === identifier);
87
- if (!group) {
88
- logger_1.default.info(`Could not find group ${identifier}`);
89
- }
90
- else {
91
- statement.principal = `group:${group.id}`;
92
- }
93
- }
94
- else if (type === 'user') {
95
- const orgUser = orgUsers.find((x) => x.user.email === identifier);
96
- if (!orgUser) {
97
- logger_1.default.info(`Could not find user ${identifier}`);
98
- }
99
- else {
100
- statement.principal = `user:${orgUser.user.id}`;
101
- }
102
- }
103
- return statement;
104
- }
105
- reducedTypePropertyPolicies.forEach((policy) => {
106
- policy.policy.statements = policy.policy.statements.map((x) => fillPrincipal(x));
107
- });
108
- const currentTPPolicies = await new sdk_1.Entities().get({
109
- entityName: 'type-property-policy',
110
- });
111
- const currentTPPByIdentifier = {};
112
- for (const currentTPP of currentTPPolicies) {
113
- currentTPPByIdentifier[currentTPP.identifier] = currentTPP;
114
- }
115
- const loadedTPPByIdentifier = {};
116
- for (const loadedTPP of reducedTypePropertyPolicies) {
117
- loadedTPPByIdentifier[loadedTPP.identifier] = loadedTPP;
118
- }
119
- for (const [identifier, loadedTPP] of Object.entries(loadedTPPByIdentifier)) {
120
- try {
121
- const found = currentTPPByIdentifier[identifier];
122
- if (!found) {
123
- logger_1.default.info(`Creating: ${identifier}`);
124
- await new sdk_1.Entities().create({
125
- entityName: 'type-property-policy',
126
- object: loadedTPP,
127
- });
128
- }
129
- else {
130
- logger_1.default.info(`Updating: ${identifier}`);
131
- await new sdk_1.Entities().update({
132
- entityName: 'type-property-policy',
133
- id: found.id,
134
- object: loadedTPP,
135
- });
136
- }
137
- }
138
- catch (err) {
139
- logger_1.default.error(`Error Uploading Type Property Policy: ${err}`);
140
- }
141
- }
142
- for (const [identifier, currentTPP] of Object.entries(currentTPPByIdentifier)) {
143
- try {
144
- const found = loadedTPPByIdentifier[identifier];
145
- if (!found) {
146
- logger_1.default.info(`Deleting: ${identifier}`);
147
- await new sdk_1.Entities().delete({
148
- entityName: 'type-property-policy',
149
- id: currentTPP['id'],
150
- });
151
- }
152
- }
153
- catch (err) {
154
- logger_1.default.error(`Error Type Property Policy: ${err}`);
155
- }
156
- }
157
- }
158
- async function uploadTypePropertyPolicyLinks(reducedTypePropertyPolicyLinks) {
159
- const typesWithProperties = await (0, type_extractor_1.getTypes)();
160
- const typeProperties = [];
161
- typesWithProperties.forEach((type) => {
162
- if (type.typeProperties) {
163
- for (const tp of type.typeProperties) {
164
- tp.typeId = type.id;
165
- tp.typeSlug = type.slug;
166
- typeProperties.push(tp);
167
- }
168
- }
169
- });
170
- const currentTPPs = await new sdk_1.Entities().get({
171
- entityName: 'type-property-policy',
172
- });
173
- const currentTPPLinks = await new sdk_1.Entities().get({
174
- entityName: 'type-property-policy-link',
175
- });
176
- logger_1.default.info(`found ${currentTPPLinks.length} current type property policy links`);
177
- logger_1.default.info(`found ${reducedTypePropertyPolicyLinks.length} type property policy links to load`);
178
- const currentLinksHashes = {};
179
- for (const currentLink of currentTPPLinks) {
180
- const foundTPs = findAllOccurrences(typeProperties, (tp) => tp.id === currentLink.typePropertyId);
181
- for (const foundTP of foundTPs) {
182
- const foundTPP = currentTPPs.find((tpp) => tpp.id === currentLink.typePropertyPolicyId);
183
- if (!foundTP || !foundTPP) {
184
- logger_1.default.info(`skipping unhashable, invalid policy link: ${JSON.stringify(currentLink, null, 2)}`);
185
- continue;
186
- }
187
- const hash = `${foundTP.typeSlug}|${foundTP.slug}|${foundTPP.identifier}`;
188
- currentLinksHashes[hash] = currentLink;
189
- }
190
- }
191
- logger_1.default.debug(`current links hashes: ${JSON.stringify(currentLinksHashes, null, 2)}`);
192
- const reducedLinksByHashes = {};
193
- for (const loadedLink of reducedTypePropertyPolicyLinks) {
194
- const hash = `${loadedLink.typeSlug}|${loadedLink.typePropertySlug}|${loadedLink.typePropertyPolicyIdentifier}`;
195
- reducedLinksByHashes[hash] = loadedLink;
196
- }
197
- const toCreate = Object.keys(reducedLinksByHashes)
198
- .filter((x) => !currentLinksHashes[x])
199
- .map((x) => {
200
- return {
201
- [x]: reducedLinksByHashes[x],
202
- };
203
- })
204
- .reduce((a, b) => Object.assign(a, b), {});
205
- const toDelete = _.uniqBy(Object.keys(currentLinksHashes)
206
- .filter((x) => !reducedLinksByHashes[x])
207
- .map((x) => {
208
- return {
209
- [x]: currentLinksHashes[x],
210
- };
211
- }), 'id').reduce((a, b) => Object.assign(a, b), {});
212
- logger_1.default.debug(`reduced links hashes: ${JSON.stringify(reducedLinksByHashes, null, 2)}`);
213
- logger_1.default.info(`found ${Object.keys(toCreate).length} type property policy links to create`);
214
- logger_1.default.info(`found ${Object.keys(toDelete).length} type property policy links to delete`);
215
- logger_1.default.debug(`to create: ${JSON.stringify(toCreate, null, 2)}`);
216
- logger_1.default.debug(`to delete: ${JSON.stringify(toDelete, null, 2)}`);
217
- logger_1.default.debug(`current links hashes to delete: ${JSON.stringify(Object.keys(currentLinksHashes).filter((x) => !reducedLinksByHashes[x]), null, 2)}`);
218
- // fs.writeFileSync('toCreate.json', JSON.stringify(toCreate, null, 2));
219
- // fs.writeFileSync('toDelete.json', JSON.stringify(toDelete, null, 2));
220
- // fs.writeFileSync('currentLinksHashes.json', JSON.stringify(currentLinksHashes, null, 2));
221
- // fs.writeFileSync('reducedLinksByHashes.json', JSON.stringify(reducedLinksByHashes, null, 2));
222
- // fs.writeFileSync(
223
- // 'current_link_hashes_to_delete.json',
224
- // JSON.stringify(
225
- // Object.keys(currentLinksHashes).filter((x) => !reducedLinksByHashes[x]),
226
- // null,
227
- // 2,
228
- // ),
229
- // );
230
- // return;
231
- for (const [hash, link] of Object.entries(toCreate)) {
232
- try {
233
- if (!transformReducedLink(link, typeProperties, currentTPPs)) {
234
- continue;
235
- }
236
- logger_1.default.info(`Creating: ${hash}: ${JSON.stringify(link, null, 2)}`);
237
- await new sdk_1.Entities().create({
238
- entityName: 'type-property-policy-link',
239
- object: {
240
- typePropertyPolicyId: link.typePropertyPolicyId,
241
- typePropertyId: link.typePropertyId,
242
- },
243
- });
244
- }
245
- catch (err) {
246
- logger_1.default.error(`Error Uploading type property policy links: ${err}`);
247
- }
248
- }
249
- for (const [hash, link] of Object.entries(toDelete)) {
250
- try {
251
- logger_1.default.info(`Deleting: ${hash}`);
252
- await new sdk_1.Entities().delete({
253
- entityName: 'type-property-policy-link',
254
- id: link['id'],
255
- });
256
- }
257
- catch (err) {
258
- logger_1.default.error(`Error Deleting type property policy link: ${err}`);
259
- }
260
- }
261
- function transformReducedLink(TPPLink, typeProperties, typePropertyPolicies) {
262
- const foundTP = typeProperties.find((tp) => tp.slug === TPPLink.typePropertySlug && tp.typeSlug === TPPLink.typeSlug);
263
- if (!foundTP) {
264
- logger_1.default.error(`Could not find type property with slug ${TPPLink.typePropertySlug} `);
265
- return false;
266
- }
267
- TPPLink.typePropertyId = foundTP.id;
268
- const foundTPP = typePropertyPolicies.find((tpp) => tpp.identifier === TPPLink.typePropertyPolicyIdentifier);
269
- if (!foundTPP) {
270
- logger_1.default.error(`Could not find type property policy with identifier ${TPPLink.typePropertyPolicyIdentifier} `);
271
- return false;
272
- }
273
- TPPLink.typePropertyPolicyId = foundTPP.id;
274
- return true;
275
- }
276
- }
277
- function findAllOccurrences(array, evaluator) {
278
- const found = [];
279
- for (let i = 0; i < array.length; i++) {
280
- const element = array[i];
281
- if (evaluator(element)) {
282
- found.push(element);
283
- }
284
- }
285
- return found;
286
- }
287
- exports.findAllOccurrences = findAllOccurrences;
21
+ `,
22
+ ];
23
+ static flags = {
24
+ ...basecommand_1.BaseCommand.baseFlags,
25
+ dir: core_1.Flags.string({
26
+ char: 'd',
27
+ description: 'The directory from which to export the type property policy data. Defaults to the current directory. The type property policy data will be loaded from $dir/type-property-policies/*.yml',
28
+ required: false,
29
+ default: '.',
30
+ }),
31
+ };
32
+ async run() {
33
+ return await uploadTypePropertyPolicies(this.flags.dir);
34
+ }
35
+ }
36
+ exports.default = UploadTypePropertyPolicies;
37
+ async function uploadTypePropertyPolicies(dir) {
38
+ try {
39
+ await (0, login_1.authUser)();
40
+ logger_1.default.info(`${chalk_1.default.yellow.bold('TYPE PROPERTY POLICY')} Uploading`);
41
+ const [reducedTypePropertyPolicies, reducedTypePropertyPolicyLinks] = await loadTPPolicies(dir);
42
+ await uploadTPPolicyObjects(reducedTypePropertyPolicies);
43
+ await uploadTypePropertyPolicyLinks(reducedTypePropertyPolicyLinks);
44
+ logger_1.default.info(`${chalk_1.default.yellow.bold('TYPE PROPERTY POLICY')} Uploaded`);
45
+ }
46
+ catch (e) {
47
+ logger_1.default.info(`${chalk_1.default.red.bold('FAIL')} Type Property Policy Upload Failed . ${e}`);
48
+ //TODO make this only print if a debug flag is set
49
+ console.trace(e);
50
+ return;
51
+ }
52
+ logger_1.default.info(`${chalk_1.default.green.bold('COMPLETE')} Type Property Policy Upload Complete.`);
53
+ }
54
+ exports.uploadTypePropertyPolicies = uploadTypePropertyPolicies;
55
+ function loadTPPolicies(fromDir) {
56
+ const tpps = [];
57
+ let tppLinks = [];
58
+ const dir = path.join(fromDir, 'type-property-policies');
59
+ try {
60
+ const files = fs_1.default.readdirSync(dir);
61
+ for (const file of files) {
62
+ tpps.push(js_yaml_1.default.load(fs_1.default.readFileSync(path.join(dir, file), 'utf8')));
63
+ }
64
+ tppLinks = js_yaml_1.default.load(fs_1.default.readFileSync(path.join(fromDir, 'type-property-policy-links.yml'), 'utf8'));
65
+ return [tpps, tppLinks];
66
+ }
67
+ catch (e) {
68
+ throw new Error(`ERROR PARSING YAML: ${e}`);
69
+ }
70
+ }
71
+ async function uploadTPPolicyObjects(reducedTypePropertyPolicies) {
72
+ const orgUsers = await (0, users_1.getUserOrgs)();
73
+ const groups = await (0, users_1.getGroups)();
74
+ function fillPrincipal(statement) {
75
+ const principal = statement?.principal;
76
+ if (!principal) {
77
+ logger_1.default.warn(`skipping bad statement principal ${statement?.principal}`);
78
+ return statement;
79
+ }
80
+ const [type, identifier] = principal.split(':');
81
+ if (!type || !identifier) {
82
+ logger_1.default.warn(`skipping bad statement principal ${statement?.principal}`);
83
+ return statement;
84
+ }
85
+ if (type === 'group') {
86
+ const group = groups.find((x) => x.name === identifier);
87
+ if (!group) {
88
+ logger_1.default.info(`Could not find group ${identifier}`);
89
+ }
90
+ else {
91
+ statement.principal = `group:${group.id}`;
92
+ }
93
+ }
94
+ else if (type === 'user') {
95
+ const orgUser = orgUsers.find((x) => x.user.email === identifier);
96
+ if (!orgUser) {
97
+ logger_1.default.info(`Could not find user ${identifier}`);
98
+ }
99
+ else {
100
+ statement.principal = `user:${orgUser.user.id}`;
101
+ }
102
+ }
103
+ return statement;
104
+ }
105
+ reducedTypePropertyPolicies.forEach((policy) => {
106
+ policy.policy.statements = policy.policy.statements.map((x) => fillPrincipal(x));
107
+ });
108
+ const currentTPPolicies = await new sdk_1.Entities().get({
109
+ entityName: 'type-property-policy',
110
+ });
111
+ const currentTPPByIdentifier = {};
112
+ for (const currentTPP of currentTPPolicies) {
113
+ currentTPPByIdentifier[currentTPP.identifier] = currentTPP;
114
+ }
115
+ const loadedTPPByIdentifier = {};
116
+ for (const loadedTPP of reducedTypePropertyPolicies) {
117
+ loadedTPPByIdentifier[loadedTPP.identifier] = loadedTPP;
118
+ }
119
+ for (const [identifier, loadedTPP] of Object.entries(loadedTPPByIdentifier)) {
120
+ try {
121
+ const found = currentTPPByIdentifier[identifier];
122
+ if (!found) {
123
+ logger_1.default.info(`Creating: ${identifier}`);
124
+ await new sdk_1.Entities().create({
125
+ entityName: 'type-property-policy',
126
+ object: loadedTPP,
127
+ });
128
+ }
129
+ else {
130
+ logger_1.default.info(`Updating: ${identifier}`);
131
+ await new sdk_1.Entities().update({
132
+ entityName: 'type-property-policy',
133
+ id: found.id,
134
+ object: loadedTPP,
135
+ });
136
+ }
137
+ }
138
+ catch (err) {
139
+ logger_1.default.error(`Error Uploading Type Property Policy: ${err}`);
140
+ }
141
+ }
142
+ for (const [identifier, currentTPP] of Object.entries(currentTPPByIdentifier)) {
143
+ try {
144
+ const found = loadedTPPByIdentifier[identifier];
145
+ if (!found) {
146
+ logger_1.default.info(`Deleting: ${identifier}`);
147
+ await new sdk_1.Entities().delete({
148
+ entityName: 'type-property-policy',
149
+ id: currentTPP['id'],
150
+ });
151
+ }
152
+ }
153
+ catch (err) {
154
+ logger_1.default.error(`Error Type Property Policy: ${err}`);
155
+ }
156
+ }
157
+ }
158
+ async function uploadTypePropertyPolicyLinks(reducedTypePropertyPolicyLinks) {
159
+ const typesWithProperties = await (0, type_extractor_1.getTypes)();
160
+ const typeProperties = [];
161
+ typesWithProperties.forEach((type) => {
162
+ if (type.typeProperties) {
163
+ for (const tp of type.typeProperties) {
164
+ tp.typeId = type.id;
165
+ tp.typeSlug = type.slug;
166
+ typeProperties.push(tp);
167
+ }
168
+ }
169
+ });
170
+ const currentTPPs = await new sdk_1.Entities().get({
171
+ entityName: 'type-property-policy',
172
+ });
173
+ const currentTPPLinks = await new sdk_1.Entities().get({
174
+ entityName: 'type-property-policy-link',
175
+ });
176
+ logger_1.default.info(`found ${currentTPPLinks.length} current type property policy links`);
177
+ logger_1.default.info(`found ${reducedTypePropertyPolicyLinks.length} type property policy links to load`);
178
+ const currentLinksHashes = {};
179
+ for (const currentLink of currentTPPLinks) {
180
+ const foundTPs = findAllOccurrences(typeProperties, (tp) => tp.id === currentLink.typePropertyId);
181
+ for (const foundTP of foundTPs) {
182
+ const foundTPP = currentTPPs.find((tpp) => tpp.id === currentLink.typePropertyPolicyId);
183
+ if (!foundTP || !foundTPP) {
184
+ logger_1.default.info(`skipping unhashable, invalid policy link: ${JSON.stringify(currentLink, null, 2)}`);
185
+ continue;
186
+ }
187
+ const hash = `${foundTP.typeSlug}|${foundTP.slug}|${foundTPP.identifier}`;
188
+ currentLinksHashes[hash] = currentLink;
189
+ }
190
+ }
191
+ logger_1.default.debug(`current links hashes: ${JSON.stringify(currentLinksHashes, null, 2)}`);
192
+ const reducedLinksByHashes = {};
193
+ for (const loadedLink of reducedTypePropertyPolicyLinks) {
194
+ const hash = `${loadedLink.typeSlug}|${loadedLink.typePropertySlug}|${loadedLink.typePropertyPolicyIdentifier}`;
195
+ reducedLinksByHashes[hash] = loadedLink;
196
+ }
197
+ const toCreate = Object.keys(reducedLinksByHashes)
198
+ .filter((x) => !currentLinksHashes[x])
199
+ .map((x) => {
200
+ return {
201
+ [x]: reducedLinksByHashes[x],
202
+ };
203
+ })
204
+ .reduce((a, b) => Object.assign(a, b), {});
205
+ const toDelete = _.uniqBy(Object.keys(currentLinksHashes)
206
+ .filter((x) => !reducedLinksByHashes[x])
207
+ .map((x) => {
208
+ return {
209
+ [x]: currentLinksHashes[x],
210
+ };
211
+ }), 'id').reduce((a, b) => Object.assign(a, b), {});
212
+ logger_1.default.debug(`reduced links hashes: ${JSON.stringify(reducedLinksByHashes, null, 2)}`);
213
+ logger_1.default.info(`found ${Object.keys(toCreate).length} type property policy links to create`);
214
+ logger_1.default.info(`found ${Object.keys(toDelete).length} type property policy links to delete`);
215
+ logger_1.default.debug(`to create: ${JSON.stringify(toCreate, null, 2)}`);
216
+ logger_1.default.debug(`to delete: ${JSON.stringify(toDelete, null, 2)}`);
217
+ logger_1.default.debug(`current links hashes to delete: ${JSON.stringify(Object.keys(currentLinksHashes).filter((x) => !reducedLinksByHashes[x]), null, 2)}`);
218
+ // fs.writeFileSync('toCreate.json', JSON.stringify(toCreate, null, 2));
219
+ // fs.writeFileSync('toDelete.json', JSON.stringify(toDelete, null, 2));
220
+ // fs.writeFileSync('currentLinksHashes.json', JSON.stringify(currentLinksHashes, null, 2));
221
+ // fs.writeFileSync('reducedLinksByHashes.json', JSON.stringify(reducedLinksByHashes, null, 2));
222
+ // fs.writeFileSync(
223
+ // 'current_link_hashes_to_delete.json',
224
+ // JSON.stringify(
225
+ // Object.keys(currentLinksHashes).filter((x) => !reducedLinksByHashes[x]),
226
+ // null,
227
+ // 2,
228
+ // ),
229
+ // );
230
+ // return;
231
+ for (const [hash, link] of Object.entries(toCreate)) {
232
+ try {
233
+ if (!transformReducedLink(link, typeProperties, currentTPPs)) {
234
+ continue;
235
+ }
236
+ logger_1.default.info(`Creating: ${hash}: ${JSON.stringify(link, null, 2)}`);
237
+ await new sdk_1.Entities().create({
238
+ entityName: 'type-property-policy-link',
239
+ object: {
240
+ typePropertyPolicyId: link.typePropertyPolicyId,
241
+ typePropertyId: link.typePropertyId,
242
+ },
243
+ });
244
+ }
245
+ catch (err) {
246
+ logger_1.default.error(`Error Uploading type property policy links: ${err}`);
247
+ }
248
+ }
249
+ for (const [hash, link] of Object.entries(toDelete)) {
250
+ try {
251
+ logger_1.default.info(`Deleting: ${hash}`);
252
+ await new sdk_1.Entities().delete({
253
+ entityName: 'type-property-policy-link',
254
+ id: link['id'],
255
+ });
256
+ }
257
+ catch (err) {
258
+ logger_1.default.error(`Error Deleting type property policy link: ${err}`);
259
+ }
260
+ }
261
+ function transformReducedLink(TPPLink, typeProperties, typePropertyPolicies) {
262
+ const foundTP = typeProperties.find((tp) => tp.slug === TPPLink.typePropertySlug && tp.typeSlug === TPPLink.typeSlug);
263
+ if (!foundTP) {
264
+ logger_1.default.error(`Could not find type property with slug ${TPPLink.typePropertySlug} `);
265
+ return false;
266
+ }
267
+ TPPLink.typePropertyId = foundTP.id;
268
+ const foundTPP = typePropertyPolicies.find((tpp) => tpp.identifier === TPPLink.typePropertyPolicyIdentifier);
269
+ if (!foundTPP) {
270
+ logger_1.default.error(`Could not find type property policy with identifier ${TPPLink.typePropertyPolicyIdentifier} `);
271
+ return false;
272
+ }
273
+ TPPLink.typePropertyPolicyId = foundTPP.id;
274
+ return true;
275
+ }
276
+ }
277
+ function findAllOccurrences(array, evaluator) {
278
+ const found = [];
279
+ for (let i = 0; i < array.length; i++) {
280
+ const element = array[i];
281
+ if (evaluator(element)) {
282
+ found.push(element);
283
+ }
284
+ }
285
+ return found;
286
+ }
287
+ exports.findAllOccurrences = findAllOccurrences;
@@ -1,13 +1,13 @@
1
- import { BaseCommand } from '../../basecommand';
2
- export default class UploadTypes extends BaseCommand {
3
- static description: string;
4
- static examples: string[];
5
- static flags: {
6
- dir: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
- merge: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
8
- alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
9
- logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
10
- };
11
- run(): Promise<void>;
12
- }
13
- export declare function uploadTypes(dir: string, isMerge: boolean): Promise<void>;
1
+ import { BaseCommand } from '../../basecommand';
2
+ export default class UploadTypes extends BaseCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ dir: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
+ merge: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
8
+ alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
9
+ logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
10
+ };
11
+ run(): Promise<void>;
12
+ }
13
+ export declare function uploadTypes(dir: string, isMerge: boolean): Promise<void>;