From 3df0bbde902bc4bf603f12094383399e1fc3168f Mon Sep 17 00:00:00 2001 From: sagpembo Date: Tue, 26 Jul 2022 13:34:28 +0100 Subject: [PATCH 1/7] changed debug to be global moved help text to each function added experimental apis (use at own risk) --- .gitignore | 2 + README.md | 272 +++++++++++++++++++++++++++---- flowservice.js | 38 ++++- projects.js | 279 +++++++++++++++++++++++--------- recipe.js | 66 +++++--- rest.js | 155 +++++++++++++++++- roles.js | 91 +++++++---- themes.js | 183 +++++++++++++-------- unofficial.js | 407 ++++++++++++++++++++++++++++++++++++++++++++++ users.js | 1 - wmiocli.js | 428 ++++++++++++------------------------------------- workflow.js | 118 +++++++++----- 12 files changed, 1447 insertions(+), 593 deletions(-) create mode 100644 unofficial.js diff --git a/.gitignore b/.gitignore index c2658d7..b8e0d43 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ node_modules/ +ca.pem +test.sh diff --git a/README.md b/README.md index df97ad5..9d22cef 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ This CLI tool has been tested against This project is licensed under the Apache 2.0 License - see the LICENSE file for details These tools are provided as-is and without warranty or support. They do not constitute part of the Software AG product suite. Users are free to use, fork and modify them, subject to the license agreement. While Software AG welcomes contributions, we cannot guarantee to include every contribution in the master project. -Contact us via the TECHcommunity if you have any questions. +Contact us via the TECHcommunity (https://techcommunity.softwareag.com/) if you have any questions. # Installation ``` @@ -32,39 +32,103 @@ node wmiocli.js --help Usage: wmiocli [options] [command] Options: - -V, --version output the version number - -d, --domain Tenant Doamin Name, e.g. "tenant.int-aws-us.webmethods.io" - -u, --user Tenant User ID - -p, --password Tenant User Password - -t, --timeout timeout in seconds (default: one minute) - --prettyprint Pretty Print JSON output - --verbose Verbose output useful for diagnosing issues - -h, --help display help for command + -V, --version + output the version number + -d, --domain + Tenant Doamin Name, e.g. "tenant.int-aws-us.webmethods.io" + -u, --user + Tenant User ID + -p, --password + Tenant User Password + -t, --timeout + timeout in seconds (default: one minute) + --prettyprint + Pretty Print JSON output + --verbose + Verbose output useful for diagnosing issues + -h, --help + display help for command Commands: - project [project-name] Lists all projects or view an individual project, specified via project name or uid - project-assets Lists project assets from given project name or uid - project-create Create project with given name - project-update Update project with new name - project-delete Delete project with given id + project [project-name] + Lists all projects or view an individual project, specified via project name or uid + project-assets + Lists project assets from given project name or uid + project-create + Create project with given name + project-update + Update project with new name + project-delete + Delete project with given id project-publish Pubilsh project to another tenant with given id - project-deploy deploy published project with given version into tenant - role [role-id] Lists all roles or views an individual role - role-create Create roles and specify the permissions for that role. Roles-list should be provided as follows projectName,r,w,e;project name 2,r; - role-update Create roles and specify the permissions for that role. Roles-list should be provided as follows projectName,r,w,e;project name 2,r; - role-delete Delete a roles with the given role id - user Lists all users - user-role-assignment Assigns a user to roles - workflow-export Export workflow with id from project - workflow-import Import workflow into project from file - workflow-delete Delete workflow from project - workflow-execute Execute workflow from project - workflow-status Gets Execution status for workflow execution - flowservice-export Export FlowService with name from project - flowservice-import Import FlowService from into project - flowservice-delete Delete FlowService from project - flowservice-execute [input-json] Execute FlowService from project with data - help [command] display help for command + project-deploy + deploy published project with given version into tenant + project-param [param-uid] + Lists all project parameters from given project name, or specific parameter with given paramater uid + project-param-create + Creates a project parameter with given values + project-param-update + Updates a project parameter matching the provided UID with given values + project-param-delete + Deletes a project parameter mathcing the given paramater uid + project-webhooks-list + List webhooks in a project + project-webhooks-regenerate + Regenerate a webhook in a project for a given workflow UID + project-webhooks-auth + Set authenatication type (none,login,token) for a webhook in a project for a given workflow UID + role [role-id] + Lists all roles or views an individual role + role-create + Create roles and specify the permissions for that role. Roles-list should be provided as follows projectName,r,w,e;project name 2,r; + role-update + Create roles and specify the permissions for that role. Roles-list should be provided as follows projectName,r,w,e;project name 2,r; + role-delete + Delete a roles with the given role id + user + Lists all users + user-role-assignment + Assigns a user to roles + workflow-export + Export workflow with id from project + workflow-import + Import workflow into project from file + workflow-delete + Delete workflow from project + workflow-execute + Execute workflow from project + workflow-status + Gets Execution status for workflow execution + flowservice-export + Export FlowService with name from project + flowservice-import + Import FlowService from into project + flowservice-delete + Delete FlowService from project + flowservice-execute [input-json] + Execute FlowService from project with data + theme [theme-uid] + Lists themes or views an individual theme, specified via uid + theme-create [footer-text] [about-page] + Create theme with given data + theme-update [footer-text] [about-page] + Update theme with the given UID with given data + theme-delete + Delete theme with the given UID + theme-activate + Activate theme with the given UID + theme-deactivate + Deactivate theme with the given UID + recipe [recipe-uid] + List all Workflow recipes, or get a single recipe with a given recipe UID + recipe-delete + Delete Workflow recipe with a given recipe UID + recipe-create + Create Workfllow Receipt from file + unofficial [recipe-uid] + List all Workflow recipes, or get a single recipe with a given recipe UID + help [command] + display help for command Examples: @@ -122,21 +186,80 @@ Examples: -p password project-assets fl65d3aa87fc1783ea5cf8c8 - /Publish Project to another tenant: + Publish Project to another tenant: $ node wmiocli.js -d tenant.int-aws-us.webmethods.io -u user -p password - project-publish fl65d3aa87fc1783ea5cf8c8 'My deployment' 'target.int-aws-us.webmethods.io' 'targetuser' 'targetpassword' '{"output":{"workflows":["fla73a20e13dd6736cf9c355","fl3cfd145262bbc5d44acff3"],"flows":["mapLeads"],"rest_api":[],"soap_api":[],"listener":[],"messaging":[]}}' + project-publish fl65d3aa87fc1783ea5cf8c8 'My deployment' 'target.int-aws-us.webmethods.io' + 'targetuser' 'targetpassword' + '{"output":{"workflows":["fla73a20e13dd6736cf9c355","fl3cfd145262bbc5d44acff3"], + "flows":["mapLeads"],"rest_api":[],"soap_api":[],"listener":[],"messaging":[]}}' - /Deploy published Project in the tenant with the given name and deploy version: + Deploy published Project in the tenant with the given name and deploy version: $ node wmiocli.js -d tenant.int-aws-us.webmethods.io -u user -p password project-deploy projectName 1 + + List Project Workflow Parameters or gets an individual where name is specified + $ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + project-param projectName [param-name] + + Create Project Workflow Parameter + $ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + project-param-create projectName param-name param-value required isPassword + + e.g. node wmiocli.js -d env -u user -p pass project-param-create project name dave false false + + Update Project Workflow Parameter + $ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + project-param-update projectName param-uid param-name param-value required isPassword + + Delete Project Workflow Parameter + $ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + project-param-delete projectName param-uid + + Project webhooks List + $ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + project-webhooks-list [project-uid] + + Regenerate webhook token + $ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + project-webhooks-regenerate project-uid webhook-uid + + Change webhook Auth + $ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + project-webhooks-auth project-uid webhook-uid auth-type + + e.g. + node wmiocli.js -d env -u user -p pass project-webhooks-auth flf1111 flf2222 login + + Workflow Export Workflow from a given project (identified from URL in webMethods.io when in workflow canvas, @@ -237,4 +360,85 @@ Examples: -u user -p password role-delete 'roleId' + + + Recipes + + Get recipe list or individual recipe + $ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + recipe [recipe-Uid] + + Creates a Workflow recipe from a workflow export + $ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + recipe-create export-flf111111.zip + + Deletes a Workflow recipe with the provided UID + $ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + recipe-delete fl1771d591cfb4f31e558daf + + + Themes + + Lists whitelabel themes + $ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + theme [theme-uid] + + The theme settings returned can be use as a way to create the theme. + You can use jq to retrieve the theme settings by piping the output to jq, e.g. + + node wmiocli.js -d env -u user -p pass theme fl40018d9a1a273bb8aa92bf | jq -c .output.settings.theme > ~/dracula-theme.txt + + Deletes a whitelabel theme + $ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + theme-delete [theme-uid] + + Creates a new whitelabel theme + $ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + theme-create dracula 'desc' [theme-settings] "Footer Text" "About Page" + + Theme settings can be used from the list example above, e.g. + node wmiocli.js -d env -u user -p pass theme-create dracula7 'updated' "`cat ~/dracula-theme.txt`" 'Footer' 'About' + + Updates a whitelabel theme + $ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + theme-update themeid dracula 'desc' [theme-settings] "Footer Text" "About Page" + + Theme settings can be used from the list example above, e.g. + node wmiocli.js -d env -u user -p pass theme-update themeid dracula7 'updated' "`cat ~/dracula-theme.txt`" 'Footer' 'About' + + Activates a whitelabel theme + $ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + theme-activate [theme-uid] + + Deactivates a whitelabel theme + $ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + theme-deactivate [theme-uid] + ``` diff --git a/flowservice.js b/flowservice.js index 5568530..d10d3ef 100644 --- a/flowservice.js +++ b/flowservice.js @@ -15,6 +15,42 @@ function debug(message){ dbg.message(" " + message); } +function help(){ + return ` +\x1b[4mFlowService\x1b[0m + +\x1b[32mExport FlowService from a given project (identified from URL in webMethods.io when in FlowEditor +i.e. https://tenant.int-aws-us.webmethods.io/#/projects/\x1b[1mfl65d3aa87fc1783ea5cf8c8\x1b[0m\x1b[32m/flow-editor/\x1b[1mmyFlowService\x1b[0m\x1b[32m):\x1b[0m\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + flowservice-export fl65d3aa87fc1783ea5cf8c8 myFlowService export.zip + +\x1b[32mImport Flowservice from a given file into a project \x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + flowservice-import fl65d3aa87fc1783ea5cf8c8 export.zip + +\x1b[32mDelete FlowService from a given project\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + flowservice-delete fl65d3aa87fc1783ea5cf8c8 myFlowService + +\x1b[32mExecute a FlowService from a given project\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + flowservice-execute fl65d3aa87fc1783ea5cf8c8 myFlowService + +`; +} + function init(inDomainName, inUsername, inPassword,inTimeout,inPrettyPrint,projectId){ domainName = inDomainName; username = inUsername; @@ -96,4 +132,4 @@ function deleteFlowService(flowId){ rest.del(url,username,password,timeout,{},processResponse); } -module.exports = { init, exportFlowService, importFlowService, runFlowService, deleteFlowService }; +module.exports = {help, init, exportFlowService, importFlowService, runFlowService, deleteFlowService }; diff --git a/projects.js b/projects.js index 4e54689..9955ea0 100644 --- a/projects.js +++ b/projects.js @@ -5,18 +5,141 @@ */ const request = require('./rest.js'); -const dbg = require('./debug.js'); -var domainName, username,password,timeout; + +var domainName, username, password, timeout; var prettyprint = false; var url; -function debug(message){ +function debug(message) { dbg.message(" " + message); } +function help() { + return ` +\x1b[4mProjects\x1b[0m + +\x1b[32mList projects in a tenant:\x1b[0m +$ node wmiocli.js -d tenant.int-aws-us.webmethods.io -u user -p password project + +\x1b[32mView individual project using project ID (indentified from URL in webMethods.io when in a project, i.e. https://tenant.int-aws-us.webmethods.io/#/projects/\x1b[1mfl65d3aa87fc1783ea5cf8c8\x1b[32m/workflows):\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + project fl65d3aa87fc1783ea5cf8c8 + +\x1b[32mView individual project with given project name:\x1b[0m + $ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + project Default + +\x1b[32mView Project assets from project with given name:\x1b[0m + $ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + project-assets Default + +\x1b[32mUpdate Project name:\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + project-update fl65d3aa87fc1783ea5cf8c8 "my New Name" + +\x1b[32mDelete Project:\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + project-delete fl65d3aa87fc1783ea5cf8c8 -function init(inDomainName, inUsername, inPassword,inTimeout,inPrettyprint){ +\x1b[32mGet Project Assets:\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + project-assets fl65d3aa87fc1783ea5cf8c8 + +\x1b[32mPublish Project to another tenant:\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + project-publish fl65d3aa87fc1783ea5cf8c8 'My deployment' 'target.int-aws-us.webmethods.io' + 'targetuser' 'targetpassword' + '{"output":{"workflows":["fla73a20e13dd6736cf9c355","fl3cfd145262bbc5d44acff3"], + "flows":["mapLeads"],"rest_api":[],"soap_api":[],"listener":[],"messaging":[]}}' + + +\x1b[32mDeploy published Project in the tenant with the given name and deploy version:\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + project-deploy projectName 1 + + +\x1b[32mList Project Workflow Parameters or gets an individual where name is specified\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + project-param projectName [param-name] + +\x1b[32mCreate Project Workflow Parameter\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + project-param-create projectName param-name param-value required isPassword + + e.g. node wmiocli.js -d env -u user -p pass project-param-create project name dave false false + +\x1b[32mUpdate Project Workflow Parameter\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + project-param-update projectName param-uid param-name param-value required isPassword + +\x1b[32mDelete Project Workflow Parameter\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + project-param-delete projectName param-uid + +\x1b[32mProject webhooks List\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + project-webhooks-list [project-uid] + +\x1b[32mRegenerate webhook token\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + project-webhooks-regenerate project-uid webhook-uid + +\x1b[32mChange webhook Auth\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + project-webhooks-auth project-uid webhook-uid auth-type + + e.g. + node wmiocli.js -d env -u user -p pass project-webhooks-auth flf1111 flf2222 login + +`; +} +function init(inDomainName, inUsername, inPassword, inTimeout, inPrettyprint) { domainName = inDomainName; username = inUsername; password = inPassword; @@ -34,109 +157,109 @@ function init(inDomainName, inUsername, inPassword,inTimeout,inPrettyprint){ * @param {return data from REST request} data * @param {status} status */ -function processResponse(data,status){ - if(prettyprint==true){ - console.log(JSON.stringify(data,null,4)); +function processResponse(data, status) { + if (prettyprint == true) { + console.log(JSON.stringify(data, null, 4)); } - else{ + else { console.log(JSON.stringify(data)); } - - if(status!=0){ + + if (status != 0) { process.exit(status); } } /* Projects */ -function list(projectId){ +function list(projectId) { debug("List Projects ID[" + projectId + "]"); - if(projectId)url+="/" + projectId; - request.get(url,username,password,timeout,processResponse); + if (projectId) url += "/" + projectId; + request.get(url, username, password, timeout, processResponse); } -function create(projectName){ +function create(projectName) { debug("Create Project ID[" + projectName + "]"); - var data={"name":projectName}; - request.post(url,username,password,timeout,data,processResponse); + var data = { "name": projectName }; + request.post(url, username, password, timeout, data, processResponse); } -function update(projectId, projectName){ +function update(projectId, projectName) { debug("Update Project ID[" + projectId + "] Name[" + projectName + "]"); url += "/" + projectId; - var data={"name":projectName}; - request.put(url,username,password,timeout,data,processResponse); + var data = { "name": projectName }; + request.put(url, username, password, timeout, data, processResponse); } -function del(projectId){ +function del(projectId) { debug("Create Project ID[" + projectId + "]"); url += "/" + projectId; - var data={}; - request.httpDelete(url,username,password,timeout,data,processResponse); + var data = {}; + request.httpDelete(url, username, password, timeout, data, processResponse); } /* Project Assets */ -function listAssets(projectId){ +function listAssets(projectId) { debug("List Assets [" + projectId + "]"); - if(projectId)url+="/" + projectId + "/assets"; - request.get(url,username,password,timeout,processResponse); + if (projectId) url += "/" + projectId + "/assets"; + request.get(url, username, password, timeout, processResponse); } /* Project Params */ -function listParam(projectId,paramId){ +function listParam(projectId, paramId) { debug("List Params [" + projectId + "] Param ID [" + paramId + "]"); - if(projectId)url+="/" + projectId + "/params"; - if(paramId)url +="/" + paramId; - request.get(url,username,password,timeout,processResponse); + if (projectId) url += "/" + projectId + "/params"; + if (paramId) url += "/" + paramId; + request.get(url, username, password, timeout, processResponse); } -function createParam(projectId,paramName,paramValue,required,isPassword){ - debug("Create Param Project ID[" + projectId + "] Name [" + paramName + "] value ["+paramValue + "] required [" + required + "] isPassword [" + isPassword + "]" ); - if(projectId)url+="/" + projectId + "/params"; - var data={"key":paramName,"value":paramValue,"required":required,"isPassword":isPassword}; - request.post(url,username,password,timeout,data,processResponse); +function createParam(projectId, paramName, paramValue, required, isPassword) { + debug("Create Param Project ID[" + projectId + "] Name [" + paramName + "] value [" + paramValue + "] required [" + required + "] isPassword [" + isPassword + "]"); + if (projectId) url += "/" + projectId + "/params"; + var data = { "key": paramName, "value": paramValue, "required": required, "isPassword": isPassword }; + request.post(url, username, password, timeout, data, processResponse); } -function updateParam(projectId,paramId,paramName,paramValue,required,isPassword){ - debug("Update Param ProjectId [" + projectId + "] Param ID[" + paramId + "] Name [" + paramName + "] value ["+paramValue + "] required [" + required + "] isPassword [" + isPassword + "]" ); - if(projectId)url+="/" + projectId + "/params"; - if(paramId)url +="/" + paramId; - var data={"key":paramName,"value":paramValue,"required":required,"isPassword":isPassword}; - request.put(url,username,password,timeout,data,processResponse); +function updateParam(projectId, paramId, paramName, paramValue, required, isPassword) { + debug("Update Param ProjectId [" + projectId + "] Param ID[" + paramId + "] Name [" + paramName + "] value [" + paramValue + "] required [" + required + "] isPassword [" + isPassword + "]"); + if (projectId) url += "/" + projectId + "/params"; + if (paramId) url += "/" + paramId; + var data = { "key": paramName, "value": paramValue, "required": required, "isPassword": isPassword }; + request.put(url, username, password, timeout, data, processResponse); } -function deleteParam(projectId,paramId){ +function deleteParam(projectId, paramId) { debug("Delete Param ProjectId [" + projectId + "] Param ID[" + paramId + "]"); - if(projectId)url+="/" + projectId + "/params"; - if(paramId)url +="/" + paramId; - var data={}; - request.httpDelete(url,username,password,timeout,data,processResponse); + if (projectId) url += "/" + projectId + "/params"; + if (paramId) url += "/" + paramId; + var data = {}; + request.httpDelete(url, username, password, timeout, data, processResponse); } /* Webhook APIs */ -function listWebhooks(projectId){ +function listWebhooks(projectId) { debug("List webhooks ProjectId [" + projectId + "]"); - if(projectId)url+="/" + projectId + "/webhook-flows"; - request.get(url,username,password,timeout,processResponse); + if (projectId) url += "/" + projectId + "/webhook-flows"; + request.get(url, username, password, timeout, processResponse); } -function regenWebhook(projectId,workflowUid){ +function regenWebhook(projectId, workflowUid) { debug("List webhooks ProjectId [" + projectId + "] workflowUid [" + workflowUid + "]"); - if(projectId)url+="/" + projectId + "/webhook-flows"; - if(workflowUid)url +="/" + workflowUid + "/reset"; - request.put(url,username,password,timeout,{},processResponse); + if (projectId) url += "/" + projectId + "/webhook-flows"; + if (workflowUid) url += "/" + workflowUid + "/reset"; + request.put(url, username, password, timeout, {}, processResponse); } -function setWebhookAuth(projectId,workflowUid,authType){ +function setWebhookAuth(projectId, workflowUid, authType) { debug("List webhooks ProjectId [" + projectId + "] workflowUid [" + workflowUid + "] auth type [" + authType + "]"); - if(projectId)url+="/" + projectId + "/webhook-flows"; - if(workflowUid)url +="/" + workflowUid + "/auth"; - var data={"auth": authType}; - request.post(url,username,password,timeout,data,processResponse); + if (projectId) url += "/" + projectId + "/webhook-flows"; + if (workflowUid) url += "/" + workflowUid + "/auth"; + var data = { "auth": authType }; + request.post(url, username, password, timeout, data, processResponse); } - + /* Deployment */ /** @@ -147,24 +270,24 @@ function setWebhookAuth(projectId,workflowUid,authType){ * @param {tenant url} destTenantDomainName * @param {assets to publish} assets */ -function pub(projectId,publishName,targetTenantDomainName,targetUserId,targetUserPassword,assetsJson){ +function pub(projectId, publishName, targetTenantDomainName, targetUserId, targetUserPassword, assetsJson) { debug("Project Pub ProjectId [" + projectId + "] publishName [" + publishName + "] target Tenant [" + targetTenantDomainName + "]"); //{"output":{"workflows":["fla73a20e13dd6736cf9c355","fl3cfd145262bbc5d44acff3"],"flows":["mapLeads"],"rest_api":[],"soap_api":[],"listener":[],"messaging":[]}} url += "/" + projectId + "/push"; - - var jsonStr='{'; - jsonStr+='"name": "' + publishName + '",'; - jsonStr+='"destination_tenant_detail": {'; - jsonStr+='"username": "' + targetUserId + '",'; - jsonStr+='"password": "' + targetUserPassword + '",'; - jsonStr+='"url": "' + "https://" + targetTenantDomainName + '"'; - jsonStr+='},'; + + var jsonStr = '{'; + jsonStr += '"name": "' + publishName + '",'; + jsonStr += '"destination_tenant_detail": {'; + jsonStr += '"username": "' + targetUserId + '",'; + jsonStr += '"password": "' + targetUserPassword + '",'; + jsonStr += '"url": "' + "https://" + targetTenantDomainName + '"'; + jsonStr += '},'; assetsJson = assetsJson.replace(/\"flows\"/g, "\"flow_services\""); - jsonStr+=assetsJson.substring(11,assetsJson.length-2); - jsonStr+="}"; + jsonStr += assetsJson.substring(11, assetsJson.length - 2); + jsonStr += "}"; data = JSON.parse(jsonStr); - request.post(url,username,password,timeout,data,processResponse) + request.post(url, username, password, timeout, data, processResponse) } /** @@ -172,16 +295,16 @@ function pub(projectId,publishName,targetTenantDomainName,targetUserId,targetUse * @param {publish name} publishName * @param {version number} version */ -function deploy(projectName, version) -{ +function deploy(projectName, version) { debug("Project Deploy ProjectName [" + projectName + "] Version [" + version + "]"); url += "/" + projectName + "/deploy"; - data={"version":parseInt(version)}; - request.post(url,username,password,timeout,data,processResponse); -} + data = { "version": parseInt(version) }; + request.post(url, username, password, timeout, data, processResponse); +} -module.exports = { init, list, create, update, del, - listAssets, pub, deploy, - createParam,updateParam,listParam,deleteParam, +module.exports = { + help, init, list, create, update, del, + listAssets, pub, deploy, + createParam, updateParam, listParam, deleteParam, listWebhooks, regenWebhook, setWebhookAuth }; diff --git a/recipe.js b/recipe.js index 13a4601..1811358 100644 --- a/recipe.js +++ b/recipe.js @@ -5,23 +5,49 @@ */ const rest = require('./rest.js'); -const dbg = require('./debug.js'); - -var domainName, username,password,timeout,prettyprint; +var domainName, username, password, timeout, prettyprint; var url; -function debug(message){ +function debug(message) { dbg.message(" " + message); } +function help() { + return ` +\x1b[4mRecipes\x1b[0m + +\x1b[32mGet recipe list or individual recipe\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + recipe [recipe-Uid] + +\x1b[32mCreates a Workflow recipe from a workflow export\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + recipe-create export-flf111111.zip + +\x1b[32mDeletes a Workflow recipe with the provided UID\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + recipe-delete fl1771d591cfb4f31e558daf + + + `; +} -function init(inDomainName, inUsername, inPassword,inTimeout,inPrettyPrint){ +function init(inDomainName, inUsername, inPassword, inTimeout, inPrettyPrint) { domainName = inDomainName; username = inUsername; password = inPassword; timeout = inTimeout; prettyprint = inPrettyPrint; - url = "https://" + domainName + "/apis/v1/rest/recipes" ; + url = "https://" + domainName + "/apis/v1/rest/recipes"; debug("Username [" + username + "]"); debug("URL [" + url + "]"); debug("Timeout [" + timeout + "]"); @@ -32,35 +58,35 @@ function init(inDomainName, inUsername, inPassword,inTimeout,inPrettyPrint){ * @param {return data from REST request} data * @param {status} status */ - function processResponse(data,status){ - if(prettyprint==true){ - console.log(JSON.stringify(data,null,4)); +function processResponse(data, status) { + if (prettyprint == true) { + console.log(JSON.stringify(data, null, 4)); } - else{ + else { console.log(JSON.stringify(data)); } - - if(status!=0){ + + if (status != 0) { process.exit(status); } } -function create(filename){ +function create(filename) { debug("Creating Recipe from file [" + filename + "]"); - rest.postUploadFile(url,username,password,timeout,undefined,filename,processResponse); + rest.postUploadFile(url, username, password, timeout, undefined, filename, processResponse); } -function list(recipeUid){ - if(recipeUid)url+="/" + recipeUid; +function list(recipeUid) { + if (recipeUid) url += "/" + recipeUid; debug("List Recipes [" + recipeUid + "]"); - rest.get(url,username,password,timeout,processResponse); + rest.get(url, username, password, timeout, processResponse); } -function del(recipeUid){ +function del(recipeUid) { debug("Deleting Recipe with ID [" + recipeUid + "]"); url += "/" + recipeUid; - rest.del(url,username,password,timeout,{},processResponse); + rest.del(url, username, password, timeout, {}, processResponse); } -module.exports = { init, list, del, create }; +module.exports = { help, init, list, del, create }; diff --git a/rest.js b/rest.js index e5f233d..eff1ec2 100644 --- a/rest.js +++ b/rest.js @@ -6,12 +6,61 @@ const request = require('request'); const fs = require ('fs'); -const dbg = require('./debug.js'); +const cj = request.jar(); +cookieJar = []; function debug(message){ dbg.message(" " + message); } +function addCookieToJar(cookie,domainName) +{ + debug(". adding cookie:" + cookie); + cookieJar.push(cookie); + cj.setCookie(cookie,domainName); +} + +function displayCookies() +{ + for(var i=0;i { if(body)debug("BODY:" + JSON.stringify(body)); @@ -82,6 +132,7 @@ function sendBody(restEndPoint,user,pass,timeout,data,type,callback){ }, body: data }; + requestModifiers(options); debug(JSON.stringify(options)); request(options, (err, res, body) => { @@ -126,6 +177,7 @@ function postUploadFile(restEndPoint,user,pass,timeout,data,filename,callback){ }, body: data }; + requestModifiers(options); debug(JSON.stringify(options)); request(options, (err, res, body) => { @@ -167,6 +219,7 @@ function postDownloadFile(restEndPoint,user,pass,timeout,data,filename,callback) }, body: data }; + requestModifiers(options); debug(JSON.stringify(options)); request(options, (err, res, body) => { @@ -243,6 +296,7 @@ function del(restEndPoint,user,pass,timeout,data,callback){ password: pass } }; + requestModifiers(options); debug(JSON.stringify(options)); request(options, (err, res, body) => { if(body)debug("BODY:" + JSON.stringify(body)); @@ -266,4 +320,101 @@ function del(restEndPoint,user,pass,timeout,data,callback){ }); } -module.exports = { get, post, put, del, postDownloadFile, postUploadFile, downloadFile, httpDelete }; +function custom(restEndPoint,user,pass,timeout,jsonBody,formBody,type,callback,cookies,headers,jsonFlag,redirect){ + var options = { + url: restEndPoint, + method: type, + followRedirect: false, + followAllRedirects: false, + followOriginalHttpMethod: false, + timeout: timeout*1000, + headers: { + }, + jar:cj + }; + requestModifiers(options); + + //Redirects + if(redirect && redirect==true){ + options.followAllRedirects=true; + options.followRedirect=true; + options.followOriginalHttpMethod = true; + } + + //Use JSON Based data/responses + if(jsonFlag===undefined) options.json = true; + else options.json = jsonFlag; + + //Authentication + if(user!==undefined) + { + options.auth={}; + options.auth.username = user; + options.auth.password = pass; + } + + //Body Content + if(jsonBody!==undefined)options.body=jsonBody; + if(formBody!==undefined) + { + debug("Processing Form"); + options.form={}; + for(var i=0;i { + + //if(body)console.log("BODY:" + JSON.stringify(body)); + + if(err)console.log(err); + //if(res)console.log("RES:" + JSON.stringify(res)); + + return callback(restEndPoint,err,body,res); + }); +} + +module.exports = { get, post, put, del, postDownloadFile, postUploadFile, downloadFile, httpDelete, custom, addCookieToJar, displayCookies }; diff --git a/roles.js b/roles.js index 4985f8d..cc0d36b 100644 --- a/roles.js +++ b/roles.js @@ -6,25 +6,58 @@ */ const request = require('./rest.js'); -const dbg = require('./debug.js'); -var domainName, username,password,timeout; +var domainName, username, password, timeout; var prettyprint; var url; -function checkForErrors(inBody) -{ +function checkForErrors(inBody) { //Error Codes //Any error response - + } -function debug(message){ +function debug(message) { dbg.message(" " + message); } +function help() { + return ` +\x1b[4mRoles\x1b[0m + +\x1b[32mGet roles list or individual role\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + role [role-name] -function init(inDomainName, inUsername, inPassword,inTimeout,inPrettyprint){ +\x1b[32mCreates a role\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + role-create 'rolename' 'role description' 'project 1 name,r,w,e;project 2 name,r;' + +\x1b[32mUpdates a role with a provided Id\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + role-update 'roleId' 'rolename' 'role description' 'project 1 name,r,w,e;project 2 name,r;' + +\x1b[32mDelete a role with a provided Id\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + role-delete 'roleId' + +`; +} + + +function init(inDomainName, inUsername, inPassword, inTimeout, inPrettyprint) { domainName = inDomainName; username = inUsername; password = inPassword; @@ -41,25 +74,25 @@ function init(inDomainName, inUsername, inPassword,inTimeout,inPrettyprint){ * @param {return data from REST request} data * @param {status} status */ - function processResponse(data,status){ - if(prettyprint==true){ - console.log(JSON.stringify(data,null,4)); +function processResponse(data, status) { + if (prettyprint == true) { + console.log(JSON.stringify(data, null, 4)); } - else{ + else { console.log(JSON.stringify(data)); } - - if(status!=0){ + + if (status != 0) { process.exit(status); } } -function list(roleId){ +function list(roleId) { debug("List [" + roleId + "]"); - url+="/roles"; - if(roleId)url+="/" + roleId - request.get(url,username,password,timeout,processResponse); + url += "/roles"; + if (roleId) url += "/" + roleId + request.get(url, username, password, timeout, processResponse); } function parseRoleListInput(rolesList) { @@ -83,26 +116,26 @@ function parseRoleListInput(rolesList) { return projects; } -function insert(name,description,projects){ +function insert(name, description, projects) { debug("Insert [" + name + "]"); - url+="/roles"; + url += "/roles"; projects = parseRoleListInput(projects); - var data={"name":name,"description":description, projects}; - request.post(url,username,password,timeout,data,processResponse); + var data = { "name": name, "description": description, projects }; + request.post(url, username, password, timeout, data, processResponse); } -function update(roleId, name,description,projects){ +function update(roleId, name, description, projects) { debug("Update [" + roleId + "]"); - url+="/roles/" + roleId; + url += "/roles/" + roleId; projects = parseRoleListInput(projects); - var data={"name":name,"description":description, projects}; - request.put(url,username,password,timeout,data,processResponse); + var data = { "name": name, "description": description, projects }; + request.put(url, username, password, timeout, data, processResponse); } -function del(roleId){ +function del(roleId) { debug("Delte [" + roleId + "]"); - url+="/roles/" + roleId; - request.del(url,username,password,timeout,undefined,processResponse); + url += "/roles/" + roleId; + request.del(url, username, password, timeout, undefined, processResponse); } -module.exports = { init, list, insert, update, del }; +module.exports = {help, init, list, insert, update, del }; diff --git a/themes.js b/themes.js index 9e97541..4ed8e89 100644 --- a/themes.js +++ b/themes.js @@ -5,25 +5,82 @@ */ const request = require('./rest.js'); -const dbg = require('./debug.js'); -var domainName, username,password,timeout; +var domainName, username, password, timeout; var prettyprint = false; var url; -function debug(message){ +function debug(message) { dbg.message(" " + message); } +function help() { + return ` +\x1b[4mThemes\x1b[0m + +\x1b[32mLists whitelabel themes\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + theme [theme-uid] + + The theme settings returned can be use as a way to create the theme. + You can use jq to retrieve the theme settings by piping the output to jq, e.g. + + node wmiocli.js -d env -u user -p pass theme fl40018d9a1a273bb8aa92bf | jq -c .output.settings.theme > ~/dracula-theme.txt + +\x1b[32mDeletes a whitelabel theme\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + theme-delete [theme-uid] + +\x1b[32mCreates a new whitelabel theme\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + theme-create dracula 'desc' [theme-settings] "Footer Text" "About Page" + + Theme settings can be used from the list example above, e.g. + node wmiocli.js -d env -u user -p pass theme-create dracula7 'updated' "\`cat ~/dracula-theme.txt\`" 'Footer' 'About' + +\x1b[32mUpdates a whitelabel theme\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + theme-update themeid dracula 'desc' [theme-settings] "Footer Text" "About Page" + + Theme settings can be used from the list example above, e.g. + node wmiocli.js -d env -u user -p pass theme-update themeid dracula7 'updated' "\`cat ~/dracula-theme.txt\`" 'Footer' 'About' + +\x1b[32mActivates a whitelabel theme\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + theme-activate [theme-uid] + +\x1b[32mDeactivates a whitelabel theme\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + theme-deactivate [theme-uid] + + `; +} -function checkForErrors(inBody) -{ +function checkForErrors(inBody) { //Error Codes //Any error response - + } -function init(inDomainName, inUsername, inPassword,inTimeout,inPrettyprint){ +function init(inDomainName, inUsername, inPassword, inTimeout, inPrettyprint) { domainName = inDomainName; username = inUsername; password = inPassword; @@ -40,27 +97,27 @@ function init(inDomainName, inUsername, inPassword,inTimeout,inPrettyprint){ * @param {return data from REST request} data * @param {status} status */ -function processResponse(data,status){ - if(prettyprint==true){ - console.log(JSON.stringify(data,null,4)); +function processResponse(data, status) { + if (prettyprint == true) { + console.log(JSON.stringify(data, null, 4)); } - else{ + else { console.log(JSON.stringify(data)); - + } - - if(status!=0){ + + if (status != 0) { process.exit(status); } } -function list(themeUid){ - debug("List themeUid["+ themeUid + "]") - if(themeUid)url+="/" + themeUid; - request.get(url,username,password,timeout,processResponse); +function list(themeUid) { + debug("List themeUid[" + themeUid + "]") + if (themeUid) url += "/" + themeUid; + request.get(url, username, password, timeout, processResponse); } -function create(themeName,themeDescription,theme,footerContent,aboutPageContent){ +function create(themeName, themeDescription, theme, footerContent, aboutPageContent) { debug("Create Name [" + themeName + "] Desc [" + themeDescription + "]"); debug("Theme [" + theme + "]"); debug("Footer [" + footerContent + "]"); @@ -68,13 +125,13 @@ function create(themeName,themeDescription,theme,footerContent,aboutPageContent) themeObj = JSON.parse(theme); var footer; var about; - + //If footer is not specified get it from the theme - if(footerContent!==undefined && footerContent !==null)footer=footerContent + if (footerContent !== undefined && footerContent !== null) footer = footerContent else footer = themeObj.footerContent; - + //If about is not specified get it from the theme - if(aboutPageContent!==undefined && aboutPageContent !==null)about=aboutPageContent + if (aboutPageContent !== undefined && aboutPageContent !== null) about = aboutPageContent else about = themeObj.aboutPageContent; //Remove footer/about page from the theme @@ -82,40 +139,39 @@ function create(themeName,themeDescription,theme,footerContent,aboutPageContent) themeObj.aboutPageContent = undefined; //Remove default favIcon - causes issues - if(themeObj.favIconFileName=="default-favicon.svg") - { - themeObj.favIconFileName=undefined; - themeObj.favIconImage=undefined; + if (themeObj.favIconFileName == "default-favicon.svg") { + themeObj.favIconFileName = undefined; + themeObj.favIconImage = undefined; } theme = JSON.stringify(themeObj); - + var jsonStr = "{"; - jsonStr+='"name":' + '"' + themeName + '",'; - jsonStr+='"description":' + '"' + themeDescription + '",'; - jsonStr+='"theme":' + theme; - jsonStr+= ','; - jsonStr+='"footerContent":' + '"' + footerContent + '",'; - jsonStr+='"aboutPageContent":' + '"' + aboutPageContent + '"'; - jsonStr+="}"; + jsonStr += '"name":' + '"' + themeName + '",'; + jsonStr += '"description":' + '"' + themeDescription + '",'; + jsonStr += '"theme":' + theme; + jsonStr += ','; + jsonStr += '"footerContent":' + '"' + footerContent + '",'; + jsonStr += '"aboutPageContent":' + '"' + aboutPageContent + '"'; + jsonStr += "}"; data = JSON.parse(jsonStr); - request.post(url,username,password,timeout,data,processResponse); + request.post(url, username, password, timeout, data, processResponse); } -function update(themeUid, themeName,themeDescription,theme,footerContent,aboutPageContent){ +function update(themeUid, themeName, themeDescription, theme, footerContent, aboutPageContent) { debug("Update Theme UID [" + themeUid + "]"); url += "/" + themeUid; themeObj = JSON.parse(theme); var footer; var about; - + //If footer is not specified get it from the theme - if(footerContent!==undefined && footerContent !==null)footer=footerContent + if (footerContent !== undefined && footerContent !== null) footer = footerContent else footer = themeObj.footerContent; - + //If about is not specified get it from the theme - if(aboutPageContent!==undefined && aboutPageContent !==null)about=aboutPageContent + if (aboutPageContent !== undefined && aboutPageContent !== null) about = aboutPageContent else about = themeObj.aboutPageContent; //Remove footer/about page from the theme @@ -123,46 +179,45 @@ function update(themeUid, themeName,themeDescription,theme,footerContent,aboutPa themeObj.aboutPageContent = undefined; //Remove default favIcon - causes issues - if(themeObj.favIconFileName=="default-favicon.svg") - { - themeObj.favIconFileName=undefined; - themeObj.favIconImage=undefined; + if (themeObj.favIconFileName == "default-favicon.svg") { + themeObj.favIconFileName = undefined; + themeObj.favIconImage = undefined; } theme = JSON.stringify(themeObj); - + var jsonStr = "{"; - jsonStr+='"name":' + '"' + themeName + '",'; - jsonStr+='"description":' + '"' + themeDescription + '",'; - jsonStr+='"theme":' + theme; - jsonStr+= ','; - jsonStr+='"footerContent":' + '"' + footerContent + '",'; - jsonStr+='"aboutPageContent":' + '"' + aboutPageContent + '"'; - jsonStr+="}"; + jsonStr += '"name":' + '"' + themeName + '",'; + jsonStr += '"description":' + '"' + themeDescription + '",'; + jsonStr += '"theme":' + theme; + jsonStr += ','; + jsonStr += '"footerContent":' + '"' + footerContent + '",'; + jsonStr += '"aboutPageContent":' + '"' + aboutPageContent + '"'; + jsonStr += "}"; data = JSON.parse(jsonStr); - request.put(url,username,password,timeout,data,processResponse); + request.put(url, username, password, timeout, data, processResponse); } -function del(themeUid){ +function del(themeUid) { debug("Delete Theme UID [" + themeUid + "]"); url += "/" + themeUid; - var data={}; - request.httpDelete(url,username,password,timeout,data,processResponse); + var data = {}; + request.httpDelete(url, username, password, timeout, data, processResponse); } -function activate(themeUid){ +function activate(themeUid) { debug("Activate Theme UID [" + themeUid + "]"); url += "/" + themeUid + "/activate"; - var data={}; - request.put(url,username,password,timeout,data,processResponse); + var data = {}; + request.put(url, username, password, timeout, data, processResponse); } -function deactivate(themeUid){ +function deactivate(themeUid) { debug("Deactivate Theme UID [" + themeUid + "]"); url += "/" + themeUid + "/deactivate"; - var data={}; - request.put(url,username,password,timeout,data,processResponse); + var data = {}; + request.put(url, username, password, timeout, data, processResponse); } //, update, del, default, activate, deactivate -module.exports = {init, list, create,update,del,activate,deactivate}; +module.exports = { help, init, list, create, update, del, activate, deactivate }; diff --git a/unofficial.js b/unofficial.js new file mode 100644 index 0000000..54fc554 --- /dev/null +++ b/unofficial.js @@ -0,0 +1,407 @@ +/* + * webMethods.io CLI + * Copyright 2022 Software AG + * Apache-2.0 + */ + +// ------------------------------------------------------------------------------ +// PLEASE NOTE - These functions are NOT provided by NON public APIs, and +// therefore unsupported - use these at your own risk! +// ------------------------------------------------------------------------------ + +const request = require('request'); +const rest = require('./rest.js'); +const fs = require('fs'); + + +var domainName, username,password,timeout; +var prettyprint = false; +var url; + +var authtoken=""; +var uid=""; +var csrf=""; +var projectId; +var nextUrl,formUrl; +var finalCall; +var loginStageCounter = 0; + +function debug(message){ + dbg.message(" " + message); +} + +function init(inDomainName, inUsername, inPassword,inTimeout,inPrettyprint){ + + dbg.message("UNSUPPORTED APIs - USE THESE AT YOUR OWN RISK"); + domainName = inDomainName; + username = inUsername; + password = inPassword; + timeout = inTimeout; + prettyprint = inPrettyprint; + url = "https://" + domainName; + dbg.message("Username [" + username + "]"); + dbg.message("URL [" + url + "]"); + dbg.message("Timeout [" + timeout + "]"); +} + +function user() +{ + finalCall = execUserInfo; + loginPhase1(); +} + +function stages() +{ + finalCall = stageInfo; + loginPhase1(); +} + +function projectWorkflows(inProjectId) +{ + projectId = inProjectId; + finalCall = projectWorkflowsInfo; + loginPhase1(); +} + +function projectFlowservices(inProjectId) +{ + projectId = inProjectId; + finalCall = projectFlowServicesInfo; + loginPhase1(); +} + +function connectorAccounts(inProjectId) +{ + projectId = inProjectId; + finalCall = usedConnectorAccountsInfo; + loginPhase1(); +} + +function getProjectAccountConfig(inProjectId) +{ + projectId = inProjectId; + finalCall = getProjectAccountConfigInfo; + loginPhase1(); +} + + +function stageInfo() +{ + debug("Stage Info"); + var endPoint = "https://" + domainName + "/enterprise/v1/stages?allRegion=false"; + debug("Next URL [" + endPoint + "]"); + + var headers = [ + {name:"authtoken",value:authtoken}, + {name:"accept",value:"application/json"}, + {name:"x-csrf-token",value:csrf}, + ]; + rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",processResponse,undefined,headers,true,false); +} + +function getProjectAccountConfigInfo() +{ + debug("PRojet Account Config Info"); + var endPoint = "https://" + domainName + "/enterprise/v1/configdata"; + debug("Next URL [" + endPoint + "]"); + + var headers = [ + {name:"authtoken",value:authtoken}, + {name:"accept",value:"application/json"}, + {name:"project_uid",value:projectId}, + {name:"x-csrf-token",value:csrf}, + ]; + rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",processResponse,undefined,headers,true,false); +} + + +function usedConnectorAccountsInfo() +{ + debug("Used Connectors Info"); + var endPoint = "https://" + domainName + "/enterprise/v1/user/auths"; + debug("Next URL [" + endPoint + "]"); + + var headers = [ + {name:"authtoken",value:authtoken}, + {name:"accept",value:"application/json"}, + {name:"project_uid",value:projectId}, + {name:"x-csrf-token",value:csrf}, + ]; + rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",processResponse,undefined,headers,true,false); +} + +function projectWorkflowsInfo() +{ + + debug("Project Workflows Info"); + var endPoint = "https://" + domainName + "/enterprise/v1/flows?limit=1000&skip=0&filter=recent&tags=&query="; + debug("Next URL [" + endPoint + "]"); + + var headers = [ + {name:"authtoken",value:authtoken}, + {name:"accept",value:"application/json"}, + {name:"project_uid",value:projectId}, + {name:"x-csrf-token",value:csrf}, + ]; + rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",processProjectsResponse,undefined,headers,true,false); +} + +function projectFlowServicesInfo() +{ + + debug("Project FlowServices Info"); + var endPoint = "https://" + domainName + "/integration/rest/ut-flow/flow-metadata/" + projectId + "?skip=0&limit=1000"; + debug("Next URL [" + endPoint + "]"); + + var headers = [ + {name:"authtoken",value:authtoken}, + {name:"accept",value:"application/json"}, + {name:"project_uid",value:projectId}, + {name:"x-csrf-token",value:csrf}, + ]; + rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",processResponse,undefined,headers,true,false); +} + + +function execUserInfo() +{ + debug("Exec User Info"); + var endPoint = "https://" + domainName + "/enterprise/v1/user"; + debug("Next URL [" + endPoint + "]"); + + var headers = [ + {name:"authtoken",value:authtoken}, + {name:"accept",value:"application/json"}, + ]; + rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",processResponse,undefined,headers,true,false); +} + +/** Logs in via Software AG Cloud! */ +function loginPhase1() +{ + debug("LOGIN Phase 1") + var endPoint = url + "/integration/sagcloud/"; + rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",loginResponse,undefined,undefined,true,false); + +} + +function loginPhase2() +{ + debug("LOGIN Phase 2") + var endPoint = nextUrl; + debug("Next URL [" + endPoint + "]"); + formUrl = endPoint; + rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",loginResponse,undefined,undefined,true,false); +} + +function loginPhase3() +{ + debug("LOGIN Phase 3") + var endPoint = nextUrl; + debug("Next URL [" + endPoint + "]"); + + var headers = [ + {name:"Referer",value:formUrl}, + {name:"content-type",value:"application/x-www-form-urlencoded"}, + {name:"Accept",value:"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"}, + ]; + var form = [{name:"username",value:username}, + {name:"password",value:password}]; + + rest.custom(endPoint,undefined,undefined,60,undefined,form,"POST",loginResponse,undefined,undefined,true,false); +} + +function loginRedirectPhase(inId) +{ + debug("LOGIN (Redirect) Phase " + inId); + var endPoint = nextUrl; + debug("Next URL [" + endPoint + "]"); + + var headers = [ + {name:"Accept",value:"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"}, + ]; + rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",loginResponse,undefined,undefined,true,false); +} + +function loginUserPhase(inId) +{ + debug("LOGIN (USER) Phase " + inId); + var endPoint = "https://" + domainName + "/enterprise/v1/user"; + debug("Next URL [" + endPoint + "]"); + + var headers = [ + {name:"authtoken",value:authtoken}, + {name:"accept",value:"application/json"}, + ]; + rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",processUserResponse,undefined,headers,true,false); +} + +function checkResponse(res,body) +{ + debug("Response Status Code =" + res.statusCode); + if(res.statusCode == 302){ + nextUrl = res.headers.location; + debug("Redirect URL [" + nextUrl + "]"); + } + + if(res.statusCode == 200){ + //debug(body); + } + + if(res.statusCode == 400 || res.statusCode == 404 || res.statusCode == 500 || res.statusCode == 502 || res.statusCode == 403 || res.statusCode == 401) + { + debug("Failed to login via Software AG Cloud - exiting") + console.log(res); + process.exit(99); + } + +} + +function processProjectsResponse(url,err,body,res){ + //console.log(body); + + if(res.statusCode==200) + { + var output = {}; + output.workflows=[]; + + for(var i=0;i0) + { + for(var i=0;i")[0]; + str = str.split("action=\"")[1]; + str = str.split("\"")[0]; + str = str.replace(/&/g,"&"); + nextUrl = str; + nextCall = loginPhase3(); + break; + + case 3: + checkResponse(res,body); + nextCall = loginRedirectPhase(4); + break; + + case 4: + checkResponse(res,body); + nextCall = loginRedirectPhase(5); + break; + case 5: + checkResponse(res,body); + nextCall = loginRedirectPhase(6); + break; + case 6: + checkResponse(res,body); + if(nextUrl.indexOf('/#/sso/success?')==0) + { + authtoken = nextUrl.split("?sid=")[1].split("&")[0]; + uid = nextUrl.split("&tenant_uid=")[1]; + debug("authtoken [" + authtoken +"]"); + debug("tenantuid [" + uid +"]"); + nextCall=loginUserPhase(7); + } + + } + + + + //Invoke next call in chain + if(nextCall!==undefined)nextCall(); + + +} + + +module.exports = {init,user,stages,projectWorkflows,projectFlowservices,connectorAccounts,getProjectAccountConfig}; \ No newline at end of file diff --git a/users.js b/users.js index 0f1ecc6..571d488 100644 --- a/users.js +++ b/users.js @@ -6,7 +6,6 @@ */ const request = require('./rest.js'); -const dbg = require('./debug.js'); var domainName, username,password,timeout; var prettyprint; diff --git a/wmiocli.js b/wmiocli.js index b6fed30..b44c4e3 100644 --- a/wmiocli.js +++ b/wmiocli.js @@ -3,25 +3,30 @@ * Copyright 2022 Software AG * Apache-2.0 */ - +const { Command, Option } = require('commander'); +const { exit } = require('process'); +const readline = require('readline-sync'); var project = require('./projects.js'); var role = require('./roles.js'); var user = require('./users.js'); var wf = require('./workflow.js'); var theme = require('./themes.js'); var recipe = require('./recipe.js'); -var dbg = require('./debug.js'); var flowservice = require('./flowservice.js'); -var prettyprint = false; +var unofficial = require('./unofficial.js'); + +dbg = require('./debug.js'); +prettyprint = false; +proxy = undefined; +caCertFile = undefined; +ignoreTLS = false; + var compat = false; var tenantDomain; var tenantUser; var tenantPw; -const { Command, Option } = require('commander'); -const { exit } = require('process'); -const readline = require('readline-sync'); function readFromConsole(question,isPassword) { @@ -42,6 +47,21 @@ function checkOptions(){ dbg.enableDebug(); } + if(program.opts().proxy !== undefined) + { + proxy = program.opts().proxy; + debug("Using Proxy: " + proxy); + } + if(program.opts().caCert !== undefined) + { + caCertFile = program.opts().caCert; + debug("Using CA Cert File: " + caCertFile); + } + + ignoreTLS = program.opts().ignoreTLSErrors; + + + if(program.opts().prettyprint == true) { prettyprint = true; @@ -52,6 +72,10 @@ function checkOptions(){ } else{ tenantDomain = program.opts().domain + if(tenantDomain.indexOf("http")==0){ + console.log("Please provide the tenant domain name only (without https:// prefix and any URL suffix\ne.g. 'tenant.int-aws-us.webmethods.io'"); + process.exit(1); + } } if(program.opts().user == undefined){ @@ -71,9 +95,10 @@ function checkOptions(){ } function debug(message){ - dbg.message(" " + message) + dbg.message("
" + message); } const program = new Command(); + program //Program Info @@ -84,12 +109,16 @@ program .option('-u, --user ', 'Tenant User ID') .option('-p, --password ', 'Tenant User Password') //.requiredOption('-p, --password ', 'Tenant User Password') - + //options .addOption(new Option('-t, --timeout ', 'timeout in seconds').default(60, 'one minute')) .option('--prettyprint','Pretty Print JSON output') .option('--verbose','Verbose output useful for diagnosing issues') + .option('--proxy ','URL for proxy server if required') + .option('--caCert ','Path to a CACert PEM file if required') + .option('--ignoreTLSErrors','Ignore TLS errors') + //Additional help .addHelpText('before', ` @@ -98,322 +127,27 @@ program │\x1b[0m This tool provides command line access to the webMethods.io Integration APIs\x1b[34m │ │\x1b[0m Intended to aid usage within DevOps Scenarios for asset deployment \x1b[34m │ └──────────────────────────────────────────────────────────────────────────────┘\x1b[0m -`) - - .addHelpText('after', ` - -Examples: - - \x1b[4mHelp\x1b[0m - \x1b[32mShow the command line help:\x1b[0m - $ node wmiocli.js --help + `) - \x1b[4mProjects\x1b[0m - - \x1b[32mList projects in a tenant:\x1b[0m - $ node wmiocli.js -d tenant.int-aws-us.webmethods.io -u user -p password project - - \x1b[32mView individual project using project ID (indentified from URL in webMethods.io when in a project, i.e. https://tenant.int-aws-us.webmethods.io/#/projects/\x1b[1mfl65d3aa87fc1783ea5cf8c8\x1b[32m/workflows):\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - project fl65d3aa87fc1783ea5cf8c8 - - \x1b[32mView individual project with given project name:\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - project Default - - \x1b[32mView Project assets from project with given name:\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - project-assets Default - - \x1b[32mUpdate Project name:\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - project-update fl65d3aa87fc1783ea5cf8c8 "my New Name" - - \x1b[32mDelete Project:\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - project-delete fl65d3aa87fc1783ea5cf8c8 - - \x1b[32mGet Project Assets:\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - project-assets fl65d3aa87fc1783ea5cf8c8 - - \x1b[32mPublish Project to another tenant:\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - project-publish fl65d3aa87fc1783ea5cf8c8 'My deployment' 'target.int-aws-us.webmethods.io' - 'targetuser' 'targetpassword' - '{"output":{"workflows":["fla73a20e13dd6736cf9c355","fl3cfd145262bbc5d44acff3"], - "flows":["mapLeads"],"rest_api":[],"soap_api":[],"listener":[],"messaging":[]}}' - - - \x1b[32mDeploy published Project in the tenant with the given name and deploy version:\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - project-deploy projectName 1 - - - \x1b[32mList Project Workflow Parameters or gets an individual where name is specified\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - project-param projectName [param-name] - - \x1b[32mCreate Project Workflow Parameter\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - project-param-create projectName param-name param-value required isPassword - - e.g. node wmiocli.js -d env -u user -p pass project-param-create project name dave false false - - \x1b[32mUpdate Project Workflow Parameter\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - project-param-update projectName param-uid param-name param-value required isPassword - - \x1b[32mDelete Project Workflow Parameter\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - project-param-delete projectName param-uid - - \x1b[32mProject webhooks List\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - project-webhooks-list [project-uid] - - \x1b[32mRegenerate webhook token\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - project-webhooks-regenerate project-uid webhook-uid - - \x1b[32mChange webhook Auth\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - project-webhooks-auth project-uid webhook-uid auth-type - - e.g. - node wmiocli.js -d env -u user -p pass project-webhooks-auth flf1111 flf2222 login - - - \x1b[4mWorkflow\x1b[0m - - \x1b[32mExport Workflow from a given project (identified from URL in webMethods.io when in workflow canvas, - i.e. https://tenant.int-aws-us.webmethods.io/#/projects/\x1b[1mfl65d3aa87fc1783ea5cf8c8\x1b[0m\x1b[32m/workflows/\x1b[1mfl52232a2dfafbd6536963d7\x1b[0m\x1b[32m/edit):\x1b[0m\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - workflow-export fl65d3aa87fc1783ea5cf8c8 fl52232a2dfafbd6536963d7 export.zip - - \x1b[32mImport Workflow from a given file into a project \x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - workflow-import fl65d3aa87fc1783ea5cf8c8 export.zip - - \x1b[32mDelete Workflow from a given project\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - workflow-delete fl65d3aa87fc1783ea5cf8c8 fl52232a2dfafbd6536963d7 - - \x1b[32mExecute a Workflow from a given project\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - workflow-execute fl65d3aa87fc1783ea5cf8c8 fl52232a2dfafbd6536963d7 - - \x1b[32mGet Workflow execution status from a given project\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - workflow-status fl65d3aa87fc1783ea5cf8c8 vbid3d247cd26aa5e19354e1fc6951766a3d19c049bee11d - - - \x1b[4mFlowService\x1b[0m - - \x1b[32mExport FlowService from a given project (identified from URL in webMethods.io when in FlowEditor - i.e. https://tenant.int-aws-us.webmethods.io/#/projects/\x1b[1mfl65d3aa87fc1783ea5cf8c8\x1b[0m\x1b[32m/flow-editor/\x1b[1mmyFlowService\x1b[0m\x1b[32m):\x1b[0m\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - flowservice-export fl65d3aa87fc1783ea5cf8c8 myFlowService export.zip - - \x1b[32mImport Flowservice from a given file into a project \x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - flowservice-import fl65d3aa87fc1783ea5cf8c8 export.zip - - \x1b[32mDelete FlowService from a given project\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - flowservice-delete fl65d3aa87fc1783ea5cf8c8 myFlowService - - \x1b[32mExecute a FlowService from a given project\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - flowservice-execute fl65d3aa87fc1783ea5cf8c8 myFlowService - - - \x1b[4mRoles\x1b[0m - - \x1b[32mGet roles list or individual role\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - role [role-name] - - \x1b[32mCreates a role\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - role-create 'rolename' 'role description' 'project 1 name,r,w,e;project 2 name,r;' - - \x1b[32mUpdates a role with a provided Id\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - role-update 'roleId' 'rolename' 'role description' 'project 1 name,r,w,e;project 2 name,r;' - - \x1b[32mDelete a role with a provided Id\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - role-delete 'roleId' - - - \x1b[4mRecipes\x1b[0m - - \x1b[32mGet recipe list or individual recipe\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - recipe [recipe-Uid] - - \x1b[32mCreates a Workflow recipe from a workflow export\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - recipe-create export-flf111111.zip - - \x1b[32mDeletes a Workflow recipe with the provided UID\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - recipe-delete fl1771d591cfb4f31e558daf - - - \x1b[4mThemes\x1b[0m - - \x1b[32mLists whitelabel themes\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - theme [theme-uid] - - The theme settings returned can be use as a way to create the theme. - You can use jq to retrieve the theme settings by piping the output to jq, e.g. - - node wmiocli.js -d env -u user -p pass theme fl40018d9a1a273bb8aa92bf | jq -c .output.settings.theme > ~/dracula-theme.txt - - \x1b[32mDeletes a whitelabel theme\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - theme-delete [theme-uid] - - \x1b[32mCreates a new whitelabel theme\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - theme-create dracula 'desc' [theme-settings] "Footer Text" "About Page" - - Theme settings can be used from the list example above, e.g. - node wmiocli.js -d env -u user -p pass theme-create dracula7 'updated' "\`cat ~/dracula-theme.txt\`" 'Footer' 'About' - - \x1b[32mUpdates a whitelabel theme\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - theme-update themeid dracula 'desc' [theme-settings] "Footer Text" "About Page" - - Theme settings can be used from the list example above, e.g. - node wmiocli.js -d env -u user -p pass theme-update themeid dracula7 'updated' "\`cat ~/dracula-theme.txt\`" 'Footer' 'About' + .addHelpText('after', ` - \x1b[32mActivates a whitelabel theme\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - theme-activate [theme-uid] +Examples: - \x1b[32mDeactivates a whitelabel theme\x1b[0m - $ node wmiocli.js - -d tenant.int-aws-us.webmethods.io - -u user - -p password - theme-deactivate [theme-uid] +\x1b[4mHelp\x1b[0m -`) +\x1b[32mShow the command line help:\x1b[0m +$ node wmiocli.js --help +` + + project.help() + + wf.help() + + flowservice.help() + + role.help() + + recipe.help() + + theme.help() +) .showSuggestionAfterError() ; @@ -786,14 +520,58 @@ program.command('flowservice-execute [input-json]') recipe.create(filename); }); - /* - program.command('project-delete ') - .description('Delete project with given id') - .action((projectId) => { - checkOptions(); - project.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) - project.del(projectId); - });*/ + /** + * ------------------------------------------------------------------------------------------------------------------------------------ + * unofficial non-public APIs + * ------------------------------------------------------------------------------------------------------------------------------------ + */ + program.command('unofficial-user') + .description('Get User information') + .action(() => { + checkOptions(); + unofficial.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) + unofficial.user(); + }); + + program.command('unofficial-stages') + .description('Get Stage information') + .action(() => { + checkOptions(); + unofficial.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) + unofficial.stages(); + }); + + program.command('unofficial-project-workflows ') + .description('Get Information about project workflows') + .action((projectId) => { + checkOptions(); + unofficial.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) + unofficial.projectWorkflows(projectId); + }); + + program.command('unofficial-project-flowservices ') + .description('Get Information about project FlowServices') + .action((projectId) => { + checkOptions(); + unofficial.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) + unofficial.projectFlowservices(projectId); + }); + + program.command('unofficial-project-connector-accounts ') + .description('Get Information about project connector acconts') + .action((projectId) => { + checkOptions(); + unofficial.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) + unofficial.connectorAccounts(projectId); + }); + + program.command('unofficial-project-connector-accontw-wf-config ') + .description('Get Configuratoin Information about project connector acconts') + .action((projectId) => { + checkOptions(); + unofficial.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) + unofficial.getProjectAccountConfig(projectId); + }); program.parse(); diff --git a/workflow.js b/workflow.js index c0a6564..e03b061 100644 --- a/workflow.js +++ b/workflow.js @@ -5,23 +5,64 @@ */ const rest = require('./rest.js'); -const dbg = require('./debug.js'); - -var domainName, username,password,timeout,prettyprint; +var domainName, username, password, timeout, prettyprint; var url; -function debug(message){ +function debug(message) { dbg.message(" " + message); } -function init(inDomainName, inUsername, inPassword,inTimeout,inPrettyPrint,projectId){ +function help() { + return ` +\x1b[4mWorkflow\x1b[0m + +\x1b[32mExport Workflow from a given project (identified from URL in webMethods.io when in workflow canvas, +i.e. https://tenant.int-aws-us.webmethods.io/#/projects/\x1b[1mfl65d3aa87fc1783ea5cf8c8\x1b[0m\x1b[32m/workflows/\x1b[1mfl52232a2dfafbd6536963d7\x1b[0m\x1b[32m/edit):\x1b[0m\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + workflow-export fl65d3aa87fc1783ea5cf8c8 fl52232a2dfafbd6536963d7 export.zip + +\x1b[32mImport Workflow from a given file into a project \x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + workflow-import fl65d3aa87fc1783ea5cf8c8 export.zip + +\x1b[32mDelete Workflow from a given project\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + workflow-delete fl65d3aa87fc1783ea5cf8c8 fl52232a2dfafbd6536963d7 + +\x1b[32mExecute a Workflow from a given project\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + workflow-execute fl65d3aa87fc1783ea5cf8c8 fl52232a2dfafbd6536963d7 + +\x1b[32mGet Workflow execution status from a given project\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + workflow-status fl65d3aa87fc1783ea5cf8c8 vbid3d247cd26aa5e19354e1fc6951766a3d19c049bee11d + +`; +} + +function init(inDomainName, inUsername, inPassword, inTimeout, inPrettyPrint, projectId) { domainName = inDomainName; username = inUsername; password = inPassword; timeout = inTimeout; prettyprint = inPrettyPrint; - url = "https://" + domainName + "/apis/v1/rest/projects/" + projectId ; + url = "https://" + domainName + "/apis/v1/rest/projects/" + projectId; debug("Username [" + username + "]"); debug("URL [" + url + "]"); debug("Timeout [" + timeout + "]"); @@ -32,77 +73,76 @@ function init(inDomainName, inUsername, inPassword,inTimeout,inPrettyPrint,proje * @param {return data from REST request} data * @param {status} status */ - function processResponse(data,status){ - if(prettyprint==true){ - console.log(JSON.stringify(data,null,4)); +function processResponse(data, status) { + if (prettyprint == true) { + console.log(JSON.stringify(data, null, 4)); } - else{ + else { console.log(JSON.stringify(data)); } - - if(status!=0){ + + if (status != 0) { process.exit(status); } } -function downloadExport(data,status,filename){ +function downloadExport(data, status, filename) { debug("Downloading Export"); - if(status!=0){ + if (status != 0) { console.log(JSON.stringify(data)); process.exit(status); } - else{ - rest.downloadFile(data,filename,downloadCompleted); + else { + rest.downloadFile(data, filename, downloadCompleted); } } -function downloadCompleted(data,status,filename) -{ +function downloadCompleted(data, status, filename) { debug("Download Completed"); - if(status!=0){ + if (status != 0) { console.log('{'); - console.log(' workflow-export":"error", "filename":"'+ filename +','); + console.log(' workflow-export":"error", "filename":"' + filename + ','); console.log(JSON.stringifydata); console.log('}'); process.exit(status); } - else{ - console.log('{"workflow-export":"success", "filename":"'+ filename + '"}'); + else { + console.log('{"workflow-export":"success", "filename":"' + filename + '"}'); } } -function exportwf(wfId, filename){ +function exportwf(wfId, filename) { debug("Exporting Workflow"); - url+="/workflows/" + wfId + "/export"; - var data={}; - rest.postDownloadFile(url,username,password,timeout,data,filename,downloadExport); + url += "/workflows/" + wfId + "/export"; + var data = {}; + rest.postDownloadFile(url, username, password, timeout, data, filename, downloadExport); } -function importwf(filename){ +function importwf(filename) { debug("Importing Workflow"); - url+="/workflow-import"; - rest.postUploadFile(url,username,password,timeout,undefined,filename,processResponse); - + url += "/workflow-import"; + rest.postUploadFile(url, username, password, timeout, undefined, filename, processResponse); + } -function runwf(workflowId){ +function runwf(workflowId) { debug("Running Workflow with ID [" + workflowId + "]"); url += "/workflows/" + workflowId + "/run"; - rest.post(url,username,password,timeout,undefined,processResponse); - + rest.post(url, username, password, timeout, undefined, processResponse); + } -function statuswf(runId){ +function statuswf(runId) { debug("Getting Workflow Status with run id [" + runId + "]"); - url += "/workflow-run/" + runId ; + url += "/workflow-run/" + runId; debug("URL is: " + url); - rest.get(url,username,password,timeout,processResponse); + rest.get(url, username, password, timeout, processResponse); } -function deletewf(workflowId){ +function deletewf(workflowId) { debug("Deleting Workflow with ID [" + workflowId + "]"); url += "/workflows/" + workflowId; - rest.del(url,username,password,timeout,{},processResponse); + rest.del(url, username, password, timeout, {}, processResponse); } -module.exports = { init, exportwf, importwf, runwf, statuswf, deletewf }; +module.exports = { help, init, exportwf, importwf, runwf, statuswf, deletewf }; From eacda0b0b49beb883148173bae98885458a54ff3 Mon Sep 17 00:00:00 2001 From: sagpembo Date: Tue, 26 Jul 2022 13:43:25 +0100 Subject: [PATCH 2/7] changed filename to experimental --- unofficial.js => experimental.js | 6 ++-- wmiocli.js | 48 ++++++++++++++++---------------- 2 files changed, 27 insertions(+), 27 deletions(-) rename unofficial.js => experimental.js (98%) diff --git a/unofficial.js b/experimental.js similarity index 98% rename from unofficial.js rename to experimental.js index 54fc554..760051b 100644 --- a/unofficial.js +++ b/experimental.js @@ -5,7 +5,7 @@ */ // ------------------------------------------------------------------------------ -// PLEASE NOTE - These functions are NOT provided by NON public APIs, and +// PLEASE NOTE - These functions are provided by NON public APIs, and // therefore unsupported - use these at your own risk! // ------------------------------------------------------------------------------ @@ -27,12 +27,12 @@ var finalCall; var loginStageCounter = 0; function debug(message){ - dbg.message(" " + message); + dbg.message(" " + message); } function init(inDomainName, inUsername, inPassword,inTimeout,inPrettyprint){ - dbg.message("UNSUPPORTED APIs - USE THESE AT YOUR OWN RISK"); + dbg.message("EXPERIMENTAL/UNSUPPORTED APIs - USE THESE AT YOUR OWN RISK"); domainName = inDomainName; username = inUsername; password = inPassword; diff --git a/wmiocli.js b/wmiocli.js index b44c4e3..5f6e4cc 100644 --- a/wmiocli.js +++ b/wmiocli.js @@ -13,7 +13,7 @@ var wf = require('./workflow.js'); var theme = require('./themes.js'); var recipe = require('./recipe.js'); var flowservice = require('./flowservice.js'); -var unofficial = require('./unofficial.js'); +var experimental = require('./experimental.js'); dbg = require('./debug.js'); prettyprint = false; @@ -522,55 +522,55 @@ program.command('flowservice-execute [input-json]') /** * ------------------------------------------------------------------------------------------------------------------------------------ - * unofficial non-public APIs + * experimental non-public APIs * ------------------------------------------------------------------------------------------------------------------------------------ */ - program.command('unofficial-user') + program.command('experimental-user') .description('Get User information') .action(() => { checkOptions(); - unofficial.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) - unofficial.user(); + experimental.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) + experimental.user(); }); - program.command('unofficial-stages') + program.command('experimental-stages') .description('Get Stage information') .action(() => { checkOptions(); - unofficial.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) - unofficial.stages(); + experimental.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) + experimental.stages(); }); - program.command('unofficial-project-workflows ') - .description('Get Information about project workflows') + program.command('experimental-project-workflows ') + .description('Get information about project workflows') .action((projectId) => { checkOptions(); - unofficial.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) - unofficial.projectWorkflows(projectId); + experimental.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) + experimental.projectWorkflows(projectId); }); - program.command('unofficial-project-flowservices ') - .description('Get Information about project FlowServices') + program.command('experimental-project-flowservices ') + .description('Get information about project FlowServices') .action((projectId) => { checkOptions(); - unofficial.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) - unofficial.projectFlowservices(projectId); + experimental.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) + experimental.projectFlowservices(projectId); }); - program.command('unofficial-project-connector-accounts ') - .description('Get Information about project connector acconts') + program.command('experimental-project-connector-accounts ') + .description('Get Information about project connector accounts') .action((projectId) => { checkOptions(); - unofficial.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) - unofficial.connectorAccounts(projectId); + experimental.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) + experimental.connectorAccounts(projectId); }); - program.command('unofficial-project-connector-accontw-wf-config ') - .description('Get Configuratoin Information about project connector acconts') + program.command('experimental-project-connector-account-wf-config ') + .description('Get configuration information about project connector accounts') .action((projectId) => { checkOptions(); - unofficial.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) - unofficial.getProjectAccountConfig(projectId); + experimental.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) + experimental.getProjectAccountConfig(projectId); }); program.parse(); From 8e00f29e4d9cd572fe060dd7c933d74f4ca93c3b Mon Sep 17 00:00:00 2001 From: sagpembo Date: Mon, 15 Aug 2022 09:21:57 +0100 Subject: [PATCH 3/7] added new experimental options --- experimental.js | 92 ++++++++++++++++++++++++++++++++++++--- package-lock.json | 108 +++++++++++++++++++++++----------------------- wmiocli.js | 19 +++++++- 3 files changed, 158 insertions(+), 61 deletions(-) diff --git a/experimental.js b/experimental.js index 760051b..6336a5e 100644 --- a/experimental.js +++ b/experimental.js @@ -12,6 +12,7 @@ const request = require('request'); const rest = require('./rest.js'); const fs = require('fs'); +const { findSourceMap } = require('module'); var domainName, username,password,timeout; @@ -22,6 +23,7 @@ var authtoken=""; var uid=""; var csrf=""; var projectId; +var projectName ; var nextUrl,formUrl; var finalCall; var loginStageCounter = 0; @@ -84,6 +86,50 @@ function getProjectAccountConfig(inProjectId) loginPhase1(); } +function projectDeployments(inProjectId) +{ + debug("Listing project deployments for projectId [" + inProjectId + "]"); + projectId = inProjectId; + finalCall = getProjectDeployments; + loginPhase1(); +} + +function searchProject(inProjectName) +{ + projectName = inProjectName; + finalCall = searchProjectsByName; + loginPhase1(); +} + + +function searchProjectsByName() +{ + debug("Search Projects By Name [" + projectName + "]"); + var endPoint = "https://" + domainName + "/enterprise/v1/projects?limit=25&skip=0&q=" + projectName; + debug("Next URL [" + endPoint + "]"); + + var headers = [ + {name:"authtoken",value:authtoken}, + {name:"accept",value:"application/json"}, + {name:"x-csrf-token",value:csrf}, + ]; + rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",processResponse,undefined,headers,true,false); +} + +function getProjectDeployments() +{ + debug("Executing Project Deployments call"); + var endPoint = "https://" + domainName + "/enterprise/v1/deployments"; + debug("Next URL [" + endPoint + "]"); + + var headers = [ + {name:"authtoken",value:authtoken}, + {name:"accept",value:"application/json"}, + {name:"project_uid",value:projectId}, + {name:"x-csrf-token",value:csrf}, + ]; + rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",processResponse,undefined,headers,true,false); +} function stageInfo() { @@ -101,7 +147,7 @@ function stageInfo() function getProjectAccountConfigInfo() { - debug("PRojet Account Config Info"); + debug("Project Account Config Info"); var endPoint = "https://" + domainName + "/enterprise/v1/configdata"; debug("Next URL [" + endPoint + "]"); @@ -245,7 +291,7 @@ function checkResponse(res,body) } if(res.statusCode == 200){ - //debug(body); + debug(body); } if(res.statusCode == 400 || res.statusCode == 404 || res.statusCode == 500 || res.statusCode == 502 || res.statusCode == 403 || res.statusCode == 401) @@ -254,9 +300,40 @@ function checkResponse(res,body) console.log(res); process.exit(99); } +} + +function checkPhase3Response(res,body) +{ + debug("Response Status Code =" + res.statusCode); + if(res.statusCode == 302){ + nextUrl = res.headers.location; + debug("Redirect URL [" + nextUrl + "]"); + } + + if(res.statusCode == 200){ + //debug(body); + //find + //extract the error and return error message + err = body.split('')[0]; + + error ={} + error.message = err; + debug("Failed to login via Software AG Cloud [" + err + "] - exiting") + console.log(JSON.stringify(error)); + + process.exit(401); + } + if(res.statusCode == 400 || res.statusCode == 404 || res.statusCode == 500 || res.statusCode == 502 || res.statusCode == 403 || res.statusCode == 401) + { + debug("Failed to login via Software AG Cloud - exiting") + console.log(res); + process.exit(99); + } } + function processProjectsResponse(url,err,body,res){ //console.log(body); @@ -370,7 +447,7 @@ function loginResponse(url,err,body,res){ break; case 3: - checkResponse(res,body); + checkPhase3Response(res,body); nextCall = loginRedirectPhase(4); break; @@ -398,10 +475,13 @@ function loginResponse(url,err,body,res){ //Invoke next call in chain - if(nextCall!==undefined)nextCall(); - + if(nextCall!==undefined) + { + debug("Found target call... initiating"); + nextCall(); + } } -module.exports = {init,user,stages,projectWorkflows,projectFlowservices,connectorAccounts,getProjectAccountConfig}; \ No newline at end of file +module.exports = {init,user,stages,projectWorkflows,projectFlowservices,connectorAccounts,getProjectAccountConfig,searchProject,projectDeployments}; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 2d4406b..9da6dcc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,10 +10,10 @@ "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", "dev": true, "requires": { - "fast-deep-equal": "^3.1.1", - "fast-json-stable-stringify": "^2.0.0", - "json-schema-traverse": "^0.4.1", - "uri-js": "^4.2.2" + "fast-deep-equal": "3.1.3", + "fast-json-stable-stringify": "2.1.0", + "json-schema-traverse": "0.4.1", + "uri-js": "4.4.1" } }, "asn1": { @@ -22,7 +22,7 @@ "integrity": "sha512-ix/FxPn0MDjeyJ7i/yoHGFt/EX6LyNbxSEhPPXODPL+KB0VPk86UYfL0lMdy+KCnv+fmvIzySwaK5COwqVbWTQ==", "dev": true, "requires": { - "safer-buffer": "~2.1.0" + "safer-buffer": "2.1.2" } }, "assert-plus": { @@ -55,7 +55,7 @@ "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=", "dev": true, "requires": { - "tweetnacl": "^0.14.3" + "tweetnacl": "0.14.5" } }, "caseless": { @@ -70,7 +70,7 @@ "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", "dev": true, "requires": { - "delayed-stream": "~1.0.0" + "delayed-stream": "1.0.0" } }, "commander": { @@ -91,7 +91,7 @@ "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", "dev": true, "requires": { - "assert-plus": "^1.0.0" + "assert-plus": "1.0.0" } }, "delayed-stream": { @@ -106,8 +106,8 @@ "integrity": "sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=", "dev": true, "requires": { - "jsbn": "~0.1.0", - "safer-buffer": "^2.1.0" + "jsbn": "0.1.1", + "safer-buffer": "2.1.2" } }, "extend": { @@ -146,9 +146,9 @@ "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", "dev": true, "requires": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.6", - "mime-types": "^2.1.12" + "asynckit": "0.4.0", + "combined-stream": "1.0.8", + "mime-types": "2.1.34" } }, "getpass": { @@ -157,7 +157,7 @@ "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", "dev": true, "requires": { - "assert-plus": "^1.0.0" + "assert-plus": "1.0.0" } }, "har-schema": { @@ -172,8 +172,8 @@ "integrity": "sha512-nmT2T0lljbxdQZfspsno9hgrG3Uir6Ks5afism62poxqBM6sDnMEuPmzTq8XN0OEwqKLLdh1jQI3qyE66Nzb3w==", "dev": true, "requires": { - "ajv": "^6.12.3", - "har-schema": "^2.0.0" + "ajv": "6.12.6", + "har-schema": "2.0.0" } }, "http-signature": { @@ -182,9 +182,9 @@ "integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=", "dev": true, "requires": { - "assert-plus": "^1.0.0", - "jsprim": "^1.2.2", - "sshpk": "^1.7.0" + "assert-plus": "1.0.0", + "jsprim": "1.4.2", + "sshpk": "1.17.0" } }, "is-typedarray": { @@ -291,26 +291,26 @@ "integrity": "sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==", "dev": true, "requires": { - "aws-sign2": "~0.7.0", - "aws4": "^1.8.0", - "caseless": "~0.12.0", - "combined-stream": "~1.0.6", - "extend": "~3.0.2", - "forever-agent": "~0.6.1", - "form-data": "~2.3.2", - "har-validator": "~5.1.3", - "http-signature": "~1.2.0", - "is-typedarray": "~1.0.0", - "isstream": "~0.1.2", - "json-stringify-safe": "~5.0.1", - "mime-types": "~2.1.19", - "oauth-sign": "~0.9.0", - "performance-now": "^2.1.0", - "qs": "~6.5.2", - "safe-buffer": "^5.1.2", - "tough-cookie": "~2.5.0", - "tunnel-agent": "^0.6.0", - "uuid": "^3.3.2" + "aws-sign2": "0.7.0", + "aws4": "1.11.0", + "caseless": "0.12.0", + "combined-stream": "1.0.8", + "extend": "3.0.2", + "forever-agent": "0.6.1", + "form-data": "2.3.3", + "har-validator": "5.1.5", + "http-signature": "1.2.0", + "is-typedarray": "1.0.0", + "isstream": "0.1.2", + "json-stringify-safe": "5.0.1", + "mime-types": "2.1.34", + "oauth-sign": "0.9.0", + "performance-now": "2.1.0", + "qs": "6.5.3", + "safe-buffer": "5.2.1", + "tough-cookie": "2.5.0", + "tunnel-agent": "0.6.0", + "uuid": "3.4.0" } }, "safe-buffer": { @@ -331,15 +331,15 @@ "integrity": "sha512-/9HIEs1ZXGhSPE8X6Ccm7Nam1z8KcoCqPdI7ecm1N33EzAetWahvQWVqLZtaZQ+IDKX4IyA2o0gBzqIMkAagHQ==", "dev": true, "requires": { - "asn1": "~0.2.3", - "assert-plus": "^1.0.0", - "bcrypt-pbkdf": "^1.0.0", - "dashdash": "^1.12.0", - "ecc-jsbn": "~0.1.1", - "getpass": "^0.1.1", - "jsbn": "~0.1.0", - "safer-buffer": "^2.0.2", - "tweetnacl": "~0.14.0" + "asn1": "0.2.6", + "assert-plus": "1.0.0", + "bcrypt-pbkdf": "1.0.2", + "dashdash": "1.14.1", + "ecc-jsbn": "0.1.2", + "getpass": "0.1.7", + "jsbn": "0.1.1", + "safer-buffer": "2.1.2", + "tweetnacl": "0.14.5" } }, "tough-cookie": { @@ -348,8 +348,8 @@ "integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==", "dev": true, "requires": { - "psl": "^1.1.28", - "punycode": "^2.1.1" + "psl": "1.8.0", + "punycode": "2.1.1" } }, "tunnel-agent": { @@ -358,7 +358,7 @@ "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", "dev": true, "requires": { - "safe-buffer": "^5.0.1" + "safe-buffer": "5.2.1" } }, "tweetnacl": { @@ -373,7 +373,7 @@ "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", "dev": true, "requires": { - "punycode": "^2.1.0" + "punycode": "2.1.1" } }, "uuid": { @@ -388,9 +388,9 @@ "integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=", "dev": true, "requires": { - "assert-plus": "^1.0.0", + "assert-plus": "1.0.0", "core-util-is": "1.0.2", - "extsprintf": "^1.2.0" + "extsprintf": "1.3.0" } } } diff --git a/wmiocli.js b/wmiocli.js index 5f6e4cc..996f589 100644 --- a/wmiocli.js +++ b/wmiocli.js @@ -572,7 +572,24 @@ program.command('flowservice-execute [input-json]') experimental.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) experimental.getProjectAccountConfig(projectId); }); - + + program.command('experimental-project-search ') + .description('Search project info by name') + .action((projectName) => { + checkOptions(); + experimental.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) + experimental.searchProject(projectName); + }); + + program.command('experimental-project-deployments ') + .description('List all project deployments') + .action((projectId) => { + checkOptions(); + experimental.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) + experimental.projectDeployments(projectId); + }); + + program.parse(); From 338874194091ca4e64bb86b506911d5ee059075a Mon Sep 17 00:00:00 2001 From: sagpembo Date: Thu, 25 Aug 2022 15:14:21 +0100 Subject: [PATCH 4/7] added project-assets-detail --- projects.js | 19 ++++++++++++++++--- wmiocli.js | 9 +++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/projects.js b/projects.js index 9955ea0..c6c9816 100644 --- a/projects.js +++ b/projects.js @@ -41,7 +41,14 @@ $ node wmiocli.js -d tenant.int-aws-us.webmethods.io -u user -p password - project-assets Default + project-assets Default + +\x1b[32mView Project assets (All Details) from project with given name:\x1b[0m + $ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + project-assets-detailed Default \x1b[32mUpdate Project name:\x1b[0m $ node wmiocli.js @@ -106,7 +113,7 @@ $ node wmiocli.js -p password project-param-update projectName param-uid param-name param-value required isPassword -\x1b[32mDelete Project Workflow Parameter\x1b[0m +\x1b[32mDelete Project Workflow Parameter matching the provided parameter id\x1b[0m $ node wmiocli.js -d tenant.int-aws-us.webmethods.io -u user @@ -205,6 +212,12 @@ function listAssets(projectId) { request.get(url, username, password, timeout, processResponse); } +function listAssetsDetailed(projectId) { + debug("List Assets [" + projectId + "]"); + if (projectId) url += "/" + projectId + "/assets?complete=true" ; + request.get(url, username, password, timeout, processResponse); +} + /* Project Params */ function listParam(projectId, paramId) { debug("List Params [" + projectId + "] Param ID [" + paramId + "]"); @@ -304,7 +317,7 @@ function deploy(projectName, version) { module.exports = { help, init, list, create, update, del, - listAssets, pub, deploy, + listAssets, listAssetsDetailed, pub, deploy, createParam, updateParam, listParam, deleteParam, listWebhooks, regenWebhook, setWebhookAuth }; diff --git a/wmiocli.js b/wmiocli.js index 996f589..0241e2d 100644 --- a/wmiocli.js +++ b/wmiocli.js @@ -175,6 +175,15 @@ program.command('project-assets ') if(resp)console.log(resp); }); +program.command('project-assets-detailed ') +.description('Lists project assets (All Details) from given project name or uid') +.action((projectName) => { + checkOptions(); + project.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) + var resp = project.listAssetsDetailed(projectName); + if(resp)console.log(resp); +}); + program.command('project-create ') .description('Create project with given name') .action((projectName) => { From 74c3d61374bd03b25ff06d63ba9c6a6a18098f75 Mon Sep 17 00:00:00 2001 From: sagpembo Date: Tue, 20 Sep 2022 23:02:20 +0100 Subject: [PATCH 5/7] experimental updates 10.15 API updates --- experimental.js | 289 +++++++++++++++++++++++++++++++++++++++++++++++- projects.js | 32 +++++- rest.js | 9 +- wmiocli.js | 62 +++++++++-- workflow.js | 17 ++- 5 files changed, 394 insertions(+), 15 deletions(-) diff --git a/experimental.js b/experimental.js index 6336a5e..f6376aa 100644 --- a/experimental.js +++ b/experimental.js @@ -13,6 +13,7 @@ const request = require('request'); const rest = require('./rest.js'); const fs = require('fs'); const { findSourceMap } = require('module'); +const { brotliDecompress, brotliCompressSync } = require('zlib'); var domainName, username,password,timeout; @@ -23,11 +24,22 @@ var authtoken=""; var uid=""; var csrf=""; var projectId; +var workflowId; var projectName ; +var executionStatus; +var startDate; +var endDate; +var startOrResume; var nextUrl,formUrl; var finalCall; var loginStageCounter = 0; +const maxRunningWorkflows = 20; + +function info(message){ + message = " INFO: \x1b[32m" + message + "\x1b[0m" + console.log(message); +} function debug(message){ dbg.message(" " + message); } @@ -101,6 +113,281 @@ function searchProject(inProjectName) loginPhase1(); } +function getMonitorInfo(inExecutionStatus,inStartDate,inEndDate,inProjectId,inWorkflowId,) +{ + projectId = inProjectId; + workflowId = inWorkflowId; + executionStatus = inExecutionStatus; + startDate = inStartDate; + endDate = inEndDate; + finalCall = getLogs; + loginPhase1(); +} + +function workflowResubmit(instartOrResume, inStartDate,inEndDate, inProjectId,inWorkflowId,) +{ + projectId = inProjectId; + workflowId = inWorkflowId; + startDate = inStartDate; + endDate = inEndDate; + startOrResume = instartOrResume; + finalCall = checkResubmissions; + loginPhase1(); +} + +function debugMonitorInfo() +{ + debug("Monitor Project: [" + projectName + "]"); + debug("Monitor workflowId: [" + workflowId + "]"); + debug("Monitor executionStatus: [" + executionStatus + "]"); + debug("Monitor startDate: [" + startDate + "]"); + debug("Monitor endDate: [" + endDate + "]"); +} + +function processMonitorBody() +{ + var body={}; + + if(endDate)body.end_date = endDate; + if(startDate)body.start_date = startDate; + else + { + startDate = new Date(); + startDate.setHours(0); + startDate.setMinutes(0); + startDate.setSeconds(0); + startDate.setMilliseconds(0); + + if(!endDate) + { + endDate = new Date; + endDate.setHours(23); + endDate.setMinutes(59); + endDate.setSeconds(59); + endDate.setMilliseconds(999); + } + body.start_date=startDate; + body.end_date=endDate; + } + + if(projectId)body.projects=[projectId] + if(workflowId)body.workflows = [workflowId]; + if(executionStatus)body.execution_status = [executionStatus]; + body.skip=0; + body.limit=20; + return body; +} + +function setHeaders() +{ + var headers = [ + {name:"authtoken",value:authtoken}, + {name:"accept",value:"application/json"}, + {name:"x-csrf-token",value:csrf}, + ]; + return headers; +} + +function checkResubmissions() +{ + debug("Check Resubmissions") + debugMonitorInfo(); + //Check running + var endPoint = "https://" + domainName + "/enterprise/v1/metrics/workflowexecutions/logs"; + debug("Next URL [" + endPoint + "]"); + var body=processMonitorBody(); + body.execution_status=["running"]; + var headers = setHeaders(); + rest.custom(endPoint,undefined,undefined,60,body,undefined,"POST",processRunningResponse,undefined,headers,true,false); +} + +function processResubmissions(reprocessCount) +{ + debug("Process Resubmissions") + debugMonitorInfo(); + //Check running + var endPoint = "https://" + domainName + "/enterprise/v1/metrics/workflowexecutions/logs"; + debug("Next URL [" + endPoint + "]"); + var body=processMonitorBody(); + body.limit=reprocessCount; + body.execution_status=["failed"]; + var headers = setHeaders(); + rest.custom(endPoint,undefined,undefined,60,body,undefined,"POST",processListResponse,undefined,headers,true,false); +} + +function processSingleResubmission(a,b, vbid) +{ + info("Processing Resubmission [" + a + " of " + b + "] Action [" + startOrResume + "] VBID [" + vbid + "]"); + var endPoint = "https://cpointegrationdev.int-aws-de.webmethods.io/enterprise/v1/tenant/account/billlogs/" + vbid; + debug("Next URL [" + endPoint + "]"); + //var body=processMonitorBody(); + //body.limit=reprocessCount; + //body.execution_status=["failed"]; + var headers = setHeaders(); + rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",processSingleResubmissionResponse,undefined,headers,true,false); +} + +function finishProcessSingleResubmission(vbid,wfuid,payloaduid,projectuid,flowname,stoptime) +{ + info("Actioning Resubmission Action [" + startOrResume + "] VBID [" + vbid + "]"); + var endPoint = "https://" + domainName + "/enterprise/v1/execute/" + wfuid + "/resume" + debug("Next URL [" + endPoint + "]"); + //var body=processMonitorBody(); + //body.limit=reprocessCount; + //body.execution_status=["failed"]; + var headers = [ + {name:"authtoken",value:authtoken}, + {name:"accept",value:"application/json"}, + {name:"x-csrf-token",value:csrf}, + {name:"project_uid",value:projectuid}, + ]; + var body = {"bill_uid":vbid,"__is_checkpoint_run__":true,"payload_uid":payloaduid,"checkpointLogs":[]}; + rest.custom(endPoint,undefined,undefined,60,body,undefined,"POST",processFinalSingleResubmissionResponse,undefined,headers,true,false); +} + +function processFinalSingleResubmissionResponse(url,err,body,res){ + if(res.statusCode==200) + { + info("Processed"); + } + else + { + info("Failed to Resubmit entry") + console.log(body); + process.exit(99); + } +} + +function processSingleResubmissionResponse(url,err,body,res){ + if(res.statusCode==200) + { + if(body.output.uid) + { + info("Found Monitor Entry"); + info("VBID [" + body.output.uid + "]"); + info("Flow UID [" + body.output.flow_uid + "]"); + info("Payload UID [" + body.output.payload_uid + "]"); + info("Project_UID [" + body.output.project_uid + "]"); + info("Flow Name [" + body.output.flow_name + "]"); + info("Stop time [" + body.output.stop_time + "]"); + finishProcessSingleResubmission(body.output.uid,body.output.flow_uid,body.output.payload_uid,body.output.project_uid,body.output.flow_name,body.output.stop_time); + } + else{ + + info("Not able to find monitor entry"); + } + } + else + { + info("Failed to get Monitor entry") + console.log(body); + process.exit(99); + } +} + +function processRunningResponse(url,err,body,res){ + //console.log(body); + if(res.statusCode==200) + { + //... do something next + if(body.output.count==0) + { + info("No Workflows Running") + info("Can Resubmit [" + (maxRunningWorkflows - body.output.count) + "] executions"); + } + else{ + info("Workflows Running [" +body.output.count + "]") + if(body.output.count ') }); program.command('project-param [param-uid]') -.description('Lists all project parameters from given project name, or specific parameter with given paramater uid') +.description('Lists all project parameters from given project name, or specific parameter with given parameter uid') .action((projectName,paramName) => { checkOptions(); project.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) @@ -294,6 +294,22 @@ program.command('project-webhooks-auth ') project.setWebhookAuth(projectId,workflowUid,authType); }); +program.command('project-triggers-list ') +.description('Provide a list of triggers within a project') +.action((projectId) => { + checkOptions(); + project.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) + project.listTriggers(projectId); +}); + +program.command('project-triggers-delete ') +.description('Delete a trigger within a project with the given IDs') +.action((projectId,triggerId) => { + checkOptions(); + project.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) + project.deleteTrigger(projectId,triggerId); +}); + /** * ------------------------------------------------------------------------------------------------------------------------------------ @@ -362,7 +378,7 @@ program.command('user-role-assignment ') /** * ------------------------------------------------------------------------------------------------------------------------------------ - * WORKFLOW IMPORT/EXPORT/DELETE/EXECUTE/STATUS + * WORKFLOW IMPORT/EXPORT/DELETE/EXECUTE/STATUS/CREATE * ------------------------------------------------------------------------------------------------------------------------------------ */ program.command('workflow-export ') @@ -407,6 +423,14 @@ program.command('workflow-status ') wf.statuswf(runId); }); +program.command('workflow-create ') +.description('Creates a blank workflow with the given name/description') +.action((projectId, workflowName,workflowDescription) => { + checkOptions(); + wf.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,projectId); + wf.createwf(workflowName,workflowDescription); +}); + /** * ------------------------------------------------------------------------------------------------------------------------------------ * FLOW SERVICE IMPORT/EXPORT/DELETE/EXECUTE @@ -534,7 +558,8 @@ program.command('flowservice-execute [input-json]') * experimental non-public APIs * ------------------------------------------------------------------------------------------------------------------------------------ */ - program.command('experimental-user') + program.command('experimental-user',{hidden: true}) + .addHelpCommand("HELP") .description('Get User information') .action(() => { checkOptions(); @@ -542,7 +567,7 @@ program.command('flowservice-execute [input-json]') experimental.user(); }); - program.command('experimental-stages') + program.command('experimental-stages',{hidden: true}) .description('Get Stage information') .action(() => { checkOptions(); @@ -550,7 +575,7 @@ program.command('flowservice-execute [input-json]') experimental.stages(); }); - program.command('experimental-project-workflows ') + program.command('experimental-project-workflows ',{hidden: true}) .description('Get information about project workflows') .action((projectId) => { checkOptions(); @@ -558,7 +583,7 @@ program.command('flowservice-execute [input-json]') experimental.projectWorkflows(projectId); }); - program.command('experimental-project-flowservices ') + program.command('experimental-project-flowservices ',{hidden: true}) .description('Get information about project FlowServices') .action((projectId) => { checkOptions(); @@ -566,7 +591,7 @@ program.command('flowservice-execute [input-json]') experimental.projectFlowservices(projectId); }); - program.command('experimental-project-connector-accounts ') + program.command('experimental-project-connector-accounts ',{hidden: true}) .description('Get Information about project connector accounts') .action((projectId) => { checkOptions(); @@ -574,7 +599,7 @@ program.command('flowservice-execute [input-json]') experimental.connectorAccounts(projectId); }); - program.command('experimental-project-connector-account-wf-config ') + program.command('experimental-project-connector-account-wf-config ',{hidden: true}) .description('Get configuration information about project connector accounts') .action((projectId) => { checkOptions(); @@ -582,7 +607,7 @@ program.command('flowservice-execute [input-json]') experimental.getProjectAccountConfig(projectId); }); - program.command('experimental-project-search ') + program.command('experimental-project-search ',{hidden: true}) .description('Search project info by name') .action((projectName) => { checkOptions(); @@ -590,13 +615,30 @@ program.command('flowservice-execute [input-json]') experimental.searchProject(projectName); }); - program.command('experimental-project-deployments ') + program.command('experimental-project-deployments ',{hidden: true}) .description('List all project deployments') .action((projectId) => { checkOptions(); experimental.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) experimental.projectDeployments(projectId); }); + + program.command('experimental-workflow-monitor [start-date] [end-date] [project-id] [workflow-id] [execution-status]',{hidden: true}) + .description('List Workflow Monitor') + .action((executionStatus,startDate,endDate,projectId,workflowId) => { + checkOptions(); + experimental.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) + experimental.getMonitorInfo(executionStatus,startDate,endDate,projectId,workflowId); + }); + + program.command('experimental-workflow-resubmit [restart-or-resume] [start-date] [end-date] [project-id] [workflow-id]',{hidden: true}) + .description('Resubmit workflows from monitor') + .action((restartOrResume,startDate,endDate,projectId,workflowId) => { + checkOptions(); + experimental.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) + experimental.workflowResubmit(restartOrResume, startDate, endDate, projectId,workflowId); + }); + program.parse(); diff --git a/workflow.js b/workflow.js index e03b061..5ff4df3 100644 --- a/workflow.js +++ b/workflow.js @@ -32,6 +32,13 @@ $ node wmiocli.js -p password workflow-import fl65d3aa87fc1783ea5cf8c8 export.zip +\x1b[32mCreate a blank workflow\x1b[0m +$ node wmiocli.js + -d tenant.int-aws-us.webmethods.io + -u user + -p password + workflow-create fl65d3aa87fc1783ea5cf8c8 "name" "description" + \x1b[32mDelete Workflow from a given project\x1b[0m $ node wmiocli.js -d tenant.int-aws-us.webmethods.io @@ -52,7 +59,7 @@ $ node wmiocli.js -u user -p password workflow-status fl65d3aa87fc1783ea5cf8c8 vbid3d247cd26aa5e19354e1fc6951766a3d19c049bee11d - + `; } @@ -145,4 +152,10 @@ function deletewf(workflowId) { rest.del(url, username, password, timeout, {}, processResponse); } -module.exports = { help, init, exportwf, importwf, runwf, statuswf, deletewf }; +function createwf(workflowName,workflowDesc) { + debug("Creating Workflow with Name [" + workflowName + "]"); + url += "/workflows/"; + rest.post(url, username, password, timeout, {"name":workflowName,"description":workflowDesc}, processResponse); +} + +module.exports = { help, init, exportwf, importwf, runwf, statuswf, deletewf, createwf }; From 021c7405389c5995319046f22d0199eceefbe640 Mon Sep 17 00:00:00 2001 From: sagpembo Date: Thu, 22 Sep 2022 17:25:57 +0100 Subject: [PATCH 6/7] modifed debug to create different levels --- debug.js | 86 ++++++++++++++++++++++++++++--- experimental.js | 134 ++++++++++++++++++++++-------------------------- flowservice.js | 2 +- projects.js | 2 +- recipe.js | 2 +- rest.js | 8 +-- roles.js | 2 +- themes.js | 2 +- users.js | 2 +- wmiocli.js | 45 +++++++++++++--- workflow.js | 2 +- 11 files changed, 190 insertions(+), 97 deletions(-) diff --git a/debug.js b/debug.js index b397579..60d1972 100644 --- a/debug.js +++ b/debug.js @@ -4,16 +4,88 @@ * Apache-2.0 */ -var debug = false; + +const white = "\x1b[37m"; +const Dim = "\x1b[2m"; +const Reset = "\x1b[0m"; +const Green = "\x1b[32m"; +const Red = "\x1b[31m"; +const Cyan = "\x1b[36m"; +const Yellow = "\x1b[33m" + + +const lvl_permanent = -1; +const lvl_off = 0; +const lvl_error = 1; +const lvl_warning = 2; +const lvl_info = 3; +const lvl_debug = 4; + + +var defaultLevel = 0; +activeLevel = 0; + +const prefix =""; + function enableDebug(){ - debug = true; - } + // console.log(Yellow + "ENABLED DEBUG" + Reset ); + setLogLevel(lvl_debug); +} + +function setLogLevel(inLevel){ + + activeLevel = inLevel; + // console.log(Yellow + "SETTING ACTIVE LEVEL TO: " + inLevel ); + // console.log(Yellow + "SETTING: " + activeLevel ); +} -function message(inMessage) +function message(inMessage,level) { - if(debug==true){ - console.log("." + inMessage); + + // console.log(Green + "DEBUG Level:" + level + Reset ); + var message = inMessage; + if(level==undefined)level = 4; + if(level==lvl_permanent)console.log(message); + else + { + // console.log(Green + "Using Level:" + level + Reset ); + // console.log(Green + "Defau Level:" + defaultLevel + Reset ); + + + if(level>activeLevel)return; + switch (level) + { + case lvl_off: + //Nothing to do + break; + + case lvl_debug: + message = Dim + "DEBUG:" + prefix +":"+ inMessage + Reset; + console.log(message); + break; + + case lvl_info: + message = white + "INFO:" + prefix +":"+ inMessage + Reset; + console.log(message); + break; + + case lvl_warning: + message = Yellow + "WARN:" + prefix +":"+ inMessage + Reset; + console.log(message); + break; + + case lvl_error: + message = Red + "ERROR:" + prefix + inMessage + Reset; + console.log(message); + break; + } + } + + + + } -module.exports = { enableDebug, message }; + +module.exports = { enableDebug, message, setLogLevel }; diff --git a/experimental.js b/experimental.js index f6376aa..7686c7f 100644 --- a/experimental.js +++ b/experimental.js @@ -9,11 +9,9 @@ // therefore unsupported - use these at your own risk! // ------------------------------------------------------------------------------ -const request = require('request'); -const rest = require('./rest.js'); -const fs = require('fs'); -const { findSourceMap } = require('module'); -const { brotliDecompress, brotliCompressSync } = require('zlib'); +const request = require("request"); +const rest = require("./rest.js"); + var domainName, username,password,timeout; @@ -36,26 +34,22 @@ var loginStageCounter = 0; const maxRunningWorkflows = 20; -function info(message){ - message = " INFO: \x1b[32m" + message + "\x1b[0m" - console.log(message); -} function debug(message){ - dbg.message(" " + message); + dbg.message(" " + message,4); } function init(inDomainName, inUsername, inPassword,inTimeout,inPrettyprint){ - dbg.message("EXPERIMENTAL/UNSUPPORTED APIs - USE THESE AT YOUR OWN RISK"); + dbg.message("EXPERIMENTAL/UNSUPPORTED APIs - USE THESE AT YOUR OWN RISK",4); domainName = inDomainName; username = inUsername; password = inPassword; timeout = inTimeout; prettyprint = inPrettyprint; url = "https://" + domainName; - dbg.message("Username [" + username + "]"); - dbg.message("URL [" + url + "]"); - dbg.message("Timeout [" + timeout + "]"); + dbg.message("Username [" + username + "]",4); + dbg.message("URL [" + url + "]",4); + dbg.message("Timeout [" + timeout + "]",4); } function user() @@ -100,7 +94,7 @@ function getProjectAccountConfig(inProjectId) function projectDeployments(inProjectId) { - debug("Listing project deployments for projectId [" + inProjectId + "]"); + dbg.message("Listing project deployments for projectId [" + inProjectId + "]",4); projectId = inProjectId; finalCall = getProjectDeployments; loginPhase1(); @@ -113,7 +107,7 @@ function searchProject(inProjectName) loginPhase1(); } -function getMonitorInfo(inExecutionStatus,inStartDate,inEndDate,inProjectId,inWorkflowId,) +function getMonitorInfo(inExecutionStatus,inStartDate,inEndDate,inProjectId,inWorkflowId) { projectId = inProjectId; workflowId = inWorkflowId; @@ -124,7 +118,7 @@ function getMonitorInfo(inExecutionStatus,inStartDate,inEndDate,inProjectId,inWo loginPhase1(); } -function workflowResubmit(instartOrResume, inStartDate,inEndDate, inProjectId,inWorkflowId,) +function workflowResubmit(instartOrResume, inStartDate,inEndDate, inProjectId,inWorkflowId) { projectId = inProjectId; workflowId = inWorkflowId; @@ -217,7 +211,7 @@ function processResubmissions(reprocessCount) function processSingleResubmission(a,b, vbid) { - info("Processing Resubmission [" + a + " of " + b + "] Action [" + startOrResume + "] VBID [" + vbid + "]"); + dbg.message("Processing Resubmission [" + a + " of " + b + "] Action [" + startOrResume + "] VBID [" + vbid + "]",); var endPoint = "https://cpointegrationdev.int-aws-de.webmethods.io/enterprise/v1/tenant/account/billlogs/" + vbid; debug("Next URL [" + endPoint + "]"); //var body=processMonitorBody(); @@ -229,7 +223,7 @@ function processSingleResubmission(a,b, vbid) function finishProcessSingleResubmission(vbid,wfuid,payloaduid,projectuid,flowname,stoptime) { - info("Actioning Resubmission Action [" + startOrResume + "] VBID [" + vbid + "]"); + dbg.message("Actioning Resubmission Action [" + startOrResume + "] VBID [" + vbid + "]",3); var endPoint = "https://" + domainName + "/enterprise/v1/execute/" + wfuid + "/resume" debug("Next URL [" + endPoint + "]"); //var body=processMonitorBody(); @@ -248,12 +242,12 @@ function finishProcessSingleResubmission(vbid,wfuid,payloaduid,projectuid,flowna function processFinalSingleResubmissionResponse(url,err,body,res){ if(res.statusCode==200) { - info("Processed"); + dbg.message("Processed",3); } else { - info("Failed to Resubmit entry") - console.log(body); + dbg.message("Failed to Resubmit entry",1) + dbg.message(body,1); process.exit(99); } } @@ -263,47 +257,46 @@ function processSingleResubmissionResponse(url,err,body,res){ { if(body.output.uid) { - info("Found Monitor Entry"); - info("VBID [" + body.output.uid + "]"); - info("Flow UID [" + body.output.flow_uid + "]"); - info("Payload UID [" + body.output.payload_uid + "]"); - info("Project_UID [" + body.output.project_uid + "]"); - info("Flow Name [" + body.output.flow_name + "]"); - info("Stop time [" + body.output.stop_time + "]"); + dbg.message("Found Monitor Entry",3); + dbg.message("VBID [" + body.output.uid + "]",4); + dbg.message("Flow UID [" + body.output.flow_uid + "]",4); + dbg.message("Payload UID [" + body.output.payload_uid + "]",4); + dbg.message("Project_UID [" + body.output.project_uid + "]",4); + dbg.message("Flow Name [" + body.output.flow_name + "]",4); + dbg.message("Stop time [" + body.output.stop_time + "]",4); finishProcessSingleResubmission(body.output.uid,body.output.flow_uid,body.output.payload_uid,body.output.project_uid,body.output.flow_name,body.output.stop_time); } else{ - info("Not able to find monitor entry"); + dbg.message("Not able to find monitor entry",1); } } else { - info("Failed to get Monitor entry") - console.log(body); + dbg.message("Failed to get Monitor entry",1) + dbg.message(body,1); process.exit(99); } } function processRunningResponse(url,err,body,res){ - //console.log(body); if(res.statusCode==200) { //... do something next if(body.output.count==0) { - info("No Workflows Running") - info("Can Resubmit [" + (maxRunningWorkflows - body.output.count) + "] executions"); + dbg.message("No Workflows Running",4) + dbg.message("Can Resubmit [" + (maxRunningWorkflows - body.output.count) + "] executions",4); } else{ - info("Workflows Running [" +body.output.count + "]") + dbg.message("Workflows Running [" +body.output.count + "]",2) if(body.output.count " + message); + dbg.message(" " + message,4); } function help(){ diff --git a/projects.js b/projects.js index ccaf1c9..92ff66d 100644 --- a/projects.js +++ b/projects.js @@ -12,7 +12,7 @@ var prettyprint = false; var url; function debug(message) { - dbg.message(" " + message); + dbg.message(" " + message,4); } function help() { diff --git a/recipe.js b/recipe.js index 1811358..7e7e002 100644 --- a/recipe.js +++ b/recipe.js @@ -10,7 +10,7 @@ var domainName, username, password, timeout, prettyprint; var url; function debug(message) { - dbg.message(" " + message); + dbg.message(" " + message,4); } function help() { return ` diff --git a/rest.js b/rest.js index d4646f9..9920aed 100644 --- a/rest.js +++ b/rest.js @@ -10,7 +10,7 @@ const cj = request.jar(); cookieJar = []; function debug(message){ - dbg.message(" " + message); + dbg.message(":" + message,4); } function addCookieToJar(cookie,domainName) @@ -46,11 +46,11 @@ function enableCACert(options){ } } -function ignoreTLS(options) +function setignoreTLS(options) { if(ignoreTLS) { - debug("\x1b[31m***** WARNING: Ignoring TLS Errors has been enabled *****\x1b[0m"); + debug("\x1b[31m***** WARNING: Ignoring TLS Errors has been enabled *****\x1b[0m",2); process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0; } } @@ -58,7 +58,7 @@ function ignoreTLS(options) function requestModifiers(options){ enableProxy(options); enableCACert(options); - ignoreTLS(options); + setignoreTLS(options); } function get(restEndPoint,user,pass,timeout,callback) diff --git a/roles.js b/roles.js index cc0d36b..539f35d 100644 --- a/roles.js +++ b/roles.js @@ -18,7 +18,7 @@ function checkForErrors(inBody) { } function debug(message) { - dbg.message(" " + message); + dbg.message(" " + message,4); } function help() { diff --git a/themes.js b/themes.js index 4ed8e89..c4623da 100644 --- a/themes.js +++ b/themes.js @@ -11,7 +11,7 @@ var prettyprint = false; var url; function debug(message) { - dbg.message(" " + message); + dbg.message(" " + message,4); } function help() { diff --git a/users.js b/users.js index 571d488..ff2d177 100644 --- a/users.js +++ b/users.js @@ -19,7 +19,7 @@ function checkForErrors(inBody) } function debug(message){ - dbg.message(" " + message); + dbg.message(" " + message,4); } diff --git a/wmiocli.js b/wmiocli.js index 4565eec..2814b21 100644 --- a/wmiocli.js +++ b/wmiocli.js @@ -14,6 +14,7 @@ var theme = require('./themes.js'); var recipe = require('./recipe.js'); var flowservice = require('./flowservice.js'); var experimental = require('./experimental.js'); +const { setLogLevel } = require('./debug.js'); dbg = require('./debug.js'); prettyprint = false; @@ -43,9 +44,6 @@ function readFromConsole(question,isPassword) } function checkOptions(){ - if(program.opts().verbose==true){ - dbg.enableDebug(); - } if(program.opts().proxy !== undefined) { @@ -67,6 +65,40 @@ function checkOptions(){ prettyprint = true; } + var levelInput = program.opts().loglevel + if(program.opts().verbose == true) + { + levelInput = "DEBUG"; + } + + if(levelInput == undefined && !program.opts().verbose){ + levelInput = "OFF"; + } + else + { + switch (levelInput) + { + case "OFF": + dbg.setLogLevel(0); + break; + case "ERROR": + dbg.setLogLevel(1); + break; + case "WARN": + dbg.setLogLevel(2); + break; + case "INFO": + dbg.setLogLevel(3); + break; + case "DEBUG": + dbg.setLogLevel(4); + break; + default: + console.log("-level incorrectly set, should be one of: OFF, ERROR, WARN, INFO, DEBUG"); + process.exit(1); + } + } + if(program.opts().domain == undefined){ tenantDomain = readFromConsole('Please type your tenant domain name: '); } @@ -95,7 +127,7 @@ function checkOptions(){ } function debug(message){ - dbg.message("
" + message); + dbg.message("
" + message,4); } const program = new Command(); @@ -113,7 +145,8 @@ program //options .addOption(new Option('-t, --timeout ', 'timeout in seconds').default(60, 'one minute')) .option('--prettyprint','Pretty Print JSON output') - .option('--verbose','Verbose output useful for diagnosing issues') + .option('--verbose','Enables full debug mode (replaced by --loglevel DEBUG)') + .option('--loglevel ','Change the logging level of DEBUG, INFO,WARN,ERROR,OFF (default being off)') .option('--proxy ','URL for proxy server if required') .option('--caCert ','Path to a CACert PEM file if required') @@ -623,7 +656,7 @@ program.command('flowservice-execute [input-json]') experimental.projectDeployments(projectId); }); - program.command('experimental-workflow-monitor [start-date] [end-date] [project-id] [workflow-id] [execution-status]',{hidden: true}) + program.command('experimental-workflow-monitor [execution-status] [start-date] [end-date] [project-id] [workflow-id] ',{hidden: true}) .description('List Workflow Monitor') .action((executionStatus,startDate,endDate,projectId,workflowId) => { checkOptions(); diff --git a/workflow.js b/workflow.js index 5ff4df3..f417ea2 100644 --- a/workflow.js +++ b/workflow.js @@ -10,7 +10,7 @@ var domainName, username, password, timeout, prettyprint; var url; function debug(message) { - dbg.message(" " + message); + dbg.message(" " + message,4); } function help() { From c3017ee71db137b0211001e57e98e3b86d9a0883 Mon Sep 17 00:00:00 2001 From: sagpembo Date: Thu, 22 Sep 2022 22:58:56 +0100 Subject: [PATCH 7/7] added messaging --- experimental.js | 114 ++++++++++++++++++++++++++++++++++++++---------- wmiocli.js | 24 +++++++++- 2 files changed, 114 insertions(+), 24 deletions(-) diff --git a/experimental.js b/experimental.js index 7686c7f..38bfc8e 100644 --- a/experimental.js +++ b/experimental.js @@ -28,6 +28,8 @@ var executionStatus; var startDate; var endDate; var startOrResume; +var queueOrTopic; +var messagingName; var nextUrl,formUrl; var finalCall; var loginStageCounter = 0; @@ -118,6 +120,33 @@ function getMonitorInfo(inExecutionStatus,inStartDate,inEndDate,inProjectId,inWo loginPhase1(); } +function messagingDelete(inQueueOrTopic, inProjectId,inMessagingName) +{ + projectId = inProjectId; + messagingName = inMessagingName; + queueOrTopic = inQueueOrTopic; + finalCall = doMessagingDelete; + loginPhase1(); +} + +function messagingCreate(inQueueOrTopic, inProjectId,inMessagingName) +{ + projectId = inProjectId; + messagingName = inMessagingName; + queueOrTopic = inQueueOrTopic; + finalCall = doMessagingCreate; + loginPhase1(); +} + +function messagingStats(inProjectId,inMessagingName) +{ + projectId = inProjectId; + messagingName = inMessagingName; + finalCall = getMessagingStats; + loginPhase1(); +} + + function workflowResubmit(instartOrResume, inStartDate,inEndDate, inProjectId,inWorkflowId) { projectId = inProjectId; @@ -192,7 +221,7 @@ function checkResubmissions() var body=processMonitorBody(); body.execution_status=["running"]; var headers = setHeaders(); - rest.custom(endPoint,undefined,undefined,60,body,undefined,"POST",processRunningResponse,undefined,headers,true,false); + rest.custom(endPoint,undefined,undefined,timeout,body,undefined,"POST",processRunningResponse,undefined,headers,true,false); } function processResubmissions(reprocessCount) @@ -206,7 +235,7 @@ function processResubmissions(reprocessCount) body.limit=reprocessCount; body.execution_status=["failed"]; var headers = setHeaders(); - rest.custom(endPoint,undefined,undefined,60,body,undefined,"POST",processListResponse,undefined,headers,true,false); + rest.custom(endPoint,undefined,undefined,timeout,body,undefined,"POST",processListResponse,undefined,headers,true,false); } function processSingleResubmission(a,b, vbid) @@ -218,7 +247,7 @@ function processSingleResubmission(a,b, vbid) //body.limit=reprocessCount; //body.execution_status=["failed"]; var headers = setHeaders(); - rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",processSingleResubmissionResponse,undefined,headers,true,false); + rest.custom(endPoint,undefined,undefined,timeout,undefined,undefined,"GET",processSingleResubmissionResponse,undefined,headers,true,false); } function finishProcessSingleResubmission(vbid,wfuid,payloaduid,projectuid,flowname,stoptime) @@ -236,7 +265,7 @@ function finishProcessSingleResubmission(vbid,wfuid,payloaduid,projectuid,flowna {name:"project_uid",value:projectuid}, ]; var body = {"bill_uid":vbid,"__is_checkpoint_run__":true,"payload_uid":payloaduid,"checkpointLogs":[]}; - rest.custom(endPoint,undefined,undefined,60,body,undefined,"POST",processFinalSingleResubmissionResponse,undefined,headers,true,false); + rest.custom(endPoint,undefined,undefined,timeout,body,undefined,"POST",processFinalSingleResubmissionResponse,undefined,headers,true,false); } function processFinalSingleResubmissionResponse(url,err,body,res){ @@ -370,6 +399,43 @@ function processRunningResponse(url,err,body,res){ } } +function doMessagingCreate() +{ + debug("Messaging Item Creation") + var endPoint = "https://" +domainName + "/integration/rest/messaging/admin/destinations?projectName=" + projectId + "&type=" + queueOrTopic; + debug("Next URL [" + endPoint + "]"); + var body; + if(queueOrTopic=="queue")body={"queueName":messagingName}; + else if (queueOrTopic=="topic")body={"topicName":messagingName} + else dbg.message("Please provide either 'queue' or 'topic'",1); + var headers = setHeaders(); + rest.custom(endPoint,undefined,undefined,timeout,body,undefined,"POST",processResponse,undefined,headers,true,false); +} + +function doMessagingDelete() +{ + debug("Messaging Item Deletion") + var endPoint = "https://" +domainName + "/integration/rest/messaging/admin/destinations/" + messagingName + "?projectName=" + projectId + "&type=" + queueOrTopic; + debug("Next URL [" + endPoint + "]"); + var body; + if(queueOrTopic=="queue")body={"queueName":messagingName}; + else if (queueOrTopic=="topic")body={"topicName":messagingName} + else dbg.message("Please provide either 'queue' or 'topic'",1); + var headers = setHeaders(); + rest.custom(endPoint,undefined,undefined,60,body,undefined,"DELETE",processResponse,undefined,headers,true,false); + //rest.del(endPoint,undefined,undefined,timeout,undefined,processResponse); +} + +function getMessagingStats() +{ + debug("Messaging Stats"); + var endPoint = "https://" +domainName + "/integration/rest/messaging/runtime/destinations/"+messagingName+"/metrics?projectName=" + projectId ; + debug("Next URL [" + endPoint + "]"); + var headers = setHeaders(); + var body; + rest.custom(endPoint,undefined,undefined,timeout,body,undefined,"GET",processResponse,undefined,headers,true,false); +} + function getLogs() { debugMonitorInfo(); @@ -377,7 +443,7 @@ function getLogs() debug("Next URL [" + endPoint + "]"); var body=processMonitorBody(); var headers = setHeaders(); - rest.custom(endPoint,undefined,undefined,60,body,undefined,"POST",processResponse,undefined,headers,true,false); + rest.custom(endPoint,undefined,undefined,timeout,body,undefined,"POST",processResponse,undefined,headers,true,false); } @@ -392,7 +458,7 @@ function searchProjectsByName() {name:"accept",value:"application/json"}, {name:"x-csrf-token",value:csrf}, ]; - rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",processResponse,undefined,headers,true,false); + rest.custom(endPoint,undefined,undefined,timeout,undefined,undefined,"GET",processResponse,undefined,headers,true,false); } function getProjectDeployments() @@ -407,7 +473,7 @@ function getProjectDeployments() {name:"project_uid",value:projectId}, {name:"x-csrf-token",value:csrf}, ]; - rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",processResponse,undefined,headers,true,false); + rest.custom(endPoint,undefined,undefined,timeout,undefined,undefined,"GET",processResponse,undefined,headers,true,false); } function stageInfo() @@ -421,7 +487,7 @@ function stageInfo() {name:"accept",value:"application/json"}, {name:"x-csrf-token",value:csrf}, ]; - rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",processResponse,undefined,headers,true,false); + rest.custom(endPoint,undefined,undefined,timeout,undefined,undefined,"GET",processResponse,undefined,headers,true,false); } function getProjectAccountConfigInfo() @@ -436,7 +502,7 @@ function getProjectAccountConfigInfo() {name:"project_uid",value:projectId}, {name:"x-csrf-token",value:csrf}, ]; - rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",processResponse,undefined,headers,true,false); + rest.custom(endPoint,undefined,undefined,timeout,undefined,undefined,"GET",processResponse,undefined,headers,true,false); } @@ -452,7 +518,7 @@ function usedConnectorAccountsInfo() {name:"project_uid",value:projectId}, {name:"x-csrf-token",value:csrf}, ]; - rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",processResponse,undefined,headers,true,false); + rest.custom(endPoint,undefined,undefined,timeout,undefined,undefined,"GET",processResponse,undefined,headers,true,false); } function projectWorkflowsInfo() @@ -468,7 +534,7 @@ function projectWorkflowsInfo() {name:"project_uid",value:projectId}, {name:"x-csrf-token",value:csrf}, ]; - rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",processProjectsResponse,undefined,headers,true,false); + rest.custom(endPoint,undefined,undefined,timeout,undefined,undefined,"GET",processProjectsResponse,undefined,headers,true,false); } function projectFlowServicesInfo() @@ -484,7 +550,7 @@ function projectFlowServicesInfo() {name:"project_uid",value:projectId}, {name:"x-csrf-token",value:csrf}, ]; - rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",processResponse,undefined,headers,true,false); + rest.custom(endPoint,undefined,undefined,timeout,undefined,undefined,"GET",processResponse,undefined,headers,true,false); } @@ -498,7 +564,7 @@ function execUserInfo() {name:"authtoken",value:authtoken}, {name:"accept",value:"application/json"}, ]; - rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",processResponse,undefined,headers,true,false); + rest.custom(endPoint,undefined,undefined,timeout,undefined,undefined,"GET",processResponse,undefined,headers,true,false); } /** Logs in via Software AG Cloud! */ @@ -506,7 +572,7 @@ function loginPhase1() { debug("LOGIN Phase 1") var endPoint = url + "/integration/sagcloud/"; - rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",loginResponse,undefined,undefined,true,false); + rest.custom(endPoint,undefined,undefined,timeout,undefined,undefined,"GET",loginResponse,undefined,undefined,true,false); } @@ -516,7 +582,7 @@ function loginPhase2() var endPoint = nextUrl; debug("Next URL [" + endPoint + "]"); formUrl = endPoint; - rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",loginResponse,undefined,undefined,true,false); + rest.custom(endPoint,undefined,undefined,timeout,undefined,undefined,"GET",loginResponse,undefined,undefined,true,false); } function loginPhase3() @@ -533,7 +599,7 @@ function loginPhase3() var form = [{name:"username",value:username}, {name:"password",value:password}]; - rest.custom(endPoint,undefined,undefined,60,undefined,form,"POST",loginResponse,undefined,undefined,true,false); + rest.custom(endPoint,undefined,undefined,timeout,undefined,form,"POST",loginResponse,undefined,undefined,true,false); } function loginRedirectPhase(inId) @@ -545,7 +611,7 @@ function loginRedirectPhase(inId) var headers = [ {name:"Accept",value:"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"}, ]; - rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",loginResponse,undefined,undefined,true,false); + rest.custom(endPoint,undefined,undefined,timeout,undefined,undefined,"GET",loginResponse,undefined,undefined,true,false); } function loginUserPhase(inId) @@ -558,7 +624,7 @@ function loginUserPhase(inId) {name:"authtoken",value:authtoken}, {name:"accept",value:"application/json"}, ]; - rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",processUserResponse,undefined,headers,true,false); + rest.custom(endPoint,undefined,undefined,timeout,undefined,undefined,"GET",processUserResponse,undefined,headers,true,false); } function checkResponse(res,body) @@ -636,10 +702,10 @@ function processProjectsResponse(url,err,body,res){ if(prettyprint==true){ - dbg.message(JSON.stringify(output,null,4),5); + dbg.message(JSON.stringify(output,null,4),-1); } else{ - dbg.message((JSON.stringify(output)),5); + dbg.message((JSON.stringify(output)),-1); } } else @@ -653,10 +719,10 @@ function processResponse(url,err,body,res){ if(res.statusCode==200) { if(prettyprint==true){ - dbg.message(JSON.stringify(body,null,4),5); + dbg.message(JSON.stringify(body,null,4),-1); } else{ - dbg.message((JSON.stringify(body)),5); + dbg.message((JSON.stringify(body)),-1); } } else @@ -759,4 +825,6 @@ function loginResponse(url,err,body,res){ } -module.exports = {init,user,stages,projectWorkflows,projectFlowservices,connectorAccounts,getProjectAccountConfig,searchProject,getMonitorInfo,workflowResubmit,projectDeployments}; \ No newline at end of file +module.exports = {init,user,stages,projectWorkflows,projectFlowservices,connectorAccounts, + getProjectAccountConfig,searchProject,getMonitorInfo,workflowResubmit, + projectDeployments,messagingCreate,messagingStats,messagingDelete}; \ No newline at end of file diff --git a/wmiocli.js b/wmiocli.js index 2814b21..9702e98 100644 --- a/wmiocli.js +++ b/wmiocli.js @@ -672,7 +672,29 @@ program.command('flowservice-execute [input-json]') experimental.workflowResubmit(restartOrResume, startDate, endDate, projectId,workflowId); }); - + program.command('experimental-messaging-create ',{hidden: true}) + .description('Create a messaging queue or topic') + .action((queueOrTopc,name,projectId) => { + checkOptions(); + experimental.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) + experimental.messagingCreate(queueOrTopc,projectId,name); + }); + + program.command('experimental-messaging-delete ',{hidden: true}) + .description('Delete a messaging queue or topic') + .action((queueOrTopc,name,projectId) => { + checkOptions(); + experimental.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) + experimental.messagingDelete(queueOrTopc,projectId,name); + }); + + program.command('experimental-messaging-stats ',{hidden: true}) + .description('Get Messaging Stats') + .action((name,projectId) => { + checkOptions(); + experimental.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint) + experimental.messagingStats(projectId,name); + }); program.parse();