@contrail/cli 1.0.38 → 1.0.40
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/api/apps.js +85 -0
- 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/deploy-app/workflow-definition-deployer.js +2 -1
- package/lib/apps/install-app/app-installer.js +21 -4
- package/lib/apps/upgrade-app/app-upgrader.js +1 -1
- package/lib/cli.js +112 -44
- 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/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/workflow-templates/local-workflow-template-deployer.d.ts +11 -0
- package/lib/workflow-templates/local-workflow-template-deployer.js +102 -0
- package/lib/workflow-templates/workflow-template-commands.d.ts +4 -0
- package/lib/workflow-templates/workflow-template-commands.js +51 -0
- package/lib/workflow-templates/workflow-template-deployer.d.ts +4 -0
- package/lib/workflow-templates/workflow-template-deployer.js +25 -0
- package/package.json +1 -1
- 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 +114 -44
- package/src/config/config.ts +2 -2
- package/src/config/configCommands.ts +26 -1
- package/src/interfaces.ts +76 -6
- 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/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/interfaces.js
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
export var AppOrgStatus;
|
|
2
|
+
(function (AppOrgStatus) {
|
|
3
|
+
AppOrgStatus["INSTALLING"] = "INSTALLING";
|
|
4
|
+
AppOrgStatus["FAILED_INSTALLING"] = "FAILED_INSTALLING";
|
|
5
|
+
AppOrgStatus["READY"] = "READY";
|
|
6
|
+
AppOrgStatus["DELETING"] = "DELETING";
|
|
7
|
+
AppOrgStatus["FAILED_DELETING"] = "FAILED_DELETING";
|
|
8
|
+
})(AppOrgStatus || (AppOrgStatus = {}));
|
|
9
|
+
export var AppVersionStatus;
|
|
10
|
+
(function (AppVersionStatus) {
|
|
11
|
+
AppVersionStatus["PUBLISHING"] = "PUBLISHING";
|
|
12
|
+
AppVersionStatus["FAILED_PUBLISHING"] = "FAILED_PUBLISHING";
|
|
13
|
+
AppVersionStatus["PUBLISHED"] = "PUBLISHED";
|
|
14
|
+
AppVersionStatus["ARCHIVING"] = "ARCHIVING";
|
|
15
|
+
AppVersionStatus["FAILED_ARCHIVING"] = "FAILED_ARCHIVING";
|
|
16
|
+
AppVersionStatus["ARCHIVED"] = "ARCHIVED";
|
|
17
|
+
})(AppVersionStatus || (AppVersionStatus = {}));
|
|
18
|
+
export class AppVersion {
|
|
19
|
+
}
|
|
20
|
+
export class AppApiKey {
|
|
21
|
+
}
|
|
1
22
|
export class ConfigProperty {
|
|
2
23
|
}
|
|
3
24
|
export class TriggerKeyDefinition {
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { WorkflowTemplate, WorkflowTemplateDeclaration } from '../interfaces';
|
|
2
|
+
export declare class LocalWorkflowTemplateDeployer {
|
|
3
|
+
deployWorkflows(wtDeclaration: WorkflowTemplateDeclaration): Promise<void>;
|
|
4
|
+
deployWorkflowTemplate(workflowKey: string, workflow: WorkflowTemplate, existingWorkflows: Array<any>): Promise<any>;
|
|
5
|
+
private createNewWorkflowTemplate;
|
|
6
|
+
private populateActionIds;
|
|
7
|
+
private updateWorkflowTemplate;
|
|
8
|
+
deleteWorkflowTemplates(wtDeclaration: WorkflowTemplateDeclaration): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export declare function getWorkflowTemplateIdentifier(workflowKey: string): string;
|
|
11
|
+
export declare function getActionByIdentifier(identifier: string): Promise<any>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
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 {
|
|
5
|
+
async deployWorkflows(wtDeclaration) {
|
|
6
|
+
// FETCH ALL WORKFLOWS FROM THE API.
|
|
7
|
+
const existingWorkflows = await getExistingWorkflowTemplates();
|
|
8
|
+
// UPSERT / DELETE BASED ON WORKFLOW TEMPLATES IDENTIFIER
|
|
9
|
+
console.log('%s \tDeploying workflow templates.', chalk.yellow.bold('WORKFLOW TEMPLATES'));
|
|
10
|
+
for (const workflowKey of Object.keys(wtDeclaration.workflows)) {
|
|
11
|
+
await this.deployWorkflowTemplate(workflowKey, wtDeclaration.workflows[workflowKey], existingWorkflows);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
async deployWorkflowTemplate(workflowKey, workflow, existingWorkflows) {
|
|
15
|
+
console.log(`%s \tDeploying workflow: ${workflowKey}`, chalk.yellow.bold('WORKFLOW TEMPLATES'));
|
|
16
|
+
const identifier = getWorkflowTemplateIdentifier(workflowKey);
|
|
17
|
+
const existingTemplate = existingWorkflows.find(ad => ad.identifier === identifier);
|
|
18
|
+
if (existingTemplate) {
|
|
19
|
+
return await this.updateWorkflowTemplate(workflowKey, existingTemplate, workflow);
|
|
20
|
+
}
|
|
21
|
+
return await this.createNewWorkflowTemplate(workflowKey, workflow);
|
|
22
|
+
}
|
|
23
|
+
async createNewWorkflowTemplate(workflowKey, workflowTemplate) {
|
|
24
|
+
await this.populateActionIds(workflowTemplate, workflowKey);
|
|
25
|
+
const newObject = {
|
|
26
|
+
identifier: getWorkflowTemplateIdentifier(workflowKey),
|
|
27
|
+
name: workflowTemplate.name,
|
|
28
|
+
triggerKey: workflowTemplate.triggerKey,
|
|
29
|
+
workflowDefinition: workflowTemplate.workflowDefinition,
|
|
30
|
+
isActive: workflowTemplate.isActive,
|
|
31
|
+
supportingAppId: workflowTemplate.supportingAppId,
|
|
32
|
+
messageGroupId: workflowTemplate.messageGroupId,
|
|
33
|
+
parallelWorkerCount: workflowTemplate.parallelWorkerCount,
|
|
34
|
+
};
|
|
35
|
+
const newWorkflowTemplate = await createWorkflowTemplate(newObject);
|
|
36
|
+
console.log(`%s Created new workflow definition: ${workflowKey}`, chalk.yellow.bold('WORKFLOW TEMPLATES'));
|
|
37
|
+
return newWorkflowTemplate;
|
|
38
|
+
}
|
|
39
|
+
async populateActionIds(workflowTemplate, workflowKey) {
|
|
40
|
+
var _a;
|
|
41
|
+
if (!((_a = workflowTemplate === null || workflowTemplate === void 0 ? void 0 : workflowTemplate.workflowDefinition) === null || _a === void 0 ? void 0 : _a.paths)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
for (const path of workflowTemplate.workflowDefinition.paths) {
|
|
45
|
+
if (!(path === null || path === void 0 ? void 0 : path.actionDefinitionConfigs)) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
for (const actionConfiguration of path.actionDefinitionConfigs) {
|
|
49
|
+
const actionKey = actionConfiguration.action;
|
|
50
|
+
try {
|
|
51
|
+
const actionEntity = await getActionByIdentifier(actionKey);
|
|
52
|
+
actionConfiguration.id = actionEntity.id;
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
console.log(e);
|
|
56
|
+
}
|
|
57
|
+
if (!actionConfiguration.id) {
|
|
58
|
+
throw new Error(`Could not find action ${actionKey} declared in ${workflowKey}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async updateWorkflowTemplate(workflowKey, existingWorkflowTemplate, workflowTemplate) {
|
|
64
|
+
await this.populateActionIds(workflowTemplate, workflowKey);
|
|
65
|
+
const updates = Object.assign(new Object(), {
|
|
66
|
+
name: workflowTemplate.name,
|
|
67
|
+
triggerKey: workflowTemplate.triggerKey,
|
|
68
|
+
workflowDefinition: workflowTemplate.workflowDefinition
|
|
69
|
+
});
|
|
70
|
+
const updatedWorkflowTemplate = await apiUpdateWorkflowTemplate({ id: existingWorkflowTemplate.id, updates });
|
|
71
|
+
console.log(`%s Updated existing workflow template: ${updatedWorkflowTemplate.identifier}`, chalk.yellow.bold('WORKFLOW TEMPLATES'));
|
|
72
|
+
return updatedWorkflowTemplate;
|
|
73
|
+
}
|
|
74
|
+
async deleteWorkflowTemplates(wtDeclaration) {
|
|
75
|
+
// FETCH ALL WORKFLOWS FROM THE API.
|
|
76
|
+
const existingWorkflows = await getExistingWorkflowTemplates();
|
|
77
|
+
// UPSERT / DELETE BASED ON WORKFLOW TEMPLATES IDENTIFIER
|
|
78
|
+
console.log('%s \tDELETING workflow templates.', chalk.yellow.bold('WORKFLOW TEMPLATES'));
|
|
79
|
+
for (const workflowKey of Object.keys(wtDeclaration.workflows)) {
|
|
80
|
+
const identifier = getWorkflowTemplateIdentifier(workflowKey);
|
|
81
|
+
const existingTemplate = existingWorkflows.find(ad => ad.identifier === identifier);
|
|
82
|
+
if (existingTemplate) {
|
|
83
|
+
try {
|
|
84
|
+
await deleteWorkflowTemplate(identifier);
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
console.log('%s \tFAILED to delete workflow template %s.', chalk.red.bold('WORKFLOW TEMPLATES'), identifier);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
console.log('%s \tUnable to locate workflow template %s.', chalk.yellow.bold('WORKFLOW TEMPLATES'), identifier);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
export function getWorkflowTemplateIdentifier(workflowKey) {
|
|
97
|
+
return workflowKey;
|
|
98
|
+
}
|
|
99
|
+
export async function getActionByIdentifier(identifier) {
|
|
100
|
+
const result = await getEventWorkflowActionDefinition({ identifier });
|
|
101
|
+
return result.length > 0 ? result[0] : {};
|
|
102
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
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 { LocalWorkflowTemplateDeployer } from './local-workflow-template-deployer';
|
|
7
|
+
import { WorkflowTemplateDeployer } from './workflow-template-deployer';
|
|
8
|
+
export async function deleteWorkflowTemplates() {
|
|
9
|
+
await authUser();
|
|
10
|
+
await new WorkflowTemplateDeployer().deleteWorkflowTemplates();
|
|
11
|
+
}
|
|
12
|
+
export async function localDeleteWorkflowTemplate() {
|
|
13
|
+
let wtDeclaration;
|
|
14
|
+
try {
|
|
15
|
+
wtDeclaration = loadTemplateConfig();
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
console.log(`%s Workflow Deletion Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
await authUser();
|
|
22
|
+
await new LocalWorkflowTemplateDeployer().deleteWorkflowTemplates(wtDeclaration);
|
|
23
|
+
}
|
|
24
|
+
export async function localDeployWorkflowTemplate() {
|
|
25
|
+
let wtDeclaration;
|
|
26
|
+
try {
|
|
27
|
+
wtDeclaration = loadTemplateConfig();
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
console.log(`%s Workflow Deletion Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
await authUser();
|
|
34
|
+
await new LocalWorkflowTemplateDeployer().deployWorkflows(wtDeclaration);
|
|
35
|
+
}
|
|
36
|
+
export async function listWorkflowTemplate() {
|
|
37
|
+
await authUser();
|
|
38
|
+
return await new WorkflowTemplateDeployer().listExistingWorkflowTemplates();
|
|
39
|
+
}
|
|
40
|
+
function loadTemplateConfig() {
|
|
41
|
+
const TARGET_DIR = process.cwd();
|
|
42
|
+
try {
|
|
43
|
+
const separator = getSeparatorByPlatform();
|
|
44
|
+
const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + 'workflow.yml', 'utf8'));
|
|
45
|
+
console.log(doc);
|
|
46
|
+
return doc;
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -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
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
|
|