Skip to content

Commit

Permalink
Merge pull request #25 from SoftwareAG/development
Browse files Browse the repository at this point in the history
added delete-users and list users experimental features
  • Loading branch information
sagpembo authored Jun 12, 2024
2 parents 8aa0743 + 1404710 commit 8eb13be
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 15 deletions.
101 changes: 94 additions & 7 deletions experimental.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ var url;

var authtoken="";
var uid="";
var userUid = "";
var csrf="";
var filterUsername="";
var projectId;
var workflowId;
var projectName ;
Expand Down Expand Up @@ -71,10 +73,6 @@ function generateUUID(){
return guidstring;
}

function debug(message){
logger.debug("<EXPERIMENTAL> " + message);
}

function init(inDomainName, inUsername, inPassword,inTimeout,inPrettyprint){

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


function getUserList(inUsername)
{
filterUsername = inUsername;
finalCall = getUsers;
loginPhase1();
}

function deleteUser(inUid)
{
userUid = inUid
finalCall = deleteIntegrationUser;
loginPhase1();
}

function flowserviceDetails(inProjectId,includeEdgeFlows)
{
projectId = inProjectId;
Expand All @@ -98,6 +110,24 @@ function flowserviceDetails(inProjectId,includeEdgeFlows)
loginPhase1();
}

function deleteIntegrationUser()
{
logger.debug("Deleting Integration User [" + userUid + "]");
var endPoint = "https://" +domainName + "/enterprise/v1/users/" + userUid;
var body;
logger.debug("Next URL [" + endPoint + "]");
var headers = setHeaders(true);
headers.push({name:"Accept", value:"application/json, text/plain, */*"});
headers.push({name:"accept-encoding", value:"gzip, deflate, br"});
headers.push({name:"content-type", value:"application/json"});
headers.push({name:"Connection", value:"keep-alive"});
headers.push({name:"DNT", value:"1"});
headers.push({name:"Cache-Control", value:"no-cache"});
headers.push({name:"Origin",value:"https://" +domainName});
headers.push({name:"Referer",value:"https://" +domainName + "/"});
rest_fetch.custom(endPoint,undefined,undefined,timeout,body,undefined,"DELETE",processResponse,headers,true,false);
}

function processflowDetails()
{
logger.debug("Process FlowService Details - Project [" + projectId + "] Include Edge flows [" + incEdgeFlows + "]");
Expand Down Expand Up @@ -168,6 +198,16 @@ function flowserviceScheduler(inFlowServiceId, inScheduleStatus, inProjectId)
loginPhase1();
}

function getUsers()
{
logger.debug("Getting Integration User [" + username + "]");
var endPoint = "https://" +domainName + "/enterprise/v1/tenant/users";
logger.debug("Next URL [" + endPoint + "]");
var headers = setHeaders();
var body;
rest_fetch.custom(endPoint,undefined,undefined,timeout,body,undefined,"GET",processUserListResponse,headers,true,false);
}

function processScheduleStatus()
{
logger.debug("Process FlowService Schedule Status - Project [" + projectId + "] FlowService [" + flowServiceId + "] Status [" + scheduleStatus + "]");
Expand Down Expand Up @@ -355,15 +395,19 @@ function processMonitorBody()
return body;
}

function setHeaders()
function setHeaders(omitAccept)
{
var headers = [
{name:"authtoken",value:authtoken},
{name:"accept",value:"application/json"},
{name:"X-Requested-With",value:"XMLHttpRequest"},
{name:"X-Request-ID",value:generateUUID()},
{name:"x-csrf-token",value:csrf},
];

if(omitAccept===undefined || omitAccept===null || omitAccept==false){
headers.push({name:"accept",value:"application/json"});
}

if(projectId!==undefined && projectId!==null && projectId.length>0)
{
headers.push({name:"Project_uid",value:projectId});
Expand Down Expand Up @@ -1046,6 +1090,9 @@ function processProjectsResponse(url,err,body,res){
}

function processResponse(url,err,body,res){
if(err!==undefined && err!==null)logger.error(err);
logger.debug("HTTP Response Status [" + res.status + "]");
logger.debug("HTTP Resposne Status Text [" + res.statusText + "]");
if(res.status==200)
{
if(prettyprint==true){
Expand All @@ -1063,6 +1110,45 @@ function processResponse(url,err,body,res){
}
}


function processUserListResponse(url,err,body,res){

if(res.status==200)
{
var jsonObj={};
jsonObj.output={};
if(filterUsername!==undefined && filterUsername !== null && filterUsername.length>0){
//Filter down to the right user
//console.log("**********" + body.output.objects[0].wmic_username);
for(var j=0;j<body.output.objects.length;j++){
if(body.output.objects[j].wmic_username==filterUsername){
var objects=[];
objects.push(body.output.objects[j]);
jsonObj.output.objects=objects;
break;
}
}
}
else{
jsonObj = body;
}

if(prettyprint==true){
console.log(JSON.stringify(jsonObj,null,4));
}
else{
console.log((JSON.stringify(jsonObj)));
}
}
else
{
if(jsonObj!==null)console.log((JSON.stringify(jsonObj)));
else logger.warn("Failed to login via Software AG Cloud - exiting");
process.exit(99);
}
}


function processUserResponse(url,err,body,res){
if(res.status==200)
{
Expand Down Expand Up @@ -1163,7 +1249,8 @@ function loginResponse(url,err,body,res){


module.exports = {init, help,
user,stages,
user,getUserList,deleteUser,
stages,
searchProject,
projectDeployments,
projectWorkflows,projectFlowservices,
Expand Down
20 changes: 12 additions & 8 deletions rest-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ function error(message){

function addAllCookies(res,domainName){
domain = domainName;
if(res===undefined || res ===null || res.headers===undefined||res.headers==null){
logger.warn("No Response/Heaaders found");
return;
}
const setCookieHeaders = res.headers.raw()['set-cookie'];
// console.log("res--->");
// console.log(res);
Expand Down Expand Up @@ -85,7 +89,7 @@ function displayCookies()
function enableProxy(options){
if(proxy)
{
info("Enabling Proxy");
info("Enabling Proxy: " + proxy);
//options.proxy = proxy;
proxyAgent = new HttpsProxyAgent(proxy)
options.agent = proxyAgent;
Expand Down Expand Up @@ -285,9 +289,9 @@ function del(restEndPoint,user,pass,timeout,data,callback){


async function custom(restEndPoint,user,pass,timeout,jsonBody,formBody,type,callback,headers,jsonFlag,redirect,filename,formObject){
info("FETCH Custom REST call Started");

//debug("User: " + user);
info("FETCH Custom REST call Started [" + restEndPoint + "]");
debug("Type [" + type + "]");

var options = {
url: restEndPoint,
method: type,
Expand Down Expand Up @@ -385,12 +389,13 @@ async function custom(restEndPoint,user,pass,timeout,jsonBody,formBody,type,call

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

//debug("Options\n " + JSON.stringify(options) + "\n -----");
debug("Options [\n " + JSON.stringify(options) + "\n ]");
var response;
var data;
var err=undefined;
try{
var err=undefined; try{
debug("Making call to Endpoint [" + restEndPoint + "]");
response = await fetch(restEndPoint,options);

// Check if the response has a Content-Type header
const contentType = response.headers.get('Content-Type');
if (contentType && contentType.includes('application/json')) {
Expand All @@ -411,7 +416,6 @@ async function custom(restEndPoint,user,pass,timeout,jsonBody,formBody,type,call
finally{
//Implement if needed
}

return callback(restEndPoint,err,data,response,filename);
}

Expand Down
17 changes: 17 additions & 0 deletions wmiocli.js
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,22 @@ program.command('experimental-user', { hidden: hideExperimental })
experimental.user();
});

program.command('experimental-user-list [username]', { hidden: hideExperimental })
.description('Get list of users from integration, or for a single user with the given username')
.action((username) => {
checkOptions();
experimental.init(tenantDomain, tenantUser, tenantPw, program.opts().timeout, program.opts().prettyprint)
experimental.getUserList(username);
})

program.command('experimental-user-delete <username>', { hidden: hideExperimental })
.description('Deletes a user from integration only')
.action((username) => {
checkOptions();
experimental.init(tenantDomain, tenantUser, tenantPw, program.opts().timeout, program.opts().prettyprint)
experimental.deleteUser(username);
})

program.command('experimental-stages', { hidden: hideExperimental })
.description('Get Stage information')
.action(() => {
Expand Down Expand Up @@ -1000,6 +1016,7 @@ program.command('experimental-flowservice-http <project-id> <flowservice-id> <en
experimental.init(tenantDomain, tenantUser, tenantPw, program.opts().timeout, program.opts().prettyprint)
experimental.flowserviceDetails(projectId,"false");
})


program.parse();

Expand Down

0 comments on commit 8eb13be

Please sign in to comment.