@contrail/cli 1.0.43 → 1.0.46
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/cli.js +13 -0
- package/lib/projects/interfaces.d.ts +35 -0
- package/lib/projects/interfaces.js +15 -0
- package/lib/projects/project-uploader.d.ts +1 -0
- package/lib/projects/project-uploader.js +47 -0
- package/lib/types/interfaces.d.ts +1 -0
- package/lib/types/types-extractor.js +1 -0
- package/lib/types/types-uploader.js +4 -0
- package/package.json +3 -3
- package/src/cli.ts +14 -0
- package/src/projects/interfaces.ts +35 -0
- package/src/projects/project-uploader.ts +59 -0
- package/src/types/interfaces.ts +1 -0
- package/src/types/types-extractor.ts +1 -0
- package/src/types/types-uploader.ts +4 -0
- 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/cli.js
CHANGED
|
@@ -13,6 +13,7 @@ import { deleteWorkflowTemplates, localDeployWorkflowTemplate, listWorkflowTempl
|
|
|
13
13
|
import { installApp, uninstallApp } from './apps/install-app/app-installer';
|
|
14
14
|
import { upgradeApp } from './apps/upgrade-app/app-upgrader';
|
|
15
15
|
import { cliInstallWorkflowTemplateDefinitions, listWorkflowTemplateDefinitions } from './workflow-template-definitions/workflow-template-definition-commands';
|
|
16
|
+
import { configureProject } from './projects/project-uploader';
|
|
16
17
|
const cliUsage = require('command-line-usage');
|
|
17
18
|
/**
|
|
18
19
|
* Built using documentation here:
|
|
@@ -135,6 +136,18 @@ export async function cli(args) {
|
|
|
135
136
|
}
|
|
136
137
|
break;
|
|
137
138
|
}
|
|
139
|
+
case 'projects': {
|
|
140
|
+
switch (command) {
|
|
141
|
+
case 'configure': {
|
|
142
|
+
await configureProject(args);
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
default: {
|
|
146
|
+
printIllegalCommand();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
138
151
|
case 'workflow-templates': {
|
|
139
152
|
switch (command) {
|
|
140
153
|
case 'load': {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare class CommonConfiguration {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
}
|
|
4
|
+
export declare enum AssortmentType {
|
|
5
|
+
ASSORTMENT = "ASSORTMENT",
|
|
6
|
+
BOARD = "BOARD",
|
|
7
|
+
PLAN = "PLAN",
|
|
8
|
+
SHOWCASE = "SHOWCASE"
|
|
9
|
+
}
|
|
10
|
+
export declare class AssortmentConfiguration {
|
|
11
|
+
identifier: string;
|
|
12
|
+
name: string;
|
|
13
|
+
type: AssortmentType;
|
|
14
|
+
sourceAssortmentIdentifier?: string;
|
|
15
|
+
composedFromAssortmentIdentifiers?: string[];
|
|
16
|
+
ownerAtts?: {
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
};
|
|
19
|
+
assortmentAtts?: {
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export declare class Folder {
|
|
24
|
+
identifier: string;
|
|
25
|
+
name: string;
|
|
26
|
+
assortments: AssortmentConfiguration[];
|
|
27
|
+
subFolders: Folder[];
|
|
28
|
+
}
|
|
29
|
+
export declare class ProjectConfiguration {
|
|
30
|
+
projectName: string;
|
|
31
|
+
identifier: string;
|
|
32
|
+
commonConfig: CommonConfiguration;
|
|
33
|
+
assortments: AssortmentConfiguration[];
|
|
34
|
+
subFolders: Folder[];
|
|
35
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export class CommonConfiguration {
|
|
2
|
+
}
|
|
3
|
+
export var AssortmentType;
|
|
4
|
+
(function (AssortmentType) {
|
|
5
|
+
AssortmentType["ASSORTMENT"] = "ASSORTMENT";
|
|
6
|
+
AssortmentType["BOARD"] = "BOARD";
|
|
7
|
+
AssortmentType["PLAN"] = "PLAN";
|
|
8
|
+
AssortmentType["SHOWCASE"] = "SHOWCASE";
|
|
9
|
+
})(AssortmentType || (AssortmentType = {}));
|
|
10
|
+
export class AssortmentConfiguration {
|
|
11
|
+
}
|
|
12
|
+
export class Folder {
|
|
13
|
+
}
|
|
14
|
+
export class ProjectConfiguration {
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function configureProject(args: any): Promise<void>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Request } from '@contrail/sdk';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import { authUser } from '../auth/login';
|
|
5
|
+
import { getSeparatorByPlatform } from '../common';
|
|
6
|
+
import yaml from 'js-yaml';
|
|
7
|
+
export async function configureProject(args) {
|
|
8
|
+
try {
|
|
9
|
+
await authUser();
|
|
10
|
+
console.log('%s Parsing Template.', chalk.blue.bold('START'));
|
|
11
|
+
console.log('%s Uploading', chalk.yellow.bold('PROJECT'));
|
|
12
|
+
const templateFileLocation = args[3];
|
|
13
|
+
console.log('Using Template File Location: ', templateFileLocation);
|
|
14
|
+
await uploadProject(templateFileLocation);
|
|
15
|
+
console.log('%s Uploaded', chalk.yellow.bold('PROJECT'));
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
console.log(`%s Project Upload Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
console.log('%s Project Upload Complete.', chalk.green.bold('COMPLETE'));
|
|
22
|
+
}
|
|
23
|
+
function getProjectFile(fileName) {
|
|
24
|
+
const CURRENT_DIR = process.cwd();
|
|
25
|
+
try {
|
|
26
|
+
const separator = getSeparatorByPlatform();
|
|
27
|
+
const fullPath = CURRENT_DIR + separator + fileName;
|
|
28
|
+
console.log('Getting file from path: ', fullPath);
|
|
29
|
+
const doc = yaml.load(fs.readFileSync(fullPath, 'utf8'));
|
|
30
|
+
return doc.projectConfiguration;
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function uploadProject(templateFileLocation) {
|
|
37
|
+
const projectConfiguration = getProjectFile(templateFileLocation);
|
|
38
|
+
console.log('Configuring Project.');
|
|
39
|
+
await Request.request('/project-configurator', {
|
|
40
|
+
method: 'POST',
|
|
41
|
+
body: JSON.stringify(projectConfiguration),
|
|
42
|
+
headers: {
|
|
43
|
+
Accept: 'application/json',
|
|
44
|
+
'Content-Type': 'application/json',
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
@@ -72,6 +72,7 @@ export async function getReducedTypes(optionSets) {
|
|
|
72
72
|
propertyType: typeProperty.propertyType,
|
|
73
73
|
label: typeProperty.label,
|
|
74
74
|
editable: typeProperty.editable,
|
|
75
|
+
searchable: typeProperty.searchable,
|
|
75
76
|
core: typeProperty.core,
|
|
76
77
|
typePropertyOptionSetName: optionSetNameById[typeProperty.typePropertyOptionSetId],
|
|
77
78
|
formula: typeProperty.formula,
|
|
@@ -136,6 +136,7 @@ async function uploadReducedTypeProperties(type, currentPropertyTypes, newProper
|
|
|
136
136
|
slug: newPropertyType.slug,
|
|
137
137
|
label: newPropertyType.label,
|
|
138
138
|
editable: newPropertyType.editable,
|
|
139
|
+
searchable: newPropertyType.searchable,
|
|
139
140
|
core: newPropertyType.core,
|
|
140
141
|
typePropertyOptionSetId: optionSetIdByName[newPropertyType.typePropertyOptionSetName],
|
|
141
142
|
formula: newPropertyType.formula,
|
|
@@ -162,6 +163,7 @@ async function uploadReducedTypeProperties(type, currentPropertyTypes, newProper
|
|
|
162
163
|
slug: newPropertyType.slug,
|
|
163
164
|
label: newPropertyType.label,
|
|
164
165
|
editable: newPropertyType.editable,
|
|
166
|
+
searchable: newPropertyType.searchable,
|
|
165
167
|
core: newPropertyType.core,
|
|
166
168
|
typePropertyOptionSetId: optionSetIdByName[newPropertyType.typePropertyOptionSetName],
|
|
167
169
|
formula: newPropertyType.formula,
|
|
@@ -204,6 +206,7 @@ function typePropertiesEqual(typeProperty1, typeProperty2, optionSetIdByName) {
|
|
|
204
206
|
slug: typeProperty1.slug,
|
|
205
207
|
label: typeProperty1.label,
|
|
206
208
|
editable: typeProperty1.editable,
|
|
209
|
+
searchable: typeProperty1.searchable,
|
|
207
210
|
core: typeProperty1.core,
|
|
208
211
|
typePropertyOptionSetId: optionSetIdByName[typeProperty1.typePropertyOptionSetName],
|
|
209
212
|
formula: typeProperty1.formula,
|
|
@@ -219,6 +222,7 @@ function typePropertiesEqual(typeProperty1, typeProperty2, optionSetIdByName) {
|
|
|
219
222
|
slug: typeProperty2.slug,
|
|
220
223
|
label: typeProperty2.label,
|
|
221
224
|
editable: typeProperty2.editable,
|
|
225
|
+
searchable: typeProperty2.searchable,
|
|
222
226
|
core: typeProperty2.core,
|
|
223
227
|
typePropertyOptionSetId: optionSetIdByName[typeProperty2.typePropertyOptionSetName],
|
|
224
228
|
formula: typeProperty2.formula,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.46",
|
|
4
4
|
"description": "VibeIQ's Contrail Platform CLI.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"author": "",
|
|
24
24
|
"license": "ISC",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@contrail/sdk": "^1.
|
|
27
|
-
"@contrail/types": "^
|
|
26
|
+
"@contrail/sdk": "^1.1.43",
|
|
27
|
+
"@contrail/types": "^3.0.20",
|
|
28
28
|
"@contrail/util": "^1.0.17",
|
|
29
29
|
"amazon-cognito-identity-js": "^5.2.3",
|
|
30
30
|
"arg": "^4.0.1",
|
package/src/cli.ts
CHANGED
|
@@ -14,6 +14,8 @@ import { deleteWorkflowTemplates, localDeployWorkflowTemplate, listWorkflowTempl
|
|
|
14
14
|
import { installApp, uninstallApp } from './apps/install-app/app-installer';
|
|
15
15
|
import { upgradeApp } from './apps/upgrade-app/app-upgrader';
|
|
16
16
|
import { cliInstallWorkflowTemplateDefinitions, listWorkflowTemplateDefinitions } from './workflow-template-definitions/workflow-template-definition-commands';
|
|
17
|
+
import { configureProject } from './projects/project-uploader';
|
|
18
|
+
|
|
17
19
|
const cliUsage = require('command-line-usage');
|
|
18
20
|
|
|
19
21
|
/**
|
|
@@ -145,6 +147,18 @@ export async function cli(args) {
|
|
|
145
147
|
}
|
|
146
148
|
break;
|
|
147
149
|
}
|
|
150
|
+
case 'projects': {
|
|
151
|
+
switch (command) {
|
|
152
|
+
case 'configure': {
|
|
153
|
+
await configureProject(args);
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
default: {
|
|
157
|
+
printIllegalCommand();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
148
162
|
case 'workflow-templates': {
|
|
149
163
|
switch (command) {
|
|
150
164
|
case 'load': {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export class CommonConfiguration {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export enum AssortmentType {
|
|
6
|
+
ASSORTMENT = 'ASSORTMENT',
|
|
7
|
+
BOARD = 'BOARD',
|
|
8
|
+
PLAN = 'PLAN',
|
|
9
|
+
SHOWCASE = 'SHOWCASE',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class AssortmentConfiguration {
|
|
13
|
+
identifier: string;
|
|
14
|
+
name: string;
|
|
15
|
+
type: AssortmentType;
|
|
16
|
+
sourceAssortmentIdentifier?: string;
|
|
17
|
+
composedFromAssortmentIdentifiers?: string[];
|
|
18
|
+
ownerAtts?: {[key: string]: any};
|
|
19
|
+
assortmentAtts?: {[key: string]: any};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class Folder {
|
|
23
|
+
identifier: string;
|
|
24
|
+
name: string;
|
|
25
|
+
assortments: AssortmentConfiguration[];
|
|
26
|
+
subFolders: Folder[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class ProjectConfiguration {
|
|
30
|
+
projectName: string;
|
|
31
|
+
identifier: string;
|
|
32
|
+
commonConfig: CommonConfiguration;
|
|
33
|
+
assortments: AssortmentConfiguration[];
|
|
34
|
+
subFolders: Folder[];
|
|
35
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Request } from '@contrail/sdk';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import { authUser } from '../auth/login';
|
|
5
|
+
import { getSeparatorByPlatform } from '../common';
|
|
6
|
+
import { ProjectConfiguration } from './interfaces';
|
|
7
|
+
|
|
8
|
+
import yaml from 'js-yaml';
|
|
9
|
+
|
|
10
|
+
export async function configureProject(args) {
|
|
11
|
+
try {
|
|
12
|
+
await authUser();
|
|
13
|
+
console.log('%s Parsing Template.', chalk.blue.bold('START'));
|
|
14
|
+
|
|
15
|
+
console.log('%s Uploading', chalk.yellow.bold('PROJECT'));
|
|
16
|
+
const templateFileLocation = args[3];
|
|
17
|
+
console.log('Using Template File Location: ', templateFileLocation);
|
|
18
|
+
await uploadProject(templateFileLocation);
|
|
19
|
+
console.log('%s Uploaded', chalk.yellow.bold('PROJECT'));
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
console.log(`%s Project Upload Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
console.log('%s Project Upload Complete.', chalk.green.bold('COMPLETE'));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function getProjectFile(fileName){
|
|
31
|
+
const CURRENT_DIR = process.cwd();
|
|
32
|
+
try {
|
|
33
|
+
const separator = getSeparatorByPlatform();
|
|
34
|
+
const fullPath = CURRENT_DIR + separator + fileName;
|
|
35
|
+
console.log('Getting file from path: ', fullPath);
|
|
36
|
+
|
|
37
|
+
const doc = yaml.load(fs.readFileSync(fullPath, 'utf8'));
|
|
38
|
+
return doc.projectConfiguration;
|
|
39
|
+
} catch (e) {
|
|
40
|
+
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function uploadProject(templateFileLocation) {
|
|
45
|
+
const projectConfiguration: ProjectConfiguration[] = getProjectFile(templateFileLocation);
|
|
46
|
+
console.log('Configuring Project.');
|
|
47
|
+
|
|
48
|
+
await Request.request(
|
|
49
|
+
'/project-configurator',
|
|
50
|
+
{
|
|
51
|
+
method: 'POST',
|
|
52
|
+
body: JSON.stringify(projectConfiguration),
|
|
53
|
+
headers: {
|
|
54
|
+
Accept: 'application/json',
|
|
55
|
+
'Content-Type': 'application/json',
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
}
|
package/src/types/interfaces.ts
CHANGED
|
@@ -92,6 +92,7 @@ export async function getReducedTypes(optionSets) {
|
|
|
92
92
|
propertyType: typeProperty.propertyType,
|
|
93
93
|
label: typeProperty.label,
|
|
94
94
|
editable: typeProperty.editable,
|
|
95
|
+
searchable: typeProperty.searchable,
|
|
95
96
|
core: typeProperty.core,
|
|
96
97
|
typePropertyOptionSetName: optionSetNameById[typeProperty.typePropertyOptionSetId],
|
|
97
98
|
formula: typeProperty.formula,
|
|
@@ -162,6 +162,7 @@ async function uploadReducedTypeProperties(type, currentPropertyTypes, newProper
|
|
|
162
162
|
slug: newPropertyType.slug,
|
|
163
163
|
label: newPropertyType.label,
|
|
164
164
|
editable: newPropertyType.editable,
|
|
165
|
+
searchable: newPropertyType.searchable,
|
|
165
166
|
core: newPropertyType.core,
|
|
166
167
|
typePropertyOptionSetId: optionSetIdByName[newPropertyType.typePropertyOptionSetName],
|
|
167
168
|
formula: newPropertyType.formula,
|
|
@@ -188,6 +189,7 @@ async function uploadReducedTypeProperties(type, currentPropertyTypes, newProper
|
|
|
188
189
|
slug: newPropertyType.slug,
|
|
189
190
|
label: newPropertyType.label,
|
|
190
191
|
editable: newPropertyType.editable,
|
|
192
|
+
searchable: newPropertyType.searchable,
|
|
191
193
|
core: newPropertyType.core,
|
|
192
194
|
typePropertyOptionSetId: optionSetIdByName[newPropertyType.typePropertyOptionSetName],
|
|
193
195
|
formula: newPropertyType.formula,
|
|
@@ -234,6 +236,7 @@ function typePropertiesEqual(typeProperty1, typeProperty2, optionSetIdByName): b
|
|
|
234
236
|
slug: typeProperty1.slug,
|
|
235
237
|
label: typeProperty1.label,
|
|
236
238
|
editable: typeProperty1.editable,
|
|
239
|
+
searchable: typeProperty1.searchable,
|
|
237
240
|
core: typeProperty1.core,
|
|
238
241
|
typePropertyOptionSetId: optionSetIdByName[typeProperty1.typePropertyOptionSetName],
|
|
239
242
|
formula: typeProperty1.formula,
|
|
@@ -250,6 +253,7 @@ function typePropertiesEqual(typeProperty1, typeProperty2, optionSetIdByName): b
|
|
|
250
253
|
slug: typeProperty2.slug,
|
|
251
254
|
label: typeProperty2.label,
|
|
252
255
|
editable: typeProperty2.editable,
|
|
256
|
+
searchable: typeProperty2.searchable,
|
|
253
257
|
core: typeProperty2.core,
|
|
254
258
|
typePropertyOptionSetId: optionSetIdByName[typeProperty2.typePropertyOptionSetName],
|
|
255
259
|
formula: typeProperty2.formula,
|
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
|
-
}
|