-
Notifications
You must be signed in to change notification settings - Fork 5
/
recipe.js
93 lines (77 loc) · 2.28 KB
/
recipe.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
/*
* 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("<RECIPE> " + message);
}
function help() {
return `
\x1b[4mRecipes\x1b[0m
\x1b[32mGet recipe list or individual recipe\x1b[0m
$ node wmiocli.js
-d tenant.int-aws-us.webmethods.io
-u user
-p password
recipe [recipe-Uid]
\x1b[32mCreates a Workflow recipe from a workflow export\x1b[0m
$ node wmiocli.js
-d tenant.int-aws-us.webmethods.io
-u user
-p password
recipe-create export-flf111111.zip
\x1b[32mDeletes a Workflow recipe with the provided UID\x1b[0m
$ node wmiocli.js
-d tenant.int-aws-us.webmethods.io
-u user
-p password
recipe-delete fl1771d591cfb4f31e558daf
`;
}
function init(inDomainName, inUsername, inPassword, inTimeout, inPrettyPrint) {
domainName = inDomainName;
username = inUsername;
password = inPassword;
timeout = inTimeout;
prettyprint = inPrettyPrint;
url = "https://" + domainName + "/apis/v1/rest/recipes";
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 != 200) {
process.exit(status);
}
}
function create(filename) {
debug("Creating Recipe from file [" + filename + "]");
rest.postUploadFile(url, username, password, timeout, undefined, filename,"recipe", processResponse);
}
function list(recipeUid) {
if (recipeUid) url += "/" + recipeUid;
debug("List Recipes [" + recipeUid + "]");
rest.get(url, username, password, timeout, processResponse);
}
function del(recipeUid) {
debug("Deleting Recipe with ID [" + recipeUid + "]");
url += "/" + recipeUid;
rest.del(url, username, password, timeout, {}, processResponse);
}
module.exports = { help, init, list, del, create };