@contrail/cli 1.0.71 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1034 -5
- package/bin/dev +17 -0
- package/bin/dev.cmd +3 -0
- package/bin/run +5 -0
- package/bin/run.cmd +3 -0
- package/{lib → dist}/api/apps.d.ts +13 -13
- package/dist/api/apps.js +96 -0
- package/{lib → dist}/api/event-workflow-action-definition.d.ts +1 -1
- package/dist/api/event-workflow-action-definition.js +11 -0
- package/{lib → dist}/api/event-workflow-template-definition.d.ts +6 -6
- package/dist/api/event-workflow-template-definition.js +26 -0
- package/{lib → dist}/api/event-workflow-templates.d.ts +7 -7
- package/dist/api/event-workflow-templates.js +32 -0
- package/dist/api/types.d.ts +7 -0
- package/dist/api/types.js +52 -0
- package/{lib → dist}/auth/auth.d.ts +9 -9
- package/dist/auth/auth.js +6 -0
- package/{lib → dist}/auth/login.d.ts +2 -2
- package/{lib → dist}/auth/login.js +146 -141
- package/dist/commands/app/create.d.ts +6 -0
- package/dist/commands/app/create.js +15 -0
- package/dist/commands/app/delete.d.ts +7 -0
- package/dist/commands/app/delete.js +38 -0
- package/dist/commands/app/install.d.ts +11 -0
- package/dist/commands/app/install.js +117 -0
- package/dist/commands/app/publish.d.ts +7 -0
- package/dist/commands/app/publish.js +45 -0
- package/dist/commands/app/uninstall.d.ts +10 -0
- package/dist/commands/app/uninstall.js +58 -0
- package/dist/commands/app/upgrade.d.ts +11 -0
- package/dist/commands/app/upgrade.js +79 -0
- package/dist/commands/colors/deleteAll.d.ts +6 -0
- package/dist/commands/colors/deleteAll.js +30 -0
- package/dist/commands/colors/load.d.ts +6 -0
- package/dist/commands/colors/load.js +29 -0
- package/dist/commands/config/list.d.ts +6 -0
- package/dist/commands/config/list.js +15 -0
- package/dist/commands/config/remove.d.ts +14 -0
- package/dist/commands/config/remove.js +26 -0
- package/dist/commands/config/set.d.ts +13 -0
- package/dist/commands/config/set.js +29 -0
- package/dist/commands/loader-process/load.d.ts +9 -0
- package/dist/commands/loader-process/load.js +33 -0
- package/dist/commands/loader-process/upload-and-load.d.ts +10 -0
- package/dist/commands/loader-process/upload-and-load.js +35 -0
- package/dist/commands/projects/export.d.ts +10 -0
- package/dist/commands/projects/export.js +34 -0
- package/dist/commands/projects/list.d.ts +6 -0
- package/dist/commands/projects/list.js +34 -0
- package/dist/commands/projects/load.d.ts +9 -0
- package/{lib/projects/project-uploader.js → dist/commands/projects/load.js} +106 -105
- package/dist/commands/types/exportOptionSetHierarchies.d.ts +7 -0
- package/{lib/types/option-set-hierarchy-exporter.js → dist/commands/types/exportOptionSetHierarchies.js} +130 -113
- package/{lib/types/types-extractor.d.ts → dist/commands/types/getAll.d.ts} +29 -27
- package/{lib/types/types-extractor.js → dist/commands/types/getAll.js} +267 -318
- package/dist/commands/types/loadAll.d.ts +7 -0
- package/dist/commands/types/loadAll.js +41 -0
- package/dist/commands/types/mergeOptionSets.d.ts +9 -0
- package/{lib/types/option-set-merger.js → dist/commands/types/mergeOptionSets.js} +114 -105
- package/dist/commands/types/mergeTypeProperties.d.ts +11 -0
- package/dist/commands/types/mergeTypeProperties.js +89 -0
- package/dist/commands/types/parseOptionSetsHierarchyLocalFile.d.ts +10 -0
- package/dist/commands/types/parseOptionSetsHierarchyLocalFile.js +112 -0
- package/dist/commands/types/parseOptionSetsLocalFiles.d.ts +14 -0
- package/dist/commands/types/parseOptionSetsLocalFiles.js +153 -0
- package/dist/commands/types/parseOptionSetsToFolderStructure.d.ts +10 -0
- package/dist/commands/types/parseOptionSetsToFolderStructure.js +104 -0
- package/dist/commands/types/parseTypesFromFiles.d.ts +10 -0
- package/dist/commands/types/parseTypesFromFiles.js +34 -0
- package/dist/commands/types/parseTypesFromLocalFiles.d.ts +10 -0
- package/dist/commands/types/parseTypesFromLocalFiles.js +34 -0
- package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.d.ts +11 -0
- package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.js +36 -0
- package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.d.ts +10 -0
- package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.js +35 -0
- package/dist/commands/types/uploadOptionSetHierarchies.d.ts +7 -0
- package/{lib/types/option-set-hierarchy-uploader.js → dist/commands/types/uploadOptionSetHierarchies.js} +130 -113
- package/dist/commands/types/uploadOptionSets.d.ts +7 -0
- package/{lib/types/option-set-uploader.js → dist/commands/types/uploadOptionSets.js} +115 -98
- package/dist/commands/types/uploadOptionSetsHierarchyLocalFile.d.ts +11 -0
- package/{lib/types/option-set-hierarchy-parser.js → dist/commands/types/uploadOptionSetsHierarchyLocalFile.js} +128 -140
- package/dist/commands/types/uploadRuleSets.d.ts +7 -0
- package/{lib/types/rule-set-uploader.js → dist/commands/types/uploadRuleSets.js} +189 -172
- package/dist/commands/types/uploadTypePropertyPolicies.d.ts +7 -0
- package/{lib/types/type-property-policy-uploader.js → dist/commands/types/uploadTypePropertyPolicies.js} +195 -178
- package/dist/commands/types/uploadUsageInfo.d.ts +7 -0
- package/{lib/types/usage-info-uploader.js → dist/commands/types/uploadUsageInfo.js} +149 -132
- package/dist/commands/users/export.d.ts +9 -0
- package/dist/commands/users/export.js +60 -0
- package/dist/commands/users/upload.d.ts +9 -0
- package/dist/commands/users/upload.js +65 -0
- package/dist/commands/workflow-template-definitions/install.d.ts +6 -0
- package/dist/commands/workflow-template-definitions/install.js +17 -0
- package/dist/commands/workflow-template-definitions/list.d.ts +6 -0
- package/dist/commands/workflow-template-definitions/list.js +17 -0
- package/dist/commands/workflow-templates/delete.d.ts +6 -0
- package/dist/commands/workflow-templates/delete.js +17 -0
- package/dist/commands/workflow-templates/list.d.ts +6 -0
- package/dist/commands/workflow-templates/list.js +17 -0
- package/dist/commands/workflow-templates/load.d.ts +9 -0
- package/dist/commands/workflow-templates/load.js +21 -0
- package/{lib → dist}/common.d.ts +1 -1
- package/dist/common.js +9 -0
- package/{lib/apps/deploy-app → dist/helpers/app}/actions-deployer.d.ts +11 -11
- package/{lib/apps/deploy-app → dist/helpers/app}/actions-deployer.js +122 -114
- package/{lib/apps/deploy-app → dist/helpers/app}/app-deployer.d.ts +8 -8
- package/{lib/apps/deploy-app → dist/helpers/app}/app-deployer.js +98 -93
- package/{lib/apps/deploy-app → dist/helpers/app}/app-template-parsers.d.ts +7 -7
- package/{lib/apps/deploy-app → dist/helpers/app}/app-template-parsers.js +43 -38
- package/dist/helpers/app/load-app-config.d.ts +1 -0
- package/dist/helpers/app/load-app-config.js +18 -0
- package/dist/helpers/app/setup-template.d.ts +1 -0
- package/dist/helpers/app/setup-template.js +38 -0
- package/dist/helpers/colors/helpers.d.ts +4 -0
- package/dist/helpers/colors/helpers.js +74 -0
- package/{lib → dist/helpers}/config/config.d.ts +6 -6
- package/dist/helpers/config/config.js +76 -0
- package/dist/helpers/loader-process/helpers.d.ts +2 -0
- package/{lib/loader-process/loader-process.js → dist/helpers/loader-process/helpers.js} +98 -120
- package/dist/helpers/projects/helpers.d.ts +2 -0
- package/{lib/projects/project-exporter.js → dist/helpers/projects/helpers.js} +165 -187
- package/{lib → dist/helpers}/types/csv-parser.d.ts +1 -1
- package/{lib → dist/helpers}/types/csv-parser.js +56 -51
- package/dist/helpers/types/type-extractor.d.ts +1 -0
- package/dist/helpers/types/type-extractor.js +32 -0
- package/dist/helpers/types/type-parser.d.ts +4 -0
- package/dist/helpers/types/type-parser.js +118 -0
- package/{lib/types/types-uploader.d.ts → dist/helpers/types/type-uploader.d.ts} +1 -1
- package/{lib/types/types-uploader.js → dist/helpers/types/type-uploader.js} +244 -239
- package/{lib → dist/helpers}/workflow-template-definitions/workflow-template-definition-deployer.d.ts +12 -12
- package/{lib → dist/helpers}/workflow-template-definitions/workflow-template-definition-deployer.js +156 -151
- package/{lib/workflow-templates/local-workflow-template-deployer.d.ts → dist/helpers/workflow-templates/helper.d.ts} +17 -11
- package/dist/helpers/workflow-templates/helper.js +166 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -0
- package/{lib → dist}/interfaces.d.ts +323 -191
- package/dist/interfaces.js +63 -0
- package/{templates → dist/templates}/typescript/Dockerfile +15 -15
- package/{templates → dist/templates}/typescript/README.md +10 -10
- package/{templates → dist/templates}/typescript/app.yml +49 -49
- package/{templates → dist/templates}/typescript/docker_deploy.bat +1 -1
- package/{templates → dist/templates}/typescript/package.json +54 -54
- package/{templates → dist/templates}/typescript/src/actions/logItem.ts +25 -25
- package/{templates → dist/templates}/typescript/src/framework/action-dispatcher.ts +89 -89
- package/{templates → dist/templates}/typescript/src/framework/app-config.ts +26 -26
- package/{templates → dist/templates}/typescript/src/framework/handler.ts +11 -11
- package/{templates → dist/templates}/typescript/src/framework/index.ts +2 -2
- package/{templates → dist/templates}/typescript/src/framework/interfaces.ts +32 -32
- package/{templates → dist/templates}/typescript/src/framework/logger.ts +21 -21
- package/{templates → dist/templates}/typescript/src/framework/mock-server.ts +31 -31
- package/{templates → dist/templates}/typescript/tsconfig.json +28 -28
- package/oclif.manifest.json +821 -0
- package/package.json +116 -72
- package/.eslintrc.js +0 -53
- package/.vscode/settings.json +0 -6
- package/bin/init +0 -4
- package/lib/api/apps.js +0 -85
- package/lib/api/event-workflow-action-definition.js +0 -7
- package/lib/api/event-workflow-template-definition.js +0 -20
- package/lib/api/event-workflow-templates.js +0 -25
- package/lib/apps/create-app/create.d.ts +0 -1
- package/lib/apps/create-app/create.js +0 -60
- package/lib/apps/create-app/setup-template.d.ts +0 -1
- package/lib/apps/create-app/setup-template.js +0 -34
- package/lib/apps/deploy-app/deploy.d.ts +0 -2
- package/lib/apps/deploy-app/deploy.js +0 -58
- package/lib/apps/install-app/app-installer.d.ts +0 -2
- package/lib/apps/install-app/app-installer.js +0 -120
- package/lib/apps/upgrade-app/app-upgrader.d.ts +0 -3
- package/lib/apps/upgrade-app/app-upgrader.js +0 -126
- package/lib/auth/auth.js +0 -2
- package/lib/cli.d.ts +0 -5
- package/lib/cli.js +0 -524
- package/lib/colors/color-loader.d.ts +0 -2
- package/lib/colors/color-loader.js +0 -96
- package/lib/common.js +0 -5
- package/lib/config/config.js +0 -70
- package/lib/config/configCommands.d.ts +0 -3
- package/lib/config/configCommands.js +0 -34
- package/lib/interfaces.js +0 -25
- package/lib/loader-process/loader-process.d.ts +0 -2
- package/lib/projects/interfaces.d.ts +0 -77
- package/lib/projects/interfaces.js +0 -23
- package/lib/projects/project-exporter.d.ts +0 -2
- package/lib/projects/project-uploader.d.ts +0 -1
- package/lib/types/allUploader.d.ts +0 -1
- package/lib/types/allUploader.js +0 -24
- package/lib/types/interfaces.d.ts +0 -55
- package/lib/types/interfaces.js +0 -1
- package/lib/types/option-set-hierarchy-exporter.d.ts +0 -1
- package/lib/types/option-set-hierarchy-parser.d.ts +0 -2
- package/lib/types/option-set-hierarchy-uploader.d.ts +0 -1
- package/lib/types/option-set-merger.d.ts +0 -1
- package/lib/types/option-set-parser.d.ts +0 -3
- package/lib/types/option-set-parser.js +0 -140
- package/lib/types/option-set-uploader.d.ts +0 -1
- package/lib/types/parse-types.d.ts +0 -4
- package/lib/types/parse-types.js +0 -189
- package/lib/types/rule-set-uploader.d.ts +0 -1
- package/lib/types/type-property-policy-uploader.d.ts +0 -1
- package/lib/types/types-properties-merger.d.ts +0 -1
- package/lib/types/types-properties-merger.js +0 -75
- package/lib/types/usage-info-uploader.d.ts +0 -1
- package/lib/users/user-exporter.d.ts +0 -1
- package/lib/users/user-exporter.js +0 -41
- package/lib/users/user-uploader.d.ts +0 -1
- package/lib/users/user-uploader.js +0 -45
- package/lib/workflow-template-definitions/workflow-template-definition-commands.d.ts +0 -2
- package/lib/workflow-template-definitions/workflow-template-definition-commands.js +0 -10
- package/lib/workflow-templates/local-workflow-template-deployer.js +0 -102
- package/lib/workflow-templates/workflow-template-commands.d.ts +0 -4
- package/lib/workflow-templates/workflow-template-commands.js +0 -51
- package/lib/workflow-templates/workflow-template-deployer.d.ts +0 -4
- package/lib/workflow-templates/workflow-template-deployer.js +0 -26
- package/publish.bat +0 -5
- package/publish.sh +0 -5
- package/src/api/apps.ts +0 -97
- package/src/api/event-workflow-action-definition.ts +0 -8
- package/src/api/event-workflow-template-definition.ts +0 -23
- package/src/api/event-workflow-templates.ts +0 -29
- package/src/apps/create-app/create.ts +0 -74
- package/src/apps/create-app/setup-template.ts +0 -38
- package/src/apps/deploy-app/actions-deployer.ts +0 -140
- package/src/apps/deploy-app/app-deployer.ts +0 -105
- package/src/apps/deploy-app/app-template-parsers.ts +0 -44
- package/src/apps/deploy-app/deploy.ts +0 -66
- package/src/apps/install-app/app-installer.ts +0 -126
- package/src/apps/upgrade-app/app-upgrader.ts +0 -132
- package/src/auth/auth.ts +0 -10
- package/src/auth/login.ts +0 -155
- package/src/cli.ts +0 -540
- package/src/colors/color-loader.ts +0 -112
- package/src/colors/colors.csv +0 -866
- package/src/common.ts +0 -5
- package/src/config/config.ts +0 -74
- package/src/config/configCommands.ts +0 -38
- package/src/interfaces.ts +0 -200
- package/src/loader-process/loader-process.ts +0 -152
- package/src/projects/interfaces.ts +0 -73
- package/src/projects/project-exporter.ts +0 -225
- package/src/projects/project-uploader.ts +0 -131
- package/src/types/allUploader.ts +0 -28
- package/src/types/csv-parser.ts +0 -59
- package/src/types/interfaces.ts +0 -58
- package/src/types/option-set-hierarchy-exporter.ts +0 -125
- package/src/types/option-set-hierarchy-parser.ts +0 -169
- package/src/types/option-set-hierarchy-uploader.ts +0 -122
- package/src/types/option-set-merger.ts +0 -124
- package/src/types/option-set-parser.ts +0 -166
- package/src/types/option-set-uploader.ts +0 -108
- package/src/types/parse-types.ts +0 -227
- package/src/types/rule-set-uploader.ts +0 -187
- package/src/types/type-property-policy-uploader.ts +0 -192
- package/src/types/types-extractor.ts +0 -369
- package/src/types/types-properties-merger.ts +0 -90
- package/src/types/types-uploader.ts +0 -271
- package/src/types/usage-info-uploader.ts +0 -139
- package/src/users/user-exporter.ts +0 -52
- package/src/users/user-uploader.ts +0 -58
- package/src/workflow-template-definitions/workflow-template-definition-commands.ts +0 -13
- package/src/workflow-template-definitions/workflow-template-definition-deployer.ts +0 -184
- package/src/workflow-templates/local-workflow-template-deployer.ts +0 -126
- package/src/workflow-templates/workflow-template-commands.ts +0 -59
- package/src/workflow-templates/workflow-template-deployer.ts +0 -30
- package/templates/javascript/actions/example/action.js +0 -38
- package/templates/javascript/app.yml +0 -53
- package/templates/javascript/package.json +0 -23
- package/templates/typescript/package-lock.json +0 -14
- package/tsconfig.json +0 -32
package/src/types/parse-types.ts
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
import { GetSuggestedTypes, GetTypesFromTemplate, GetTypesFromTemplateWithOptionSetsFromData } from '@contrail/types';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import { getSeparatorByPlatform } from '../common';
|
|
5
|
-
import * as csvToJson from 'csvtojson';
|
|
6
|
-
import { authUser } from '../auth/login';
|
|
7
|
-
import { getCSVFromFile } from './csv-parser';
|
|
8
|
-
|
|
9
|
-
const yaml = require('js-yaml');
|
|
10
|
-
|
|
11
|
-
// This uses local files to get the data to parse into types
|
|
12
|
-
export async function ParseTypesFromLocalFiles(args) {
|
|
13
|
-
try {
|
|
14
|
-
if (args?.length < 4) {
|
|
15
|
-
throw new Error('File names must be included.');
|
|
16
|
-
}
|
|
17
|
-
console.log('%s Parsing', chalk.yellow.bold('TYPES AND OPTION SETS'));
|
|
18
|
-
const fileLocations = (args as Array<string>).slice(3);
|
|
19
|
-
console.log('Using File Location(s): ', fileLocations);
|
|
20
|
-
|
|
21
|
-
await parseTypesFromLocalFiles(fileLocations);
|
|
22
|
-
console.log('%s Parsed', chalk.yellow.bold('TYPES AND OPTION SETS'));
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
catch (e) {
|
|
26
|
-
console.log(`%s Parsing Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
console.log('%s Parsing Complete.', chalk.green.bold('COMPLETE'));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// This uses VibeIq file ids to get the data to parse into types
|
|
34
|
-
export async function ParseTypesFromFiles(args) {
|
|
35
|
-
try {
|
|
36
|
-
if (args?.length < 4) {
|
|
37
|
-
throw new Error('File ids must be included.');
|
|
38
|
-
}
|
|
39
|
-
console.log('%s Parsing', chalk.yellow.bold('TYPES AND OPTION SETS'));
|
|
40
|
-
const fileIds = (args as Array<string>).slice(3);
|
|
41
|
-
console.log('Using FileId(s): ', fileIds);
|
|
42
|
-
|
|
43
|
-
await parseTypesFromFiles(fileIds);
|
|
44
|
-
console.log('%s Parsed', chalk.yellow.bold('TYPES AND OPTION SETS'));
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
catch (e) {
|
|
48
|
-
console.log(`%s Parsing Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
console.log('%s Parsing Complete.', chalk.green.bold('COMPLETE'));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// This uses local files to get type template file and the data file to parse into types
|
|
56
|
-
export async function ParseTypesFromTemplateFromLocalFiles(args) {
|
|
57
|
-
try {
|
|
58
|
-
if (args?.length < 5) {
|
|
59
|
-
throw new Error('File names must be included.');
|
|
60
|
-
}
|
|
61
|
-
console.log('%s Parsing', chalk.yellow.bold('TYPES AND OPTION SETS'));
|
|
62
|
-
const templateFileLocation = args[3];
|
|
63
|
-
const dataFileLocation = args[4];
|
|
64
|
-
console.log('Using Template File Location: ', templateFileLocation);
|
|
65
|
-
console.log('Using Data File Location: ', dataFileLocation);
|
|
66
|
-
|
|
67
|
-
await parseTypesFromTemplateFromLocalFiles(templateFileLocation, dataFileLocation);
|
|
68
|
-
console.log('%s Parsed', chalk.yellow.bold('TYPES AND OPTION SETS'));
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
catch (e) {
|
|
72
|
-
console.log(`%s Parsing Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
console.log('%s Parsing Complete.', chalk.green.bold('COMPLETE'));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export async function ParseTypesFromTemplateAndDataFromLocalFiles(args) {
|
|
80
|
-
try {
|
|
81
|
-
if (args?.length < 5) {
|
|
82
|
-
throw new Error('File names must be included.');
|
|
83
|
-
}
|
|
84
|
-
console.log('%s Parsing', chalk.yellow.bold('TYPES AND OPTION SETS'));
|
|
85
|
-
const templateFileLocation = args[3];
|
|
86
|
-
const dataFileLocations = (args as Array<string>).slice(4);
|
|
87
|
-
|
|
88
|
-
console.log('Using Template File Location: ', templateFileLocation);
|
|
89
|
-
console.log('Using Data File Location: ', dataFileLocations);
|
|
90
|
-
|
|
91
|
-
await parseTypesFromTemplateAndDataFromLocalFiles(templateFileLocation, dataFileLocations);
|
|
92
|
-
console.log('%s Parsed', chalk.yellow.bold('TYPES AND OPTION SETS'));
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
catch (e) {
|
|
96
|
-
console.log(`%s Parsing Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
console.log('%s Parsing Complete.', chalk.green.bold('COMPLETE'));
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async function loadDataFromLocalCSV(fileName) {
|
|
104
|
-
const CURRENT_DIR = process.cwd();
|
|
105
|
-
try {
|
|
106
|
-
const separator = getSeparatorByPlatform();
|
|
107
|
-
const fullPath = CURRENT_DIR + separator + fileName;
|
|
108
|
-
|
|
109
|
-
console.log('Getting file from path: ', fullPath);
|
|
110
|
-
const csvData = await csvToJson.default({flatKeys: true}).fromFile(fullPath);
|
|
111
|
-
|
|
112
|
-
return csvData;
|
|
113
|
-
} catch (e) {
|
|
114
|
-
throw new Error(`ERROR PARSING CSV: ${e}`);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
async function parseTypesFromLocalFiles(fileLocations: string[]) {
|
|
119
|
-
|
|
120
|
-
const csvJSONData: any[] = [];
|
|
121
|
-
for (const fileLocation of fileLocations) {
|
|
122
|
-
try {
|
|
123
|
-
console.log('Getting data for fileLocation: ', fileLocation);
|
|
124
|
-
const csvData = await loadDataFromLocalCSV(fileLocation);
|
|
125
|
-
|
|
126
|
-
console.log(`CSV import was successful. ${csvData?.length} rows found. Adding to total rows.`);
|
|
127
|
-
csvJSONData.push(...csvData);
|
|
128
|
-
}
|
|
129
|
-
catch (e) {
|
|
130
|
-
console.log('Error importing csv data.', e);
|
|
131
|
-
throw e;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
console.log(`CSV imports were successful. ${csvJSONData?.length} total rows found.`);
|
|
136
|
-
const suggestions = GetSuggestedTypes(csvJSONData);
|
|
137
|
-
saveData(suggestions.OptionSets, 'parsed_optionSets.yml');
|
|
138
|
-
saveData({ typeProperties: suggestions.TypeProperties }, 'parsed_typeProperties.yml');
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
async function parseTypesFromTemplateFromLocalFiles(templateFileLocation: string, dataFileLocation: string) {
|
|
142
|
-
|
|
143
|
-
let templateCSVData: any[] = [];
|
|
144
|
-
let dataCSVData: any[] = [];
|
|
145
|
-
try {
|
|
146
|
-
console.log('Getting template from fileLocation: ', templateFileLocation);
|
|
147
|
-
templateCSVData = await loadDataFromLocalCSV(templateFileLocation);
|
|
148
|
-
console.log(`CSV import was successful. ${templateCSVData?.length} rows found.`);
|
|
149
|
-
|
|
150
|
-
console.log('Getting data from fileLocation: ', dataFileLocation);
|
|
151
|
-
dataCSVData = await loadDataFromLocalCSV(dataFileLocation);
|
|
152
|
-
console.log(`CSV import was successful. ${dataCSVData?.length} rows found.`);
|
|
153
|
-
}
|
|
154
|
-
catch (e) {
|
|
155
|
-
console.log('Error importing csv data.', e);
|
|
156
|
-
throw e;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const types = GetTypesFromTemplate(templateCSVData, dataCSVData);
|
|
160
|
-
saveData(types.OptionSets, 'parsed_optionSets.yml');
|
|
161
|
-
saveData({ TypePropertiesByEntity: types.TypePropertiesByEntity }, 'parsed_TypePropertiesByEntity.yml');
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
async function parseTypesFromTemplateAndDataFromLocalFiles(templateFileLocation: string, dataFileLocations: string[]) {
|
|
165
|
-
|
|
166
|
-
let templateCSVData: any[] = [];
|
|
167
|
-
try {
|
|
168
|
-
console.log('Getting template from fileLocation: ', templateFileLocation);
|
|
169
|
-
templateCSVData = await loadDataFromLocalCSV(templateFileLocation);
|
|
170
|
-
console.log(`CSV import was successful. ${templateCSVData?.length} rows found.`);
|
|
171
|
-
}
|
|
172
|
-
catch (e) {
|
|
173
|
-
console.log('Error importing csv data.', e);
|
|
174
|
-
throw e;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const dataCSVData: any[] = [];
|
|
178
|
-
for (const dataFileLocation of dataFileLocations) {
|
|
179
|
-
try {
|
|
180
|
-
console.log('Getting data for dataFileLocation: ', dataFileLocation);
|
|
181
|
-
const csvData = await loadDataFromLocalCSV(dataFileLocation);
|
|
182
|
-
|
|
183
|
-
console.log(`CSV import was successful. ${csvData?.length} rows found. Adding to total rows.`);
|
|
184
|
-
dataCSVData.push(...csvData);
|
|
185
|
-
}
|
|
186
|
-
catch (e) {
|
|
187
|
-
console.log('Error importing csv data.', e);
|
|
188
|
-
throw e;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const types = GetTypesFromTemplateWithOptionSetsFromData(templateCSVData, dataCSVData);
|
|
193
|
-
saveData(types.OptionSets, 'parsed_optionSets.yml');
|
|
194
|
-
saveData({ TypePropertiesByEntity: types.TypePropertiesByEntity }, 'parsed_TypePropertiesByEntity.yml');
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
async function parseTypesFromFiles(fileIds: string[]) {
|
|
198
|
-
await authUser();
|
|
199
|
-
|
|
200
|
-
// get csv data
|
|
201
|
-
const csvJSONData: any[] = [];
|
|
202
|
-
for (const loadFileId of fileIds) {
|
|
203
|
-
try {
|
|
204
|
-
console.log('Getting data for fileId: ', loadFileId);
|
|
205
|
-
const csvJSON = await getCSVFromFile(loadFileId);
|
|
206
|
-
console.log(`CSV download was successful. ${csvJSON?.length} rows found. Adding to total rows`);
|
|
207
|
-
csvJSONData.push(...csvJSON);
|
|
208
|
-
}
|
|
209
|
-
catch (e) {
|
|
210
|
-
console.log('Error retrieving csv data', e);
|
|
211
|
-
throw e;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
console.log(`CSV downloads were successful. ${csvJSONData?.length} total rows found.`);
|
|
216
|
-
const suggestions = GetSuggestedTypes(csvJSONData);
|
|
217
|
-
|
|
218
|
-
saveData(suggestions.OptionSets, 'parsed_optionSets.yml');
|
|
219
|
-
saveData({ typeProperties: suggestions.TypeProperties }, 'parsed_typeProperties.yml');
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
function saveData(data, name) {
|
|
223
|
-
const yamlStr = yaml.dump(data);
|
|
224
|
-
const CURRENT_DIR = process.cwd();
|
|
225
|
-
const separator = getSeparatorByPlatform();
|
|
226
|
-
fs.writeFileSync(CURRENT_DIR + separator + name, yamlStr, 'utf8');
|
|
227
|
-
}
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import { Entities } from '@contrail/sdk';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import * as path from 'path';
|
|
4
|
-
import { authUser } from '../auth/login';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
|
|
7
|
-
const yaml = require('js-yaml');
|
|
8
|
-
|
|
9
|
-
export async function uploadRuleSets(args) {
|
|
10
|
-
try {
|
|
11
|
-
await authUser();
|
|
12
|
-
|
|
13
|
-
console.log('%s Uploading', chalk.yellow.bold('RULE SET'));
|
|
14
|
-
const [reducedRuleSets, reducedRuleSetLinks] = await loadReducedRuleSets();
|
|
15
|
-
await uploadRuleSetObjects(reducedRuleSets);
|
|
16
|
-
await uploadRuleSetLinkObjects(reducedRuleSetLinks);
|
|
17
|
-
console.log('%s Uploaded', chalk.yellow.bold('RULE SET'));
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
catch (e) {
|
|
21
|
-
console.log(`%s Rule Set Upload Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
console.log('%s Rule set Upload Complete.', chalk.green.bold('COMPLETE'));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function loadReducedRuleSets() {
|
|
29
|
-
const ruleSets = [];
|
|
30
|
-
let ruleSetLinks = [];
|
|
31
|
-
const TARGET_DIR = process.cwd();
|
|
32
|
-
try {
|
|
33
|
-
const files = fs.readdirSync(path.join(TARGET_DIR, 'rule-sets'));
|
|
34
|
-
for(const file of files) {
|
|
35
|
-
ruleSets.push(yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'rule-sets', file), 'utf8')));
|
|
36
|
-
}
|
|
37
|
-
ruleSetLinks = yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'rule-set-links.yml'), 'utf8'));
|
|
38
|
-
return [ruleSets, ruleSetLinks];
|
|
39
|
-
} catch (e) {
|
|
40
|
-
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async function uploadRuleSetObjects(reducedRuleSets) {
|
|
45
|
-
|
|
46
|
-
const currentRuleSets = await new Entities().get({
|
|
47
|
-
entityName: 'type-rule-set',
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const currentRuleSetsByName = {};
|
|
51
|
-
for (const currentRuleSet of currentRuleSets) {
|
|
52
|
-
currentRuleSetsByName[currentRuleSet.name] = currentRuleSet;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const loadedRuleSetsByName = {};
|
|
56
|
-
for (const loadedRuleSet of reducedRuleSets) {
|
|
57
|
-
loadedRuleSetsByName[loadedRuleSet.name] = loadedRuleSet;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
console.debug('current rule sets:', currentRuleSets);
|
|
61
|
-
console.debug('reduced rule sets:', reducedRuleSets);
|
|
62
|
-
|
|
63
|
-
for (const reducedRuleSet of reducedRuleSets) {
|
|
64
|
-
try {
|
|
65
|
-
const found = currentRuleSetsByName[reducedRuleSet.name];
|
|
66
|
-
if (!found) {
|
|
67
|
-
console.log('Creating: ', reducedRuleSet.name);
|
|
68
|
-
await new Entities().create({
|
|
69
|
-
entityName: 'type-rule-set',
|
|
70
|
-
object: reducedRuleSet
|
|
71
|
-
});
|
|
72
|
-
} else {
|
|
73
|
-
console.log('Updating: ', reducedRuleSet.name);
|
|
74
|
-
await new Entities().update({
|
|
75
|
-
entityName: 'type-rule-set',
|
|
76
|
-
id: found.id,
|
|
77
|
-
object: reducedRuleSet,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
} catch (err) {
|
|
81
|
-
throw new Error(`Error Uploading rule sets: ${err}`);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
for (const currentRuleSet of currentRuleSets) {
|
|
86
|
-
try {
|
|
87
|
-
const found = loadedRuleSetsByName[currentRuleSet.name];
|
|
88
|
-
if (!found) {
|
|
89
|
-
console.log('Deleting: ', currentRuleSet.name);
|
|
90
|
-
await new Entities().delete({
|
|
91
|
-
entityName: 'type-rule-set',
|
|
92
|
-
id: currentRuleSet.id,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
} catch (err) {
|
|
96
|
-
throw new Error(`Error Deleting rule set: ${err}`);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
async function uploadRuleSetLinkObjects(loadedRuleSetLinks) {
|
|
103
|
-
|
|
104
|
-
const types = await new Entities().get({
|
|
105
|
-
entityName: 'type',
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
const currentRuleSets = await new Entities().get({
|
|
109
|
-
entityName: 'type-rule-set',
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
const currentRuleSetLinks = await new Entities().get({
|
|
113
|
-
entityName: 'type-rule-set-link',
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
const currentLinksHashes = {};
|
|
117
|
-
for (const currentLink of currentRuleSetLinks) {
|
|
118
|
-
const foundType = types.find(t => t.id === currentLink.typeId);
|
|
119
|
-
const foundRuleSet = currentRuleSets.find(rs => rs.id === currentLink.typeRuleSetId);
|
|
120
|
-
const hash = `${foundType.slug}|${foundRuleSet.name}`;
|
|
121
|
-
currentLinksHashes[hash] = currentLink;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const reducedLinksByHashes = {};
|
|
125
|
-
for (const loadedLink of loadedRuleSetLinks) {
|
|
126
|
-
const hash = `${loadedLink.type}|${loadedLink.ruleSet}`;
|
|
127
|
-
reducedLinksByHashes[hash] = loadedLink;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
console.debug('current rule set links:', currentLinksHashes);
|
|
131
|
-
console.debug('reduced rule set links:', reducedLinksByHashes);
|
|
132
|
-
|
|
133
|
-
for (const loadedRuleSetLink of loadedRuleSetLinks) {
|
|
134
|
-
try {
|
|
135
|
-
const found = currentLinksHashes[`${loadedRuleSetLink.type}|${loadedRuleSetLink.ruleSet}`];
|
|
136
|
-
if (!found) {
|
|
137
|
-
if (!transformReducedLink(loadedRuleSetLink, types, currentRuleSets)) { continue; }
|
|
138
|
-
console.log('Creating: ', loadedRuleSetLink);
|
|
139
|
-
await new Entities().create({
|
|
140
|
-
entityName: 'type-rule-set-link',
|
|
141
|
-
object: {
|
|
142
|
-
typeRuleSetId: loadedRuleSetLink.ruleSet,
|
|
143
|
-
typeId: loadedRuleSetLink.type,
|
|
144
|
-
},
|
|
145
|
-
});
|
|
146
|
-
} else {
|
|
147
|
-
if (!transformReducedLink(loadedRuleSetLink, types, currentRuleSets)) { continue; }
|
|
148
|
-
console.log('skipping updating existing rule set link: ', loadedRuleSetLink);
|
|
149
|
-
}
|
|
150
|
-
} catch (err) {
|
|
151
|
-
throw new Error(`Error Uploading rule set links: ${err}`);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
for (const [currentLinkHash, currentLink] of Object.entries(currentLinksHashes)) {
|
|
156
|
-
try {
|
|
157
|
-
const found = reducedLinksByHashes[currentLinkHash];
|
|
158
|
-
if (!found) {
|
|
159
|
-
console.log('Deleting: ', currentLinkHash);
|
|
160
|
-
await new Entities().delete({
|
|
161
|
-
entityName: 'type-rule-set-link',
|
|
162
|
-
id: currentLink['id'],
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
} catch (err) {
|
|
166
|
-
throw new Error(`Error Deleting rule set link: ${err}`);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function transformReducedLink(ruleSetLink, types, ruleSets) {
|
|
173
|
-
const foundType = types.find(t => t.slug === ruleSetLink.type);
|
|
174
|
-
if (!foundType) {
|
|
175
|
-
console.error('Could not find type with name', ruleSetLink.type);
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
178
|
-
ruleSetLink.type = foundType.id;
|
|
179
|
-
|
|
180
|
-
const foundRuleSet = ruleSets.find(rs => rs.name === ruleSetLink.ruleSet);
|
|
181
|
-
if (!foundRuleSet) {
|
|
182
|
-
console.error('Could not find rule set with name', foundType.ruleSet);
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
ruleSetLink.ruleSet = foundRuleSet.id;
|
|
186
|
-
return true;
|
|
187
|
-
}
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import { Entities } from '@contrail/sdk';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import * as path from 'path';
|
|
4
|
-
import { authUser } from '../auth/login';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
import { getTypes } from './types-extractor';
|
|
7
|
-
|
|
8
|
-
const yaml = require('js-yaml');
|
|
9
|
-
|
|
10
|
-
export async function uploadTypePropertyPolicies(args) {
|
|
11
|
-
try {
|
|
12
|
-
await authUser();
|
|
13
|
-
|
|
14
|
-
console.log('%s Uploading', chalk.yellow.bold('TYPE PROPERTY POLICY'));
|
|
15
|
-
const [reducedTypePropertyPolicies, reducedTypePropertyPolicyLinks] = await loadTPPolicies();
|
|
16
|
-
await uploadTPPolicyObjects(reducedTypePropertyPolicies);
|
|
17
|
-
await uploadTypePropertyPolicyLinks(reducedTypePropertyPolicyLinks);
|
|
18
|
-
console.log('%s Uploaded', chalk.yellow.bold('TYPE PROPERTY POLICY'));
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
catch (e) {
|
|
22
|
-
console.log(`%s Type Property Policy Upload Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
console.log('%s Type Property Policy Upload Complete.', chalk.green.bold('COMPLETE'));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function loadTPPolicies() {
|
|
30
|
-
const tpps = [];
|
|
31
|
-
let tppLinks = [];
|
|
32
|
-
const TARGET_DIR = process.cwd();
|
|
33
|
-
try {
|
|
34
|
-
const files = fs.readdirSync(path.join(TARGET_DIR, 'type-property-policies'));
|
|
35
|
-
for(const file of files) {
|
|
36
|
-
tpps.push(yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'type-property-policies', file), 'utf8')));
|
|
37
|
-
}
|
|
38
|
-
tppLinks = yaml.load(fs.readFileSync(path.join(TARGET_DIR, 'type-property-policy-links.yml'), 'utf8'));
|
|
39
|
-
return [tpps, tppLinks];
|
|
40
|
-
} catch (e) {
|
|
41
|
-
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async function uploadTPPolicyObjects(reducedTypePropertyPolicies) {
|
|
46
|
-
|
|
47
|
-
const currentTPPolicies = await new Entities().get({
|
|
48
|
-
entityName: 'type-property-policy',
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
const currentTPPByLabel = {};
|
|
52
|
-
for (const currentTPP of currentTPPolicies) {
|
|
53
|
-
currentTPPByLabel[currentTPP.label] = currentTPP;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const loadedTPPByName = {};
|
|
57
|
-
for (const loadedTPP of reducedTypePropertyPolicies) {
|
|
58
|
-
loadedTPPByName[loadedTPP.label] = loadedTPP;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
console.debug('current tp policy:', currentTPPolicies);
|
|
62
|
-
console.debug('reduced tp policy:', reducedTypePropertyPolicies);
|
|
63
|
-
|
|
64
|
-
for (const [label, loadedTPP] of Object.entries(loadedTPPByName)) {
|
|
65
|
-
try {
|
|
66
|
-
const found = currentTPPByLabel[label];
|
|
67
|
-
if (!found) {
|
|
68
|
-
console.log('Creating: ', label);
|
|
69
|
-
await new Entities().create({
|
|
70
|
-
entityName: 'type-property-policy',
|
|
71
|
-
object: loadedTPP
|
|
72
|
-
});
|
|
73
|
-
} else {
|
|
74
|
-
console.log('Updating: ', label);
|
|
75
|
-
await new Entities().update({
|
|
76
|
-
entityName: 'type-property-policy',
|
|
77
|
-
id: found.id,
|
|
78
|
-
object: loadedTPP,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
} catch (err) {
|
|
82
|
-
throw new Error(`Error Uploading Type Property Policy: ${err}`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
for (const [label, currentTPP] of Object.entries(currentTPPByLabel)) {
|
|
87
|
-
try {
|
|
88
|
-
const found = loadedTPPByName[label];
|
|
89
|
-
if (!found) {
|
|
90
|
-
console.log('Deleting: ', label);
|
|
91
|
-
await new Entities().delete({
|
|
92
|
-
entityName: 'type-property-policy',
|
|
93
|
-
id: currentTPP['id'],
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
} catch (err) {
|
|
97
|
-
throw new Error(`Error Type Property Policy: ${err}`);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async function uploadTypePropertyPolicyLinks(reducedTypePropertyPolicyLinks) {
|
|
104
|
-
const typesWithProperties = await getTypes();
|
|
105
|
-
const typeProperties = typesWithProperties
|
|
106
|
-
.filter(t => !!t.typeProperties)
|
|
107
|
-
.map(t => t.typeProperties)
|
|
108
|
-
.reduce((a, b) => a.concat(b));
|
|
109
|
-
|
|
110
|
-
const currentTPPs = await new Entities().get({
|
|
111
|
-
entityName: 'type-property-policy',
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
const currentTPPLinks = await new Entities().get({
|
|
115
|
-
entityName: 'type-property-policy-link',
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
const currentLinksHashes = {};
|
|
119
|
-
for (const currentLink of currentTPPLinks) {
|
|
120
|
-
const foundTypeProperty = typeProperties.find(tp => tp.id === currentLink.typePropertyId);
|
|
121
|
-
const foundTPP = currentTPPs.find(tpp => tpp.id === currentLink.typePropertyPolicyId);
|
|
122
|
-
if(!foundTypeProperty || !foundTPP) {
|
|
123
|
-
console.log('skipping unhashable, invalid policy link:', currentLink);
|
|
124
|
-
}
|
|
125
|
-
const hash = `${foundTypeProperty.slug}|${foundTPP.label}`;
|
|
126
|
-
currentLinksHashes[hash] = currentLink;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const reducedLinksByHashes = {};
|
|
130
|
-
for (const loadedLink of reducedTypePropertyPolicyLinks) {
|
|
131
|
-
const hash = `${loadedLink.typePropertySlug}|${loadedLink.typePropertyPolicyLabel}`;
|
|
132
|
-
reducedLinksByHashes[hash] = loadedLink;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
console.debug('current type property policy links:', currentLinksHashes);
|
|
136
|
-
console.debug('reduced type property policy links:', reducedLinksByHashes);
|
|
137
|
-
|
|
138
|
-
for (const loadedTPPLink of reducedTypePropertyPolicyLinks) {
|
|
139
|
-
try {
|
|
140
|
-
const found = currentLinksHashes[`${loadedTPPLink.typePropertySlug}|${loadedTPPLink.typePropertyPolicyLabel}`];
|
|
141
|
-
if (!found) {
|
|
142
|
-
if (!transformReducedLink(loadedTPPLink, typeProperties, currentTPPs)) { continue; }
|
|
143
|
-
console.log('Creating: ', loadedTPPLink);
|
|
144
|
-
await new Entities().create({
|
|
145
|
-
entityName: 'type-property-policy-link',
|
|
146
|
-
object: {
|
|
147
|
-
typePropertyPolicyId: loadedTPPLink.typePropertyPolicyId,
|
|
148
|
-
typePropertyId: loadedTPPLink.typePropertyId,
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
} else {
|
|
152
|
-
if (!transformReducedLink(loadedTPPLink, typeProperties, currentTPPs)) { continue; }
|
|
153
|
-
console.log('skipping existing link: ', loadedTPPLink);
|
|
154
|
-
}
|
|
155
|
-
} catch (err) {
|
|
156
|
-
throw new Error(`Error Uploading type property policy links: ${err}`);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
for (const [currentLinkHash, currentLink] of Object.entries(currentLinksHashes)) {
|
|
161
|
-
try {
|
|
162
|
-
const found = reducedLinksByHashes[currentLinkHash];
|
|
163
|
-
if (!found) {
|
|
164
|
-
console.log('Deleting: ', currentLinkHash);
|
|
165
|
-
await new Entities().delete({
|
|
166
|
-
entityName: 'type-property-policy-link',
|
|
167
|
-
id: currentLink['id'],
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
} catch (err) {
|
|
171
|
-
throw new Error(`Error Deleting rule set link: ${err}`);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function transformReducedLink(TPPLink, typeProperties, typePropertyPolicies) {
|
|
178
|
-
const foundTP = typeProperties.find(tp => tp.slug === TPPLink.typePropertySlug);
|
|
179
|
-
if (!foundTP) {
|
|
180
|
-
console.error('Could not find type property with label', TPPLink.typePropertySlug);
|
|
181
|
-
return false;
|
|
182
|
-
}
|
|
183
|
-
TPPLink.typePropertyId = foundTP.id;
|
|
184
|
-
|
|
185
|
-
const foundTPP = typePropertyPolicies.find(tpp => tpp.label === TPPLink.typePropertyPolicyLabel);
|
|
186
|
-
if (!foundTPP) {
|
|
187
|
-
console.error('Could not find type property policy with label', TPPLink.typePropertyPolicyLabel);
|
|
188
|
-
return false;
|
|
189
|
-
}
|
|
190
|
-
TPPLink.typePropertyPolicyId = foundTPP.id;
|
|
191
|
-
return true;
|
|
192
|
-
}
|