@contrail/cli 2.1.20 → 2.1.22
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 +311 -105
- package/dist/api/apps.js +15 -15
- package/dist/api/event-workflow-action-definition.d.ts +1 -1
- package/dist/api/event-workflow-action-definition.js +1 -1
- package/dist/api/event-workflow-template-definition.d.ts +4 -3
- package/dist/api/event-workflow-templates.d.ts +5 -4
- package/dist/api/event-workflow-templates.js +2 -2
- package/dist/api/types.d.ts +10 -10
- package/dist/api/users.js +4 -2
- package/dist/auth/login.js +12 -14
- package/dist/commands/app/create.d.ts +2 -2
- package/dist/commands/app/create.js +15 -10
- package/dist/commands/app/delete.d.ts +2 -2
- package/dist/commands/app/delete.js +4 -2
- package/dist/commands/app/getApiKey.d.ts +2 -2
- package/dist/commands/app/getApiKey.js +17 -11
- package/dist/commands/app/install.d.ts +2 -2
- package/dist/commands/app/install.js +42 -25
- package/dist/commands/app/publish.d.ts +2 -2
- package/dist/commands/app/publish.js +26 -11
- package/dist/commands/app/uninstall.d.ts +2 -2
- package/dist/commands/app/uninstall.js +20 -11
- package/dist/commands/app/upgrade.d.ts +2 -2
- package/dist/commands/app/upgrade.js +46 -23
- package/dist/commands/basecommand.d.ts +7 -0
- package/dist/commands/basecommand.js +29 -0
- package/dist/commands/colors/deleteAll.d.ts +2 -2
- package/dist/commands/colors/deleteAll.js +8 -5
- package/dist/commands/colors/load.d.ts +2 -2
- package/dist/commands/colors/load.js +10 -7
- package/dist/commands/config/list.d.ts +2 -2
- package/dist/commands/config/list.js +4 -2
- package/dist/commands/config/remove.d.ts +2 -2
- package/dist/commands/config/remove.js +4 -2
- package/dist/commands/config/set.d.ts +3 -2
- package/dist/commands/config/set.js +21 -7
- package/dist/commands/groups/export.d.ts +2 -2
- package/dist/commands/groups/export.js +20 -8
- package/dist/commands/groups/upload.d.ts +3 -3
- package/dist/commands/groups/upload.js +44 -32
- package/dist/commands/instance/export.d.ts +2 -2
- package/dist/commands/instance/export.js +15 -3
- package/dist/commands/instance/import.d.ts +2 -2
- package/dist/commands/instance/import.js +9 -2
- package/dist/commands/loader-process/load.d.ts +2 -2
- package/dist/commands/loader-process/load.js +13 -6
- package/dist/commands/loader-process/upload-and-load.d.ts +2 -2
- package/dist/commands/loader-process/upload-and-load.js +18 -7
- package/dist/commands/projects/export.d.ts +2 -2
- package/dist/commands/projects/export.js +4 -2
- package/dist/commands/projects/list.d.ts +2 -2
- package/dist/commands/projects/list.js +6 -4
- package/dist/commands/projects/load.d.ts +2 -2
- package/dist/commands/projects/load.js +16 -8
- package/dist/commands/types/exportOptionSetHierarchies.d.ts +2 -2
- package/dist/commands/types/exportOptionSetHierarchies.js +15 -12
- package/dist/commands/types/getAll.d.ts +2 -2
- package/dist/commands/types/getAll.js +107 -76
- package/dist/commands/types/loadAll.d.ts +2 -2
- package/dist/commands/types/loadAll.js +12 -4
- package/dist/commands/types/mergeOptionSets.d.ts +2 -2
- package/dist/commands/types/mergeOptionSets.js +13 -10
- package/dist/commands/types/mergeTypeProperties.d.ts +2 -2
- package/dist/commands/types/mergeTypeProperties.js +12 -9
- package/dist/commands/types/parseOptionSetsHierarchyLocalFile.d.ts +2 -2
- package/dist/commands/types/parseOptionSetsHierarchyLocalFile.js +19 -15
- package/dist/commands/types/parseOptionSetsHierarchyValuesToKeysLocalFile.d.ts +10 -0
- package/dist/commands/types/parseOptionSetsHierarchyValuesToKeysLocalFile.js +102 -0
- package/dist/commands/types/parseOptionSetsLocalFiles.d.ts +2 -2
- package/dist/commands/types/parseOptionSetsLocalFiles.js +21 -21
- package/dist/commands/types/parseOptionSetsToFolderStructure.d.ts +2 -2
- package/dist/commands/types/parseOptionSetsToFolderStructure.js +17 -18
- package/dist/commands/types/parseTypesFromFiles.d.ts +2 -2
- package/dist/commands/types/parseTypesFromFiles.js +14 -8
- package/dist/commands/types/parseTypesFromLocalFiles.d.ts +2 -2
- package/dist/commands/types/parseTypesFromLocalFiles.js +10 -7
- package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.d.ts +2 -2
- package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.js +11 -8
- package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.d.ts +2 -2
- package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.js +11 -8
- package/dist/commands/types/uploadOptionSetHierarchies.d.ts +2 -2
- package/dist/commands/types/uploadOptionSetHierarchies.js +44 -32
- package/dist/commands/types/uploadOptionSets.d.ts +2 -2
- package/dist/commands/types/uploadOptionSets.js +21 -13
- package/dist/commands/types/uploadOptionSetsHierarchyLocalFile.d.ts +2 -2
- package/dist/commands/types/uploadOptionSetsHierarchyLocalFile.js +26 -19
- package/dist/commands/types/uploadRuleSets.d.ts +2 -2
- package/dist/commands/types/uploadRuleSets.js +34 -26
- package/dist/commands/types/uploadTypePolicies.d.ts +2 -2
- package/dist/commands/types/uploadTypePolicies.js +37 -29
- package/dist/commands/types/uploadTypePropertyPolicies.d.ts +2 -2
- package/dist/commands/types/uploadTypePropertyPolicies.js +38 -30
- package/dist/commands/types/uploadTypes.d.ts +2 -2
- package/dist/commands/types/uploadTypes.js +10 -4
- package/dist/commands/types/uploadUsageInfo.d.ts +2 -2
- package/dist/commands/types/uploadUsageInfo.js +32 -24
- package/dist/commands/users/export.d.ts +2 -2
- package/dist/commands/users/export.js +15 -4
- package/dist/commands/users/upload.d.ts +2 -2
- package/dist/commands/users/upload.js +6 -4
- package/dist/commands/webhooks/create.d.ts +2 -2
- package/dist/commands/webhooks/create.js +8 -6
- package/dist/commands/webhooks/delete.d.ts +2 -2
- package/dist/commands/webhooks/delete.js +8 -5
- package/dist/commands/webhooks/getWebhookTrigger.d.ts +2 -2
- package/dist/commands/webhooks/getWebhookTrigger.js +10 -9
- package/dist/commands/webhooks/list.d.ts +2 -2
- package/dist/commands/webhooks/list.js +8 -6
- package/dist/commands/workflow-template-definitions/install.d.ts +2 -2
- package/dist/commands/workflow-template-definitions/install.js +4 -2
- package/dist/commands/workflow-template-definitions/list.d.ts +2 -2
- package/dist/commands/workflow-template-definitions/list.js +4 -2
- package/dist/commands/workflow-templates/delete.d.ts +2 -2
- package/dist/commands/workflow-templates/delete.js +4 -2
- package/dist/commands/workflow-templates/export.d.ts +2 -2
- package/dist/commands/workflow-templates/export.js +19 -17
- package/dist/commands/workflow-templates/list.d.ts +2 -2
- package/dist/commands/workflow-templates/list.js +4 -2
- package/dist/commands/workflow-templates/load.d.ts +2 -2
- package/dist/commands/workflow-templates/load.js +8 -3
- package/dist/common.d.ts +4 -1
- package/dist/common.js +10 -1
- package/dist/helpers/app/actions-deployer.d.ts +2 -2
- package/dist/helpers/app/actions-deployer.js +12 -7
- package/dist/helpers/app/app-deployer.d.ts +1 -1
- package/dist/helpers/app/app-deployer.js +70 -52
- package/dist/helpers/app/app-template-parsers.js +3 -1
- package/dist/helpers/app/load-app-config.d.ts +2 -1
- package/dist/helpers/app/load-app-config.js +2 -2
- package/dist/helpers/app/setup-template.js +4 -3
- package/dist/helpers/colors/helpers.d.ts +10 -2
- package/dist/helpers/colors/helpers.js +11 -10
- package/dist/helpers/config/config.js +15 -10
- package/dist/helpers/file-helpers.js +7 -4
- package/dist/helpers/loader-process/helpers.js +14 -13
- package/dist/helpers/projects/helpers.d.ts +2 -1
- package/dist/helpers/projects/helpers.js +16 -15
- package/dist/helpers/types/csv-parser.js +17 -14
- package/dist/helpers/types/type-extractor.d.ts +1 -1
- package/dist/helpers/types/type-extractor.js +3 -2
- package/dist/helpers/types/type-parser.js +22 -21
- package/dist/helpers/types/type-uploader.js +19 -15
- package/dist/helpers/workflow-template-definitions/workflow-template-definition-deployer.d.ts +1 -1
- package/dist/helpers/workflow-template-definitions/workflow-template-definition-deployer.js +47 -28
- package/dist/helpers/workflow-templates/helper.d.ts +3 -3
- package/dist/helpers/workflow-templates/helper.js +33 -23
- package/dist/interface-converters.spec.js +15 -15
- package/dist/interfaces.d.ts +6 -0
- package/dist/logger.d.ts +3 -0
- package/dist/logger.js +32 -0
- package/dist/templates/typescript/src/actions/logItem.ts +9 -4
- package/dist/templates/typescript/src/main.ts +13 -8
- package/oclif.manifest.json +861 -31
- package/package.json +10 -7
|
@@ -9,10 +9,13 @@ 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
11
|
const type_extractor_1 = require("../../helpers/types/type-extractor");
|
|
12
|
-
const
|
|
13
|
-
|
|
12
|
+
const basecommand_1 = require("../basecommand");
|
|
13
|
+
const logger_1 = tslib_1.__importDefault(require("../../logger"));
|
|
14
|
+
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
15
|
+
class UploadOptionSetHierarchies extends basecommand_1.BaseCommand {
|
|
14
16
|
async run() {
|
|
15
17
|
const { flags } = await this.parse(UploadOptionSetHierarchies);
|
|
18
|
+
await super.setLogLevel(flags.logLevel);
|
|
16
19
|
return await uploadOptionSetHierarchies(flags.dir);
|
|
17
20
|
}
|
|
18
21
|
}
|
|
@@ -23,23 +26,28 @@ UploadOptionSetHierarchies.examples = [
|
|
|
23
26
|
`,
|
|
24
27
|
];
|
|
25
28
|
UploadOptionSetHierarchies.flags = {
|
|
26
|
-
dir: core_1.Flags.string({
|
|
29
|
+
dir: core_1.Flags.string({
|
|
30
|
+
char: 'd',
|
|
31
|
+
description: 'The directory from which to export the option set hierarchies data. Defaults to the current directory. The option set data will be loaded from $dir/option-set-hierarchies',
|
|
32
|
+
required: false,
|
|
33
|
+
default: '.',
|
|
34
|
+
}),
|
|
27
35
|
};
|
|
28
36
|
async function uploadOptionSetHierarchies(dir) {
|
|
29
37
|
try {
|
|
30
38
|
await (0, login_1.authUser)();
|
|
31
|
-
|
|
39
|
+
logger_1.default.info('%s Uploading', chalk_1.default.yellow.bold('OPTION SET HIERARCHIES'));
|
|
32
40
|
const optionSetHierarchies = await loadOptionSetHierarchies(dir);
|
|
33
41
|
await uploadOSH(optionSetHierarchies);
|
|
34
42
|
const optionSetHierarchyLinks = await loadOptionSetHierarchyLinks(dir);
|
|
35
43
|
await uploadOSHLinks(optionSetHierarchyLinks);
|
|
36
|
-
|
|
44
|
+
logger_1.default.info('%s Uploaded', chalk_1.default.yellow.bold('OPTION SET HIERARCHIES'));
|
|
37
45
|
}
|
|
38
46
|
catch (e) {
|
|
39
|
-
|
|
47
|
+
logger_1.default.info(`%s Option set hierarchy Upload Failed. ${e}`, chalk_1.default.red.bold('FAIL'));
|
|
40
48
|
return;
|
|
41
49
|
}
|
|
42
|
-
|
|
50
|
+
logger_1.default.info('%s Option set hierarchy Upload Complete.', chalk_1.default.green.bold('COMPLETE'));
|
|
43
51
|
}
|
|
44
52
|
exports.uploadOptionSetHierarchies = uploadOptionSetHierarchies;
|
|
45
53
|
function loadOptionSetHierarchies(fromDir) {
|
|
@@ -48,7 +56,7 @@ function loadOptionSetHierarchies(fromDir) {
|
|
|
48
56
|
const files = fs_1.default.readdirSync(dir);
|
|
49
57
|
const OSHs = [];
|
|
50
58
|
for (const file of files) {
|
|
51
|
-
OSHs.push(
|
|
59
|
+
OSHs.push(js_yaml_1.default.load(fs_1.default.readFileSync(path.join(dir, file), 'utf8')));
|
|
52
60
|
}
|
|
53
61
|
return OSHs;
|
|
54
62
|
}
|
|
@@ -58,7 +66,7 @@ function loadOptionSetHierarchies(fromDir) {
|
|
|
58
66
|
}
|
|
59
67
|
function loadOptionSetHierarchyLinks(fromDir) {
|
|
60
68
|
try {
|
|
61
|
-
return
|
|
69
|
+
return js_yaml_1.default.load(fs_1.default.readFileSync(path.join(fromDir, 'type-option-set-hierarchy-links.yml'), 'utf8'));
|
|
62
70
|
}
|
|
63
71
|
catch (e) {
|
|
64
72
|
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
@@ -83,8 +91,8 @@ async function uploadOSH(loadedOSHs) {
|
|
|
83
91
|
for (const loadedOSH of loadedOSHs) {
|
|
84
92
|
loadedOSHByName[loadedOSH.name] = loadedOSH;
|
|
85
93
|
}
|
|
86
|
-
|
|
87
|
-
|
|
94
|
+
logger_1.default.debug('current OSH:', currentOSHs);
|
|
95
|
+
logger_1.default.debug('loaded OSH:', loadedOSHs);
|
|
88
96
|
for (const osh of loadedOSHs) {
|
|
89
97
|
try {
|
|
90
98
|
const found = currentOSHByName[osh.name];
|
|
@@ -92,17 +100,17 @@ async function uploadOSH(loadedOSHs) {
|
|
|
92
100
|
if (!transformOSHNameToID(osh.hierarchy, optionSets)) {
|
|
93
101
|
continue;
|
|
94
102
|
}
|
|
95
|
-
|
|
103
|
+
logger_1.default.info('Creating: ', osh);
|
|
96
104
|
await new sdk_1.Entities().create({
|
|
97
105
|
entityName: 'option-set-hierarchy',
|
|
98
|
-
object: osh
|
|
106
|
+
object: osh,
|
|
99
107
|
});
|
|
100
108
|
}
|
|
101
109
|
else {
|
|
102
110
|
if (!transformOSHNameToID(osh.hierarchy, optionSets)) {
|
|
103
111
|
continue;
|
|
104
112
|
}
|
|
105
|
-
|
|
113
|
+
logger_1.default.info('Updating: ', osh);
|
|
106
114
|
await new sdk_1.Entities().update({
|
|
107
115
|
entityName: 'option-set-hierarchy',
|
|
108
116
|
id: found.id,
|
|
@@ -118,7 +126,7 @@ async function uploadOSH(loadedOSHs) {
|
|
|
118
126
|
try {
|
|
119
127
|
const found = loadedOSHByName[currentOSH.name];
|
|
120
128
|
if (!found) {
|
|
121
|
-
|
|
129
|
+
logger_1.default.info('Deleting: ', currentOSH.name);
|
|
122
130
|
await new sdk_1.Entities().delete({
|
|
123
131
|
entityName: 'option-set-hierarchy',
|
|
124
132
|
id: currentOSH.id,
|
|
@@ -132,11 +140,11 @@ async function uploadOSH(loadedOSHs) {
|
|
|
132
140
|
}
|
|
133
141
|
// transforms the passed hierarchy from names to ids, and returns true if operation succeeded.
|
|
134
142
|
function transformOSHNameToID(hierarchy, optionSets) {
|
|
135
|
-
|
|
143
|
+
logger_1.default.info('passed hierarchy:', hierarchy);
|
|
136
144
|
for (let i = 0; i < hierarchy.length; i++) {
|
|
137
|
-
const os = optionSets.find(os => os.name === hierarchy[i]);
|
|
145
|
+
const os = optionSets.find((os) => os.name === hierarchy[i]);
|
|
138
146
|
if (!os) {
|
|
139
|
-
|
|
147
|
+
logger_1.default.error('could not find option set with name', hierarchy[i], ' at position', i, 'skipping...');
|
|
140
148
|
return false;
|
|
141
149
|
}
|
|
142
150
|
hierarchy[i] = os.id;
|
|
@@ -146,7 +154,7 @@ function transformOSHNameToID(hierarchy, optionSets) {
|
|
|
146
154
|
async function uploadOSHLinks(reducedOSHLinks) {
|
|
147
155
|
const typesWithProperties = await (0, type_extractor_1.getTypes)();
|
|
148
156
|
const typeProperties = [];
|
|
149
|
-
typesWithProperties.forEach(type => {
|
|
157
|
+
typesWithProperties.forEach((type) => {
|
|
150
158
|
if (type.typeProperties) {
|
|
151
159
|
for (const tp of type.typeProperties) {
|
|
152
160
|
tp.typeId = type.id;
|
|
@@ -163,11 +171,15 @@ async function uploadOSHLinks(reducedOSHLinks) {
|
|
|
163
171
|
});
|
|
164
172
|
const currentOSHLinkHashes = {};
|
|
165
173
|
for (const currentLink of currentOSHLinks) {
|
|
166
|
-
const foundType = typesWithProperties.find(x => x.id === currentLink.typeId);
|
|
167
|
-
const foundOSH = currentOSHs.find(osh => osh.id === currentLink.optionSetHierarchyId);
|
|
168
|
-
const foundTPSlugs = typeProperties
|
|
169
|
-
|
|
170
|
-
|
|
174
|
+
const foundType = typesWithProperties.find((x) => x.id === currentLink.typeId);
|
|
175
|
+
const foundOSH = currentOSHs.find((osh) => osh.id === currentLink.optionSetHierarchyId);
|
|
176
|
+
const foundTPSlugs = typeProperties
|
|
177
|
+
.filter((x) => { var _a; return (_a = currentLink === null || currentLink === void 0 ? void 0 : currentLink.hierarchyTypePropertyIds) === null || _a === void 0 ? void 0 : _a.includes(x.id); })
|
|
178
|
+
.map((x) => x.slug);
|
|
179
|
+
if (!foundType ||
|
|
180
|
+
!foundOSH ||
|
|
181
|
+
foundTPSlugs.length !== currentLink.hierarchyTypePropertyIds.length) {
|
|
182
|
+
logger_1.default.info('skipping unhashable, invalid type option set hierarchy link:', currentLink);
|
|
171
183
|
}
|
|
172
184
|
const hash = `${foundType.slug}|${foundOSH.name}|${foundTPSlugs.sort().join('|')}`;
|
|
173
185
|
currentOSHLinkHashes[hash] = currentLink;
|
|
@@ -202,7 +214,7 @@ async function uploadOSHLinks(reducedOSHLinks) {
|
|
|
202
214
|
try {
|
|
203
215
|
const found = reducedLinksByHashes[currentLinkHash];
|
|
204
216
|
if (!found) {
|
|
205
|
-
|
|
217
|
+
logger_1.default.info('Deleting: ', currentLinkHash);
|
|
206
218
|
await new sdk_1.Entities().delete({
|
|
207
219
|
entityName: 'type-option-set-hierarchy-link',
|
|
208
220
|
id: currentLink['id'],
|
|
@@ -216,21 +228,21 @@ async function uploadOSHLinks(reducedOSHLinks) {
|
|
|
216
228
|
}
|
|
217
229
|
function transformReducedLink(OSHLink, typesWithProperties, OSHs) {
|
|
218
230
|
var _a, _b;
|
|
219
|
-
const foundType = typesWithProperties.find(x => x.slug === OSHLink.typeSlug);
|
|
231
|
+
const foundType = typesWithProperties.find((x) => x.slug === OSHLink.typeSlug);
|
|
220
232
|
if (!foundType) {
|
|
221
|
-
|
|
233
|
+
logger_1.default.error('OSH Links: Could not find type with slug', OSHLink.typeSlug);
|
|
222
234
|
return false;
|
|
223
235
|
}
|
|
224
236
|
OSHLink.typeId = foundType.id;
|
|
225
|
-
const foundTPs = (_b = (_a = foundType === null || foundType === void 0 ? void 0 : foundType.typeProperties) === null || _a === void 0 ? void 0 : _a.filter(x => OSHLink.typePropertySlugs.includes(x.slug))) !== null && _b !== void 0 ? _b : [];
|
|
237
|
+
const foundTPs = (_b = (_a = foundType === null || foundType === void 0 ? void 0 : foundType.typeProperties) === null || _a === void 0 ? void 0 : _a.filter((x) => OSHLink.typePropertySlugs.includes(x.slug))) !== null && _b !== void 0 ? _b : [];
|
|
226
238
|
if (foundTPs.length !== OSHLink.typePropertySlugs.length) {
|
|
227
|
-
|
|
239
|
+
logger_1.default.error('OSH Links: Could not find all type properties with slugs', OSHLink.typePropertySlugs);
|
|
228
240
|
return false;
|
|
229
241
|
}
|
|
230
|
-
OSHLink.hierarchyTypePropertyIds = foundTPs.map(x => x.id);
|
|
231
|
-
const foundOSH = OSHs.find(x => x.name === OSHLink.optionSetHierarchyName);
|
|
242
|
+
OSHLink.hierarchyTypePropertyIds = foundTPs.map((x) => x.id);
|
|
243
|
+
const foundOSH = OSHs.find((x) => x.name === OSHLink.optionSetHierarchyName);
|
|
232
244
|
if (!foundOSH) {
|
|
233
|
-
|
|
245
|
+
logger_1.default.error('OSH Links: Could not find option set hierarchy with name', OSHLink.optionSetHierarchyName);
|
|
234
246
|
return false;
|
|
235
247
|
}
|
|
236
248
|
OSHLink.optionSetHierarchyId = foundOSH.id;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class UploadOptionSets extends
|
|
1
|
+
import { BaseCommand } from '../basecommand';
|
|
2
|
+
export default class UploadOptionSets extends BaseCommand {
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
@@ -8,10 +8,13 @@ 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
|
|
12
|
-
|
|
11
|
+
const basecommand_1 = require("../basecommand");
|
|
12
|
+
const logger_1 = tslib_1.__importDefault(require("../../logger"));
|
|
13
|
+
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
14
|
+
class UploadOptionSets extends basecommand_1.BaseCommand {
|
|
13
15
|
async run() {
|
|
14
16
|
const { flags } = await this.parse(UploadOptionSets);
|
|
17
|
+
await super.setLogLevel(flags.logLevel);
|
|
15
18
|
return await uploadOptionSets(flags.dir);
|
|
16
19
|
}
|
|
17
20
|
}
|
|
@@ -22,21 +25,26 @@ UploadOptionSets.examples = [
|
|
|
22
25
|
`,
|
|
23
26
|
];
|
|
24
27
|
UploadOptionSets.flags = {
|
|
25
|
-
dir: core_1.Flags.string({
|
|
28
|
+
dir: core_1.Flags.string({
|
|
29
|
+
char: 'd',
|
|
30
|
+
description: 'The directory from which to export the option set data. Defaults to the current directory. The option set data will be loaded from $dir/option-sets',
|
|
31
|
+
required: false,
|
|
32
|
+
default: '.',
|
|
33
|
+
}),
|
|
26
34
|
};
|
|
27
35
|
async function uploadOptionSets(dir) {
|
|
28
36
|
try {
|
|
29
37
|
const userConfig = await (0, login_1.authUser)();
|
|
30
|
-
|
|
31
|
-
|
|
38
|
+
logger_1.default.info(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk_1.default.blue.bold('START'));
|
|
39
|
+
logger_1.default.info('%s Uploading', chalk_1.default.yellow.bold('OPTION SETS'));
|
|
32
40
|
await uploadOS(dir);
|
|
33
|
-
|
|
41
|
+
logger_1.default.info('%s Uploaded', chalk_1.default.yellow.bold('OPTION SETS'));
|
|
34
42
|
}
|
|
35
43
|
catch (e) {
|
|
36
|
-
|
|
44
|
+
logger_1.default.info(`%s Types Upload Failed. ${e}`, chalk_1.default.red.bold('FAIL'));
|
|
37
45
|
return;
|
|
38
46
|
}
|
|
39
|
-
|
|
47
|
+
logger_1.default.info('%s Types Upload Complete.', chalk_1.default.green.bold('COMPLETE'));
|
|
40
48
|
}
|
|
41
49
|
exports.uploadOptionSets = uploadOptionSets;
|
|
42
50
|
function loadOptionSets(fromDir) {
|
|
@@ -45,7 +53,7 @@ function loadOptionSets(fromDir) {
|
|
|
45
53
|
const files = fs_1.default.readdirSync(dir);
|
|
46
54
|
const optionSets = [];
|
|
47
55
|
for (const file of files) {
|
|
48
|
-
optionSets.push(
|
|
56
|
+
optionSets.push(js_yaml_1.default.load(fs_1.default.readFileSync(path.join(dir, file), 'utf8')));
|
|
49
57
|
}
|
|
50
58
|
return optionSets;
|
|
51
59
|
}
|
|
@@ -71,10 +79,10 @@ async function uploadOS(dir) {
|
|
|
71
79
|
const found = currentOptionSetsByName[optionSet.name];
|
|
72
80
|
if (!found) {
|
|
73
81
|
if (!optionSet.optionSet) {
|
|
74
|
-
|
|
82
|
+
logger_1.default.info('No OptionSet for: ', optionSet.name);
|
|
75
83
|
continue;
|
|
76
84
|
}
|
|
77
|
-
|
|
85
|
+
logger_1.default.info('Creating: ', optionSet.name);
|
|
78
86
|
await new sdk_1.Entities().create({
|
|
79
87
|
entityName: 'type-property-option-set',
|
|
80
88
|
object: {
|
|
@@ -85,7 +93,7 @@ async function uploadOS(dir) {
|
|
|
85
93
|
});
|
|
86
94
|
}
|
|
87
95
|
else {
|
|
88
|
-
|
|
96
|
+
logger_1.default.info('Updating: ', optionSet.name);
|
|
89
97
|
await new sdk_1.Entities().update({
|
|
90
98
|
entityName: 'type-property-option-set',
|
|
91
99
|
id: found.id,
|
|
@@ -105,7 +113,7 @@ async function uploadOS(dir) {
|
|
|
105
113
|
try {
|
|
106
114
|
const found = newOptionSetsByName[currentOptionSet.name];
|
|
107
115
|
if (!found) {
|
|
108
|
-
|
|
116
|
+
logger_1.default.info('Deleting: ', currentOptionSet.name);
|
|
109
117
|
await new sdk_1.Entities().delete({
|
|
110
118
|
entityName: 'type-property-option-set',
|
|
111
119
|
id: currentOptionSet.id,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class UploadOptionSetsHierarchyLocalFile extends
|
|
1
|
+
import { BaseCommand } from '../basecommand';
|
|
2
|
+
export default class UploadOptionSetsHierarchyLocalFile extends BaseCommand {
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static args: {
|
|
@@ -4,14 +4,17 @@ exports.uploadOptionSetsHierarchyLocalFile = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const path = tslib_1.__importStar(require("path"));
|
|
6
6
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
7
|
-
const
|
|
7
|
+
const csvtojson_1 = tslib_1.__importDefault(require("csvtojson"));
|
|
8
8
|
const sdk_1 = require("@contrail/sdk");
|
|
9
9
|
const util_1 = require("@contrail/util");
|
|
10
10
|
const login_1 = require("../../auth/login");
|
|
11
11
|
const core_1 = require("@oclif/core");
|
|
12
|
-
|
|
12
|
+
const basecommand_1 = require("../basecommand");
|
|
13
|
+
const logger_1 = tslib_1.__importDefault(require("../../logger"));
|
|
14
|
+
class UploadOptionSetsHierarchyLocalFile extends basecommand_1.BaseCommand {
|
|
13
15
|
async run() {
|
|
14
16
|
const { args, flags } = await this.parse(UploadOptionSetsHierarchyLocalFile);
|
|
17
|
+
await super.setLogLevel(flags.logLevel);
|
|
15
18
|
await uploadOptionSetsHierarchyLocalFile(args.file, args.name);
|
|
16
19
|
}
|
|
17
20
|
}
|
|
@@ -23,30 +26,33 @@ UploadOptionSetsHierarchyLocalFile.examples = [
|
|
|
23
26
|
];
|
|
24
27
|
UploadOptionSetsHierarchyLocalFile.args = {
|
|
25
28
|
file: core_1.Args.string({ description: 'File to parse', required: true }),
|
|
26
|
-
name: core_1.Args.string({
|
|
29
|
+
name: core_1.Args.string({
|
|
30
|
+
description: 'The name to be give to the option set hierarchy',
|
|
31
|
+
required: true,
|
|
32
|
+
}),
|
|
27
33
|
};
|
|
28
34
|
async function uploadOptionSetsHierarchyLocalFile(fileLocation, name) {
|
|
29
35
|
try {
|
|
30
36
|
await (0, login_1.authUser)();
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
logger_1.default.info('%s Importing local file', chalk_1.default.yellow.bold('OPTION SET HIERARCHY UPLOAD'));
|
|
38
|
+
logger_1.default.info('Using File: ', fileLocation);
|
|
39
|
+
logger_1.default.info('Using Name: ', name);
|
|
34
40
|
await uploadOptionSetHierarchiesLocalFile(fileLocation, name);
|
|
35
|
-
|
|
41
|
+
logger_1.default.info('%s Uploaded', chalk_1.default.yellow.bold('OPTION SET HIERARCHY UPLOAD'));
|
|
36
42
|
}
|
|
37
43
|
catch (e) {
|
|
38
|
-
|
|
44
|
+
logger_1.default.info(`%s UPLOAD Failed. ${e}`, chalk_1.default.red.bold('FAIL'));
|
|
39
45
|
return;
|
|
40
46
|
}
|
|
41
|
-
|
|
47
|
+
logger_1.default.info('%s UPLOAD Complete.', chalk_1.default.green.bold('COMPLETE'));
|
|
42
48
|
}
|
|
43
49
|
exports.uploadOptionSetsHierarchyLocalFile = uploadOptionSetsHierarchyLocalFile;
|
|
44
50
|
async function loadOptionSetHierarchyCSV(fileLocation) {
|
|
45
51
|
const TARGET_DIR = process.cwd();
|
|
46
52
|
try {
|
|
47
53
|
const fullPath = path.resolve(path.join(TARGET_DIR, fileLocation));
|
|
48
|
-
|
|
49
|
-
return await
|
|
54
|
+
logger_1.default.info('Getting file from path: ', fullPath);
|
|
55
|
+
return await (0, csvtojson_1.default)().fromFile(fullPath);
|
|
50
56
|
}
|
|
51
57
|
catch (e) {
|
|
52
58
|
throw new Error(`ERROR PARSING CSV: ${e}`);
|
|
@@ -58,7 +64,7 @@ async function parseOptionSetHierarchiesLocalFile(fileLocation) {
|
|
|
58
64
|
hierarchy: [],
|
|
59
65
|
maxDepth: 0,
|
|
60
66
|
name: 'No Name',
|
|
61
|
-
options: []
|
|
67
|
+
options: [],
|
|
62
68
|
};
|
|
63
69
|
if (!((uploadedOptionHierarchyData === null || uploadedOptionHierarchyData === void 0 ? void 0 : uploadedOptionHierarchyData.length) > 0)) {
|
|
64
70
|
return optionSetHierarchy;
|
|
@@ -69,7 +75,8 @@ async function parseOptionSetHierarchiesLocalFile(fileLocation) {
|
|
|
69
75
|
});
|
|
70
76
|
const currentOptionSetsByName = {};
|
|
71
77
|
for (const currentOptionSet of currentOptionSets) {
|
|
72
|
-
currentOptionSetsByName[util_1.StringUtil.convertToCamelCase(currentOptionSet.name)] =
|
|
78
|
+
currentOptionSetsByName[util_1.StringUtil.convertToCamelCase(currentOptionSet.name)] =
|
|
79
|
+
currentOptionSet;
|
|
73
80
|
}
|
|
74
81
|
const optionSetIds = [];
|
|
75
82
|
for (const key of keysInOrder) {
|
|
@@ -93,9 +100,9 @@ async function uploadOptionSetHierarchiesLocalFile(fileLocation, name) {
|
|
|
93
100
|
const currentOptionSetHierarchies = await new sdk_1.Entities().get({
|
|
94
101
|
entityName: 'option-set-hierarchy',
|
|
95
102
|
});
|
|
96
|
-
const existing = currentOptionSetHierarchies.find(osh => osh.name === name);
|
|
103
|
+
const existing = currentOptionSetHierarchies.find((osh) => osh.name === name);
|
|
97
104
|
if (existing) {
|
|
98
|
-
|
|
105
|
+
logger_1.default.info('Updating: ', optionSetHierarchy.name);
|
|
99
106
|
await new sdk_1.Entities().update({
|
|
100
107
|
entityName: 'option-set-hierarchy',
|
|
101
108
|
id: existing.id,
|
|
@@ -103,7 +110,7 @@ async function uploadOptionSetHierarchiesLocalFile(fileLocation, name) {
|
|
|
103
110
|
});
|
|
104
111
|
}
|
|
105
112
|
else {
|
|
106
|
-
|
|
113
|
+
logger_1.default.info('Creating: ', optionSetHierarchy.name);
|
|
107
114
|
await new sdk_1.Entities().create({
|
|
108
115
|
entityName: 'option-set-hierarchy',
|
|
109
116
|
object: optionSetHierarchy,
|
|
@@ -113,15 +120,15 @@ async function uploadOptionSetHierarchiesLocalFile(fileLocation, name) {
|
|
|
113
120
|
function addRowToOptions(optionSetHierarchy, keysInOrder, row) {
|
|
114
121
|
let options = optionSetHierarchy.options;
|
|
115
122
|
for (let i = 0; i < keysInOrder.length; i++) {
|
|
116
|
-
const optionValues = options.map(op => op.value);
|
|
123
|
+
const optionValues = options.map((op) => op.value);
|
|
117
124
|
const value = row[keysInOrder[i]];
|
|
118
125
|
if (!optionValues.includes(value)) {
|
|
119
|
-
const obj = i ===
|
|
126
|
+
const obj = i === keysInOrder.length - 1 ? { value: value } : { value: value, options: [] };
|
|
120
127
|
options.push(obj);
|
|
121
128
|
options = obj.options;
|
|
122
129
|
}
|
|
123
130
|
else {
|
|
124
|
-
const optionObj = options.find(op => op.value === value);
|
|
131
|
+
const optionObj = options.find((op) => op.value === value);
|
|
125
132
|
options = optionObj.options;
|
|
126
133
|
}
|
|
127
134
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class UploadRuleSets extends
|
|
1
|
+
import { BaseCommand } from '../basecommand';
|
|
2
|
+
export default class UploadRuleSets extends BaseCommand {
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
@@ -8,10 +8,13 @@ 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
|
|
12
|
-
|
|
11
|
+
const basecommand_1 = require("../basecommand");
|
|
12
|
+
const logger_1 = tslib_1.__importDefault(require("../../logger"));
|
|
13
|
+
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
14
|
+
class UploadRuleSets extends basecommand_1.BaseCommand {
|
|
13
15
|
async run() {
|
|
14
16
|
const { flags } = await this.parse(UploadRuleSets);
|
|
17
|
+
await super.setLogLevel(flags.logLevel);
|
|
15
18
|
await uploadRuleSets(flags.dir);
|
|
16
19
|
}
|
|
17
20
|
}
|
|
@@ -22,22 +25,27 @@ UploadRuleSets.examples = [
|
|
|
22
25
|
`,
|
|
23
26
|
];
|
|
24
27
|
UploadRuleSets.flags = {
|
|
25
|
-
dir: core_1.Flags.string({
|
|
28
|
+
dir: core_1.Flags.string({
|
|
29
|
+
char: 'd',
|
|
30
|
+
description: 'The directory from which to export the rule set data. Defaults to the current directory. The rule set data will be loaded from $dir/rule-sets/*.yml',
|
|
31
|
+
required: false,
|
|
32
|
+
default: '.',
|
|
33
|
+
}),
|
|
26
34
|
};
|
|
27
35
|
async function uploadRuleSets(dir) {
|
|
28
36
|
try {
|
|
29
37
|
await (0, login_1.authUser)();
|
|
30
|
-
|
|
38
|
+
logger_1.default.info('%s Uploading', chalk_1.default.yellow.bold('RULE SET'));
|
|
31
39
|
const [reducedRuleSets, reducedRuleSetLinks] = await loadReducedRuleSets(dir);
|
|
32
40
|
await uploadRuleSetObjects(reducedRuleSets);
|
|
33
41
|
await uploadRuleSetLinkObjects(reducedRuleSetLinks);
|
|
34
|
-
|
|
42
|
+
logger_1.default.info('%s Uploaded', chalk_1.default.yellow.bold('RULE SET'));
|
|
35
43
|
}
|
|
36
44
|
catch (e) {
|
|
37
|
-
|
|
45
|
+
logger_1.default.info(`%s Rule Set Upload Failed. ${e}`, chalk_1.default.red.bold('FAIL'));
|
|
38
46
|
return;
|
|
39
47
|
}
|
|
40
|
-
|
|
48
|
+
logger_1.default.info('%s Rule set Upload Complete.', chalk_1.default.green.bold('COMPLETE'));
|
|
41
49
|
}
|
|
42
50
|
exports.uploadRuleSets = uploadRuleSets;
|
|
43
51
|
function loadReducedRuleSets(fromDir) {
|
|
@@ -47,9 +55,9 @@ function loadReducedRuleSets(fromDir) {
|
|
|
47
55
|
try {
|
|
48
56
|
const files = fs_1.default.readdirSync(dir);
|
|
49
57
|
for (const file of files) {
|
|
50
|
-
ruleSets.push(
|
|
58
|
+
ruleSets.push(js_yaml_1.default.load(fs_1.default.readFileSync(path.join(dir, file), 'utf8')));
|
|
51
59
|
}
|
|
52
|
-
ruleSetLinks =
|
|
60
|
+
ruleSetLinks = js_yaml_1.default.load(fs_1.default.readFileSync(path.join(fromDir, 'rule-set-links.yml'), 'utf8'));
|
|
53
61
|
return [ruleSets, ruleSetLinks];
|
|
54
62
|
}
|
|
55
63
|
catch (e) {
|
|
@@ -68,20 +76,20 @@ async function uploadRuleSetObjects(reducedRuleSets) {
|
|
|
68
76
|
for (const loadedRuleSet of reducedRuleSets) {
|
|
69
77
|
loadedRuleSetsByName[loadedRuleSet.name] = loadedRuleSet;
|
|
70
78
|
}
|
|
71
|
-
|
|
72
|
-
|
|
79
|
+
logger_1.default.debug('current rule sets:', currentRuleSets);
|
|
80
|
+
logger_1.default.debug('reduced rule sets:', reducedRuleSets);
|
|
73
81
|
for (const reducedRuleSet of reducedRuleSets) {
|
|
74
82
|
try {
|
|
75
83
|
const found = currentRuleSetsByName[reducedRuleSet.name];
|
|
76
84
|
if (!found) {
|
|
77
|
-
|
|
85
|
+
logger_1.default.info('Creating: ', reducedRuleSet.name);
|
|
78
86
|
await new sdk_1.Entities().create({
|
|
79
87
|
entityName: 'type-rule-set',
|
|
80
|
-
object: reducedRuleSet
|
|
88
|
+
object: reducedRuleSet,
|
|
81
89
|
});
|
|
82
90
|
}
|
|
83
91
|
else {
|
|
84
|
-
|
|
92
|
+
logger_1.default.info('Updating: ', reducedRuleSet.name);
|
|
85
93
|
await new sdk_1.Entities().update({
|
|
86
94
|
entityName: 'type-rule-set',
|
|
87
95
|
id: found.id,
|
|
@@ -97,7 +105,7 @@ async function uploadRuleSetObjects(reducedRuleSets) {
|
|
|
97
105
|
try {
|
|
98
106
|
const found = loadedRuleSetsByName[currentRuleSet.name];
|
|
99
107
|
if (!found) {
|
|
100
|
-
|
|
108
|
+
logger_1.default.info('Deleting: ', currentRuleSet.name);
|
|
101
109
|
await new sdk_1.Entities().delete({
|
|
102
110
|
entityName: 'type-rule-set',
|
|
103
111
|
id: currentRuleSet.id,
|
|
@@ -121,8 +129,8 @@ async function uploadRuleSetLinkObjects(loadedRuleSetLinks) {
|
|
|
121
129
|
});
|
|
122
130
|
const currentLinksHashes = {};
|
|
123
131
|
for (const currentLink of currentRuleSetLinks) {
|
|
124
|
-
const foundType = types.find(t => t.id === currentLink.typeId);
|
|
125
|
-
const foundRuleSet = currentRuleSets.find(rs => rs.id === currentLink.typeRuleSetId);
|
|
132
|
+
const foundType = types.find((t) => t.id === currentLink.typeId);
|
|
133
|
+
const foundRuleSet = currentRuleSets.find((rs) => rs.id === currentLink.typeRuleSetId);
|
|
126
134
|
const hash = `${foundType.slug}|${foundRuleSet.name}`;
|
|
127
135
|
currentLinksHashes[hash] = currentLink;
|
|
128
136
|
}
|
|
@@ -131,8 +139,8 @@ async function uploadRuleSetLinkObjects(loadedRuleSetLinks) {
|
|
|
131
139
|
const hash = `${loadedLink.type}|${loadedLink.ruleSet}`;
|
|
132
140
|
reducedLinksByHashes[hash] = loadedLink;
|
|
133
141
|
}
|
|
134
|
-
//
|
|
135
|
-
//
|
|
142
|
+
// logger.debug('reduced rule set links:', reducedLinksByHashes);
|
|
143
|
+
// logger.debug('current rule set links:', currentLinksHashes);
|
|
136
144
|
for (const loadedRuleSetLink of loadedRuleSetLinks) {
|
|
137
145
|
try {
|
|
138
146
|
const found = currentLinksHashes[`${loadedRuleSetLink.type}|${loadedRuleSetLink.ruleSet}`];
|
|
@@ -140,7 +148,7 @@ async function uploadRuleSetLinkObjects(loadedRuleSetLinks) {
|
|
|
140
148
|
if (!transformReducedLink(loadedRuleSetLink, types, currentRuleSets)) {
|
|
141
149
|
continue;
|
|
142
150
|
}
|
|
143
|
-
|
|
151
|
+
logger_1.default.info('Creating: ', loadedRuleSetLink);
|
|
144
152
|
await new sdk_1.Entities().create({
|
|
145
153
|
entityName: 'type-rule-set-link',
|
|
146
154
|
object: {
|
|
@@ -153,7 +161,7 @@ async function uploadRuleSetLinkObjects(loadedRuleSetLinks) {
|
|
|
153
161
|
if (!transformReducedLink(loadedRuleSetLink, types, currentRuleSets)) {
|
|
154
162
|
continue;
|
|
155
163
|
}
|
|
156
|
-
|
|
164
|
+
logger_1.default.info('skipping updating existing rule set link: ', loadedRuleSetLink);
|
|
157
165
|
}
|
|
158
166
|
}
|
|
159
167
|
catch (err) {
|
|
@@ -164,7 +172,7 @@ async function uploadRuleSetLinkObjects(loadedRuleSetLinks) {
|
|
|
164
172
|
try {
|
|
165
173
|
const found = reducedLinksByHashes[currentLinkHash];
|
|
166
174
|
if (!found) {
|
|
167
|
-
|
|
175
|
+
logger_1.default.info('Deleting: ', currentLinkHash);
|
|
168
176
|
await new sdk_1.Entities().delete({
|
|
169
177
|
entityName: 'type-rule-set-link',
|
|
170
178
|
id: currentLink['id'],
|
|
@@ -177,15 +185,15 @@ async function uploadRuleSetLinkObjects(loadedRuleSetLinks) {
|
|
|
177
185
|
}
|
|
178
186
|
}
|
|
179
187
|
function transformReducedLink(ruleSetLink, types, ruleSets) {
|
|
180
|
-
const foundType = types.find(t => t.slug === ruleSetLink.type);
|
|
188
|
+
const foundType = types.find((t) => t.slug === ruleSetLink.type);
|
|
181
189
|
if (!foundType) {
|
|
182
|
-
|
|
190
|
+
logger_1.default.error('Could not find type with name', ruleSetLink.type);
|
|
183
191
|
return false;
|
|
184
192
|
}
|
|
185
193
|
ruleSetLink.type = foundType.id;
|
|
186
|
-
const foundRuleSet = ruleSets.find(rs => rs.name === ruleSetLink.ruleSet);
|
|
194
|
+
const foundRuleSet = ruleSets.find((rs) => rs.name === ruleSetLink.ruleSet);
|
|
187
195
|
if (!foundRuleSet) {
|
|
188
|
-
|
|
196
|
+
logger_1.default.error('Could not find rule set with name', foundType.ruleSet);
|
|
189
197
|
return false;
|
|
190
198
|
}
|
|
191
199
|
ruleSetLink.ruleSet = foundRuleSet.id;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class UploadTypePolicies extends
|
|
1
|
+
import { BaseCommand } from '../basecommand';
|
|
2
|
+
export default class UploadTypePolicies extends BaseCommand {
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|