-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathflowservice.js
135 lines (115 loc) · 3.97 KB
/
flowservice.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* webMethods.io CLI
* Copyright 2022 Software AG
* Apache-2.0
*/
const rest = require('./rest-fetch.js');
var domainName, username,password,timeout,prettyprint;
var url;
function debug(message){
logger.debug("<FLOWSERVICE> " + message);
}
function help(){
return `
\x1b[4mFlowService\x1b[0m
\x1b[32mExport FlowService from a given project (identified from URL in webMethods.io when in FlowEditor
i.e. https://tenant.int-aws-us.webmethods.io/#/projects/\x1b[1mfl65d3aa87fc1783ea5cf8c8\x1b[0m\x1b[32m/flow-editor/\x1b[1mmyFlowService\x1b[0m\x1b[32m):\x1b[0m\x1b[0m
$ node wmiocli.js
-d tenant.int-aws-us.webmethods.io
-u user
-p password
flowservice-export fl65d3aa87fc1783ea5cf8c8 myFlowService export.zip
\x1b[32mImport Flowservice from a given file into a project \x1b[0m
$ node wmiocli.js
-d tenant.int-aws-us.webmethods.io
-u user
-p password
flowservice-import fl65d3aa87fc1783ea5cf8c8 export.zip
\x1b[32mDelete FlowService from a given project\x1b[0m
$ node wmiocli.js
-d tenant.int-aws-us.webmethods.io
-u user
-p password
flowservice-delete fl65d3aa87fc1783ea5cf8c8 myFlowService
\x1b[32mExecute a FlowService from a given project\x1b[0m
$ node wmiocli.js
-d tenant.int-aws-us.webmethods.io
-u user
-p password
flowservice-execute fl65d3aa87fc1783ea5cf8c8 myFlowService
`;
}
function init(inDomainName, inUsername, inPassword,inTimeout,inPrettyPrint,projectId){
domainName = inDomainName;
username = inUsername;
password = inPassword;
timeout = inTimeout;
prettyprint = inPrettyPrint;
url = "https://" + domainName + "/apis/v1/rest/projects/" + projectId ;
debug("Username [" + username + "]");
debug("URL [" + url + "]");
debug("Timeout [" + timeout + "]");
}
/**
* Call back function to process REST response
* @param {return data from REST request} data
* @param {status} status
*/
function processResponse(restEndPointUrl, err, data, response) {
let status = response.status;
if(prettyprint==true){
console.log(JSON.stringify(data,null,4));
}
else{
console.log(JSON.stringify(data));
}
if(status!=0){
process.exit(status);
}
}
function downloadExport(restEndPointUrl, err, data, response,filename){
let status = response.status
debug("Downloading Export");
if(status!=200){
console.log(JSON.stringify(data));
process.exit(status);
}
else{
rest.downloadFile(data, filename, downloadCompleted);
}
}
function downloadCompleted(data,status,filename){
debug("Download Completed");
if(status!=0){
console.log('{');
console.log(' flowservice-export":"error", "filename":"'+ filename +',');
console.log(JSON.stringifydata);
console.log('}');
process.exit(status);
}
else{
console.log('{"flowservice-export":"success", "filename":"'+ filename + '"}');
}
}
function exportFlowService(flowId, filename){
debug("Exporting FlowService");
url+="/flows/" + flowId + "/export";
var data={};
rest.postDownloadFile(url,username,password,timeout,data,filename,downloadExport);
}
function importFlowService(filename){
debug("Importing FlowService");
url+="/flow-import";
rest.postUploadFile(url,username,password,timeout,undefined,filename,"recipe",processResponse);
}
function runFlowService(flowId,data){
debug("Running Flowservice with Name [" + flowId + "]");
url += "/flows/" + flowId + "/run";
rest.post(url,username,password,timeout,data,processResponse);
}
function deleteFlowService(flowId){
debug("Deleting FlowService with ID [" + flowId + "]");
url += "/flows/" + flowId;
rest.del(url,username,password,timeout,{},processResponse);
}
module.exports = {help, init, exportFlowService, importFlowService, runFlowService, deleteFlowService };