@contrail/cli 1.0.39 → 1.0.41
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/api/apps.d.ts +13 -0
- package/lib/{apps/app-api.js → api/apps.js} +27 -1
- package/lib/api/event-workflow-action-definition.d.ts +1 -0
- package/lib/api/event-workflow-action-definition.js +7 -0
- package/lib/api/event-workflow-template-definition.d.ts +5 -0
- package/lib/api/event-workflow-template-definition.js +14 -0
- package/lib/api/event-workflow-templates.d.ts +7 -0
- package/lib/api/event-workflow-templates.js +25 -0
- package/lib/apps/deploy-app/app-deployer.js +4 -17
- package/lib/apps/install-app/app-installer.js +21 -4
- package/lib/apps/upgrade-app/app-upgrader.js +1 -1
- package/lib/cli.js +121 -45
- package/lib/config/config.d.ts +2 -2
- package/lib/config/configCommands.d.ts +1 -0
- package/lib/config/configCommands.js +25 -1
- package/lib/interfaces.d.ts +65 -1
- package/lib/interfaces.js +21 -0
- package/lib/types/parse-types.d.ts +1 -0
- package/lib/types/parse-types.js +48 -1
- package/lib/workflow-template-definitions/workflow-template-definition-commands.d.ts +2 -0
- package/lib/workflow-template-definitions/workflow-template-definition-commands.js +10 -0
- package/lib/workflow-template-definitions/workflow-template-definition-deployer.d.ts +12 -0
- package/lib/workflow-template-definitions/workflow-template-definition-deployer.js +148 -0
- package/lib/{workflows/workflow-template-deployer.d.ts → workflow-templates/local-workflow-template-deployer.d.ts} +1 -4
- package/lib/{workflows/workflow-template-deployer.js → workflow-templates/local-workflow-template-deployer.js} +9 -34
- package/lib/workflow-templates/workflow-template-commands.d.ts +4 -0
- package/lib/{workflows/workflowCommands.js → workflow-templates/workflow-template-commands.js} +9 -4
- package/lib/workflow-templates/workflow-template-deployer.d.ts +4 -0
- package/lib/workflow-templates/workflow-template-deployer.js +25 -0
- package/package.json +2 -2
- package/src/api/apps.ts +97 -0
- package/src/api/event-workflow-action-definition.ts +8 -0
- package/src/api/event-workflow-template-definition.ts +16 -0
- package/src/api/event-workflow-templates.ts +29 -0
- package/src/apps/deploy-app/app-deployer.ts +4 -19
- package/src/apps/install-app/app-installer.ts +34 -13
- package/src/apps/upgrade-app/app-upgrader.ts +1 -1
- package/src/cli.ts +123 -45
- package/src/config/config.ts +2 -2
- package/src/config/configCommands.ts +26 -1
- package/src/interfaces.ts +76 -6
- package/src/types/parse-types.ts +58 -1
- package/src/workflow-template-definitions/workflow-template-definition-commands.ts +13 -0
- package/src/workflow-template-definitions/workflow-template-definition-deployer.ts +182 -0
- package/src/{workflows/workflow-template-deployer.ts → workflow-templates/local-workflow-template-deployer.ts} +9 -38
- package/src/{workflows/workflowCommands.ts → workflow-templates/workflow-template-commands.ts} +10 -4
- package/src/workflow-templates/workflow-template-deployer.ts +29 -0
- package/lib/apps/app-api.d.ts +0 -6
- 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 -94
- package/lib/apps/deploy-app/workflow-deployer.d.ts +0 -10
- package/lib/apps/deploy-app/workflow-deployer.js +0 -87
- package/lib/workflows/workflowCommands.d.ts +0 -3
- package/src/apps/app-api.ts +0 -66
- package/src/apps/deploy-app/workflow-definition-deployer.ts +0 -118
- package/tslint.json +0 -57
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
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { authUser } from '../auth/login';
|
|
2
|
+
import { WorkflowTemplateDefinitionDeployer } from './workflow-template-definition-deployer';
|
|
3
|
+
export async function cliInstallWorkflowTemplateDefinitions() {
|
|
4
|
+
await authUser();
|
|
5
|
+
await new WorkflowTemplateDefinitionDeployer().cliInstallWorkflowTemplateDefinitions();
|
|
6
|
+
}
|
|
7
|
+
export async function listWorkflowTemplateDefinitions() {
|
|
8
|
+
await authUser();
|
|
9
|
+
await new WorkflowTemplateDefinitionDeployer().listWorkflowTemplateDefinitions();
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { App, AppDeclaration, WorkflowDefinition, WorkflowTemplate } from '../interfaces';
|
|
2
|
+
export declare class WorkflowTemplateDefinitionDeployer {
|
|
3
|
+
cliInstallWorkflowTemplateDefinitions(): Promise<void>;
|
|
4
|
+
installWorkflowTemplateDefinitions(workflowTemplateDefinitions: WorkflowTemplate[]): Promise<void>;
|
|
5
|
+
listWorkflowTemplateDefinitions(): Promise<void>;
|
|
6
|
+
deployWorkflowTemplateDefinitions(appDeclaration: AppDeclaration, app: App): Promise<void>;
|
|
7
|
+
deployWorkflow(workflowKey: string, workflow: WorkflowDefinition, app: App, existingWorkflows: Array<any>): Promise<any>;
|
|
8
|
+
private createNewWorkflowDefinition;
|
|
9
|
+
private populateActionIds;
|
|
10
|
+
private updateWorkflowTemplateDefinition;
|
|
11
|
+
getWorkflowDeclarationIdentifier(actionKey: any, app: App): string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import inquirer from 'inquirer';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { getInstalledApps, getWorkflowTemplateDefinitionsForApp } from '../api/apps';
|
|
4
|
+
import { createWorkflowTemplate } from '../api/event-workflow-templates';
|
|
5
|
+
import { createWorkflowTemplateDefinition, updateWorkflowTemplateDefinition as apiUpdateWorkflowTemplateDefinition } from '../api/event-workflow-template-definition';
|
|
6
|
+
import { getActionDeclarationIdentifier, getActionsForApp } from '../apps/deploy-app/actions-deployer';
|
|
7
|
+
export class WorkflowTemplateDefinitionDeployer {
|
|
8
|
+
async cliInstallWorkflowTemplateDefinitions() {
|
|
9
|
+
const installedApps = await getInstalledApps();
|
|
10
|
+
if (!installedApps.length) {
|
|
11
|
+
console.log('%s \nNo apps are currently installed. You must install an app before installing its associated workflow template definitions.', chalk.red.bold('WORKFLOW DEFINITION'));
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
let answers = await inquirer.prompt([{
|
|
15
|
+
type: 'list',
|
|
16
|
+
name: 'appIdentifier',
|
|
17
|
+
message: 'Which app\'s workflow would you like to install?',
|
|
18
|
+
choices: installedApps.map(x => x.app.identifier)
|
|
19
|
+
}]);
|
|
20
|
+
const app = installedApps.find(x => x.app.identifier === answers.appIdentifier).app;
|
|
21
|
+
const workflowTemplateDefinitions = await getWorkflowTemplateDefinitionsForApp({ appId: app.id });
|
|
22
|
+
for (const definition of workflowTemplateDefinitions) {
|
|
23
|
+
console.log(chalk.yellow.bold(`- ${definition.name}`));
|
|
24
|
+
}
|
|
25
|
+
answers = await inquirer.prompt([{
|
|
26
|
+
type: 'confirm',
|
|
27
|
+
name: 'shouldInstall',
|
|
28
|
+
message: 'Confirmation: would you like to install these workflows? (yes)',
|
|
29
|
+
default: true,
|
|
30
|
+
}]);
|
|
31
|
+
if (!answers.shouldInstall) {
|
|
32
|
+
console.log('%s Canceling installing workflows template definitions.', chalk.yellow.bold('WORKFLOW DEFINITION TEMPLATE'));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
await this.installWorkflowTemplateDefinitions(workflowTemplateDefinitions);
|
|
36
|
+
}
|
|
37
|
+
async installWorkflowTemplateDefinitions(workflowTemplateDefinitions) {
|
|
38
|
+
const answers = await inquirer.prompt([{
|
|
39
|
+
type: 'confirm',
|
|
40
|
+
name: 'makeActive',
|
|
41
|
+
message: 'Should the workflows be active ?(yes)',
|
|
42
|
+
default: true,
|
|
43
|
+
}]);
|
|
44
|
+
const makeActive = answers.makeActive;
|
|
45
|
+
for (const definition of workflowTemplateDefinitions) {
|
|
46
|
+
const newObject = {
|
|
47
|
+
name: definition.name,
|
|
48
|
+
triggerKey: definition.triggerKey,
|
|
49
|
+
workflowDefinition: definition.workflowDefinition,
|
|
50
|
+
isActive: makeActive,
|
|
51
|
+
supportingAppId: definition.supportingAppId,
|
|
52
|
+
};
|
|
53
|
+
await createWorkflowTemplate(newObject);
|
|
54
|
+
}
|
|
55
|
+
console.log('%s \nInstalled workflows', chalk.green.bold('WORKFLOW DEFINITION'));
|
|
56
|
+
}
|
|
57
|
+
async listWorkflowTemplateDefinitions() {
|
|
58
|
+
const installedApps = await getInstalledApps();
|
|
59
|
+
const workflowTemplateDefinitions = [];
|
|
60
|
+
for (const appOrg of installedApps) {
|
|
61
|
+
workflowTemplateDefinitions.push(...await (await getWorkflowTemplateDefinitionsForApp({ appId: appOrg.appId })).map(x => {
|
|
62
|
+
return {
|
|
63
|
+
appName: appOrg.app.name,
|
|
64
|
+
workflowName: x.name,
|
|
65
|
+
};
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
console.log('(app name) workflow name');
|
|
69
|
+
console.log('------------------------');
|
|
70
|
+
console.log(chalk.green.bold(workflowTemplateDefinitions.map(x => `(${x.appName}) ${x.workflowName} `).join('\n')));
|
|
71
|
+
}
|
|
72
|
+
async deployWorkflowTemplateDefinitions(appDeclaration, app) {
|
|
73
|
+
// FETCH ALL WORKFLOWS FROM THE API.
|
|
74
|
+
const existingWorkflows = await getWorkflowTemplateDefinitionsForApp({ appId: app.id });
|
|
75
|
+
// UPSERT / DELETE BASED ON WORKFLOW IDENTIFIER
|
|
76
|
+
console.log('%s \tDeploying workflow definitions.', chalk.yellow.bold('WORKFLOW DEFINITION'));
|
|
77
|
+
if (appDeclaration.workflows) {
|
|
78
|
+
const localWorkflows = Object.keys(appDeclaration.workflows);
|
|
79
|
+
if ((localWorkflows === null || localWorkflows === void 0 ? void 0 : localWorkflows.length) > 0) {
|
|
80
|
+
for (const workflowKey of localWorkflows) {
|
|
81
|
+
await this.deployWorkflow(workflowKey, appDeclaration.workflows[workflowKey], app, existingWorkflows);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async deployWorkflow(workflowKey, workflow, app, existingWorkflows) {
|
|
87
|
+
console.log(`%s \tDeploying workflow definitions: ${workflowKey}`, chalk.yellow.bold('WORKFLOW DEFINITION'));
|
|
88
|
+
const identifier = this.getWorkflowDeclarationIdentifier(workflowKey, app);
|
|
89
|
+
const existingDefinition = existingWorkflows.find(ad => ad.identifier === identifier);
|
|
90
|
+
if (existingDefinition) {
|
|
91
|
+
return await this.updateWorkflowTemplateDefinition(existingDefinition, workflow, app);
|
|
92
|
+
}
|
|
93
|
+
return await this.createNewWorkflowDefinition(workflowKey, workflow, app);
|
|
94
|
+
}
|
|
95
|
+
async createNewWorkflowDefinition(workflowKey, workflowDeclaration, app) {
|
|
96
|
+
await this.populateActionIds(workflowDeclaration, app);
|
|
97
|
+
const newObject = {
|
|
98
|
+
identifier: this.getWorkflowDeclarationIdentifier(workflowKey, app),
|
|
99
|
+
name: workflowDeclaration.name,
|
|
100
|
+
ownerKey: `app:${app.id}`,
|
|
101
|
+
triggerKey: workflowDeclaration.triggerKey,
|
|
102
|
+
workflowDefinition: workflowDeclaration.workflowDefinition,
|
|
103
|
+
public: workflowDeclaration.public,
|
|
104
|
+
isActive: workflowDeclaration.isActive,
|
|
105
|
+
messageGroupId: workflowDeclaration.messageGroupId,
|
|
106
|
+
parallelWorkerCount: workflowDeclaration.parallelWorkerCount,
|
|
107
|
+
};
|
|
108
|
+
const workflowTemplate = await createWorkflowTemplateDefinition(newObject);
|
|
109
|
+
console.log(`%s Created new workflow definition definitions: ${workflowKey}`, chalk.yellow.bold('WORKFLOW DEFINITION'));
|
|
110
|
+
return workflowTemplate;
|
|
111
|
+
}
|
|
112
|
+
async populateActionIds(workflowDefinition, app) {
|
|
113
|
+
var _a;
|
|
114
|
+
const availableAppActions = await getActionsForApp(app);
|
|
115
|
+
if (!((_a = workflowDefinition.workflowDefinition) === null || _a === void 0 ? void 0 : _a.paths)) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
for (const path of workflowDefinition.workflowDefinition.paths) {
|
|
119
|
+
if (!(path === null || path === void 0 ? void 0 : path.actionDefinitionConfigs)) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
for (const actionConfiguration of path.actionDefinitionConfigs) {
|
|
123
|
+
const actionKey = actionConfiguration.action;
|
|
124
|
+
const action = availableAppActions.find(action => action.identifier === getActionDeclarationIdentifier(actionKey, app));
|
|
125
|
+
if (!action) {
|
|
126
|
+
throw new Error(`Could not find action ${actionKey} declared in workflow definition ${workflowDefinition.name}`);
|
|
127
|
+
}
|
|
128
|
+
actionConfiguration.id = action.id;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async updateWorkflowTemplateDefinition(existingWorkflowDefinition, workflowDefinition, app) {
|
|
133
|
+
await this.populateActionIds(workflowDefinition, app);
|
|
134
|
+
const updates = Object.assign(new Object(), {
|
|
135
|
+
name: workflowDefinition.name,
|
|
136
|
+
triggerKey: workflowDefinition.triggerKey,
|
|
137
|
+
workflowDefinition: workflowDefinition.workflowDefinition,
|
|
138
|
+
messageGroupId: workflowDefinition.messageGroupId,
|
|
139
|
+
parallelWorkerCount: workflowDefinition.parallelWorkerCount,
|
|
140
|
+
});
|
|
141
|
+
const updatedWorkflowDefinition = await apiUpdateWorkflowTemplateDefinition({ id: existingWorkflowDefinition.id, updates });
|
|
142
|
+
console.log(`%s Updated existing workflow definition: ${updatedWorkflowDefinition.identifier}`, chalk.yellow.bold('WORKFLOW DEFINITION'));
|
|
143
|
+
return updatedWorkflowDefinition;
|
|
144
|
+
}
|
|
145
|
+
getWorkflowDeclarationIdentifier(actionKey, app) {
|
|
146
|
+
return app.identifier + ':' + actionKey;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { WorkflowTemplate, WorkflowTemplateDeclaration } from '../interfaces';
|
|
2
|
-
export declare class
|
|
2
|
+
export declare class LocalWorkflowTemplateDeployer {
|
|
3
3
|
deployWorkflows(wtDeclaration: WorkflowTemplateDeclaration): Promise<void>;
|
|
4
|
-
getExistingWorkflowTemplates(): Promise<any>;
|
|
5
4
|
deployWorkflowTemplate(workflowKey: string, workflow: WorkflowTemplate, existingWorkflows: Array<any>): Promise<any>;
|
|
6
5
|
private createNewWorkflowTemplate;
|
|
7
6
|
private populateActionIds;
|
|
8
7
|
private updateWorkflowTemplate;
|
|
9
8
|
deleteWorkflowTemplates(wtDeclaration: WorkflowTemplateDeclaration): Promise<void>;
|
|
10
|
-
private deleteWorkflowTemplate;
|
|
11
|
-
listExistingWorkflowTemplates(): Promise<any>;
|
|
12
9
|
}
|
|
13
10
|
export declare function getWorkflowTemplateIdentifier(workflowKey: string): string;
|
|
14
11
|
export declare function getActionByIdentifier(identifier: string): Promise<any>;
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
import { Entities } from '@contrail/sdk';
|
|
2
1
|
import chalk from 'chalk';
|
|
3
|
-
|
|
2
|
+
import { getEventWorkflowActionDefinition } from '../api/event-workflow-action-definition';
|
|
3
|
+
import { createWorkflowTemplate, deleteWorkflowTemplate, getExistingWorkflowTemplates, updateWorkflowTemplate as apiUpdateWorkflowTemplate } from '../api/event-workflow-templates';
|
|
4
|
+
export class LocalWorkflowTemplateDeployer {
|
|
4
5
|
async deployWorkflows(wtDeclaration) {
|
|
5
6
|
// FETCH ALL WORKFLOWS FROM THE API.
|
|
6
|
-
const existingWorkflows = await
|
|
7
|
+
const existingWorkflows = await getExistingWorkflowTemplates();
|
|
7
8
|
// UPSERT / DELETE BASED ON WORKFLOW TEMPLATES IDENTIFIER
|
|
8
9
|
console.log('%s \tDeploying workflow templates.', chalk.yellow.bold('WORKFLOW TEMPLATES'));
|
|
9
10
|
for (const workflowKey of Object.keys(wtDeclaration.workflows)) {
|
|
10
11
|
await this.deployWorkflowTemplate(workflowKey, wtDeclaration.workflows[workflowKey], existingWorkflows);
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
|
-
async getExistingWorkflowTemplates() {
|
|
14
|
-
return await new Entities().get({
|
|
15
|
-
entityName: 'event-workflow-template'
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
14
|
async deployWorkflowTemplate(workflowKey, workflow, existingWorkflows) {
|
|
19
15
|
console.log(`%s \tDeploying workflow: ${workflowKey}`, chalk.yellow.bold('WORKFLOW TEMPLATES'));
|
|
20
16
|
const identifier = getWorkflowTemplateIdentifier(workflowKey);
|
|
@@ -36,10 +32,7 @@ export class WorkflowTemplateDeployer {
|
|
|
36
32
|
messageGroupId: workflowTemplate.messageGroupId,
|
|
37
33
|
parallelWorkerCount: workflowTemplate.parallelWorkerCount,
|
|
38
34
|
};
|
|
39
|
-
const newWorkflowTemplate = await
|
|
40
|
-
entityName: 'event-workflow-template',
|
|
41
|
-
object: newObject,
|
|
42
|
-
});
|
|
35
|
+
const newWorkflowTemplate = await createWorkflowTemplate(newObject);
|
|
43
36
|
console.log(`%s Created new workflow definition: ${workflowKey}`, chalk.yellow.bold('WORKFLOW TEMPLATES'));
|
|
44
37
|
return newWorkflowTemplate;
|
|
45
38
|
}
|
|
@@ -74,17 +67,13 @@ export class WorkflowTemplateDeployer {
|
|
|
74
67
|
triggerKey: workflowTemplate.triggerKey,
|
|
75
68
|
workflowDefinition: workflowTemplate.workflowDefinition
|
|
76
69
|
});
|
|
77
|
-
const updatedWorkflowTemplate = await
|
|
78
|
-
entityName: 'event-workflow-template',
|
|
79
|
-
id: existingWorkflowTemplate.id,
|
|
80
|
-
object: updates,
|
|
81
|
-
});
|
|
70
|
+
const updatedWorkflowTemplate = await apiUpdateWorkflowTemplate({ id: existingWorkflowTemplate.id, updates });
|
|
82
71
|
console.log(`%s Updated existing workflow template: ${updatedWorkflowTemplate.identifier}`, chalk.yellow.bold('WORKFLOW TEMPLATES'));
|
|
83
72
|
return updatedWorkflowTemplate;
|
|
84
73
|
}
|
|
85
74
|
async deleteWorkflowTemplates(wtDeclaration) {
|
|
86
75
|
// FETCH ALL WORKFLOWS FROM THE API.
|
|
87
|
-
const existingWorkflows = await
|
|
76
|
+
const existingWorkflows = await getExistingWorkflowTemplates();
|
|
88
77
|
// UPSERT / DELETE BASED ON WORKFLOW TEMPLATES IDENTIFIER
|
|
89
78
|
console.log('%s \tDELETING workflow templates.', chalk.yellow.bold('WORKFLOW TEMPLATES'));
|
|
90
79
|
for (const workflowKey of Object.keys(wtDeclaration.workflows)) {
|
|
@@ -92,7 +81,7 @@ export class WorkflowTemplateDeployer {
|
|
|
92
81
|
const existingTemplate = existingWorkflows.find(ad => ad.identifier === identifier);
|
|
93
82
|
if (existingTemplate) {
|
|
94
83
|
try {
|
|
95
|
-
await
|
|
84
|
+
await deleteWorkflowTemplate(identifier);
|
|
96
85
|
}
|
|
97
86
|
catch (e) {
|
|
98
87
|
console.log('%s \tFAILED to delete workflow template %s.', chalk.red.bold('WORKFLOW TEMPLATES'), identifier);
|
|
@@ -103,25 +92,11 @@ export class WorkflowTemplateDeployer {
|
|
|
103
92
|
}
|
|
104
93
|
}
|
|
105
94
|
}
|
|
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
95
|
}
|
|
118
96
|
export function getWorkflowTemplateIdentifier(workflowKey) {
|
|
119
97
|
return workflowKey;
|
|
120
98
|
}
|
|
121
99
|
export async function getActionByIdentifier(identifier) {
|
|
122
|
-
const result = await
|
|
123
|
-
entityName: 'event-workflow-action-definition',
|
|
124
|
-
criteria: { identifier },
|
|
125
|
-
});
|
|
100
|
+
const result = await getEventWorkflowActionDefinition({ identifier });
|
|
126
101
|
return result.length > 0 ? result[0] : {};
|
|
127
102
|
}
|
package/lib/{workflows/workflowCommands.js → workflow-templates/workflow-template-commands.js}
RENAMED
|
@@ -3,8 +3,13 @@ import fs from 'fs';
|
|
|
3
3
|
import { authUser } from '../auth/login';
|
|
4
4
|
import { getSeparatorByPlatform } from '../common';
|
|
5
5
|
const yaml = require('js-yaml');
|
|
6
|
+
import { LocalWorkflowTemplateDeployer } from './local-workflow-template-deployer';
|
|
6
7
|
import { WorkflowTemplateDeployer } from './workflow-template-deployer';
|
|
7
|
-
export async function
|
|
8
|
+
export async function deleteWorkflowTemplates() {
|
|
9
|
+
await authUser();
|
|
10
|
+
await new WorkflowTemplateDeployer().deleteWorkflowTemplates();
|
|
11
|
+
}
|
|
12
|
+
export async function localDeleteWorkflowTemplate() {
|
|
8
13
|
let wtDeclaration;
|
|
9
14
|
try {
|
|
10
15
|
wtDeclaration = loadTemplateConfig();
|
|
@@ -14,9 +19,9 @@ export async function deleteWorkflowTemplate() {
|
|
|
14
19
|
return;
|
|
15
20
|
}
|
|
16
21
|
await authUser();
|
|
17
|
-
await new
|
|
22
|
+
await new LocalWorkflowTemplateDeployer().deleteWorkflowTemplates(wtDeclaration);
|
|
18
23
|
}
|
|
19
|
-
export async function
|
|
24
|
+
export async function localDeployWorkflowTemplate() {
|
|
20
25
|
let wtDeclaration;
|
|
21
26
|
try {
|
|
22
27
|
wtDeclaration = loadTemplateConfig();
|
|
@@ -26,7 +31,7 @@ export async function deployWorkflowTemplate() {
|
|
|
26
31
|
return;
|
|
27
32
|
}
|
|
28
33
|
await authUser();
|
|
29
|
-
await new
|
|
34
|
+
await new LocalWorkflowTemplateDeployer().deployWorkflows(wtDeclaration);
|
|
30
35
|
}
|
|
31
36
|
export async function listWorkflowTemplate() {
|
|
32
37
|
await authUser();
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import inquirer from 'inquirer';
|
|
3
|
+
import { deleteWorkflowTemplate as apiDeleteWorkflowTemplate } from '../api/event-workflow-templates';
|
|
4
|
+
import { getExistingWorkflowTemplates } from '../api/event-workflow-templates';
|
|
5
|
+
export class WorkflowTemplateDeployer {
|
|
6
|
+
async deleteWorkflowTemplates() {
|
|
7
|
+
// FETCH ALL WORKFLOWS FROM THE API.
|
|
8
|
+
const existingWorkflows = await getExistingWorkflowTemplates();
|
|
9
|
+
const answers = await inquirer.prompt([{
|
|
10
|
+
type: 'checkbox',
|
|
11
|
+
name: 'wfTemplatesToDelete',
|
|
12
|
+
message: 'Which templates would you like to delete (one or more)?',
|
|
13
|
+
choices: existingWorkflows.map(x => { return { value: x.id, name: `(${x.createdOn}) ${x.name}` }; })
|
|
14
|
+
}]);
|
|
15
|
+
for (const idToDelete of answers.wfTemplatesToDelete) {
|
|
16
|
+
await apiDeleteWorkflowTemplate(idToDelete);
|
|
17
|
+
}
|
|
18
|
+
console.log('%s \tDeleted workflow templates!', chalk.green.bold('WORKFLOW TEMPLATES'));
|
|
19
|
+
}
|
|
20
|
+
async listExistingWorkflowTemplates() {
|
|
21
|
+
const templates = await getExistingWorkflowTemplates();
|
|
22
|
+
console.log(templates);
|
|
23
|
+
return templates;
|
|
24
|
+
}
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.41",
|
|
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.74",
|
|
28
28
|
"@contrail/util": "^1.0.17",
|
|
29
29
|
"amazon-cognito-identity-js": "^5.2.3",
|
|
30
30
|
"arg": "^4.0.1",
|
package/src/api/apps.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Auth } from '../auth/auth';
|
|
2
|
+
import { Entities } from '@contrail/sdk';
|
|
3
|
+
import { App, AppOrg, AppVersion, WorkflowDefinition } from '../interfaces';
|
|
4
|
+
import { authUser } from '../auth/login';
|
|
5
|
+
|
|
6
|
+
export async function getAllAvailableApps(options: { orgId: string }): Promise<App[]> {
|
|
7
|
+
const apps: App[] = [];
|
|
8
|
+
apps.push(...await new Entities().get({
|
|
9
|
+
entityName: 'app',
|
|
10
|
+
criteria: {
|
|
11
|
+
orgId: options.orgId,
|
|
12
|
+
private: true,
|
|
13
|
+
},
|
|
14
|
+
}));
|
|
15
|
+
apps.push(...await new Entities().get({
|
|
16
|
+
entityName: 'app',
|
|
17
|
+
criteria: {
|
|
18
|
+
orgId: options.orgId,
|
|
19
|
+
private: false,
|
|
20
|
+
},
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
return apps;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function getWorkflowTemplateDefinitionsForApp(options: {appId: string}): Promise<WorkflowDefinition[]> {
|
|
27
|
+
return await new Entities().get({
|
|
28
|
+
entityName: 'event-workflow-template-definition',
|
|
29
|
+
criteria: {
|
|
30
|
+
ownerKey: `app:${options.appId}`
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function getAppVersions(app): Promise<AppVersion[]> {
|
|
36
|
+
return await new Entities().get({
|
|
37
|
+
entityName: 'app-version',
|
|
38
|
+
criteria: {
|
|
39
|
+
appId: app.id
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export async function upgradeAppVersion(appOrg, appVersionId): Promise<AppOrg> {
|
|
45
|
+
return await new Entities().update({
|
|
46
|
+
entityName: 'app-org',
|
|
47
|
+
id: appOrg.id,
|
|
48
|
+
object: {
|
|
49
|
+
appVersionId: appVersionId
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function deleteAppOrg(appOrgId: string): Promise<AppOrg> {
|
|
55
|
+
return await new Entities().delete({
|
|
56
|
+
entityName: 'app-org',
|
|
57
|
+
id: appOrgId
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function getInstalledApps(): Promise<AppOrg[]> {
|
|
62
|
+
return await new Entities().get({
|
|
63
|
+
entityName: 'app-org',
|
|
64
|
+
relations: ['app']
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function installAppToOrg(app, configProperties): Promise<AppOrg> {
|
|
69
|
+
return await new Entities().create({
|
|
70
|
+
entityName: 'app-org',
|
|
71
|
+
object: {
|
|
72
|
+
appId: app.id,
|
|
73
|
+
appConfig: configProperties
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function getAvailableApps(): Promise<App[]> {
|
|
79
|
+
const orgId = Auth.config.orgId;
|
|
80
|
+
const apps = [];
|
|
81
|
+
apps.push(...await new Entities().get({
|
|
82
|
+
entityName: 'app',
|
|
83
|
+
criteria: {
|
|
84
|
+
orgId,
|
|
85
|
+
private: true,
|
|
86
|
+
},
|
|
87
|
+
}));
|
|
88
|
+
apps.push(...await new Entities().get({
|
|
89
|
+
entityName: 'app',
|
|
90
|
+
criteria: {
|
|
91
|
+
orgId,
|
|
92
|
+
private: false,
|
|
93
|
+
},
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
return apps;
|
|
97
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Entities } from '@contrail/sdk';
|
|
2
|
+
|
|
3
|
+
export async function createWorkflowTemplateDefinition(object: any) {
|
|
4
|
+
return await new Entities().create({
|
|
5
|
+
entityName: 'event-workflow-template-definition',
|
|
6
|
+
object: object,
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export async function updateWorkflowTemplateDefinition(options: {id: string, updates: any}) {
|
|
11
|
+
return await new Entities().update({
|
|
12
|
+
entityName: 'event-workflow-template-definition',
|
|
13
|
+
id: options.id,
|
|
14
|
+
object: options.updates,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Entities } from '@contrail/sdk';
|
|
2
|
+
|
|
3
|
+
export async function getExistingWorkflowTemplates() {
|
|
4
|
+
return await new Entities().get({
|
|
5
|
+
entityName: 'event-workflow-template'
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export async function createWorkflowTemplate(object) {
|
|
10
|
+
return await new Entities().create({
|
|
11
|
+
entityName: 'event-workflow-template',
|
|
12
|
+
object
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function deleteWorkflowTemplate(id: string) {
|
|
17
|
+
return await new Entities().delete({
|
|
18
|
+
entityName: 'event-workflow-template',
|
|
19
|
+
id,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function updateWorkflowTemplate(options: { id: string, updates: any }) {
|
|
24
|
+
return await new Entities().update({
|
|
25
|
+
entityName: 'event-workflow-template',
|
|
26
|
+
id: options.id,
|
|
27
|
+
object: options.updates,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
@@ -4,7 +4,8 @@ import { Auth } from '../../auth/auth';
|
|
|
4
4
|
import { ActionsDeployer, getActionsForApp, deleteAction } from './actions-deployer';
|
|
5
5
|
import { App, AppDeclaration } from '../../interfaces';
|
|
6
6
|
import { TriggerKeyDefinitionParser, ConfigPropertiesParser } from './app-template-parsers';
|
|
7
|
-
import {
|
|
7
|
+
import { WorkflowTemplateDefinitionDeployer } from '../../workflow-template-definitions/workflow-template-definition-deployer';
|
|
8
|
+
import { getAllAvailableApps } from '../../api/apps';
|
|
8
9
|
|
|
9
10
|
export class AppDeployer {
|
|
10
11
|
public async deploy(appDeclaration: AppDeclaration) {
|
|
@@ -17,28 +18,12 @@ export class AppDeployer {
|
|
|
17
18
|
app = await this.updateExistingApp(appDeclaration, app);
|
|
18
19
|
}
|
|
19
20
|
await new ActionsDeployer().deployActions(appDeclaration, app);
|
|
20
|
-
await new
|
|
21
|
+
await new WorkflowTemplateDefinitionDeployer().deployWorkflowTemplateDefinitions(appDeclaration, app);
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
public async getExistingApp(appDeclaration: AppDeclaration): Promise<App> {
|
|
24
25
|
const orgId = Auth.config.orgId;
|
|
25
|
-
const apps =
|
|
26
|
-
|
|
27
|
-
apps.push(...await new Entities().get({
|
|
28
|
-
entityName: 'app',
|
|
29
|
-
criteria: {
|
|
30
|
-
orgId,
|
|
31
|
-
private: true,
|
|
32
|
-
},
|
|
33
|
-
}));
|
|
34
|
-
apps.push(...await new Entities().get({
|
|
35
|
-
entityName: 'app',
|
|
36
|
-
criteria: {
|
|
37
|
-
orgId,
|
|
38
|
-
private: false,
|
|
39
|
-
},
|
|
40
|
-
}));
|
|
41
|
-
|
|
26
|
+
const apps = await getAllAvailableApps({orgId});
|
|
42
27
|
return apps.find(app => app.identifier === appDeclaration.appIdentifier);
|
|
43
28
|
}
|
|
44
29
|
|