Skip to content

Commit 3643a5b

Browse files
committed
added input for tenant domain, user and password
1 parent 112daa6 commit 3643a5b

File tree

3 files changed

+69
-25
lines changed

3 files changed

+69
-25
lines changed

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,8 @@
2828
"devDependencies": {
2929
"commander": "^8.3.0",
3030
"request": "^2.88.2"
31+
},
32+
"dependencies": {
33+
"readline-sync": "^1.4.10"
3134
}
3235
}

wmiocli.js

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,19 @@ var flowservice = require('./flowservice.js');
1313
var prettyprint = false;
1414
var compat = false;
1515

16+
var tenantDomain;
17+
var tenantUser;
18+
var tenantPw;
19+
1620
const { Command, Option } = require('commander');
1721
const { exit } = require('process');
22+
const readline = require('readline-sync');
23+
24+
function readFromConsole(question)
25+
{
26+
var answer = readline.question("\x1b[32m" + question + "\x1b[0m");
27+
return answer;
28+
}
1829

1930
function checkOptions(){
2031
if(program.opts().verbose==true){
@@ -26,6 +37,27 @@ function checkOptions(){
2637
prettyprint = true;
2738
}
2839

40+
if(program.opts().domain == undefined){
41+
tenantDomain = readFromConsole('Please type your tenant domain name: ');
42+
}
43+
else{
44+
tenantDomain = program.opts().domain
45+
}
46+
47+
if(program.opts().user == undefined){
48+
tenantUser = readFromConsole('Please type your tenant User ID: ');
49+
}
50+
else{
51+
tenantUser = program.opts().user
52+
}
53+
54+
if(program.opts().password == undefined){
55+
tenantPw = readFromConsole('Please type your tenant User Password: ');
56+
}
57+
else{
58+
tenantPw = program.opts().password
59+
}
60+
2961
}
3062

3163
function debug(message){
@@ -38,9 +70,10 @@ program
3870
.version('2022.07.1')
3971

4072
//required options
41-
.requiredOption('-d, --domain <tenantDomain>', 'Tenant Doamin Name, e.g. "tenant.int-aws-us.webmethods.io"')
42-
.requiredOption('-u, --user <userid>', 'Tenant User ID')
43-
.requiredOption('-p, --password <password>', 'Tenant User Password')
73+
.option('-d, --domain <tenantDomain>', 'Tenant Doamin Name, e.g. "tenant.int-aws-us.webmethods.io"')
74+
.option('-u, --user <userid>', 'Tenant User ID')
75+
.option('-p, --password <password>', 'Tenant User Password')
76+
//.requiredOption('-p, --password <password>', 'Tenant User Password')
4477

4578
//options
4679
.addOption(new Option('-t, --timeout <delay>', 'timeout in seconds').default(60, 'one minute'))
@@ -243,7 +276,7 @@ program.command('project [project-name]')
243276
.description('Lists all projects or view an individual project, specified via project name or uid')
244277
.action((projectName) => {
245278
checkOptions();
246-
project.init(program.opts().domain,program.opts().user,program.opts().password,program.opts().timeout,program.opts().prettyprint)
279+
project.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint)
247280
var resp = project.list(projectName);
248281
if(resp)console.log(resp);
249282
});
@@ -252,7 +285,7 @@ program.command('project-assets <project-name>')
252285
.description('Lists project assets from given project name or uid')
253286
.action((projectName) => {
254287
checkOptions();
255-
project.init(program.opts().domain,program.opts().user,program.opts().password,program.opts().timeout,program.opts().prettyprint)
288+
project.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint)
256289
var resp = project.listAssets(projectName);
257290
if(resp)console.log(resp);
258291
});
@@ -261,31 +294,31 @@ program.command('project-create <project-name>')
261294
.description('Create project with given name')
262295
.action((projectName) => {
263296
checkOptions();
264-
project.init(program.opts().domain,program.opts().user,program.opts().password,program.opts().timeout,program.opts().prettyprint)
297+
project.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint)
265298
project.create(projectName);
266299
});
267300

268301
program.command('project-update <project-id> <project-name>')
269302
.description('Update project with new name')
270303
.action((projectId, projectName) => {
271304
checkOptions();
272-
project.init(program.opts().domain,program.opts().user,program.opts().password,program.opts().timeout,program.opts().prettyprint)
305+
project.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint)
273306
project.update(projectId, projectName);
274307
});
275308

276309
program.command('project-delete <project-id>')
277310
.description('Delete project with given id')
278311
.action((projectId) => {
279312
checkOptions();
280-
project.init(program.opts().domain,program.opts().user,program.opts().password,program.opts().timeout,program.opts().prettyprint)
313+
project.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint)
281314
project.del(projectId);
282315
});
283316

284317
program.command('project-publish <project-id> <publish-name> <target-tenant-domain-name> <target-user-id> <target-user-password> <assets-json>')
285318
.description('Pubilsh project to another tenant with given id')
286319
.action((projectId,publishName,targetTenantDomainName,targetUserId,targetUserPassword,assetsJson) => {
287320
checkOptions();
288-
project.init(program.opts().domain,program.opts().user,program.opts().password,program.opts().timeout,program.opts().prettyprint)
321+
project.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint)
289322
project.pub(projectId,publishName,targetTenantDomainName,targetUserId,targetUserPassword,assetsJson);
290323

291324
});
@@ -294,7 +327,7 @@ program.command('project-deploy <projectName> <version>')
294327
.description('deploy published project with given version into tenant')
295328
.action((projectName, version) => {
296329
checkOptions();
297-
project.init(program.opts().domain,program.opts().user,program.opts().password,program.opts().timeout,program.opts().prettyprint)
330+
project.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint)
298331
project.deploy(projectName,version);
299332
});
300333

@@ -307,7 +340,7 @@ program.command('role [role-id]')
307340
.description('Lists all roles or views an individual role')
308341
.action((roleId) => {
309342
checkOptions();
310-
role.init(program.opts().domain,program.opts().user,program.opts().password,program.opts().timeout,program.opts().prettyprint)
343+
role.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint)
311344
var resp = role.list(roleId);
312345
if(resp)console.log(resp);
313346
});
@@ -316,23 +349,23 @@ program.command('role-create <role-name> <role-description> <roles-list>')
316349
.description('Create roles and specify the permissions for that role. Roles-list should be provided as follows projectName,r,w,e;project name 2,r;')
317350
.action((roleName,roleDescription,rolesList) => {
318351
checkOptions();
319-
role.init(program.opts().domain,program.opts().user,program.opts().password,program.opts().timeout,program.opts().prettyprint);
352+
role.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint);
320353
role.insert(roleName,roleDescription, rolesList);
321354
});
322355

323356
program.command('role-update <role-id> <role-name> <role-description> <roles-list>')
324357
.description('Create roles and specify the permissions for that role. Roles-list should be provided as follows projectName,r,w,e;project name 2,r;')
325358
.action((roleId, roleName,roleDescription,rolesList) => {
326359
checkOptions();
327-
role.init(program.opts().domain,program.opts().user,program.opts().password,program.opts().timeout,program.opts().prettyprint);
360+
role.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint);
328361
role.update(roleId, roleName,roleDescription, rolesList);
329362
});
330363

331364
program.command('role-delete <roleId>')
332365
.description('Delete a roles with the given role id')
333366
.action((roleId) => {
334367
checkOptions();
335-
role.init(program.opts().domain,program.opts().user,program.opts().password,program.opts().timeout,program.opts().prettyprint);
368+
role.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint);
336369
role.del(roleId);
337370
});
338371

@@ -349,7 +382,7 @@ program.command('user')
349382
.description('Lists all users')
350383
.action(() => {
351384
checkOptions();
352-
user.init(program.opts().domain,program.opts().user,program.opts().password,program.opts().timeout,program.opts().prettyprint);
385+
user.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint);
353386
user.list(undefined);
354387
});
355388

@@ -359,7 +392,7 @@ program.command('user-role-assignment <user-id> <role-names>')
359392
checkOptions();
360393
debug("userId: " + userId);
361394
debug("Roles: " + roleNames);
362-
user.init(program.opts().domain,program.opts().user,program.opts().password,program.opts().timeout,program.opts().prettyprint);
395+
user.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,program.opts().prettyprint);
363396
user.assignRoles(userId,roleNames);
364397
});
365398

@@ -372,7 +405,7 @@ program.command('workflow-export <project-id> <workflow-id> <filename>')
372405
.description('Export workflow with id <workflow-id> from project <project-id>')
373406
.action((projectId, workflowId, filename) => {
374407
checkOptions();
375-
wf.init(program.opts().domain,program.opts().user,program.opts().password,program.opts().timeout,projectId);
408+
wf.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,projectId);
376409
wf.exportwf(workflowId,filename);
377410
});
378411

@@ -381,7 +414,7 @@ program.command('workflow-import <project-id> <filename>')
381414
.action((projectId, filename) => {
382415
checkOptions();
383416
debug("Importing Workflow");
384-
wf.init(program.opts().domain,program.opts().user,program.opts().password,program.opts().timeout,projectId);
417+
wf.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,projectId);
385418
wf.importwf(filename);
386419
});
387420

@@ -390,23 +423,23 @@ program.command('workflow-delete <project-id> <workflow-id>')
390423
.action((projectId, workflowId) => {
391424
checkOptions();
392425
debug("Deleting Workflow [" + workflowId + "]");
393-
wf.init(program.opts().domain,program.opts().user,program.opts().password,program.opts().timeout,projectId);
426+
wf.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,projectId);
394427
wf.deletewf(workflowId);
395428
});
396429

397430
program.command('workflow-execute <project-id> <workflow-id>')
398431
.description('Execute workflow <workflow-id> from project <project-id>')
399432
.action((projectId, workflowId) => {
400433
checkOptions();
401-
wf.init(program.opts().domain,program.opts().user,program.opts().password,program.opts().timeout,projectId);
434+
wf.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,projectId);
402435
wf.runwf(workflowId)
403436
});
404437

405438
program.command('workflow-status <project-id> <run-id>')
406439
.description('Gets Execution status for workflow execution <run-id>')
407440
.action((projectId, runId) => {
408441
checkOptions();
409-
wf.init(program.opts().domain,program.opts().user,program.opts().password,program.opts().timeout,projectId);
442+
wf.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,projectId);
410443
wf.statuswf(runId);
411444
});
412445

@@ -419,33 +452,36 @@ program.command('flowservice-export <project-id> <flow-name> <file-name>')
419452
.description('Export FlowService with name <flow-name> from project <project-id>')
420453
.action((projectId, flowName,filename) => {
421454
checkOptions();
422-
flowservice.init(program.opts().domain,program.opts().user,program.opts().password,program.opts().timeout,projectId);
455+
flowservice.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,projectId);
423456
flowservice.exportFlowService(flowName,filename);
424457
});
425458

426459
program.command('flowservice-import <project-id> <filename>')
427460
.description('Import FlowService from <filename> into project <project-id>')
428461
.action((projectId, filename) => {
429462
checkOptions();
430-
flowservice.init(program.opts().domain,program.opts().user,program.opts().password,program.opts().timeout,projectId);
463+
flowservice.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,projectId);
431464
flowservice.importFlowService(filename);
432465
});
433466

434467
program.command('flowservice-delete <project-id> <flow-name>')
435468
.description('Delete FlowService <flow-name> from project <project-id>')
436469
.action((projectId, flowName) => {
437470
checkOptions();
438-
flowservice.init(program.opts().domain,program.opts().user,program.opts().password,program.opts().timeout,projectId);
471+
flowservice.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,projectId);
439472
flowservice.deleteFlowService(flowName);
440473
});
441474

442475
program.command('flowservice-execute <project-id> <flow-name> [input-json]')
443476
.description('Execute FlowService <flow-name> from project <project-id> with data <input-json>')
444477
.action((projectId, flowName,inputJson) => {
445478
checkOptions();
446-
flowservice.init(program.opts().domain,program.opts().user,program.opts().password,program.opts().timeout,projectId);
479+
flowservice.init(tenantDomain,tenantUser,tenantPw,program.opts().timeout,projectId);
447480
flowservice.runFlowService(flowName,inputJson);
448481
});
449482

483+
450484
program.parse();
451485

486+
487+

0 commit comments

Comments
 (0)