@contrail/cli 3.5.1-alpha.68d57e0 → 3.5.1-alpha.fd40e6d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,7 +17,7 @@ $ npm install -g @contrail/cli
17
17
  $ contrail COMMAND
18
18
  running command...
19
19
  $ contrail (--version)
20
- @contrail/cli/3.5.1-alpha.68d57e0 linux-x64 node-v24.14.1
20
+ @contrail/cli/3.5.1-alpha.fd40e6d linux-x64 node-v24.14.1
21
21
  $ contrail --help [COMMAND]
22
22
  USAGE
23
23
  $ contrail COMMAND
@@ -1405,7 +1405,7 @@ EXAMPLES
1405
1405
 
1406
1406
  ## `contrail types uploadUsageInfo`
1407
1407
 
1408
- Upload extracted usage info
1408
+ [DEPRECATED] Upload extracted usage info. Use uploadTypeOverrides instead.
1409
1409
 
1410
1410
  ```
1411
1411
  USAGE
@@ -1420,7 +1420,7 @@ FLAGS
1420
1420
  <options: error|warn|info|debug>
1421
1421
 
1422
1422
  DESCRIPTION
1423
- Upload extracted usage info
1423
+ [DEPRECATED] Upload extracted usage info. Use uploadTypeOverrides instead.
1424
1424
 
1425
1425
  EXAMPLES
1426
1426
  $ contrail types uploadUsageInfo
@@ -1,13 +1,8 @@
1
1
  export declare function getOptionSets(): Promise<any[]>;
2
2
  export declare function getUserLists(): Promise<any[]>;
3
3
  export declare function getOptionSetHierarchies(): Promise<any[]>;
4
- export declare function getOptionSetHierarchyLinks(): Promise<any[]>;
5
4
  export declare function getRuleSets(): Promise<any[]>;
6
- export declare function getRuleSetLinks(): Promise<any[]>;
7
- export declare function getUsageInfo(): Promise<any[]>;
8
5
  export declare function getTypePropertyPolicies(): Promise<any[]>;
9
- export declare function getTypePropertyPolicyLinks(): Promise<any[]>;
10
6
  export declare function getTypePolicies(): Promise<any[]>;
11
7
  export declare function getTypeOverrideCopies(): Promise<any[]>;
12
8
  export declare function uploadTypeOverrideObjects(reducedOverrides: any): Promise<void>;
13
- export declare function getTypePolicyLinks(): Promise<any[]>;
package/dist/api/types.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTypePolicyLinks = exports.uploadTypeOverrideObjects = exports.getTypeOverrideCopies = exports.getTypePolicies = exports.getTypePropertyPolicyLinks = exports.getTypePropertyPolicies = exports.getUsageInfo = exports.getRuleSetLinks = exports.getRuleSets = exports.getOptionSetHierarchyLinks = exports.getOptionSetHierarchies = exports.getUserLists = exports.getOptionSets = void 0;
3
+ exports.uploadTypeOverrideObjects = exports.getTypeOverrideCopies = exports.getTypePolicies = exports.getTypePropertyPolicies = exports.getRuleSets = exports.getOptionSetHierarchies = exports.getUserLists = exports.getOptionSets = void 0;
4
4
  const sdk_1 = require("@contrail/sdk");
5
5
  async function getOptionSets() {
6
6
  return await new sdk_1.Entities().get({
@@ -21,13 +21,6 @@ async function getOptionSetHierarchies() {
21
21
  });
22
22
  }
23
23
  exports.getOptionSetHierarchies = getOptionSetHierarchies;
24
- async function getOptionSetHierarchyLinks() {
25
- const entitiesClient = new sdk_1.Entities();
26
- return await entitiesClient.get({
27
- entityName: 'type-option-set-hierarchy-link',
28
- });
29
- }
30
- exports.getOptionSetHierarchyLinks = getOptionSetHierarchyLinks;
31
24
  async function getRuleSets() {
32
25
  const entitiesClient = new sdk_1.Entities();
33
26
  return await entitiesClient.get({
@@ -35,20 +28,6 @@ async function getRuleSets() {
35
28
  });
36
29
  }
37
30
  exports.getRuleSets = getRuleSets;
38
- async function getRuleSetLinks() {
39
- const entitiesClient = new sdk_1.Entities();
40
- return await entitiesClient.get({
41
- entityName: 'type-rule-set-link',
42
- });
43
- }
44
- exports.getRuleSetLinks = getRuleSetLinks;
45
- async function getUsageInfo() {
46
- const entitiesClient = new sdk_1.Entities();
47
- return await entitiesClient.get({
48
- entityName: 'type-property-usage-info',
49
- });
50
- }
51
- exports.getUsageInfo = getUsageInfo;
52
31
  async function getTypePropertyPolicies() {
53
32
  const entitiesClient = new sdk_1.Entities();
54
33
  return await entitiesClient.get({
@@ -56,13 +35,6 @@ async function getTypePropertyPolicies() {
56
35
  });
57
36
  }
58
37
  exports.getTypePropertyPolicies = getTypePropertyPolicies;
59
- async function getTypePropertyPolicyLinks() {
60
- const entitiesClient = new sdk_1.Entities();
61
- return await entitiesClient.get({
62
- entityName: 'type-property-policy-link',
63
- });
64
- }
65
- exports.getTypePropertyPolicyLinks = getTypePropertyPolicyLinks;
66
38
  async function getTypePolicies() {
67
39
  const entitiesClient = new sdk_1.Entities();
68
40
  return await entitiesClient.get({
@@ -86,10 +58,3 @@ async function uploadTypeOverrideObjects(reducedOverrides) {
86
58
  });
87
59
  }
88
60
  exports.uploadTypeOverrideObjects = uploadTypeOverrideObjects;
89
- async function getTypePolicyLinks() {
90
- const entitiesClient = new sdk_1.Entities();
91
- return await entitiesClient.get({
92
- entityName: 'type-policy-link',
93
- });
94
- }
95
- exports.getTypePolicyLinks = getTypePolicyLinks;
@@ -54,14 +54,9 @@ async function getAll(outDir, overwrite) {
54
54
  types: await (0, type_extractor_1.getTypes)(),
55
55
  optionSets: await (0, types_1.getOptionSets)(),
56
56
  optionSetHierarchies: await (0, types_1.getOptionSetHierarchies)(),
57
- optionSetHierarchyLinks: await (0, types_1.getOptionSetHierarchyLinks)(),
58
57
  ruleSets: await (0, types_1.getRuleSets)(),
59
- ruleSetLinks: await (0, types_1.getRuleSetLinks)(),
60
- usageInfo: await (0, types_1.getUsageInfo)(),
61
58
  typePropertyPolicies: await (0, types_1.getTypePropertyPolicies)(),
62
- typePropertyPolicyLinks: await (0, types_1.getTypePropertyPolicyLinks)(),
63
59
  typePolicies: await (0, types_1.getTypePolicies)(),
64
- typePolicyLinks: await (0, types_1.getTypePolicyLinks)(),
65
60
  typeOverrides: await (0, types_1.getTypeOverrideCopies)(),
66
61
  orgUsers: await (0, users_1.getUserOrgs)(),
67
62
  groups: await (0, users_1.getGroups)(),
@@ -125,31 +120,18 @@ async function saveData(reducedData, dir, overwrite) {
125
120
  split: true,
126
121
  fileLabel: 'identifier',
127
122
  },
128
- reducedOptionSetHierarchyLinks: {
129
- filename: 'type-option-set-hierarchy-links',
130
- split: false,
131
- fileLabel: '',
132
- },
133
123
  reducedRuleSets: { filename: 'rule-sets', split: true, fileLabel: 'name' },
134
- reducedRuleSetLinks: { filename: 'rule-set-links', split: false, fileLabel: '' },
135
- reducedUsageInfo: { filename: 'usage-info', split: false, fileLabel: '' },
136
124
  reducedTypePropertyPolicies: {
137
125
  filename: 'type-property-policies',
138
126
  split: true,
139
127
  fileLabel: 'label',
140
128
  },
141
- reducedTypePropertyPolicyLinks: {
142
- filename: 'type-property-policy-links',
143
- split: false,
144
- fileLabel: '',
145
- },
146
129
  reducedOverrides: {
147
130
  filename: 'type-overrides',
148
131
  split: false,
149
132
  fileLabel: '',
150
133
  },
151
134
  reducedTypePolicies: { filename: 'type-policies', split: true, fileLabel: 'label' },
152
- reducedTypePolicyLinks: { filename: 'type-policy-links', split: false, fileLabel: '' },
153
135
  };
154
136
  for (const [key, folder] of Object.entries(propertyToFolderMap)) {
155
137
  const CURRENT_DIR = process.cwd();
@@ -7,7 +7,6 @@ const chalk_1 = tslib_1.__importDefault(require("chalk"));
7
7
  const login_1 = require("../../auth/login");
8
8
  const uploadOptionSets_1 = require("./uploadOptionSets");
9
9
  const uploadOptionSetHierarchies_1 = require("./uploadOptionSetHierarchies");
10
- const uploadUsageInfo_1 = require("./uploadUsageInfo");
11
10
  const uploadRuleSets_1 = require("./uploadRuleSets");
12
11
  const uploadTypePropertyPolicies_1 = require("./uploadTypePropertyPolicies");
13
12
  const type_uploader_1 = require("../../helpers/types/type-uploader");
@@ -41,7 +40,6 @@ async function loadAll(dir, skipPolicies = false) {
41
40
  await (0, uploadOptionSets_1.uploadOptionSets)(dir);
42
41
  await (0, type_uploader_1.uploadTypes)(dir);
43
42
  await (0, uploadOptionSetHierarchies_1.uploadOptionSetHierarchies)(dir);
44
- await (0, uploadUsageInfo_1.uploadUsageInfo)(dir);
45
43
  await (0, uploadRuleSets_1.uploadRuleSets)(dir);
46
44
  if (!skipPolicies) {
47
45
  await (0, uploadTypePropertyPolicies_1.uploadTypePropertyPolicies)(dir);
@@ -62,14 +62,9 @@ async function mergeTypeProperties(fileLocation, typePaths) {
62
62
  types: await (0, type_extractor_1.getTypes)(),
63
63
  optionSets: await (0, types_2.getOptionSets)(),
64
64
  optionSetHierarchies: [],
65
- optionSetHierarchyLinks: [],
66
65
  ruleSets: [],
67
- ruleSetLinks: [],
68
- usageInfo: [],
69
66
  typePropertyPolicies: [],
70
- typePropertyPolicyLinks: [],
71
67
  typePolicies: [],
72
- typePolicyLinks: [],
73
68
  };
74
69
  const reducedData = await (0, types_1.getAllReducedTypes)(data);
75
70
  for (const typePath of typePaths) {
@@ -8,7 +8,6 @@ const path = tslib_1.__importStar(require("path"));
8
8
  const login_1 = require("../../auth/login");
9
9
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
10
10
  const core_1 = require("@oclif/core");
11
- const type_extractor_1 = require("../../helpers/types/type-extractor");
12
11
  const basecommand_1 = require("../../basecommand");
13
12
  const logger_1 = tslib_1.__importDefault(require("../../logger"));
14
13
  const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
@@ -38,8 +37,6 @@ async function uploadOptionSetHierarchies(dir) {
38
37
  logger_1.default.info(`${chalk_1.default.yellow.bold('OPTION SET HIERARCHIES')} Uploading`);
39
38
  const optionSetHierarchies = await loadOptionSetHierarchies(dir);
40
39
  await uploadOSH(optionSetHierarchies);
41
- const optionSetHierarchyLinks = await loadOptionSetHierarchyLinks(dir);
42
- await uploadOSHLinks(optionSetHierarchyLinks);
43
40
  logger_1.default.info(`${chalk_1.default.yellow.bold('OPTION SET HIERARCHIES')} Uploaded`);
44
41
  }
45
42
  catch (e) {
@@ -63,14 +60,6 @@ function loadOptionSetHierarchies(fromDir) {
63
60
  throw new Error(`ERROR PARSING YAML: ${e}`);
64
61
  }
65
62
  }
66
- function loadOptionSetHierarchyLinks(fromDir) {
67
- try {
68
- return js_yaml_1.default.load(fs_1.default.readFileSync(path.join(fromDir, 'type-option-set-hierarchy-links.yml'), 'utf8'));
69
- }
70
- catch (e) {
71
- throw new Error(`ERROR PARSING YAML: ${e}`);
72
- }
73
- }
74
63
  async function uploadOSH(loadedOSHs) {
75
64
  const optionSets = await new sdk_1.Entities().get({
76
65
  entityName: 'type-property-option-set',
@@ -150,109 +139,3 @@ function transformOSHNameToID(hierarchy, optionSets) {
150
139
  }
151
140
  return true;
152
141
  }
153
- async function uploadOSHLinks(reducedOSHLinks) {
154
- const typesWithProperties = await (0, type_extractor_1.getTypes)();
155
- const typeProperties = [];
156
- typesWithProperties.forEach((type) => {
157
- if (type.typeProperties) {
158
- for (const tp of type.typeProperties) {
159
- tp.typeId = type.id;
160
- tp.typeSlug = type.slug;
161
- typeProperties.push(tp);
162
- }
163
- }
164
- });
165
- const currentOSHs = await new sdk_1.Entities().get({
166
- entityName: 'option-set-hierarchy',
167
- });
168
- const currentOSHLinks = await new sdk_1.Entities().get({
169
- entityName: 'type-option-set-hierarchy-link',
170
- });
171
- const currentOSHLinkHashes = {};
172
- for (const currentLink of currentOSHLinks) {
173
- const foundType = typesWithProperties.find((x) => x.id === currentLink.typeId);
174
- const foundOSH = currentOSHs.find((osh) => osh.id === currentLink.optionSetHierarchyId);
175
- const foundTPSlugs = typeProperties
176
- .filter((x) => currentLink?.hierarchyTypePropertyIds?.includes(x.id))
177
- .map((x) => x.slug);
178
- if (!foundType ||
179
- !foundOSH ||
180
- foundTPSlugs.length !== currentLink.hierarchyTypePropertyIds.length) {
181
- logger_1.default.info(`skipping unhashable, invalid type option set hierarchy link: ${JSON.stringify(currentLink, null, 2)}`);
182
- }
183
- // don't mutate original array
184
- const sortedFoundTPSlugs = [...foundTPSlugs].sort();
185
- const hash = `${foundType.slug}|${foundOSH.name}|${sortedFoundTPSlugs.join('|')}`;
186
- currentOSHLinkHashes[hash] = currentLink;
187
- }
188
- const reducedLinksByHashes = {};
189
- for (const loadedLink of reducedOSHLinks) {
190
- // don't mutate original array
191
- const sortedTPSlugs = [...loadedLink.typePropertySlugs].sort();
192
- const hash = `${loadedLink.typeSlug}|${loadedLink.optionSetHierarchyIdentifier}|${sortedTPSlugs.join('|')}}`;
193
- reducedLinksByHashes[hash] = loadedLink;
194
- }
195
- for (const loadedLink of reducedOSHLinks) {
196
- try {
197
- // don't mutate original array
198
- const sortedTPSlugs = [...loadedLink.typePropertySlugs].sort();
199
- const found = currentOSHLinkHashes[`${loadedLink.typeSlug}|${loadedLink.optionSetHierarchyIdentifier}|${sortedTPSlugs.join('|')}`];
200
- if (!found) {
201
- if (!transformReducedLink(loadedLink, typesWithProperties, currentOSHs)) {
202
- continue;
203
- }
204
- logger_1.default.debug(`Creating: ${JSON.stringify(loadedLink, null, 2)}`);
205
- await new sdk_1.Entities().create({
206
- entityName: 'type-option-set-hierarchy-link',
207
- object: {
208
- hierarchyTypePropertyIds: loadedLink.hierarchyTypePropertyIds,
209
- optionSetHierarchyId: loadedLink.optionSetHierarchyId,
210
- typeId: loadedLink.typeId,
211
- },
212
- });
213
- }
214
- }
215
- catch (err) {
216
- logger_1.default.error(`Error uploading type option set hierarchy links: ${err}`);
217
- }
218
- }
219
- for (const [currentLinkHash, currentLink] of Object.entries(currentOSHLinkHashes)) {
220
- try {
221
- const found = reducedLinksByHashes[currentLinkHash];
222
- if (!found) {
223
- logger_1.default.debug(`Deleting: ${JSON.stringify(currentLinkHash)}`);
224
- await new sdk_1.Entities().delete({
225
- entityName: 'type-option-set-hierarchy-link',
226
- id: currentLink['id'],
227
- });
228
- }
229
- }
230
- catch (err) {
231
- logger_1.default.error(`Error Deleting rule set link: ${err}`);
232
- }
233
- }
234
- }
235
- function transformReducedLink(OSHLink, typesWithProperties, OSHs) {
236
- logger_1.default.debug(`OSHLink before transform: ${JSON.stringify(OSHLink, null, 2)}`);
237
- const foundType = typesWithProperties.find((x) => x.slug === OSHLink.typeSlug);
238
- if (!foundType) {
239
- logger_1.default.error(`OSH Links: Could not find type with slug ${OSHLink.typeSlug}`);
240
- return false;
241
- }
242
- OSHLink.typeId = foundType.id;
243
- const foundTPs = foundType?.typeProperties?.filter((x) => OSHLink.typePropertySlugs.includes(x.slug)) ?? [];
244
- if (foundTPs.length !== OSHLink.typePropertySlugs.length) {
245
- logger_1.default.error(`OSH Links: Could not find all type properties with slugs ${OSHLink.typePropertySlugs}`);
246
- return false;
247
- }
248
- logger_1.default.debug(`foundTPs: ${JSON.stringify(foundTPs)}`);
249
- OSHLink.hierarchyTypePropertyIds = foundTPs.map((x) => x.id);
250
- const foundOSH = OSHs.find((x) => x.identifier === OSHLink.optionSetHierarchyIdentifier);
251
- if (!foundOSH) {
252
- logger_1.default.error(`OSH Links: Could not find option set hierarchy with identifier ${OSHLink.optionSetHierarchyIdentifier}`);
253
- return false;
254
- }
255
- OSHLink.optionSetHierarchyId = foundOSH.id;
256
- logger_1.default.debug(`OSHLink after transform: ${JSON.stringify(OSHLink, null, 2)}`);
257
- return true;
258
- }
@@ -129,7 +129,7 @@ async function uploadOS(dir) {
129
129
  }
130
130
  function validateOptionSets(optionSets) {
131
131
  optionSets.forEach((optionSet) => {
132
- optionSet.optionSet.forEach((option) => {
132
+ optionSet.optionSet?.forEach((option) => {
133
133
  validateOption(option, optionSet.slug);
134
134
  });
135
135
  });
@@ -35,9 +35,8 @@ async function uploadRuleSets(dir) {
35
35
  try {
36
36
  await (0, login_1.authUser)();
37
37
  logger_1.default.info(`${chalk_1.default.yellow.bold('RULE SET')} Uploading`);
38
- const [reducedRuleSets, reducedRuleSetLinks] = await loadReducedRuleSets(dir);
38
+ const reducedRuleSets = await loadReducedRuleSets(dir);
39
39
  await uploadRuleSetObjects(reducedRuleSets);
40
- await uploadRuleSetLinkObjects(reducedRuleSetLinks);
41
40
  logger_1.default.info(`${chalk_1.default.yellow.bold('RULE SET')} Uploaded`);
42
41
  }
43
42
  catch (e) {
@@ -49,15 +48,13 @@ async function uploadRuleSets(dir) {
49
48
  exports.uploadRuleSets = uploadRuleSets;
50
49
  function loadReducedRuleSets(fromDir) {
51
50
  const ruleSets = [];
52
- let ruleSetLinks = [];
53
51
  const dir = path.join(fromDir, 'rule-sets');
54
52
  try {
55
53
  const files = fs_1.default.readdirSync(dir);
56
54
  for (const file of files) {
57
55
  ruleSets.push(js_yaml_1.default.load(fs_1.default.readFileSync(path.join(dir, file), 'utf8')));
58
56
  }
59
- ruleSetLinks = js_yaml_1.default.load(fs_1.default.readFileSync(path.join(fromDir, 'rule-set-links.yml'), 'utf8'));
60
- return [ruleSets, ruleSetLinks];
57
+ return ruleSets;
61
58
  }
62
59
  catch (e) {
63
60
  throw new Error(`ERROR PARSING YAML: ${e}`);
@@ -116,83 +113,3 @@ async function uploadRuleSetObjects(reducedRuleSets) {
116
113
  }
117
114
  }
118
115
  }
119
- async function uploadRuleSetLinkObjects(loadedRuleSetLinks) {
120
- const types = await new sdk_1.Entities().get({
121
- entityName: 'type',
122
- });
123
- const currentRuleSets = await new sdk_1.Entities().get({
124
- entityName: 'type-rule-set',
125
- });
126
- const currentRuleSetLinks = await new sdk_1.Entities().get({
127
- entityName: 'type-rule-set-link',
128
- });
129
- const currentLinksHashes = {};
130
- for (const currentLink of currentRuleSetLinks) {
131
- const foundType = types.find((t) => t.id === currentLink.typeId);
132
- const foundRuleSet = currentRuleSets.find((rs) => rs.id === currentLink.typeRuleSetId);
133
- const hash = `${foundType.slug}|${foundRuleSet.name}`;
134
- currentLinksHashes[hash] = currentLink;
135
- }
136
- const reducedLinksByHashes = {};
137
- for (const loadedLink of loadedRuleSetLinks) {
138
- const hash = `${loadedLink.type}|${loadedLink.ruleSet}`;
139
- reducedLinksByHashes[hash] = loadedLink;
140
- }
141
- for (const loadedRuleSetLink of loadedRuleSetLinks) {
142
- try {
143
- const found = currentLinksHashes[`${loadedRuleSetLink.type}|${loadedRuleSetLink.ruleSet}`];
144
- if (!found) {
145
- if (!transformReducedLink(loadedRuleSetLink, types, currentRuleSets)) {
146
- continue;
147
- }
148
- logger_1.default.info(`Creating: ${JSON.stringify(loadedRuleSetLink, null, 2)}`);
149
- await new sdk_1.Entities().create({
150
- entityName: 'type-rule-set-link',
151
- object: {
152
- typeRuleSetId: loadedRuleSetLink.ruleSet,
153
- typeId: loadedRuleSetLink.type,
154
- },
155
- });
156
- }
157
- else {
158
- if (!transformReducedLink(loadedRuleSetLink, types, currentRuleSets)) {
159
- continue;
160
- }
161
- logger_1.default.info(`skipping updating existing rule set link: ${loadedRuleSetLink}`);
162
- }
163
- }
164
- catch (err) {
165
- logger_1.default.error(`Error Uploading rule set links: ${err}`);
166
- }
167
- }
168
- for (const [currentLinkHash, currentLink] of Object.entries(currentLinksHashes)) {
169
- try {
170
- const found = reducedLinksByHashes[currentLinkHash];
171
- if (!found) {
172
- logger_1.default.info(`Deleting: ${currentLinkHash}`);
173
- await new sdk_1.Entities().delete({
174
- entityName: 'type-rule-set-link',
175
- id: currentLink['id'],
176
- });
177
- }
178
- }
179
- catch (err) {
180
- logger_1.default.error(`Error Deleting rule set link: ${err}`);
181
- }
182
- }
183
- }
184
- function transformReducedLink(ruleSetLink, types, ruleSets) {
185
- const foundType = types.find((t) => t.slug === ruleSetLink.type);
186
- if (!foundType) {
187
- logger_1.default.error(`Could not find type with name ${ruleSetLink.type}`);
188
- return false;
189
- }
190
- ruleSetLink.type = foundType.id;
191
- const foundRuleSet = ruleSets.find((rs) => rs.identifier === ruleSetLink.ruleSet);
192
- if (!foundRuleSet) {
193
- logger_1.default.error(`Could not find rule set with name ${foundType.ruleSet}`);
194
- return false;
195
- }
196
- ruleSetLink.ruleSet = foundRuleSet.id;
197
- return true;
198
- }
@@ -34,8 +34,12 @@ exports.default = UploadTypeOverrides;
34
34
  async function uploadTypeOverrides(dir) {
35
35
  try {
36
36
  await (0, login_1.authUser)();
37
- logger_1.default.info(`${chalk_1.default.yellow.bold('TYPE OVERRIDE')} Uploading`);
38
37
  const reducedOverrides = readTypeOverridesFromFile(dir);
38
+ if (!reducedOverrides || reducedOverrides.length === 0) {
39
+ logger_1.default.info(`${chalk_1.default.yellow.bold('TYPE OVERRIDE')} No overrides found in type-overrides.yml — skipping upload to avoid wiping org overrides`);
40
+ return;
41
+ }
42
+ logger_1.default.info(`${chalk_1.default.yellow.bold('TYPE OVERRIDE')} Uploading`);
39
43
  await (0, types_1.uploadTypeOverrideObjects)(reducedOverrides);
40
44
  logger_1.default.info(`${chalk_1.default.yellow.bold('TYPE OVERRIDE')} Uploaded`);
41
45
  }
@@ -47,8 +51,12 @@ async function uploadTypeOverrides(dir) {
47
51
  }
48
52
  exports.uploadTypeOverrides = uploadTypeOverrides;
49
53
  function readTypeOverridesFromFile(fromDir) {
54
+ const filePath = path.join(fromDir, 'type-overrides.yml');
55
+ if (!fs_1.default.existsSync(filePath)) {
56
+ return null;
57
+ }
50
58
  try {
51
- return js_yaml_1.default.load(fs_1.default.readFileSync(path.join(fromDir, 'type-overrides.yml'), 'utf8'));
59
+ return js_yaml_1.default.load(fs_1.default.readFileSync(filePath, 'utf8'));
52
60
  }
53
61
  catch (e) {
54
62
  throw new Error(`ERROR PARSING YAML: ${e}`);
@@ -8,7 +8,6 @@ const path = tslib_1.__importStar(require("path"));
8
8
  const login_1 = require("../../auth/login");
9
9
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
10
10
  const core_1 = require("@oclif/core");
11
- const type_extractor_1 = require("../../helpers/types/type-extractor");
12
11
  const users_1 = require("../../api/users");
13
12
  const basecommand_1 = require("../../basecommand");
14
13
  const logger_1 = tslib_1.__importDefault(require("../../logger"));
@@ -37,9 +36,8 @@ async function uploadTypePolicies(dir) {
37
36
  try {
38
37
  await (0, login_1.authUser)();
39
38
  logger_1.default.info(`${chalk_1.default.yellow.bold('TYPE POLICY')} Uploading`);
40
- const [reducedTypePolicies, reducedTypePolicyLinks] = await loadTypePolicies(dir);
39
+ const reducedTypePolicies = await loadTypePolicies(dir);
41
40
  await uploadTypePolicyObjects(reducedTypePolicies);
42
- await uploadTypePolicyLinks(reducedTypePolicyLinks);
43
41
  logger_1.default.info(`${chalk_1.default.yellow.bold('TYPE POLICY')} Uploaded`);
44
42
  }
45
43
  catch (e) {
@@ -51,15 +49,13 @@ async function uploadTypePolicies(dir) {
51
49
  exports.uploadTypePolicies = uploadTypePolicies;
52
50
  function loadTypePolicies(fromDir) {
53
51
  const tps = [];
54
- let tpLinks = [];
55
52
  const dir = path.join(fromDir, 'type-policies');
56
53
  try {
57
54
  const files = fs_1.default.readdirSync(dir);
58
55
  for (const file of files) {
59
56
  tps.push(js_yaml_1.default.load(fs_1.default.readFileSync(path.join(dir, file), 'utf8')));
60
57
  }
61
- tpLinks = js_yaml_1.default.load(fs_1.default.readFileSync(path.join(fromDir, 'type-policy-links.yml'), 'utf8'));
62
- return [tps, tpLinks];
58
+ return tps;
63
59
  }
64
60
  catch (e) {
65
61
  throw new Error(`ERROR PARSING YAML: ${e}`);
@@ -152,83 +148,3 @@ async function uploadTypePolicyObjects(reducedTypePolicies) {
152
148
  }
153
149
  }
154
150
  }
155
- async function uploadTypePolicyLinks(reducedTypePolicyLinks) {
156
- const types = await (0, type_extractor_1.getTypes)();
157
- const currentTypePolicies = await new sdk_1.Entities().get({
158
- entityName: 'type-policy',
159
- });
160
- const currentTypePolicyLinks = await new sdk_1.Entities().get({
161
- entityName: 'type-policy-link',
162
- });
163
- const currentLinksHashes = {};
164
- for (const currentLink of currentTypePolicyLinks) {
165
- const foundType = types.find((type) => type.id === currentLink.typeId);
166
- const foundTypePolicy = currentTypePolicies.find((tp) => tp.id === currentLink.typePolicyId);
167
- if (!foundType || !foundTypePolicy) {
168
- logger_1.default.info(`skipping unhashable, invalid policy link: ${JSON.stringify(currentLink, null, 2)}`);
169
- }
170
- const hash = `${foundType.slug}|${foundTypePolicy.identifier}`;
171
- currentLinksHashes[hash] = currentLink;
172
- }
173
- const reducedLinksByHashes = {};
174
- for (const loadedLink of reducedTypePolicyLinks) {
175
- const hash = `${loadedLink.typeSlug}|${loadedLink.typePolicyIdentifier}`;
176
- reducedLinksByHashes[hash] = loadedLink;
177
- }
178
- for (const loadedTPLink of reducedTypePolicyLinks) {
179
- try {
180
- const found = currentLinksHashes[`${loadedTPLink.typeSlug}|${loadedTPLink.typePolicyIdentifier}`];
181
- if (!found) {
182
- if (!transformReducedLink(loadedTPLink, types, currentTypePolicies)) {
183
- continue;
184
- }
185
- logger_1.default.info(`Creating: ${loadedTPLink.typeSlug}|${loadedTPLink.typePolicyIdentifier}`);
186
- await new sdk_1.Entities().create({
187
- entityName: 'type-policy-link',
188
- object: {
189
- typePolicyId: loadedTPLink.typePolicyId,
190
- typeId: loadedTPLink.typeId,
191
- },
192
- });
193
- }
194
- else {
195
- if (!transformReducedLink(loadedTPLink, types, currentTypePolicies)) {
196
- continue;
197
- }
198
- }
199
- }
200
- catch (err) {
201
- logger_1.default.error(`Error Uploading type policy links: ${err}`);
202
- }
203
- }
204
- for (const [currentLinkHash, currentLink] of Object.entries(currentLinksHashes)) {
205
- try {
206
- const found = reducedLinksByHashes[currentLinkHash];
207
- if (!found) {
208
- logger_1.default.info(`Deleting: ${currentLinkHash}`);
209
- await new sdk_1.Entities().delete({
210
- entityName: 'type-policy-link',
211
- id: currentLink['id'],
212
- });
213
- }
214
- }
215
- catch (err) {
216
- logger_1.default.error(`Error Deleting rule set link: ${err}`);
217
- }
218
- }
219
- }
220
- function transformReducedLink(typePolicyLink, types, typePolicies) {
221
- const foundType = types.find((type) => type.slug === typePolicyLink.typeSlug);
222
- if (!foundType) {
223
- logger_1.default.error(`Could not find type with slug ${typePolicyLink.typeSlug}`);
224
- return false;
225
- }
226
- typePolicyLink.typeId = foundType.id;
227
- const foundTypePolicy = typePolicies.find((tpp) => tpp.identifier === typePolicyLink.typePolicyIdentifier);
228
- if (!foundTypePolicy) {
229
- logger_1.default.error(`Could not find type policy with identifier ${typePolicyLink.typePolicyIdentifier}`);
230
- return false;
231
- }
232
- typePolicyLink.typePolicyId = foundTypePolicy.id;
233
- return true;
234
- }
@@ -10,4 +10,3 @@ export default class UploadTypePropertyPolicies extends BaseCommand {
10
10
  run(): Promise<void>;
11
11
  }
12
12
  export declare function uploadTypePropertyPolicies(dir: string): Promise<void>;
13
- export declare function findAllOccurrences(array: any, evaluator: any): any[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findAllOccurrences = exports.uploadTypePropertyPolicies = void 0;
3
+ exports.uploadTypePropertyPolicies = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const sdk_1 = require("@contrail/sdk");
6
6
  const fs_1 = tslib_1.__importDefault(require("fs"));
@@ -8,12 +8,10 @@ const path = tslib_1.__importStar(require("path"));
8
8
  const login_1 = require("../../auth/login");
9
9
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
10
10
  const core_1 = require("@oclif/core");
11
- const type_extractor_1 = require("../../helpers/types/type-extractor");
12
11
  const users_1 = require("../../api/users");
13
12
  const basecommand_1 = require("../../basecommand");
14
13
  const logger_1 = tslib_1.__importDefault(require("../../logger"));
15
14
  const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
16
- const _ = tslib_1.__importStar(require("lodash"));
17
15
  class UploadTypePropertyPolicies extends basecommand_1.BaseCommand {
18
16
  static description = 'Upload type property policies';
19
17
  static examples = [
@@ -38,14 +36,12 @@ async function uploadTypePropertyPolicies(dir) {
38
36
  try {
39
37
  await (0, login_1.authUser)();
40
38
  logger_1.default.info(`${chalk_1.default.yellow.bold('TYPE PROPERTY POLICY')} Uploading`);
41
- const [reducedTypePropertyPolicies, reducedTypePropertyPolicyLinks] = await loadTPPolicies(dir);
39
+ const reducedTypePropertyPolicies = await loadTPPolicies(dir);
42
40
  await uploadTPPolicyObjects(reducedTypePropertyPolicies);
43
- await uploadTypePropertyPolicyLinks(reducedTypePropertyPolicyLinks);
44
41
  logger_1.default.info(`${chalk_1.default.yellow.bold('TYPE PROPERTY POLICY')} Uploaded`);
45
42
  }
46
43
  catch (e) {
47
44
  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
45
  console.trace(e);
50
46
  return;
51
47
  }
@@ -54,15 +50,13 @@ async function uploadTypePropertyPolicies(dir) {
54
50
  exports.uploadTypePropertyPolicies = uploadTypePropertyPolicies;
55
51
  function loadTPPolicies(fromDir) {
56
52
  const tpps = [];
57
- let tppLinks = [];
58
53
  const dir = path.join(fromDir, 'type-property-policies');
59
54
  try {
60
55
  const files = fs_1.default.readdirSync(dir);
61
56
  for (const file of files) {
62
57
  tpps.push(js_yaml_1.default.load(fs_1.default.readFileSync(path.join(dir, file), 'utf8')));
63
58
  }
64
- tppLinks = js_yaml_1.default.load(fs_1.default.readFileSync(path.join(fromDir, 'type-property-policy-links.yml'), 'utf8'));
65
- return [tpps, tppLinks];
59
+ return tpps;
66
60
  }
67
61
  catch (e) {
68
62
  throw new Error(`ERROR PARSING YAML: ${e}`);
@@ -155,133 +149,3 @@ async function uploadTPPolicyObjects(reducedTypePropertyPolicies) {
155
149
  }
156
150
  }
157
151
  }
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;
@@ -2,6 +2,9 @@ import { BaseCommand } from '../../basecommand';
2
2
  import { PersistReducedUsageInfo } from '../../interfaces';
3
3
  export default class UploadUsageInfo extends BaseCommand {
4
4
  static description: string;
5
+ static deprecationOptions: {
6
+ message: string;
7
+ };
5
8
  static examples: string[];
6
9
  static flags: {
7
10
  dir: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
@@ -13,7 +13,10 @@ const basecommand_1 = require("../../basecommand");
13
13
  const logger_1 = tslib_1.__importDefault(require("../../logger"));
14
14
  const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
15
15
  class UploadUsageInfo extends basecommand_1.BaseCommand {
16
- static description = 'Upload extracted usage info';
16
+ static description = '[DEPRECATED] Upload extracted usage info. Use uploadTypeOverrides instead.';
17
+ static deprecationOptions = {
18
+ message: 'uploadUsageInfo is deprecated. Usage info is now managed as type overrides. Use `contrail types uploadTypeOverrides` instead.',
19
+ };
17
20
  static examples = [
18
21
  `$ contrail types uploadUsageInfo
19
22
  `,
@@ -303,7 +303,7 @@ async function uploadReducedTypeProperties(type, currentPropertyTypes, newProper
303
303
  }
304
304
  }
305
305
  catch (err) {
306
- throw new Error(`Error Deleting Properties: ${err}`);
306
+ logger_1.default.error(`Error Deleting Type-Property ${currentPropertyType.slug}: ${err}`);
307
307
  }
308
308
  }
309
309
  }
File without changes
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "3.5.1-alpha.68d57e0",
2
+ "version": "3.5.1-alpha.fd40e6d",
3
3
  "commands": {
4
4
  "app:create": {
5
5
  "id": "app:create",
@@ -2522,7 +2522,7 @@
2522
2522
  },
2523
2523
  "types:uploadUsageInfo": {
2524
2524
  "id": "types:uploadUsageInfo",
2525
- "description": "Upload extracted usage info",
2525
+ "description": "[DEPRECATED] Upload extracted usage info. Use uploadTypeOverrides instead.",
2526
2526
  "strict": true,
2527
2527
  "pluginName": "@contrail/cli",
2528
2528
  "pluginAlias": "@contrail/cli",
@@ -2531,6 +2531,9 @@
2531
2531
  "examples": [
2532
2532
  "$ contrail types uploadUsageInfo\n"
2533
2533
  ],
2534
+ "deprecationOptions": {
2535
+ "message": "uploadUsageInfo is deprecated. Usage info is now managed as type overrides. Use `contrail types uploadTypeOverrides` instead."
2536
+ },
2534
2537
  "flags": {
2535
2538
  "logLevel": {
2536
2539
  "name": "logLevel",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/cli",
3
- "version": "3.5.1-alpha.68d57e0",
3
+ "version": "3.5.1-alpha.fd40e6d",
4
4
  "description": "VibeIQ's Contrail Platform CLI.",
5
5
  "bin": {
6
6
  "contrail-cli": "./bin/run",