Skip to content

Commit 5d20209

Browse files
authored
Merge pull request #2 from SoftwareAG/development_v10.12
Development v10.12
2 parents a905463 + bebabf7 commit 5d20209

File tree

7 files changed

+460
-36
lines changed

7 files changed

+460
-36
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"Software",
1919
"AG",
2020
"wmiocli"
21-
2221
],
2322
"author": "Dave Pemberton",
2423
"license": "Apache-2.0",

projects.js

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
const request = require('./rest.js');
88

99
var domainName, username,password,timeout;
10+
var prettyprint = false;
1011
var url;
1112

1213
function checkForErrors(inBody)
@@ -16,21 +17,29 @@ function checkForErrors(inBody)
1617

1718
}
1819

19-
function init(inDomainName, inUsername, inPassword,inTimeout){
20+
function init(inDomainName, inUsername, inPassword,inTimeout,inPrettyprint){
2021
domainName = inDomainName;
2122
username = inUsername;
2223
password = inPassword;
2324
timeout = inTimeout;
24-
url = "https://" + domainName + "/enterprise/v1/rest/projects";
25-
//console.log("Username [" + username + "]");
26-
//console.log("URL [" + url + "]");
27-
//console.log("Timeout [" + timeout + "]");
28-
}
25+
prettyprint = inPrettyprint;
2926

30-
function processResponse(data,status)
31-
{
27+
url = "https://" + domainName + "/apis/v1/rest/projects";
28+
}
3229

33-
console.log(JSON.stringify(data));
30+
/**
31+
* Call back function to process REST response
32+
* @param {return data from REST request} data
33+
* @param {status} status
34+
*/
35+
function processResponse(data,status){
36+
if(prettyprint==true){
37+
console.log(JSON.stringify(data,null,4));
38+
}
39+
else{
40+
console.log(JSON.stringify(data));
41+
}
42+
3443
if(status!=0){
3544
process.exit(status);
3645
}
@@ -42,6 +51,11 @@ function list(projectId){
4251
request.get(url,username,password,timeout,processResponse);
4352
}
4453

54+
function listAssets(projectId){
55+
if(projectId)url+="/" + projectId + "/assets";
56+
request.get(url,username,password,timeout,processResponse);
57+
}
58+
4559
function create(projectName){
4660
var data={"name":projectName};
4761
request.post(url,username,password,timeout,data,processResponse);
@@ -54,7 +68,52 @@ function update(projectId, projectName){
5468
request.put(url,username,password,timeout,data,processResponse);
5569
}
5670

71+
function del(projectId){
72+
73+
url += "/" + projectId;
74+
var data={};
75+
request.httpDelete(url,username,password,timeout,data,processResponse);
76+
}
77+
78+
79+
80+
/**
81+
* Pushes a deployment to a destination tenant
82+
* @param {deployment name} name
83+
* @param {tenant username} destTenantuser
84+
* @param {tenant password} destTenantPw
85+
* @param {tenant url} destTenantDomainName
86+
* @param {assets to publish} assets
87+
*/
88+
function pub(projectId,publishName,targetTenantDomainName,targetUserId,targetUserPassword,assetsJson){
89+
//{"output":{"workflows":["fla73a20e13dd6736cf9c355","fl3cfd145262bbc5d44acff3"],"flows":["mapLeads"],"rest_api":[],"soap_api":[],"listener":[],"messaging":[]}}
90+
url += "/" + projectId + "/push";
91+
92+
var jsonStr='{';
93+
jsonStr+='"name": "' + publishName + '",';
94+
jsonStr+='"destination_tenant_detail": {';
95+
jsonStr+='"username": "' + targetUserId + '",';
96+
jsonStr+='"password": "' + targetUserPassword + '",';
97+
jsonStr+='"url": "' + "https://" + targetTenantDomainName + '"';
98+
jsonStr+='},';
99+
assetsJson = assetsJson.replace(/\"flows\"/g, "\"flow_services\"");
100+
jsonStr+=assetsJson.substring(11,assetsJson.length-2);
101+
jsonStr+="}";
57102

103+
data = JSON.parse(jsonStr);
104+
request.post(url,username,password,timeout,data,processResponse)
105+
}
58106

107+
/**
108+
*
109+
* @param {publish name} publishName
110+
* @param {version number} version
111+
*/
112+
function deploy(projectName, version)
113+
{
114+
url += "/" + projectName + "/deploy";
115+
data={"version":parseInt(version)};
116+
request.post(url,username,password,timeout,data,processResponse);
117+
}
59118

60-
module.exports = { init, list, create, update };
119+
module.exports = { init, list, listAssets, create, update, del, pub, deploy};

rest.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ function put(restEndPoint,user,pass,timeout,data,callback){
4848
sendBody(restEndPoint,user,pass,timeout,data,'PUT',callback);
4949
}
5050

51+
function httpDelete(restEndPoint,user,pass,timeout,data,callback){
52+
sendBody(restEndPoint,user,pass,timeout,data,'DELETE',callback);
53+
}
54+
55+
5156
function post(restEndPoint,user,pass,timeout,data,callback){
5257
sendBody(restEndPoint,user,pass,timeout,data,'POST',callback);
5358
}
@@ -229,4 +234,4 @@ function del(restEndPoint,user,pass,timeout,data,callback){
229234
});
230235
}
231236

232-
module.exports = { get, post, put, del, postDownloadFile, postUploadFile, downloadFile };
237+
module.exports = { get, post, put, del, postDownloadFile, postUploadFile, downloadFile, httpDelete };

roles.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* webMethods.io CLI
3+
* Copyright 2022 Software AG
4+
* Apache-2.0
5+
* [roles.js] Project Roles APIs
6+
*/
7+
8+
const request = require('./rest.js');
9+
const dbg = require('./debug.js');
10+
11+
var domainName, username,password,timeout;
12+
var prettyprint;
13+
var url;
14+
15+
function checkForErrors(inBody)
16+
{
17+
//Error Codes
18+
//Any error response
19+
20+
}
21+
22+
function debug(message){
23+
dbg.message("<ROLES> " + message);
24+
}
25+
26+
27+
function init(inDomainName, inUsername, inPassword,inTimeout,inPrettyprint){
28+
domainName = inDomainName;
29+
username = inUsername;
30+
password = inPassword;
31+
timeout = inTimeout;
32+
prettyprint = inPrettyprint;
33+
url = "https://" + domainName + "/apis/v1/rest";
34+
//console.log("Username [" + username + "]");
35+
//console.log("URL [" + url + "]");
36+
//console.log("Timeout [" + timeout + "]");
37+
}
38+
39+
/**
40+
* Call back function to process REST response
41+
* @param {return data from REST request} data
42+
* @param {status} status
43+
*/
44+
function processResponse(data,status){
45+
if(prettyprint==true){
46+
console.log(JSON.stringify(data,null,4));
47+
}
48+
else{
49+
console.log(JSON.stringify(data));
50+
}
51+
52+
if(status!=0){
53+
process.exit(status);
54+
}
55+
}
56+
57+
58+
function list(roleId){
59+
url+="/roles";
60+
if(roleId)url+="/" + roleId
61+
request.get(url,username,password,timeout,processResponse);
62+
}
63+
64+
function parseRoleListInput(rolesList) {
65+
var arr = rolesList.split(";");
66+
var jsonStr = '[';
67+
for (var rolesCount = 0; rolesCount < arr.length; rolesCount++) {
68+
var roleDetail = arr[rolesCount].split(",");
69+
jsonStr += '{"' + roleDetail[0] + '": [';
70+
for (var permsCount = 1; permsCount < roleDetail.length; permsCount++) {
71+
jsonStr += '"' + roleDetail[permsCount] + '"';
72+
if (permsCount < roleDetail.length - 1)
73+
jsonStr += ",";
74+
}
75+
jsonStr += "]}";
76+
if (rolesCount < arr.length - 1)
77+
jsonStr += ",";
78+
}
79+
jsonStr += "]";
80+
var projects = JSON.parse(jsonStr);
81+
return projects;
82+
}
83+
84+
function insert(name,description,projects){
85+
url+="/roles";
86+
projects = parseRoleListInput(projects);
87+
var data={"name":name,"description":description, projects};
88+
request.post(url,username,password,timeout,data,processResponse);
89+
}
90+
91+
function update(roleId, name,description,projects){
92+
url+="/roles/" + roleId;
93+
projects = parseRoleListInput(projects);
94+
var data={"name":name,"description":description, projects};
95+
request.put(url,username,password,timeout,data,processResponse);
96+
}
97+
98+
function del(roleId){
99+
url+="/roles/" + roleId;
100+
debug("Delte URL: " + url);
101+
request.del(url,username,password,timeout,undefined,processResponse);
102+
}
103+
104+
module.exports = { init, list, insert, update, del };

users.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* webMethods.io CLI
3+
* Copyright 2022 Software AG
4+
* Apache-2.0
5+
* [users.js] Users APIs
6+
*/
7+
8+
const request = require('./rest.js');
9+
const dbg = require('./debug.js');
10+
11+
var domainName, username,password,timeout;
12+
var prettyprint;
13+
var url;
14+
15+
function checkForErrors(inBody)
16+
{
17+
//Error Codes
18+
//Any error response
19+
20+
}
21+
22+
function debug(message){
23+
dbg.message("<USERS> " + message);
24+
}
25+
26+
27+
function init(inDomainName, inUsername, inPassword,inTimeout,inPrettyprint){
28+
domainName = inDomainName;
29+
username = inUsername;
30+
password = inPassword;
31+
timeout = inTimeout;
32+
prettyprint = inPrettyprint;
33+
url = "https://" + domainName + "/apis/v1/rest";
34+
//console.log("Username [" + username + "]");
35+
//console.log("URL [" + url + "]");
36+
//console.log("Timeout [" + timeout + "]");
37+
}
38+
39+
/**
40+
* Call back function to process REST response
41+
* @param {return data from REST request} data
42+
* @param {status} status
43+
*/
44+
function processResponse(data,status){
45+
if(prettyprint==true){
46+
console.log(JSON.stringify(data,null,4));
47+
}
48+
else{
49+
console.log(JSON.stringify(data));
50+
}
51+
52+
if(status!=0){
53+
process.exit(status);
54+
}
55+
}
56+
57+
58+
function list(userId){
59+
url+="/users";
60+
if(userId)url+="/" + userId
61+
debug("USERS URL: " + url);
62+
request.get(url,username,password,timeout,processResponse);
63+
}
64+
65+
function parseRoleListInput(rolesList) {
66+
var arr = rolesList.split(";");
67+
var jsonStr = '[';
68+
for (var rolesCount = 0; rolesCount < arr.length; rolesCount++) {
69+
var roleDetail = arr[rolesCount].split(",");
70+
jsonStr += '{"' + roleDetail[0] + '": [';
71+
for (var permsCount = 1; permsCount < roleDetail.length; permsCount++) {
72+
jsonStr += '"' + roleDetail[permsCount] + '"';
73+
if (permsCount < roleDetail.length - 1)
74+
jsonStr += ",";
75+
}
76+
jsonStr += "]}";
77+
if (rolesCount < arr.length - 1)
78+
jsonStr += ",";
79+
}
80+
jsonStr += "]";
81+
var projects = JSON.parse(jsonStr);
82+
return projects;
83+
}
84+
85+
function assignRoles(userid, roles){
86+
url += "/assign-roles";
87+
debug("URL is [" + url + "]");
88+
roles = roles.split(",");
89+
data={"username":userid,roles};
90+
console.log(data);
91+
request.put(url,username,password,timeout,data,processResponse);
92+
}
93+
94+
module.exports = { init, list, assignRoles };

0 commit comments

Comments
 (0)