From 1404710af0f8919d47bc241725ce22e6f6709278 Mon Sep 17 00:00:00 2001 From: sagpembo Date: Wed, 12 Jun 2024 11:23:54 +0100 Subject: [PATCH] added delete-users and list users experimental features --- experimental.js | 101 ++++++++++++++++++++++++++++++++++++++++++++---- rest-fetch.js | 20 ++++++---- wmiocli.js | 17 ++++++++ 3 files changed, 123 insertions(+), 15 deletions(-) diff --git a/experimental.js b/experimental.js index bbeceef..5e7baa6 100644 --- a/experimental.js +++ b/experimental.js @@ -19,7 +19,9 @@ var url; var authtoken=""; var uid=""; +var userUid = ""; var csrf=""; +var filterUsername=""; var projectId; var workflowId; var projectName ; @@ -71,10 +73,6 @@ function generateUUID(){ return guidstring; } -function debug(message){ - logger.debug(" " + message); -} - function init(inDomainName, inUsername, inPassword,inTimeout,inPrettyprint){ logger.warn("EXPERIMENTAL/UNSUPPORTED APIs - USE THESE AT YOUR OWN RISK"); @@ -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; @@ -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 + "]"); @@ -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 + "]"); @@ -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}); @@ -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){ @@ -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"); // console.log(res); @@ -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; @@ -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, @@ -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')) { @@ -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); } diff --git a/wmiocli.js b/wmiocli.js index 1ba25cd..0c293a4 100644 --- a/wmiocli.js +++ b/wmiocli.js @@ -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 ', { 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(() => { @@ -1000,6 +1016,7 @@ program.command('experimental-flowservice-http