Skip to content

Commit 754e6e9

Browse files
committed
wip updates for 10.12 apis
1 parent 3a2e46c commit 754e6e9

File tree

4 files changed

+362
-17
lines changed

4 files changed

+362
-17
lines changed

projects.js

Lines changed: 41 additions & 7 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,32 @@ 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+
prettyprint = inPrettyprint;
26+
27+
url = "https://" + domainName + "/apis/v1/rest/projects";
2528
//console.log("Username [" + username + "]");
2629
//console.log("URL [" + url + "]");
2730
//console.log("Timeout [" + timeout + "]");
2831
}
2932

30-
function processResponse(data,status)
31-
{
32-
33-
console.log(JSON.stringify(data));
33+
/**
34+
* Call back function to process REST response
35+
* @param {return data from REST request} data
36+
* @param {status} status
37+
*/
38+
function processResponse(data,status){
39+
if(prettyprint==true){
40+
console.log(JSON.stringify(data,null,4));
41+
}
42+
else{
43+
console.log(JSON.stringify(data));
44+
}
45+
3446
if(status!=0){
3547
process.exit(status);
3648
}
@@ -42,6 +54,11 @@ function list(projectId){
4254
request.get(url,username,password,timeout,processResponse);
4355
}
4456

57+
function listAssets(projectId){
58+
if(projectId)url+="/" + projectId + "/assets";
59+
request.get(url,username,password,timeout,processResponse);
60+
}
61+
4562
function create(projectName){
4663
var data={"name":projectName};
4764
request.post(url,username,password,timeout,data,processResponse);
@@ -54,7 +71,24 @@ function update(projectId, projectName){
5471
request.put(url,username,password,timeout,data,processResponse);
5572
}
5673

74+
/**
75+
* Pushes a deployment to a destination tenant
76+
* @param {deployment name} name
77+
* @param {tenant username} tenantUn
78+
* @param {tenant password} tenantPw
79+
* @param {tenant url} tenantUrl
80+
* @param {array of workflow ids} workflows
81+
* @param {array of flowservice names} flowServices
82+
* @param {array of restAPIs} restAPIs
83+
* @param {array of soapAPIs} soapAPIs
84+
* @param {array of listeners} listeners
85+
* @param {array of messaging subscribers} messagings
86+
*/
87+
function push(name,tenantUn,tenantPw,tenantUrl,workflows,flowServices,restAPIs,soapAPIs,listeners,messagings)
88+
{
89+
90+
}
5791

5892

5993

60-
module.exports = { init, list, create, update };
94+
module.exports = { init, list, listAssets, create, update };

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)