@contrail/cli 1.0.40 → 1.0.42
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/lib/auth/login.js +2 -2
- package/lib/cli.js +10 -2
- package/lib/types/parse-types.d.ts +1 -0
- package/lib/types/parse-types.js +48 -1
- package/package.json +2 -2
- package/src/auth/login.ts +2 -2
- package/src/cli.ts +10 -2
- package/src/types/parse-types.ts +58 -1
- package/lib/apps/app-api.d.ts +0 -6
- package/lib/apps/app-api.js +0 -59
- package/lib/apps/deploy-app/docker-action-builder.d.ts +0 -10
- package/lib/apps/deploy-app/docker-action-builder.js +0 -97
- package/lib/apps/deploy-app/interfaces.d.ts +0 -76
- package/lib/apps/deploy-app/interfaces.js +0 -4
- package/lib/apps/deploy-app/workflow-definition-deployer.d.ts +0 -10
- package/lib/apps/deploy-app/workflow-definition-deployer.js +0 -95
- package/lib/apps/deploy-app/workflow-deployer.d.ts +0 -10
- package/lib/apps/deploy-app/workflow-deployer.js +0 -87
- package/lib/workflows/workflow-template-deployer.d.ts +0 -14
- package/lib/workflows/workflow-template-deployer.js +0 -127
- package/lib/workflows/workflowCommands.d.ts +0 -3
- package/lib/workflows/workflowCommands.js +0 -46
package/lib/auth/login.js
CHANGED
|
@@ -4,8 +4,8 @@ import { Request, setConfig as setSdkConfig } from '@contrail/sdk';
|
|
|
4
4
|
import { Auth } from './auth';
|
|
5
5
|
import { getConfig, storeConfig } from '../config/config';
|
|
6
6
|
const CONFIGURATION = {
|
|
7
|
-
userPoolId: 'us-east-
|
|
8
|
-
clientId: process.env.CONTRAIL_COGNITO_CLIENT_ID || '
|
|
7
|
+
userPoolId: 'us-east-1_qIaNZdUfm',
|
|
8
|
+
clientId: process.env.CONTRAIL_COGNITO_CLIENT_ID || '7knkt34gfacbgd0ghnuspefdfg',
|
|
9
9
|
};
|
|
10
10
|
export async function authUser() {
|
|
11
11
|
console.debug('authorizing user');
|
package/lib/cli.js
CHANGED
|
@@ -6,7 +6,7 @@ import { UploadOptionSets } from './types/option-set-uploader';
|
|
|
6
6
|
import { ParseOptionSetsLocalFiles } from './types/option-set-parser';
|
|
7
7
|
import { MergeOptionSets } from './types/option-set-merger';
|
|
8
8
|
import { MergeTypeProperties } from './types/types-properties-merger';
|
|
9
|
-
import { ParseTypesFromFiles, ParseTypesFromLocalFiles, ParseTypesFromTemplateFromLocalFiles } from './types/parse-types';
|
|
9
|
+
import { ParseTypesFromFiles, ParseTypesFromLocalFiles, ParseTypesFromTemplateFromLocalFiles, ParseTypesFromTemplateAndDataFromLocalFiles } from './types/parse-types';
|
|
10
10
|
import { loadColors, deleteColors } from './colors/color-loader';
|
|
11
11
|
import { listConfig, removeConfig, setConfig } from './config/configCommands';
|
|
12
12
|
import { deleteWorkflowTemplates, localDeployWorkflowTemplate, listWorkflowTemplate } from './workflow-templates/workflow-template-commands';
|
|
@@ -97,6 +97,10 @@ export async function cli(args) {
|
|
|
97
97
|
ParseTypesFromTemplateFromLocalFiles(args);
|
|
98
98
|
break;
|
|
99
99
|
}
|
|
100
|
+
case 'parseTypesFromTemplateAndDataFromLocalFiles': {
|
|
101
|
+
ParseTypesFromTemplateAndDataFromLocalFiles(args);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
100
104
|
case 'parseTypesFromFiles': {
|
|
101
105
|
ParseTypesFromFiles(args);
|
|
102
106
|
break;
|
|
@@ -312,7 +316,11 @@ const helpSections = [
|
|
|
312
316
|
},
|
|
313
317
|
{
|
|
314
318
|
name: 'parseTypesFromTemplateFromLocalFiles <File Paths>',
|
|
315
|
-
summary: 'Parse CSV files into Types and OptionSets from local files.\n'
|
|
319
|
+
summary: 'Parse CSV files into Types and OptionSets from local type template files.\n'
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
name: 'parseTypesFromTemplateAndDataFromLocalFiles <File Paths>',
|
|
323
|
+
summary: 'Parse CSV files into Types and OptionSets from local type template and data files.\n'
|
|
316
324
|
},
|
|
317
325
|
{
|
|
318
326
|
name: 'parseTypesFromFiles <fileIds>',
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export declare function ParseTypesFromLocalFiles(args: any): Promise<void>;
|
|
2
2
|
export declare function ParseTypesFromFiles(args: any): Promise<void>;
|
|
3
3
|
export declare function ParseTypesFromTemplateFromLocalFiles(args: any): Promise<void>;
|
|
4
|
+
export declare function ParseTypesFromTemplateAndDataFromLocalFiles(args: any): Promise<void>;
|
package/lib/types/parse-types.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GetSuggestedTypes, GetTypesFromTemplate } from '@contrail/types';
|
|
1
|
+
import { GetSuggestedTypes, GetTypesFromTemplate, GetTypesFromTemplateWithOptionSetsFromData } from '@contrail/types';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import { getSeparatorByPlatform } from '../common';
|
|
@@ -62,6 +62,25 @@ export async function ParseTypesFromTemplateFromLocalFiles(args) {
|
|
|
62
62
|
}
|
|
63
63
|
console.log('%s Parsing Complete.', chalk.green.bold('COMPLETE'));
|
|
64
64
|
}
|
|
65
|
+
export async function ParseTypesFromTemplateAndDataFromLocalFiles(args) {
|
|
66
|
+
try {
|
|
67
|
+
if ((args === null || args === void 0 ? void 0 : args.length) < 5) {
|
|
68
|
+
throw new Error('File names must be included.');
|
|
69
|
+
}
|
|
70
|
+
console.log('%s Parsing', chalk.yellow.bold('TYPES AND OPTION SETS'));
|
|
71
|
+
const templateFileLocation = args[3];
|
|
72
|
+
const dataFileLocations = args.slice(4);
|
|
73
|
+
console.log('Using Template File Location: ', templateFileLocation);
|
|
74
|
+
console.log('Using Data File Location: ', dataFileLocations);
|
|
75
|
+
await parseTypesFromTemplateAndDataFromLocalFiles(templateFileLocation, dataFileLocations);
|
|
76
|
+
console.log('%s Parsed', chalk.yellow.bold('TYPES AND OPTION SETS'));
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
console.log(`%s Parsing Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
console.log('%s Parsing Complete.', chalk.green.bold('COMPLETE'));
|
|
83
|
+
}
|
|
65
84
|
async function loadDataFromLocalCSV(fileName) {
|
|
66
85
|
const CURRENT_DIR = process.cwd();
|
|
67
86
|
try {
|
|
@@ -113,6 +132,34 @@ async function parseTypesFromTemplateFromLocalFiles(templateFileLocation, dataFi
|
|
|
113
132
|
saveData({ optionSets: types.OptionSets }, 'parsed_optionSets.yml');
|
|
114
133
|
saveData({ TypePropertiesByEntity: types.TypePropertiesByEntity }, 'parsed_TypePropertiesByEntity.yml');
|
|
115
134
|
}
|
|
135
|
+
async function parseTypesFromTemplateAndDataFromLocalFiles(templateFileLocation, dataFileLocations) {
|
|
136
|
+
let templateCSVData = [];
|
|
137
|
+
try {
|
|
138
|
+
console.log('Getting template from fileLocation: ', templateFileLocation);
|
|
139
|
+
templateCSVData = await loadDataFromLocalCSV(templateFileLocation);
|
|
140
|
+
console.log(`CSV import was successful. ${templateCSVData === null || templateCSVData === void 0 ? void 0 : templateCSVData.length} rows found.`);
|
|
141
|
+
}
|
|
142
|
+
catch (e) {
|
|
143
|
+
console.log('Error importing csv data.', e);
|
|
144
|
+
throw e;
|
|
145
|
+
}
|
|
146
|
+
const dataCSVData = [];
|
|
147
|
+
for (const dataFileLocation of dataFileLocations) {
|
|
148
|
+
try {
|
|
149
|
+
console.log('Getting data for dataFileLocation: ', dataFileLocation);
|
|
150
|
+
const csvData = await loadDataFromLocalCSV(dataFileLocation);
|
|
151
|
+
console.log(`CSV import was successful. ${csvData === null || csvData === void 0 ? void 0 : csvData.length} rows found. Adding to total rows.`);
|
|
152
|
+
dataCSVData.push(...csvData);
|
|
153
|
+
}
|
|
154
|
+
catch (e) {
|
|
155
|
+
console.log('Error importing csv data.', e);
|
|
156
|
+
throw e;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const types = GetTypesFromTemplateWithOptionSetsFromData(templateCSVData, dataCSVData);
|
|
160
|
+
saveData({ optionSets: types.OptionSets }, 'parsed_optionSets.yml');
|
|
161
|
+
saveData({ TypePropertiesByEntity: types.TypePropertiesByEntity }, 'parsed_TypePropertiesByEntity.yml');
|
|
162
|
+
}
|
|
116
163
|
async function parseTypesFromFiles(fileIds) {
|
|
117
164
|
await authUser();
|
|
118
165
|
// get csv data
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.42",
|
|
4
4
|
"description": "VibeIQ's Contrail Platform CLI.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"license": "ISC",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@contrail/sdk": "^1.0.154",
|
|
27
|
-
"@contrail/types": "^2.0.
|
|
27
|
+
"@contrail/types": "^2.0.75",
|
|
28
28
|
"@contrail/util": "^1.0.17",
|
|
29
29
|
"amazon-cognito-identity-js": "^5.2.3",
|
|
30
30
|
"arg": "^4.0.1",
|
package/src/auth/login.ts
CHANGED
|
@@ -5,8 +5,8 @@ import { Auth, AuthContext } from './auth';
|
|
|
5
5
|
import { getConfig, storeConfig } from '../config/config';
|
|
6
6
|
|
|
7
7
|
const CONFIGURATION = {
|
|
8
|
-
userPoolId: 'us-east-
|
|
9
|
-
clientId: process.env.CONTRAIL_COGNITO_CLIENT_ID || '
|
|
8
|
+
userPoolId: 'us-east-1_qIaNZdUfm',
|
|
9
|
+
clientId: process.env.CONTRAIL_COGNITO_CLIENT_ID || '7knkt34gfacbgd0ghnuspefdfg',
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export async function authUser(): Promise<AuthContext> {
|
package/src/cli.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { UploadOptionSets } from './types/option-set-uploader';
|
|
|
7
7
|
import { ParseOptionSetsLocalFiles } from './types/option-set-parser';
|
|
8
8
|
import { MergeOptionSets } from './types/option-set-merger';
|
|
9
9
|
import { MergeTypeProperties } from './types/types-properties-merger';
|
|
10
|
-
import { ParseTypesFromFiles, ParseTypesFromLocalFiles, ParseTypesFromTemplateFromLocalFiles } from './types/parse-types';
|
|
10
|
+
import { ParseTypesFromFiles, ParseTypesFromLocalFiles, ParseTypesFromTemplateFromLocalFiles, ParseTypesFromTemplateAndDataFromLocalFiles } from './types/parse-types';
|
|
11
11
|
import { loadColors, deleteColors } from './colors/color-loader';
|
|
12
12
|
import { listConfig, removeConfig, setConfig } from './config/configCommands';
|
|
13
13
|
import { deleteWorkflowTemplates, localDeployWorkflowTemplate, listWorkflowTemplate } from './workflow-templates/workflow-template-commands';
|
|
@@ -106,6 +106,10 @@ export async function cli(args) {
|
|
|
106
106
|
ParseTypesFromTemplateFromLocalFiles(args);
|
|
107
107
|
break;
|
|
108
108
|
}
|
|
109
|
+
case 'parseTypesFromTemplateAndDataFromLocalFiles': {
|
|
110
|
+
ParseTypesFromTemplateAndDataFromLocalFiles(args);
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
109
113
|
case 'parseTypesFromFiles': {
|
|
110
114
|
ParseTypesFromFiles(args);
|
|
111
115
|
break;
|
|
@@ -327,7 +331,11 @@ const helpSections = [
|
|
|
327
331
|
},
|
|
328
332
|
{
|
|
329
333
|
name: 'parseTypesFromTemplateFromLocalFiles <File Paths>',
|
|
330
|
-
summary: 'Parse CSV files into Types and OptionSets from local files.\n'
|
|
334
|
+
summary: 'Parse CSV files into Types and OptionSets from local type template files.\n'
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
name: 'parseTypesFromTemplateAndDataFromLocalFiles <File Paths>',
|
|
338
|
+
summary: 'Parse CSV files into Types and OptionSets from local type template and data files.\n'
|
|
331
339
|
},
|
|
332
340
|
{
|
|
333
341
|
name: 'parseTypesFromFiles <fileIds>',
|
package/src/types/parse-types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GetSuggestedTypes, GetTypesFromTemplate } from '@contrail/types';
|
|
1
|
+
import { GetSuggestedTypes, GetTypesFromTemplate, GetTypesFromTemplateWithOptionSetsFromData } from '@contrail/types';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import { getSeparatorByPlatform } from '../common';
|
|
@@ -76,6 +76,30 @@ export async function ParseTypesFromTemplateFromLocalFiles(args) {
|
|
|
76
76
|
console.log('%s Parsing Complete.', chalk.green.bold('COMPLETE'));
|
|
77
77
|
}
|
|
78
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
|
+
|
|
79
103
|
async function loadDataFromLocalCSV(fileName) {
|
|
80
104
|
const CURRENT_DIR = process.cwd();
|
|
81
105
|
try {
|
|
@@ -137,6 +161,39 @@ async function parseTypesFromTemplateFromLocalFiles(templateFileLocation: string
|
|
|
137
161
|
saveData({ TypePropertiesByEntity: types.TypePropertiesByEntity }, 'parsed_TypePropertiesByEntity.yml');
|
|
138
162
|
}
|
|
139
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({ optionSets: types.OptionSets }, 'parsed_optionSets.yml');
|
|
194
|
+
saveData({ TypePropertiesByEntity: types.TypePropertiesByEntity }, 'parsed_TypePropertiesByEntity.yml');
|
|
195
|
+
}
|
|
196
|
+
|
|
140
197
|
async function parseTypesFromFiles(fileIds: string[]) {
|
|
141
198
|
await authUser();
|
|
142
199
|
|
package/lib/apps/app-api.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare function getAppVersions(app: any): Promise<any>;
|
|
2
|
-
export declare function upgradeAppVersion(appOrg: any, appVersionId: any): Promise<any>;
|
|
3
|
-
export declare function deleteAppOrg(appOrgId: string): Promise<any>;
|
|
4
|
-
export declare function getInstalledApps(): Promise<any>;
|
|
5
|
-
export declare function installAppToOrg(app: any, configProperties: any): Promise<any>;
|
|
6
|
-
export declare function getAvailableApps(): Promise<any[]>;
|
package/lib/apps/app-api.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { Entities } from '@contrail/sdk';
|
|
2
|
-
import { Auth } from '../auth/auth';
|
|
3
|
-
export async function getAppVersions(app) {
|
|
4
|
-
return await new Entities().get({
|
|
5
|
-
entityName: 'app-version',
|
|
6
|
-
criteria: {
|
|
7
|
-
appId: app.id
|
|
8
|
-
}
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
export async function upgradeAppVersion(appOrg, appVersionId) {
|
|
12
|
-
return await new Entities().update({
|
|
13
|
-
entityName: 'app-org',
|
|
14
|
-
id: appOrg.id,
|
|
15
|
-
object: {
|
|
16
|
-
appVersionId: appVersionId
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
export async function deleteAppOrg(appOrgId) {
|
|
21
|
-
return await new Entities().delete({
|
|
22
|
-
entityName: 'app-org',
|
|
23
|
-
id: appOrgId
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
export async function getInstalledApps() {
|
|
27
|
-
return await new Entities().get({
|
|
28
|
-
entityName: 'app-org',
|
|
29
|
-
relations: ['app']
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
export async function installAppToOrg(app, configProperties) {
|
|
33
|
-
return await new Entities().create({
|
|
34
|
-
entityName: 'app-org',
|
|
35
|
-
object: {
|
|
36
|
-
appId: app.id,
|
|
37
|
-
appConfig: configProperties
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
export async function getAvailableApps() {
|
|
42
|
-
const orgId = Auth.config.orgId;
|
|
43
|
-
const apps = [];
|
|
44
|
-
apps.push(...await new Entities().get({
|
|
45
|
-
entityName: 'app',
|
|
46
|
-
criteria: {
|
|
47
|
-
orgId,
|
|
48
|
-
private: true,
|
|
49
|
-
},
|
|
50
|
-
}));
|
|
51
|
-
apps.push(...await new Entities().get({
|
|
52
|
-
entityName: 'app',
|
|
53
|
-
criteria: {
|
|
54
|
-
orgId,
|
|
55
|
-
private: false,
|
|
56
|
-
},
|
|
57
|
-
}));
|
|
58
|
-
return apps;
|
|
59
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { App, AppDeclaration, AppActionDeclaration } from '../../interfaces';
|
|
2
|
-
export declare class ActionsDeployer {
|
|
3
|
-
deployActions(appDeclaration: AppDeclaration, app: App): Promise<void>;
|
|
4
|
-
getActionsForApp(app: App): Promise<any>;
|
|
5
|
-
deployAction(actionKey: string, actionDeclaration: AppActionDeclaration, app: App, existingActions: Array<any>): Promise<void>;
|
|
6
|
-
private createNewActionDefinition;
|
|
7
|
-
private updateActionDefinition;
|
|
8
|
-
getActionDeclarationIdentifier(actionKey: any, app: App): string;
|
|
9
|
-
getFunction(actionDeclaration: AppActionDeclaration): Promise<string>;
|
|
10
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { Entities } from '@contrail/sdk';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import { ConfigPropertiesParser } from './app-template-parsers';
|
|
4
|
-
import { getSeparatorByPlatform } from '../../common';
|
|
5
|
-
import fs from 'fs';
|
|
6
|
-
export class ActionsDeployer {
|
|
7
|
-
async deployActions(appDeclaration, app) {
|
|
8
|
-
// FETCH ALL ACTIONS FROM THE API.
|
|
9
|
-
const existingActions = await this.getActionsForApp(app);
|
|
10
|
-
// UPSERT / DELETE BASED ON ACTION IDENTIFIER
|
|
11
|
-
console.log('%s \tDeploying actions.', chalk.yellow.bold('ACTION'));
|
|
12
|
-
for (const actionKey of Object.keys(appDeclaration.actions)) {
|
|
13
|
-
await this.deployAction(actionKey, appDeclaration.actions[actionKey], app, existingActions);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
async getActionsForApp(app) {
|
|
17
|
-
return await new Entities().get({
|
|
18
|
-
entityName: 'event-workflow-action-definition',
|
|
19
|
-
criteria: { ownerKey: `app:${app.id}` },
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
async deployAction(actionKey, actionDeclaration, app, existingActions) {
|
|
23
|
-
console.log(`%s \tDeploying action: ${actionKey}`, chalk.yellow.bold('ACTION'));
|
|
24
|
-
const identifier = this.getActionDeclarationIdentifier(actionKey, app);
|
|
25
|
-
const existingDefinition = existingActions.find(ad => ad.identifier === identifier);
|
|
26
|
-
if (!existingDefinition) {
|
|
27
|
-
await this.createNewActionDefinition(actionKey, actionDeclaration, app);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
await this.updateActionDefinition(existingDefinition, actionDeclaration);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
async createNewActionDefinition(actionKey, actionDeclaration, app) {
|
|
34
|
-
let configProperties;
|
|
35
|
-
if (actionDeclaration === null || actionDeclaration === void 0 ? void 0 : actionDeclaration.actionConfiguration) {
|
|
36
|
-
configProperties = ConfigPropertiesParser.getConfigProperties(actionDeclaration.actionConfiguration);
|
|
37
|
-
}
|
|
38
|
-
const newObject = {
|
|
39
|
-
identifier: this.getActionDeclarationIdentifier(actionKey, app),
|
|
40
|
-
name: actionDeclaration.name,
|
|
41
|
-
ownerKey: `app:${app.id}`,
|
|
42
|
-
public: app.public,
|
|
43
|
-
configProperties,
|
|
44
|
-
};
|
|
45
|
-
const functionString = await this.getFunction(actionDeclaration);
|
|
46
|
-
if (functionString) {
|
|
47
|
-
newObject.executeFunctionString = functionString;
|
|
48
|
-
}
|
|
49
|
-
const actionDefinition = await new Entities().create({
|
|
50
|
-
entityName: 'event-workflow-action-definition',
|
|
51
|
-
object: newObject,
|
|
52
|
-
});
|
|
53
|
-
console.log(`%s Created new action definition: ${actionKey}`, chalk.yellow.bold('APP'));
|
|
54
|
-
return actionDefinition;
|
|
55
|
-
}
|
|
56
|
-
async updateActionDefinition(existingActionDefinition, actionDeclaration) {
|
|
57
|
-
let configProperties;
|
|
58
|
-
if (actionDeclaration === null || actionDeclaration === void 0 ? void 0 : actionDeclaration.actionConfiguration) {
|
|
59
|
-
configProperties = ConfigPropertiesParser.getConfigProperties(actionDeclaration.actionConfiguration);
|
|
60
|
-
}
|
|
61
|
-
else if (!(actionDeclaration === null || actionDeclaration === void 0 ? void 0 : actionDeclaration.actionConfiguration) && existingActionDefinition.configProperties) {
|
|
62
|
-
configProperties = null;
|
|
63
|
-
}
|
|
64
|
-
const updates = {
|
|
65
|
-
name: actionDeclaration.name,
|
|
66
|
-
// public: actionDeclaration.public, // TODO - an actions visibility is allowed to change
|
|
67
|
-
configProperties,
|
|
68
|
-
};
|
|
69
|
-
const functionString = await this.getFunction(actionDeclaration);
|
|
70
|
-
if (functionString) {
|
|
71
|
-
updates.executeFunctionString = functionString;
|
|
72
|
-
}
|
|
73
|
-
const actionDefinition = await new Entities().update({
|
|
74
|
-
entityName: 'event-workflow-action-definition',
|
|
75
|
-
id: existingActionDefinition.id,
|
|
76
|
-
object: updates,
|
|
77
|
-
});
|
|
78
|
-
console.log(`%s Updated existing action definition: ${actionDefinition.identifier}`, chalk.yellow.bold('APP'));
|
|
79
|
-
return actionDefinition;
|
|
80
|
-
}
|
|
81
|
-
getActionDeclarationIdentifier(actionKey, app) {
|
|
82
|
-
return app.identifier + ':' + actionKey;
|
|
83
|
-
}
|
|
84
|
-
async getFunction(actionDeclaration) {
|
|
85
|
-
if (!actionDeclaration.handler) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
if (!actionDeclaration.handler.endsWith('.js')) {
|
|
89
|
-
throw new Error('Action handler must be a .js file.');
|
|
90
|
-
}
|
|
91
|
-
const CURRENT_DIR = process.cwd();
|
|
92
|
-
const separator = getSeparatorByPlatform();
|
|
93
|
-
const functionLocation = CURRENT_DIR + separator + actionDeclaration.handler;
|
|
94
|
-
const content = fs.readFileSync(functionLocation);
|
|
95
|
-
return content.toString();
|
|
96
|
-
}
|
|
97
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/** Describes the derivative JSON / object represented
|
|
2
|
-
* in app.yml file.
|
|
3
|
-
*/
|
|
4
|
-
export interface AppDeclaration {
|
|
5
|
-
appIdentifier: string;
|
|
6
|
-
appName: string;
|
|
7
|
-
appDescription?: string;
|
|
8
|
-
visibility: 'private' | 'public';
|
|
9
|
-
publisher: string;
|
|
10
|
-
version: string;
|
|
11
|
-
eventWorkflowTriggerKeyMapping: string;
|
|
12
|
-
thumbnail?: string;
|
|
13
|
-
keywords?: Array<string>;
|
|
14
|
-
actions?: {
|
|
15
|
-
[key: string]: AppActionDeclaration;
|
|
16
|
-
};
|
|
17
|
-
appConfiguration: ConfigPropertyElements;
|
|
18
|
-
triggers: {
|
|
19
|
-
[key: string]: AppTriggerDeclaration;
|
|
20
|
-
};
|
|
21
|
-
isDockerBased?: boolean;
|
|
22
|
-
}
|
|
23
|
-
export interface ConfigPropertyElements {
|
|
24
|
-
[key: string]: ConfigPropertyElement;
|
|
25
|
-
}
|
|
26
|
-
export interface ConfigPropertyElement {
|
|
27
|
-
propertyType: string;
|
|
28
|
-
options?: any[];
|
|
29
|
-
label: string;
|
|
30
|
-
}
|
|
31
|
-
export interface AppActionDeclaration {
|
|
32
|
-
handler: string;
|
|
33
|
-
name: string;
|
|
34
|
-
description?: string;
|
|
35
|
-
actionConfiguration?: ConfigPropertyElements;
|
|
36
|
-
}
|
|
37
|
-
export interface AppTriggerDeclaration {
|
|
38
|
-
key: string;
|
|
39
|
-
name: string;
|
|
40
|
-
external?: boolean;
|
|
41
|
-
description?: string;
|
|
42
|
-
}
|
|
43
|
-
export interface App {
|
|
44
|
-
id: string;
|
|
45
|
-
identifier: string;
|
|
46
|
-
name: string;
|
|
47
|
-
public: boolean;
|
|
48
|
-
description?: string;
|
|
49
|
-
publisher: string;
|
|
50
|
-
thumbnail: string;
|
|
51
|
-
eventWorkflowTriggerKeyMapping: string;
|
|
52
|
-
configProperties?: ConfigProperty[];
|
|
53
|
-
triggerKeyDefinitions?: TriggerKeyDefinition[];
|
|
54
|
-
}
|
|
55
|
-
export declare class ConfigProperty {
|
|
56
|
-
slug: string;
|
|
57
|
-
propertyType: string;
|
|
58
|
-
options?: any[];
|
|
59
|
-
label: string;
|
|
60
|
-
}
|
|
61
|
-
export interface EventWorkflowActionDefinition {
|
|
62
|
-
id?: string;
|
|
63
|
-
identifier?: string;
|
|
64
|
-
name?: string;
|
|
65
|
-
executeFunctionString?: string;
|
|
66
|
-
ownerKey?: string;
|
|
67
|
-
public?: boolean;
|
|
68
|
-
configProperties?: ConfigProperty[];
|
|
69
|
-
isDockerBased?: boolean;
|
|
70
|
-
}
|
|
71
|
-
export declare class TriggerKeyDefinition {
|
|
72
|
-
name: string;
|
|
73
|
-
description?: string;
|
|
74
|
-
triggerKey: string;
|
|
75
|
-
external?: boolean;
|
|
76
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { App, AppDeclaration, WorkflowDefinition } from '../../interfaces';
|
|
2
|
-
export declare class WorkflowDefinitionDeployer {
|
|
3
|
-
deployWorkflowDefinitions(appDeclaration: AppDeclaration, app: App): Promise<void>;
|
|
4
|
-
getWorkflowDefinitionsForApp(app: App): Promise<any>;
|
|
5
|
-
deployWorkflow(workflowKey: string, workflow: WorkflowDefinition, app: App, existingWorkflows: Array<any>): Promise<any>;
|
|
6
|
-
private createNewWorkflowDefinition;
|
|
7
|
-
private populateActionIds;
|
|
8
|
-
private updateWorkflowDefinition;
|
|
9
|
-
getWorkflowDeclarationIdentifier(actionKey: any, app: App): string;
|
|
10
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { Entities } from '@contrail/sdk';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import { getActionDeclarationIdentifier, getActionsForApp } from './actions-deployer';
|
|
4
|
-
export class WorkflowDefinitionDeployer {
|
|
5
|
-
async deployWorkflowDefinitions(appDeclaration, app) {
|
|
6
|
-
// FETCH ALL WORKFLOWS FROM THE API.
|
|
7
|
-
const existingWorkflows = await this.getWorkflowDefinitionsForApp(app);
|
|
8
|
-
// UPSERT / DELETE BASED ON WORKFLOW IDENTIFIER
|
|
9
|
-
console.log('%s \tDeploying workflow definitions.', chalk.yellow.bold('WORKFLOW DEFINITION'));
|
|
10
|
-
if (appDeclaration.workflows) {
|
|
11
|
-
const localWorkflows = Object.keys(appDeclaration.workflows);
|
|
12
|
-
if ((localWorkflows === null || localWorkflows === void 0 ? void 0 : localWorkflows.length) > 0) {
|
|
13
|
-
for (const workflowKey of localWorkflows) {
|
|
14
|
-
await this.deployWorkflow(workflowKey, appDeclaration.workflows[workflowKey], app, existingWorkflows);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
async getWorkflowDefinitionsForApp(app) {
|
|
20
|
-
return await new Entities().get({
|
|
21
|
-
entityName: 'event-workflow-template-definition',
|
|
22
|
-
criteria: { ownerKey: `app:${app.id}` },
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
async deployWorkflow(workflowKey, workflow, app, existingWorkflows) {
|
|
26
|
-
console.log(`%s \tDeploying workflow definitions: ${workflowKey}`, chalk.yellow.bold('WORKFLOW DEFINITION'));
|
|
27
|
-
const identifier = this.getWorkflowDeclarationIdentifier(workflowKey, app);
|
|
28
|
-
const existingDefinition = existingWorkflows.find(ad => ad.identifier === identifier);
|
|
29
|
-
if (existingDefinition) {
|
|
30
|
-
return await this.updateWorkflowDefinition(existingDefinition, workflow, app);
|
|
31
|
-
}
|
|
32
|
-
return await this.createNewWorkflowDefinition(workflowKey, workflow, app);
|
|
33
|
-
}
|
|
34
|
-
async createNewWorkflowDefinition(workflowKey, workflowDeclaration, app) {
|
|
35
|
-
var _a;
|
|
36
|
-
await this.populateActionIds(workflowDeclaration, app);
|
|
37
|
-
const newObject = {
|
|
38
|
-
identifier: this.getWorkflowDeclarationIdentifier(workflowKey, app),
|
|
39
|
-
name: workflowDeclaration.name,
|
|
40
|
-
ownerKey: `app:${app.id}`,
|
|
41
|
-
triggerKey: workflowDeclaration.triggerKey,
|
|
42
|
-
workflowDefinition: workflowDeclaration.workflowDefinition,
|
|
43
|
-
public: (_a = workflowDeclaration.public) !== null && _a !== void 0 ? _a : false,
|
|
44
|
-
isActive: workflowDeclaration.isActive,
|
|
45
|
-
messageGroupId: workflowDeclaration.messageGroupId,
|
|
46
|
-
parallelWorkerCount: workflowDeclaration.parallelWorkerCount,
|
|
47
|
-
};
|
|
48
|
-
const workflowTemplate = await new Entities().create({
|
|
49
|
-
entityName: 'event-workflow-template-definition',
|
|
50
|
-
object: newObject,
|
|
51
|
-
});
|
|
52
|
-
console.log(`%s Created new workflow definition definitions: ${workflowKey}`, chalk.yellow.bold('WORKFLOW DEFINITION'));
|
|
53
|
-
return workflowTemplate;
|
|
54
|
-
}
|
|
55
|
-
async populateActionIds(workflowDefinition, app) {
|
|
56
|
-
var _a;
|
|
57
|
-
const availableAppActions = await getActionsForApp(app);
|
|
58
|
-
if (!((_a = workflowDefinition.workflowDefinition) === null || _a === void 0 ? void 0 : _a.paths)) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
for (const path of workflowDefinition.workflowDefinition.paths) {
|
|
62
|
-
if (!(path === null || path === void 0 ? void 0 : path.actionDefinitionConfigs)) {
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
for (const actionConfiguration of path.actionDefinitionConfigs) {
|
|
66
|
-
const actionKey = actionConfiguration.action;
|
|
67
|
-
const action = availableAppActions.find(action => action.identifier === getActionDeclarationIdentifier(actionKey, app));
|
|
68
|
-
if (!action) {
|
|
69
|
-
throw new Error(`Could not find action ${actionKey} declared in workflow definition ${workflowDefinition.name}`);
|
|
70
|
-
}
|
|
71
|
-
actionConfiguration.id = action.id;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
async updateWorkflowDefinition(existingWorkflowDefinition, workflowDefinition, app) {
|
|
76
|
-
await this.populateActionIds(workflowDefinition, app);
|
|
77
|
-
const updates = Object.assign(new Object(), {
|
|
78
|
-
name: workflowDefinition.name,
|
|
79
|
-
triggerKey: workflowDefinition.triggerKey,
|
|
80
|
-
workflowDefinition: workflowDefinition.workflowDefinition,
|
|
81
|
-
messageGroupId: workflowDefinition.messageGroupId,
|
|
82
|
-
parallelWorkerCount: workflowDefinition.parallelWorkerCount,
|
|
83
|
-
});
|
|
84
|
-
const updatedWorkflowDefinition = await new Entities().update({
|
|
85
|
-
entityName: 'event-workflow-template-definition',
|
|
86
|
-
id: existingWorkflowDefinition.id,
|
|
87
|
-
object: updates,
|
|
88
|
-
});
|
|
89
|
-
console.log(`%s Updated existing workflow definition: ${updatedWorkflowDefinition.identifier}`, chalk.yellow.bold('WORKFLOW DEFINITION'));
|
|
90
|
-
return updatedWorkflowDefinition;
|
|
91
|
-
}
|
|
92
|
-
getWorkflowDeclarationIdentifier(actionKey, app) {
|
|
93
|
-
return app.identifier + ':' + actionKey;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { App, AppDeclaration, WorkflowTemplateDeclaration } from './interfaces';
|
|
2
|
-
export declare class WorkflowDeployer {
|
|
3
|
-
deployWorkflows(appDeclaration: AppDeclaration, app: App): Promise<void>;
|
|
4
|
-
getWorkflowsForApp(app: App): Promise<any>;
|
|
5
|
-
deployWorkflow(workflowKey: string, workflow: WorkflowTemplateDeclaration, app: App, existingWorkflows: Array<any>, appDeclaration: AppDeclaration): Promise<any>;
|
|
6
|
-
private createNewWorkflowDefinition;
|
|
7
|
-
private populateActionIds;
|
|
8
|
-
private updateWorkflowDefinition;
|
|
9
|
-
getWorkflowDeclarationIdentifier(actionKey: any, app: App): string;
|
|
10
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { Entities } from '@contrail/sdk';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import { getActionDeclarationIdentifier, getActionsForApp } from './actions-deployer';
|
|
4
|
-
export class WorkflowDeployer {
|
|
5
|
-
async deployWorkflows(appDeclaration, app) {
|
|
6
|
-
// FETCH ALL WORKFLOWS FROM THE API.
|
|
7
|
-
const existingWorkflows = await this.getWorkflowsForApp(app);
|
|
8
|
-
// UPSERT / DELETE BASED ON WORKFLOW IDENTIFIER
|
|
9
|
-
console.log('%s \tDeploying workflows.', chalk.yellow.bold('WORKFLOW'));
|
|
10
|
-
for (const workflowKey of Object.keys(appDeclaration.workflows)) {
|
|
11
|
-
await this.deployWorkflow(workflowKey, appDeclaration.workflows[workflowKey], app, existingWorkflows, appDeclaration);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
async getWorkflowsForApp(app) {
|
|
15
|
-
return await new Entities().get({
|
|
16
|
-
entityName: 'event-workflow-template',
|
|
17
|
-
criteria: { ownerKey: `app:${app.id}` },
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
async deployWorkflow(workflowKey, workflow, app, existingWorkflows, appDeclaration) {
|
|
21
|
-
console.log(`%s \tDeploying workflow: ${workflowKey}`, chalk.yellow.bold('WORKFLOW'));
|
|
22
|
-
const identifier = this.getWorkflowDeclarationIdentifier(workflowKey, app);
|
|
23
|
-
const existingDefinition = existingWorkflows.find(ad => ad.identifier === identifier);
|
|
24
|
-
if (existingDefinition) {
|
|
25
|
-
return await this.updateWorkflowDefinition(existingDefinition, workflow, app, appDeclaration);
|
|
26
|
-
}
|
|
27
|
-
return await this.createNewWorkflowDefinition(workflowKey, workflow, app, appDeclaration);
|
|
28
|
-
}
|
|
29
|
-
async createNewWorkflowDefinition(workflowKey, workflowDeclaration, app, appDeclaration) {
|
|
30
|
-
await this.populateActionIds(workflowDeclaration, appDeclaration, app);
|
|
31
|
-
const newObject = {
|
|
32
|
-
identifier: this.getWorkflowDeclarationIdentifier(workflowKey, app),
|
|
33
|
-
name: workflowDeclaration.name,
|
|
34
|
-
ownerKey: `app:${app.id}`,
|
|
35
|
-
triggerKey: workflowDeclaration.triggerKey,
|
|
36
|
-
workflowDefinition: workflowDeclaration.workflowDefinition,
|
|
37
|
-
isActive: workflowDeclaration.isActive,
|
|
38
|
-
supportingAppId: workflowDeclaration.supportingAppId,
|
|
39
|
-
messageGroupId: workflowDeclaration.messageGroupId,
|
|
40
|
-
parallelWorkerCount: workflowDeclaration.parallelWorkerCount,
|
|
41
|
-
};
|
|
42
|
-
const workflowTemplate = await new Entities().create({
|
|
43
|
-
entityName: 'event-workflow-template',
|
|
44
|
-
object: newObject,
|
|
45
|
-
});
|
|
46
|
-
console.log(`%s Created new workflow definition: ${workflowKey}`, chalk.yellow.bold('WORKFLOW'));
|
|
47
|
-
return workflowTemplate;
|
|
48
|
-
}
|
|
49
|
-
async populateActionIds(workflowDeclaration, appDeclaration, app) {
|
|
50
|
-
var _a;
|
|
51
|
-
let availableAppActions = await getActionsForApp(app);
|
|
52
|
-
if (!((_a = workflowDeclaration.workflowDefinition) === null || _a === void 0 ? void 0 : _a.paths)) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
for (const path of workflowDeclaration.workflowDefinition.paths) {
|
|
56
|
-
if (!(path === null || path === void 0 ? void 0 : path.actionDefinitionConfigs)) {
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
for (const actionConfiguration of path.actionDefinitionConfigs) {
|
|
60
|
-
const actionKey = actionConfiguration.action;
|
|
61
|
-
const action = availableAppActions.find(action => action.identifier === getActionDeclarationIdentifier(actionKey, app));
|
|
62
|
-
if (!action) {
|
|
63
|
-
throw new Error(`Could not find action ${actionKey} declared in ${workflowDeclaration.name}`);
|
|
64
|
-
}
|
|
65
|
-
actionConfiguration.id = action.id;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
async updateWorkflowDefinition(existingWorkflowDefinition, workflowDeclaration, app, appDeclaration) {
|
|
70
|
-
await this.populateActionIds(workflowDeclaration, appDeclaration, app);
|
|
71
|
-
const updates = Object.assign(new Object(), {
|
|
72
|
-
name: workflowDeclaration.name,
|
|
73
|
-
triggerKey: workflowDeclaration.triggerKey,
|
|
74
|
-
workflowDefinition: workflowDeclaration.workflowDefinition
|
|
75
|
-
});
|
|
76
|
-
const updatedWorkflowDefinition = await new Entities().update({
|
|
77
|
-
entityName: 'event-workflow-template',
|
|
78
|
-
id: existingWorkflowDefinition.id,
|
|
79
|
-
object: updates,
|
|
80
|
-
});
|
|
81
|
-
console.log(`%s Updated existing workflow definition: ${updatedWorkflowDefinition.identifier}`, chalk.yellow.bold('WORKFLOW'));
|
|
82
|
-
return updatedWorkflowDefinition;
|
|
83
|
-
}
|
|
84
|
-
getWorkflowDeclarationIdentifier(actionKey, app) {
|
|
85
|
-
return app.identifier + ':' + actionKey;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { WorkflowTemplate, WorkflowTemplateDeclaration } from '../interfaces';
|
|
2
|
-
export declare class WorkflowTemplateDeployer {
|
|
3
|
-
deployWorkflows(wtDeclaration: WorkflowTemplateDeclaration): Promise<void>;
|
|
4
|
-
getExistingWorkflowTemplates(): Promise<any>;
|
|
5
|
-
deployWorkflowTemplate(workflowKey: string, workflow: WorkflowTemplate, existingWorkflows: Array<any>): Promise<any>;
|
|
6
|
-
private createNewWorkflowTemplate;
|
|
7
|
-
private populateActionIds;
|
|
8
|
-
private updateWorkflowTemplate;
|
|
9
|
-
deleteWorkflowTemplates(wtDeclaration: WorkflowTemplateDeclaration): Promise<void>;
|
|
10
|
-
private deleteWorkflowTemplate;
|
|
11
|
-
listExistingWorkflowTemplates(): Promise<any>;
|
|
12
|
-
}
|
|
13
|
-
export declare function getWorkflowTemplateIdentifier(workflowKey: string): string;
|
|
14
|
-
export declare function getActionByIdentifier(identifier: string): Promise<any>;
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { Entities } from '@contrail/sdk';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
export class WorkflowTemplateDeployer {
|
|
4
|
-
async deployWorkflows(wtDeclaration) {
|
|
5
|
-
// FETCH ALL WORKFLOWS FROM THE API.
|
|
6
|
-
const existingWorkflows = await this.getExistingWorkflowTemplates();
|
|
7
|
-
// UPSERT / DELETE BASED ON WORKFLOW TEMPLATES IDENTIFIER
|
|
8
|
-
console.log('%s \tDeploying workflow templates.', chalk.yellow.bold('WORKFLOW TEMPLATES'));
|
|
9
|
-
for (const workflowKey of Object.keys(wtDeclaration.workflows)) {
|
|
10
|
-
await this.deployWorkflowTemplate(workflowKey, wtDeclaration.workflows[workflowKey], existingWorkflows);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
async getExistingWorkflowTemplates() {
|
|
14
|
-
return await new Entities().get({
|
|
15
|
-
entityName: 'event-workflow-template'
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
async deployWorkflowTemplate(workflowKey, workflow, existingWorkflows) {
|
|
19
|
-
console.log(`%s \tDeploying workflow: ${workflowKey}`, chalk.yellow.bold('WORKFLOW TEMPLATES'));
|
|
20
|
-
const identifier = getWorkflowTemplateIdentifier(workflowKey);
|
|
21
|
-
const existingTemplate = existingWorkflows.find(ad => ad.identifier === identifier);
|
|
22
|
-
if (existingTemplate) {
|
|
23
|
-
return await this.updateWorkflowTemplate(workflowKey, existingTemplate, workflow);
|
|
24
|
-
}
|
|
25
|
-
return await this.createNewWorkflowTemplate(workflowKey, workflow);
|
|
26
|
-
}
|
|
27
|
-
async createNewWorkflowTemplate(workflowKey, workflowTemplate) {
|
|
28
|
-
await this.populateActionIds(workflowTemplate, workflowKey);
|
|
29
|
-
const newObject = {
|
|
30
|
-
identifier: getWorkflowTemplateIdentifier(workflowKey),
|
|
31
|
-
name: workflowTemplate.name,
|
|
32
|
-
triggerKey: workflowTemplate.triggerKey,
|
|
33
|
-
workflowDefinition: workflowTemplate.workflowDefinition,
|
|
34
|
-
isActive: workflowTemplate.isActive,
|
|
35
|
-
supportingAppId: workflowTemplate.supportingAppId,
|
|
36
|
-
messageGroupId: workflowTemplate.messageGroupId,
|
|
37
|
-
parallelWorkerCount: workflowTemplate.parallelWorkerCount,
|
|
38
|
-
};
|
|
39
|
-
const newWorkflowTemplate = await new Entities().create({
|
|
40
|
-
entityName: 'event-workflow-template',
|
|
41
|
-
object: newObject,
|
|
42
|
-
});
|
|
43
|
-
console.log(`%s Created new workflow definition: ${workflowKey}`, chalk.yellow.bold('WORKFLOW TEMPLATES'));
|
|
44
|
-
return newWorkflowTemplate;
|
|
45
|
-
}
|
|
46
|
-
async populateActionIds(workflowTemplate, workflowKey) {
|
|
47
|
-
var _a;
|
|
48
|
-
if (!((_a = workflowTemplate === null || workflowTemplate === void 0 ? void 0 : workflowTemplate.workflowDefinition) === null || _a === void 0 ? void 0 : _a.paths)) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
for (const path of workflowTemplate.workflowDefinition.paths) {
|
|
52
|
-
if (!(path === null || path === void 0 ? void 0 : path.actionDefinitionConfigs)) {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
for (const actionConfiguration of path.actionDefinitionConfigs) {
|
|
56
|
-
const actionKey = actionConfiguration.action;
|
|
57
|
-
try {
|
|
58
|
-
const actionEntity = await getActionByIdentifier(actionKey);
|
|
59
|
-
actionConfiguration.id = actionEntity.id;
|
|
60
|
-
}
|
|
61
|
-
catch (e) {
|
|
62
|
-
console.log(e);
|
|
63
|
-
}
|
|
64
|
-
if (!actionConfiguration.id) {
|
|
65
|
-
throw new Error(`Could not find action ${actionKey} declared in ${workflowKey}`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
async updateWorkflowTemplate(workflowKey, existingWorkflowTemplate, workflowTemplate) {
|
|
71
|
-
await this.populateActionIds(workflowTemplate, workflowKey);
|
|
72
|
-
const updates = Object.assign(new Object(), {
|
|
73
|
-
name: workflowTemplate.name,
|
|
74
|
-
triggerKey: workflowTemplate.triggerKey,
|
|
75
|
-
workflowDefinition: workflowTemplate.workflowDefinition
|
|
76
|
-
});
|
|
77
|
-
const updatedWorkflowTemplate = await new Entities().update({
|
|
78
|
-
entityName: 'event-workflow-template',
|
|
79
|
-
id: existingWorkflowTemplate.id,
|
|
80
|
-
object: updates,
|
|
81
|
-
});
|
|
82
|
-
console.log(`%s Updated existing workflow template: ${updatedWorkflowTemplate.identifier}`, chalk.yellow.bold('WORKFLOW TEMPLATES'));
|
|
83
|
-
return updatedWorkflowTemplate;
|
|
84
|
-
}
|
|
85
|
-
async deleteWorkflowTemplates(wtDeclaration) {
|
|
86
|
-
// FETCH ALL WORKFLOWS FROM THE API.
|
|
87
|
-
const existingWorkflows = await this.getExistingWorkflowTemplates();
|
|
88
|
-
// UPSERT / DELETE BASED ON WORKFLOW TEMPLATES IDENTIFIER
|
|
89
|
-
console.log('%s \tDELETING workflow templates.', chalk.yellow.bold('WORKFLOW TEMPLATES'));
|
|
90
|
-
for (const workflowKey of Object.keys(wtDeclaration.workflows)) {
|
|
91
|
-
const identifier = getWorkflowTemplateIdentifier(workflowKey);
|
|
92
|
-
const existingTemplate = existingWorkflows.find(ad => ad.identifier === identifier);
|
|
93
|
-
if (existingTemplate) {
|
|
94
|
-
try {
|
|
95
|
-
await this.deleteWorkflowTemplate(identifier);
|
|
96
|
-
}
|
|
97
|
-
catch (e) {
|
|
98
|
-
console.log('%s \tFAILED to delete workflow template %s.', chalk.red.bold('WORKFLOW TEMPLATES'), identifier);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
console.log('%s \tUnable to locate workflow template %s.', chalk.yellow.bold('WORKFLOW TEMPLATES'), identifier);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
async deleteWorkflowTemplate(identifier) {
|
|
107
|
-
return await new Entities().delete({
|
|
108
|
-
entityName: 'event-workflow-template',
|
|
109
|
-
id: identifier,
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
async listExistingWorkflowTemplates() {
|
|
113
|
-
const templates = await this.getExistingWorkflowTemplates();
|
|
114
|
-
console.log(templates);
|
|
115
|
-
return templates;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
export function getWorkflowTemplateIdentifier(workflowKey) {
|
|
119
|
-
return workflowKey;
|
|
120
|
-
}
|
|
121
|
-
export async function getActionByIdentifier(identifier) {
|
|
122
|
-
const result = await new Entities().get({
|
|
123
|
-
entityName: 'event-workflow-action-definition',
|
|
124
|
-
criteria: { identifier },
|
|
125
|
-
});
|
|
126
|
-
return result.length > 0 ? result[0] : {};
|
|
127
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import { authUser } from '../auth/login';
|
|
4
|
-
import { getSeparatorByPlatform } from '../common';
|
|
5
|
-
const yaml = require('js-yaml');
|
|
6
|
-
import { WorkflowTemplateDeployer } from './workflow-template-deployer';
|
|
7
|
-
export async function deleteWorkflowTemplate() {
|
|
8
|
-
let wtDeclaration;
|
|
9
|
-
try {
|
|
10
|
-
wtDeclaration = loadTemplateConfig();
|
|
11
|
-
}
|
|
12
|
-
catch (e) {
|
|
13
|
-
console.log(`%s Workflow Deletion Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
await authUser();
|
|
17
|
-
await new WorkflowTemplateDeployer().deleteWorkflowTemplates(wtDeclaration);
|
|
18
|
-
}
|
|
19
|
-
export async function deployWorkflowTemplate() {
|
|
20
|
-
let wtDeclaration;
|
|
21
|
-
try {
|
|
22
|
-
wtDeclaration = loadTemplateConfig();
|
|
23
|
-
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
console.log(`%s Workflow Deletion Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
await authUser();
|
|
29
|
-
await new WorkflowTemplateDeployer().deployWorkflows(wtDeclaration);
|
|
30
|
-
}
|
|
31
|
-
export async function listWorkflowTemplate() {
|
|
32
|
-
await authUser();
|
|
33
|
-
return await new WorkflowTemplateDeployer().listExistingWorkflowTemplates();
|
|
34
|
-
}
|
|
35
|
-
function loadTemplateConfig() {
|
|
36
|
-
const TARGET_DIR = process.cwd();
|
|
37
|
-
try {
|
|
38
|
-
const separator = getSeparatorByPlatform();
|
|
39
|
-
const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + 'workflow.yml', 'utf8'));
|
|
40
|
-
console.log(doc);
|
|
41
|
-
return doc;
|
|
42
|
-
}
|
|
43
|
-
catch (e) {
|
|
44
|
-
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
45
|
-
}
|
|
46
|
-
}
|