Skip to content

Commit 1404710

Browse files
committed
added delete-users and list users experimental features
1 parent 8aa0743 commit 1404710

File tree

3 files changed

+123
-15
lines changed

3 files changed

+123
-15
lines changed

experimental.js

Lines changed: 94 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ var url;
1919

2020
var authtoken="";
2121
var uid="";
22+
var userUid = "";
2223
var csrf="";
24+
var filterUsername="";
2325
var projectId;
2426
var workflowId;
2527
var projectName ;
@@ -71,10 +73,6 @@ function generateUUID(){
7173
return guidstring;
7274
}
7375

74-
function debug(message){
75-
logger.debug("<EXPERIMENTAL> " + message);
76-
}
77-
7876
function init(inDomainName, inUsername, inPassword,inTimeout,inPrettyprint){
7977

8078
logger.warn("EXPERIMENTAL/UNSUPPORTED APIs - USE THESE AT YOUR OWN RISK");
@@ -90,6 +88,20 @@ function init(inDomainName, inUsername, inPassword,inTimeout,inPrettyprint){
9088
}
9189

9290

91+
function getUserList(inUsername)
92+
{
93+
filterUsername = inUsername;
94+
finalCall = getUsers;
95+
loginPhase1();
96+
}
97+
98+
function deleteUser(inUid)
99+
{
100+
userUid = inUid
101+
finalCall = deleteIntegrationUser;
102+
loginPhase1();
103+
}
104+
93105
function flowserviceDetails(inProjectId,includeEdgeFlows)
94106
{
95107
projectId = inProjectId;
@@ -98,6 +110,24 @@ function flowserviceDetails(inProjectId,includeEdgeFlows)
98110
loginPhase1();
99111
}
100112

113+
function deleteIntegrationUser()
114+
{
115+
logger.debug("Deleting Integration User [" + userUid + "]");
116+
var endPoint = "https://" +domainName + "/enterprise/v1/users/" + userUid;
117+
var body;
118+
logger.debug("Next URL [" + endPoint + "]");
119+
var headers = setHeaders(true);
120+
headers.push({name:"Accept", value:"application/json, text/plain, */*"});
121+
headers.push({name:"accept-encoding", value:"gzip, deflate, br"});
122+
headers.push({name:"content-type", value:"application/json"});
123+
headers.push({name:"Connection", value:"keep-alive"});
124+
headers.push({name:"DNT", value:"1"});
125+
headers.push({name:"Cache-Control", value:"no-cache"});
126+
headers.push({name:"Origin",value:"https://" +domainName});
127+
headers.push({name:"Referer",value:"https://" +domainName + "/"});
128+
rest_fetch.custom(endPoint,undefined,undefined,timeout,body,undefined,"DELETE",processResponse,headers,true,false);
129+
}
130+
101131
function processflowDetails()
102132
{
103133
logger.debug("Process FlowService Details - Project [" + projectId + "] Include Edge flows [" + incEdgeFlows + "]");
@@ -168,6 +198,16 @@ function flowserviceScheduler(inFlowServiceId, inScheduleStatus, inProjectId)
168198
loginPhase1();
169199
}
170200

201+
function getUsers()
202+
{
203+
logger.debug("Getting Integration User [" + username + "]");
204+
var endPoint = "https://" +domainName + "/enterprise/v1/tenant/users";
205+
logger.debug("Next URL [" + endPoint + "]");
206+
var headers = setHeaders();
207+
var body;
208+
rest_fetch.custom(endPoint,undefined,undefined,timeout,body,undefined,"GET",processUserListResponse,headers,true,false);
209+
}
210+
171211
function processScheduleStatus()
172212
{
173213
logger.debug("Process FlowService Schedule Status - Project [" + projectId + "] FlowService [" + flowServiceId + "] Status [" + scheduleStatus + "]");
@@ -355,15 +395,19 @@ function processMonitorBody()
355395
return body;
356396
}
357397

358-
function setHeaders()
398+
function setHeaders(omitAccept)
359399
{
360400
var headers = [
361401
{name:"authtoken",value:authtoken},
362-
{name:"accept",value:"application/json"},
363402
{name:"X-Requested-With",value:"XMLHttpRequest"},
364403
{name:"X-Request-ID",value:generateUUID()},
365404
{name:"x-csrf-token",value:csrf},
366405
];
406+
407+
if(omitAccept===undefined || omitAccept===null || omitAccept==false){
408+
headers.push({name:"accept",value:"application/json"});
409+
}
410+
367411
if(projectId!==undefined && projectId!==null && projectId.length>0)
368412
{
369413
headers.push({name:"Project_uid",value:projectId});
@@ -1046,6 +1090,9 @@ function processProjectsResponse(url,err,body,res){
10461090
}
10471091

10481092
function processResponse(url,err,body,res){
1093+
if(err!==undefined && err!==null)logger.error(err);
1094+
logger.debug("HTTP Response Status [" + res.status + "]");
1095+
logger.debug("HTTP Resposne Status Text [" + res.statusText + "]");
10491096
if(res.status==200)
10501097
{
10511098
if(prettyprint==true){
@@ -1063,6 +1110,45 @@ function processResponse(url,err,body,res){
10631110
}
10641111
}
10651112

1113+
1114+
function processUserListResponse(url,err,body,res){
1115+
1116+
if(res.status==200)
1117+
{
1118+
var jsonObj={};
1119+
jsonObj.output={};
1120+
if(filterUsername!==undefined && filterUsername !== null && filterUsername.length>0){
1121+
//Filter down to the right user
1122+
//console.log("**********" + body.output.objects[0].wmic_username);
1123+
for(var j=0;j<body.output.objects.length;j++){
1124+
if(body.output.objects[j].wmic_username==filterUsername){
1125+
var objects=[];
1126+
objects.push(body.output.objects[j]);
1127+
jsonObj.output.objects=objects;
1128+
break;
1129+
}
1130+
}
1131+
}
1132+
else{
1133+
jsonObj = body;
1134+
}
1135+
1136+
if(prettyprint==true){
1137+
console.log(JSON.stringify(jsonObj,null,4));
1138+
}
1139+
else{
1140+
console.log((JSON.stringify(jsonObj)));
1141+
}
1142+
}
1143+
else
1144+
{
1145+
if(jsonObj!==null)console.log((JSON.stringify(jsonObj)));
1146+
else logger.warn("Failed to login via Software AG Cloud - exiting");
1147+
process.exit(99);
1148+
}
1149+
}
1150+
1151+
10661152
function processUserResponse(url,err,body,res){
10671153
if(res.status==200)
10681154
{
@@ -1163,7 +1249,8 @@ function loginResponse(url,err,body,res){
11631249

11641250

11651251
module.exports = {init, help,
1166-
user,stages,
1252+
user,getUserList,deleteUser,
1253+
stages,
11671254
searchProject,
11681255
projectDeployments,
11691256
projectWorkflows,projectFlowservices,

rest-fetch.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ function error(message){
3737

3838
function addAllCookies(res,domainName){
3939
domain = domainName;
40+
if(res===undefined || res ===null || res.headers===undefined||res.headers==null){
41+
logger.warn("No Response/Heaaders found");
42+
return;
43+
}
4044
const setCookieHeaders = res.headers.raw()['set-cookie'];
4145
// console.log("res--->");
4246
// console.log(res);
@@ -85,7 +89,7 @@ function displayCookies()
8589
function enableProxy(options){
8690
if(proxy)
8791
{
88-
info("Enabling Proxy");
92+
info("Enabling Proxy: " + proxy);
8993
//options.proxy = proxy;
9094
proxyAgent = new HttpsProxyAgent(proxy)
9195
options.agent = proxyAgent;
@@ -285,9 +289,9 @@ function del(restEndPoint,user,pass,timeout,data,callback){
285289

286290

287291
async function custom(restEndPoint,user,pass,timeout,jsonBody,formBody,type,callback,headers,jsonFlag,redirect,filename,formObject){
288-
info("FETCH Custom REST call Started");
289-
290-
//debug("User: " + user);
292+
info("FETCH Custom REST call Started [" + restEndPoint + "]");
293+
debug("Type [" + type + "]");
294+
291295
var options = {
292296
url: restEndPoint,
293297
method: type,
@@ -385,12 +389,13 @@ async function custom(restEndPoint,user,pass,timeout,jsonBody,formBody,type,call
385389

386390
if(cookieStr.length>0)options.headers['Cookie']= cookieStr;
387391

388-
//debug("Options\n " + JSON.stringify(options) + "\n -----");
392+
debug("Options [\n " + JSON.stringify(options) + "\n ]");
389393
var response;
390394
var data;
391-
var err=undefined;
392-
try{
395+
var err=undefined; try{
396+
debug("Making call to Endpoint [" + restEndPoint + "]");
393397
response = await fetch(restEndPoint,options);
398+
394399
// Check if the response has a Content-Type header
395400
const contentType = response.headers.get('Content-Type');
396401
if (contentType && contentType.includes('application/json')) {
@@ -411,7 +416,6 @@ async function custom(restEndPoint,user,pass,timeout,jsonBody,formBody,type,call
411416
finally{
412417
//Implement if needed
413418
}
414-
415419
return callback(restEndPoint,err,data,response,filename);
416420
}
417421

wmiocli.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,22 @@ program.command('experimental-user', { hidden: hideExperimental })
820820
experimental.user();
821821
});
822822

823+
program.command('experimental-user-list [username]', { hidden: hideExperimental })
824+
.description('Get list of users from integration, or for a single user with the given username')
825+
.action((username) => {
826+
checkOptions();
827+
experimental.init(tenantDomain, tenantUser, tenantPw, program.opts().timeout, program.opts().prettyprint)
828+
experimental.getUserList(username);
829+
})
830+
831+
program.command('experimental-user-delete <username>', { hidden: hideExperimental })
832+
.description('Deletes a user from integration only')
833+
.action((username) => {
834+
checkOptions();
835+
experimental.init(tenantDomain, tenantUser, tenantPw, program.opts().timeout, program.opts().prettyprint)
836+
experimental.deleteUser(username);
837+
})
838+
823839
program.command('experimental-stages', { hidden: hideExperimental })
824840
.description('Get Stage information')
825841
.action(() => {
@@ -1000,6 +1016,7 @@ program.command('experimental-flowservice-http <project-id> <flowservice-id> <en
10001016
experimental.init(tenantDomain, tenantUser, tenantPw, program.opts().timeout, program.opts().prettyprint)
10011017
experimental.flowserviceDetails(projectId,"false");
10021018
})
1019+
10031020

10041021
program.parse();
10051022

0 commit comments

Comments
 (0)