-
Notifications
You must be signed in to change notification settings - Fork 2
/
ctrl-q.js
822 lines (729 loc) · 46 KB
/
ctrl-q.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
const { Command, Option } = require('commander');
const { logger, appVersion, setLoggingLevel, setCliOptions } = require('./globals');
const { logStartupInfo } = require('./lib/util/log');
// const { createUserActivityCustomProperty } = require('./lib/createuseractivitycp');
const { getMasterDimension } = require('./lib/cmd/getdim');
const { deleteMasterDimension } = require('./lib/cmd/deletedim');
const { getMasterMeasure } = require('./lib/cmd/getmeasure');
const { deleteMasterMeasure } = require('./lib/cmd/deletemeasure');
const { getVariable } = require('./lib/cmd/getvariable');
const { deleteVariable } = require('./lib/cmd/deletevariable');
const { getBookmark } = require('./lib/cmd/getbookmark');
const { importMasterItemFromFile } = require('./lib/cmd/import-masteritem-excel');
const { scrambleField } = require('./lib/cmd/scramblefield');
const { getScript } = require('./lib/cmd/getscript');
const { getTask } = require('./lib/cmd/gettask');
const { setTaskCustomProperty } = require('./lib/cmd/settaskcp');
const { importTaskFromFile } = require('./lib/cmd/importtask');
const { importAppFromFile } = require('./lib/cmd/importapp');
const { exportAppToFile } = require('./lib/cmd/exportapp');
const { testConnection } = require('./lib/cmd/testconnection');
const {
sharedParamAssertOptions,
// userActivityCustomPropertyAssertOptions,
masterItemImportAssertOptions,
masterItemMeasureDeleteAssertOptions,
masterItemDimDeleteAssertOptions,
masterItemGetAssertOptions,
variableGetAssertOptions,
variableDeleteAssertOptions,
getScriptAssertOptions,
getBookmarkAssertOptions,
getTaskAssertOptions,
setTaskCustomPropertyAssertOptions,
taskImportAssertOptions,
appImportAssertOptions,
appExportAssertOptions,
} = require('./lib/util/assert-options');
const program = new Command();
/**
* Top level async function.
* Workaround to deal with the fact that Node.js doesn't currently support top level async functions...
*/
(async () => {
// Basic app info
program
.version(appVersion)
.description(
'Ctrl-Q is a command line utility for interacting with client-managed Qlik Sense Enterprise on Windows servers.\nAmong other things the tool does bulk import of apps and tasks, manipulates master items and scrambles in-app data.'
)
.hook('preAction', (thisCommand, actionCommand) => {
const options = actionCommand.opts();
// Store CLI options in global variable
setCliOptions(options);
// Set log level & show startup info
setLoggingLevel(options.logLevel);
// eslint-disable-next-line no-underscore-dangle
logStartupInfo(options, actionCommand._name, actionCommand._description);
logger.verbose(`About to call action handler for subcommand: ${actionCommand.name()}`);
});
// Create custom properties for tracking user activity buckets, i.e. how long ago a user was last active (last login) in Sense
// program
// .command('user-activity-cp-create')
// .description(
// 'create custom property and populate it with values ("activity buckets") indicating how long ago users last logged into Sense'
// )
// .action(async (options) => {
// try {
// let optionsLocal = options;
// await sharedParamAssertOptions(options);
// optionsLocal = userActivityCustomPropertyAssertOptions(options);
// createUserActivityCustomProperty(optionsLocal);
// } catch (err) {
// logger.error(`USER ACTIVITY CP: ${err}`);
// }
// })
// .addOption(
// new Option('--log-level <level>', 'log level')
// .choices(['error', 'warn', 'info', 'verbose', 'debug', 'silly'])
// .default('info')
// )
// .requiredOption('--host <host>', 'Qlik Sense server IP/FQDN')
// .option('--port <port>', 'Qlik Sense repository API port', '4242')
// .requiredOption('--virtual-proxy <prefix>', 'Qlik Sense virtual proxy prefix', '')
// .requiredOption('--secure <true|false>', 'connection to Qlik Sense engine is via https', true)
// .option('--auth-user-dir <directory>', 'user directory for user to connect with', 'Internal')
// .option('--auth-user-id <userid>', 'user ID for user to connect with', 'sa_repository')
// .addOption(new Option('-a, --auth-type <type>', 'authentication type').choices(['cert', 'jwt']).default('cert'))
// .option('--auth-cert-file <file>', 'Qlik Sense certificate file (exported from QMC)', './cert/client.pem')
// .option('--auth-cert-key-file <file>', 'Qlik Sense certificate key file (exported from QMC)', './cert/client_key.pem')
// .option('--auth-root-cert-file <file>', 'Qlik Sense root certificate file (exported from QMC)', './cert/root.pem')
// .option('--jwt <JWT>', 'JSON Web Token (JWT) to use for authenticating with Qlik Sense', '')
// .requiredOption('--user-directory <name>', 'name of user directory whose users will be updated with activity info')
// .requiredOption('--custom-property-name <name>', 'name of custom property that will hold user activity buckets')
// .addOption(
// new Option('--force <true|false>', 'forcibly overwrite and replace custom property and its values if it already exists')
// .choices(['true', 'false'])
// .default('false')
// )
// .option('--activity-buckets <buckets...>', 'custom property values/user activity buckets to be defined. In days.', [
// '1',
// '7',
// '14',
// '30',
// '90',
// '180',
// '365',
// ]);
// Import dimensions/measures from definitions in Excel file
program
.command('master-item-import')
.description('create master items based on definitions in a file on disk')
.action(async (options) => {
try {
await sharedParamAssertOptions(options);
masterItemImportAssertOptions(options);
importMasterItemFromFile(options);
} catch (err) {
logger.error(`IMPORT EXCEL: ${err}`);
}
})
.addOption(
new Option('--log-level <level>', 'log level').choices(['error', 'warn', 'info', 'verbose', 'debug', 'silly']).default('info')
)
.requiredOption('--host <host>', 'Qlik Sense server IP/FQDN')
.option('--port <port>', 'Qlik Sense server engine port', '4747')
.option('--schema-version <string>', 'Qlik Sense engine schema version', '12.612.0')
.requiredOption('--app-id <id>', 'Qlik Sense app ID')
.requiredOption('--virtual-proxy <prefix>', 'Qlik Sense virtual proxy prefix', '')
.requiredOption('--secure <true|false>', 'connection to Qlik Sense engine is via https', true)
.requiredOption('--auth-user-dir <directory>', 'user directory for user to connect with')
.requiredOption('--auth-user-id <userid>', 'user ID for user to connect with')
.addOption(new Option('-a, --auth-type <type>', 'authentication type').choices(['cert']).default('cert'))
.option('--auth-cert-file <file>', 'Qlik Sense certificate file (exported from QMC)', './cert/client.pem')
.option('--auth-cert-key-file <file>', 'Qlik Sense certificate key file (exported from QMC)', './cert/client_key.pem')
.option('--auth-root-cert-file <file>', 'Qlik Sense root certificate file (exported from QMC)', './cert/root.pem')
.addOption(new Option('-t, --file-type <type>', 'source file type').choices(['excel']).default('excel'))
.requiredOption('--file <filename>', 'file containing master item definitions')
.requiredOption('--sheet <name>', 'name of Excel sheet where dim/measure flag column is found')
.addOption(
new Option(
'--col-ref-by <reftype>',
'how to refer to columns in the source file. Options are by name or by position (zero based)'
)
.choices(['name', 'position'])
.default('name')
)
.requiredOption(
'--col-item-type <column position or name>',
'column where dim/measure flag is found. Use "dim-single" in that column to create dimension, "dim-drilldown" for drill-down dimension, "measure" for measure',
'Master item type'
)
.requiredOption(
'--col-master-item-name <column position or name>',
'column number (zero based) or name to use as master item name',
'Master item name'
)
.requiredOption(
'--col-master-item-descr <column position or name>',
'column number (zero based) or name to use as master item description',
'Description'
)
.requiredOption(
'--col-master-item-label <column position or name>',
'column number (zero based) or name to use as master item label',
'Label'
)
.requiredOption(
'--col-master-item-expr <column position or name>',
'column number (zero based) or name to use as master item expression',
'Expression'
)
.requiredOption(
'--col-master-item-tag <column position or name>',
'column number (zero based) or name to use as master item tags',
'Tag'
)
.requiredOption(
'--col-master-item-color <column position or name>',
'column number (zero based) or name to use as color for dimensions/measures',
'Color'
)
.requiredOption(
'--col-master-item-per-value-color <column position or name>',
'column number (zero based) or name to use as per-value/segment color for dimensions/measures',
'Per value color'
)
.requiredOption('--sleep-between-imports <milliseconds>', 'sleep this many milliseconds between imports. Set to 0 to disable', 1000)
.requiredOption(
'--limit-import-count <number>',
'import at most x number of master items from the Excel file. Defaults to 0 = no limit',
0
)
.option('--dry-run', 'do a dry run, i.e. do not create or update anything - just show what would be done');
// Get measure command
program
.command('master-item-measure-get')
.description('get info about one or more master measures')
.action(async (options) => {
await sharedParamAssertOptions(options);
masterItemGetAssertOptions(options);
getMasterMeasure(options);
})
.addOption(
new Option('--log-level <level>', 'log level').choices(['error', 'warn', 'info', 'verbose', 'debug', 'silly']).default('info')
)
.requiredOption('--host <host>', 'Qlik Sense server IP/FQDN')
.option('--port <port>', 'Qlik Sense server engine port', '4747')
.option('--schema-version <string>', 'Qlik Sense engine schema version', '12.612.0')
.requiredOption('--app-id <id>', 'Qlik Sense app ID')
.requiredOption('--virtual-proxy <prefix>', 'Qlik Sense virtual proxy prefix', '')
.requiredOption('--secure <true|false>', 'connection to Qlik Sense engine is via https', true)
.requiredOption('--auth-user-dir <directory>', 'user directory for user to connect with')
.requiredOption('--auth-user-id <userid>', 'user ID for user to connect with')
.addOption(new Option('-a, --auth-type <type>', 'authentication type').choices(['cert']).default('cert'))
.option('--auth-cert-file <file>', 'Qlik Sense certificate file (exported from QMC)', './cert/client.pem')
.option('--auth-cert-key-file <file>', 'Qlik Sense certificate key file (exported from QMC)', './cert/client_key.pem')
.option('--auth-root-cert-file <file>', 'Qlik Sense root certificate file (exported from QMC)', './cert/root.pem')
.addOption(
new Option('--id-type <type>', 'type of identifier passed in the --master-item option').choices(['id', 'name']).default('name')
)
.option('--master-item <ids...>', 'master measure to retrieve. If not specified all measures will be retrieved')
.addOption(new Option('--output-format <format>', 'output format').choices(['json', 'table']).default('json'));
// Delete measure command
program
.command('master-item-measure-delete')
.description('delete master measure(s)')
.action(async (options) => {
await sharedParamAssertOptions(options);
masterItemMeasureDeleteAssertOptions(options);
deleteMasterMeasure(options);
})
.addOption(
new Option('--log-level <level>', 'log level').choices(['error', 'warn', 'info', 'verbose', 'debug', 'silly']).default('info')
)
.requiredOption('--host <host>', 'Qlik Sense server IP/FQDN')
.option('--port <port>', 'Qlik Sense server engine port', '4747')
.option('--schema-version <string>', 'Qlik Sense engine schema version', '12.612.0')
.requiredOption('--app-id <id>', 'Qlik Sense app ID')
.requiredOption('--virtual-proxy <prefix>', 'Qlik Sense virtual proxy prefix', '')
.requiredOption('--secure <true|false>', 'connection to Qlik Sense engine is via https', true)
.requiredOption('--auth-user-dir <directory>', 'user directory for user to connect with')
.requiredOption('--auth-user-id <userid>', 'user ID for user to connect with')
.addOption(new Option('-a, --auth-type <type>', 'authentication type').choices(['cert']).default('cert'))
.option('--auth-cert-file <file>', 'Qlik Sense certificate file (exported from QMC)', './cert/client.pem')
.option('--auth-cert-key-file <file>', 'Qlik Sense certificate key file (exported from QMC)', './cert/client_key.pem')
.option('--auth-root-cert-file <file>', 'Qlik Sense root certificate file (exported from QMC)', './cert/root.pem')
.addOption(new Option('--id-type <type>', 'type of identifier passed in the --master-item option').choices(['id', 'name']))
.option('--master-item <ids...>', 'names or IDs of master measures to be deleted. Multiple IDs should be space separated')
.option('--delete-all', 'delete all master measures')
.option('--dry-run', 'do a dry run, i.e. do not delete anything - just show what would be deleted');
// Get dimension command
program
.command('master-item-dim-get')
.description('get info about one or more master dimensions')
.action(async (options) => {
await sharedParamAssertOptions(options);
getMasterDimension(options);
})
.addOption(
new Option('--log-level <level>', 'log level').choices(['error', 'warn', 'info', 'verbose', 'debug', 'silly']).default('info')
)
.requiredOption('--host <host>', 'Qlik Sense server IP/FQDN')
.option('--port <port>', 'Qlik Sense server engine port', '4747')
.option('--schema-version <string>', 'Qlik Sense engine schema version', '12.612.0')
.requiredOption('--app-id <id>', 'Qlik Sense app ID')
.requiredOption('--virtual-proxy <prefix>', 'Qlik Sense virtual proxy prefix', '')
.requiredOption('--secure <true|false>', 'connection to Qlik Sense engine is via https', true)
.requiredOption('--auth-user-dir <directory>', 'user directory for user to connect with')
.requiredOption('--auth-user-id <userid>', 'user ID for user to connect with')
.addOption(new Option('-a, --auth-type <type>', 'authentication type').choices(['cert']).default('cert'))
.requiredOption('--auth-cert-file <file>', 'Qlik Sense certificate file (exported from QMC)', './cert/client.pem')
.requiredOption('--auth-cert-key-file <file>', 'Qlik Sense certificate key file (exported from QMC)', './cert/client_key.pem')
.requiredOption('--auth-root-cert-file <file>', 'Qlik Sense root certificate file (exported from QMC)', './cert/root.pem')
.addOption(
new Option('--id-type <type>', 'type of identifier passed in the --master-item option').choices(['id', 'name']).default('name')
)
.option('--master-item <ids...>', 'master dimension to retrieve. If not specified all dimensions will be retrieved')
.addOption(new Option('--output-format <format>', 'output format').choices(['json', 'table']).default('json'));
// Delete dimension command
program
.command('master-item-dim-delete')
.description('delete master dimension(s)')
.action(async (options) => {
await sharedParamAssertOptions(options);
masterItemDimDeleteAssertOptions(options);
deleteMasterDimension(options);
})
.addOption(
new Option('--log-level <level>', 'log level').choices(['error', 'warn', 'info', 'verbose', 'debug', 'silly']).default('info')
)
.requiredOption('--host <host>', 'Qlik Sense server IP/FQDN')
.option('--port <port>', 'Qlik Sense server engine port', '4747')
.option('--schema-version <string>', 'Qlik Sense engine schema version', '12.612.0')
.requiredOption('--app-id <id>', 'Qlik Sense app ID')
.requiredOption('--virtual-proxy <prefix>', 'Qlik Sense virtual proxy prefix', '')
.requiredOption('--secure <true|false>', 'connection to Qlik Sense engine is via https', true)
.requiredOption('--auth-user-dir <directory>', 'user directory for user to connect with')
.requiredOption('--auth-user-id <userid>', 'user ID for user to connect with')
.addOption(new Option('-a, --auth-type <type>', 'authentication type').choices(['cert']).default('cert'))
.option('--auth-cert-file <file>', 'Qlik Sense certificate file (exported from QMC)', './cert/client.pem')
.option('--auth-cert-key-file <file>', 'Qlik Sense certificate key file (exported from QMC)', './cert/client_key.pem')
.option('--auth-root-cert-file <file>', 'Qlik Sense root certificate file (exported from QMC)', './cert/root.pem')
.addOption(new Option('--id-type <type>', 'type of identifier passed in the --master-item option').choices(['id', 'name']))
.option('--master-item <ids...>', 'names or IDs of master dimensions to be deleted. Multiple IDs should be space separated')
.option('--delete-all', 'delete all master dimensions')
.option('--dry-run', 'do a dry run, i.e. do not delete anything - just show what would be deleted');
// Get variable command
program
.command('variable-get')
.description('get variable definitions in one or more apps')
.action(async (options) => {
await sharedParamAssertOptions(options);
variableGetAssertOptions(options);
getVariable(options);
})
.addOption(
new Option('--log-level <level>', 'log level').choices(['error', 'warn', 'info', 'verbose', 'debug', 'silly']).default('info')
)
.requiredOption('--host <host>', 'Qlik Sense server IP/FQDN')
.option('--engine-port <port>', 'Qlik Sense server engine port', '4747')
.option('--qrs-port <port>', 'Qlik Sense repository service (QRS) port', '4242')
.option('--schema-version <string>', 'Qlik Sense engine schema version', '12.612.0')
.option('--app-id <id...>', 'Qlik Sense app ID(s) to get variables from')
.option('--app-tag <tag...>', 'Qlik Sense app tag(s) to get variables')
.requiredOption('--virtual-proxy <prefix>', 'Qlik Sense virtual proxy prefix', '')
.requiredOption('--secure <true|false>', 'connection to Qlik Sense engine is via https', true)
.requiredOption('--auth-user-dir <directory>', 'user directory for user to connect with')
.requiredOption('--auth-user-id <userid>', 'user ID for user to connect with')
.addOption(new Option('-a, --auth-type <type>', 'authentication type').choices(['cert']).default('cert'))
.option('--auth-cert-file <file>', 'Qlik Sense certificate file (exported from QMC)', './cert/client.pem')
.option('--auth-cert-key-file <file>', 'Qlik Sense certificate key file (exported from QMC)', './cert/client_key.pem')
.option('--auth-root-cert-file <file>', 'Qlik Sense root certificate file (exported from QMC)', './cert/root.pem')
.addOption(
new Option('--id-type <type>', 'type of identifier passed in the --variable option').choices(['id', 'name']).default('name')
)
.option('--variable <ids...>', 'variables to retrieve. If not specified all variables will be retrieved')
.addOption(new Option('--output-format <format>', 'output format').choices(['json', 'table']).default('json'));
// Delete variable command
program
.command('variable-delete')
.description('delete one or more variables in one or more apps')
.action(async (options) => {
await sharedParamAssertOptions(options);
variableDeleteAssertOptions(options);
deleteVariable(options);
})
.addOption(
new Option('--log-level <level>', 'log level').choices(['error', 'warn', 'info', 'verbose', 'debug', 'silly']).default('info')
)
.requiredOption('--host <host>', 'Qlik Sense server IP/FQDN')
.option('--engine-port <port>', 'Qlik Sense server engine port', '4747')
.option('--qrs-port <port>', 'Qlik Sense repository service (QRS) port', '4242')
.option('--schema-version <string>', 'Qlik Sense engine schema version', '12.612.0')
.option('--app-id <id...>', 'Qlik Sense app ID(s) to get variables from')
.option('--app-tag <tag...>', 'Qlik Sense app tag(s) to get variables')
.requiredOption('--virtual-proxy <prefix>', 'Qlik Sense virtual proxy prefix', '')
.requiredOption('--secure <true|false>', 'connection to Qlik Sense engine is via https', true)
.requiredOption('--auth-user-dir <directory>', 'user directory for user to connect with')
.requiredOption('--auth-user-id <userid>', 'user ID for user to connect with')
.addOption(new Option('-a, --auth-type <type>', 'authentication type').choices(['cert']).default('cert'))
.option('--auth-cert-file <file>', 'Qlik Sense certificate file (exported from QMC)', './cert/client.pem')
.option('--auth-cert-key-file <file>', 'Qlik Sense certificate key file (exported from QMC)', './cert/client_key.pem')
.option('--auth-root-cert-file <file>', 'Qlik Sense root certificate file (exported from QMC)', './cert/root.pem')
.addOption(
new Option('--id-type <type>', 'type of identifier passed in the --variable option').choices(['id', 'name']).default('name')
)
.option('--variable <ids...>', 'variables to retrieve. If not specified all variables will be retrieved')
.option('--delete-all', 'delete all variables')
.option('--dry-run', 'do a dry run, i.e. do not delete anything - just show what would be deleted');
// Scramble field command
program
.command('field-scramble')
.description('scramble one or more fields in an app. A new app with the scrambled data is created.')
.action(async (options) => {
await sharedParamAssertOptions(options);
scrambleField(options);
})
.addOption(
new Option('--log-level <level>', 'log level').choices(['error', 'warn', 'info', 'verbose', 'debug', 'silly']).default('info')
)
.requiredOption('--host <host>', 'Qlik Sense server IP/FQDN')
.option('--port <port>', 'Qlik Sense server engine port', '4747')
.option('--schema-version <string>', 'Qlik Sense engine schema version', '12.612.0')
.requiredOption('--app-id <id>', 'Qlik Sense app ID')
.requiredOption('--virtual-proxy <prefix>', 'Qlik Sense virtual proxy prefix', '')
.requiredOption('--secure <true|false>', 'connection to Qlik Sense engine is via https', true)
.requiredOption('--auth-user-dir <directory>', 'user directory for user to connect with')
.requiredOption('--auth-user-id <userid>', 'user ID for user to connect with')
.addOption(new Option('-a, --auth-type <type>', 'authentication type').choices(['cert']).default('cert'))
.option('--auth-cert-file <file>', 'Qlik Sense certificate file (exported from QMC)', './cert/client.pem')
.option('--auth-cert-key-file <file>', 'Qlik Sense certificate key file (exported from QMC)', './cert/client_key.pem')
.option('--auth-root-cert-file <file>', 'Qlik Sense root certificate file (exported from QMC)', './cert/root.pem')
.requiredOption('--field-name <names...>', 'name of field(s) to be scrambled')
.requiredOption('--new-app-name <name>', 'name of new app that will contain scrambled data');
// Get script command
program
.command('script-get')
.description('get script from Qlik Sense app')
.action(async (options) => {
await sharedParamAssertOptions(options);
getScriptAssertOptions(options);
getScript(options);
})
.addOption(
new Option('--log-level <level>', 'log level').choices(['error', 'warn', 'info', 'verbose', 'debug', 'silly']).default('info')
)
.requiredOption('--host <host>', 'Qlik Sense server IP/FQDN')
.option('--port <port>', 'Qlik Sense server engine port', '4747')
.option('--schema-version <string>', 'Qlik Sense engine schema version', '12.612.0')
.requiredOption('--app-id <id>', 'Qlik Sense app ID')
.requiredOption('--virtual-proxy <prefix>', 'Qlik Sense virtual proxy prefix', '')
.requiredOption('--secure <true|false>', 'connection to Qlik Sense engine is via https', true)
.requiredOption('--auth-user-dir <directory>', 'user directory for user to connect with')
.requiredOption('--auth-user-id <userid>', 'user ID for user to connect with')
.addOption(new Option('-a, --auth-type <type>', 'authentication type').choices(['cert']).default('cert'))
.option('--auth-cert-file <file>', 'Qlik Sense certificate file (exported from QMC)', './cert/client.pem')
.option('--auth-cert-key-file <file>', 'Qlik Sense certificate key file (exported from QMC)', './cert/client_key.pem')
.option('--auth-root-cert-file <file>', 'Qlik Sense root certificate file (exported from QMC)', './cert/root.pem');
// Get bookmark command
program
.command('bookmark-get')
.description('get info about one or more bookmarks')
.action(async (options) => {
await sharedParamAssertOptions(options);
getBookmarkAssertOptions(options);
getBookmark(options);
})
.addOption(
new Option('--log-level <level>', 'log level').choices(['error', 'warn', 'info', 'verbose', 'debug', 'silly']).default('info')
)
.requiredOption('--host <host>', 'Qlik Sense server IP/FQDN')
.option('--port <port>', 'Qlik Sense server engine port', '4747')
.option('--schema-version <string>', 'Qlik Sense engine schema version', '12.612.0')
.requiredOption('--app-id <id>', 'Qlik Sense app ID')
.requiredOption('--virtual-proxy <prefix>', 'Qlik Sense virtual proxy prefix', '')
.requiredOption('--secure <true|false>', 'connection to Qlik Sense engine is via https', true)
.requiredOption('--auth-user-dir <directory>', 'user directory for user to connect with')
.requiredOption('--auth-user-id <userid>', 'user ID for user to connect with')
.addOption(new Option('-a, --auth-type <type>', 'authentication type').choices(['cert']).default('cert'))
.option('--auth-cert-file <file>', 'Qlik Sense certificate file (exported from QMC)', './cert/client.pem')
.option('--auth-cert-key-file <file>', 'Qlik Sense certificate key file (exported from QMC)', './cert/client_key.pem')
.option('--auth-root-cert-file <file>', 'Qlik Sense root certificate file (exported from QMC)', './cert/root.pem')
.addOption(
new Option('--id-type <type>', 'type of bookmark identifier passed in the --bookmark option')
.choices(['id', 'name'])
.default('name')
)
.option('--bookmark <bookmarks...>', 'bookmark to retrieve. If not specified all bookmarks will be retrieved')
.option('--output-format <json|table>', 'output format', 'json');
// Get tasks command
program
.command('task-get')
.description('get info about one or more tasks')
.action(async (options) => {
const newOptions = options;
// If options.tableDetails is true, it means --table-details was passed as options without any explicit value.
// This is allowed, but should be interpreted as "all" table details.
// Make options.tableDetails an array with all possible table details.
if (options.tableDetails === true) {
newOptions.tableDetails = [
'common',
'extprogram',
'lastexecution',
'tag',
'customproperty',
'schematrigger',
'compositetrigger',
'comptimeconstraint',
'comprule',
];
}
await sharedParamAssertOptions(newOptions);
getTaskAssertOptions(newOptions);
getTask(newOptions);
})
.addOption(
new Option('--log-level <level>', 'log level').choices(['error', 'warn', 'info', 'verbose', 'debug', 'silly']).default('info')
)
.requiredOption('--host <host>', 'Qlik Sense server IP/FQDN')
.option('--port <port>', 'Qlik Sense repository service (QRS) port', '4242')
.option('--schema-version <string>', 'Qlik Sense engine schema version', '12.612.0')
.requiredOption('--virtual-proxy <prefix>', 'Qlik Sense virtual proxy prefix', '')
.requiredOption('--secure <true|false>', 'connection to Qlik Sense engine is via https', true)
.requiredOption('--auth-user-dir <directory>', 'user directory for user to connect with')
.requiredOption('--auth-user-id <userid>', 'user ID for user to connect with')
.addOption(new Option('-a, --auth-type <type>', 'authentication type').choices(['cert']).default('cert'))
.option('--auth-cert-file <file>', 'Qlik Sense certificate file (exported from QMC)', './cert/client.pem')
.option('--auth-cert-key-file <file>', 'Qlik Sense certificate key file (exported from QMC)', './cert/client_key.pem')
.option('--auth-root-cert-file <file>', 'Qlik Sense root certificate file (exported from QMC)', './cert/root.pem')
.addOption(
new Option('--task-type <type...>', 'type of tasks to include')
.choices(['reload', 'ext-program'])
.default(['reload', 'ext-program'])
)
.option('--task-id <ids...>', 'use task IDs to select which tasks to retrieve. Only allowed when --output-format=table')
.option('--task-tag <tags...>', 'use tags to select which tasks to retrieve. Only allowed when --output-format=table')
.addOption(new Option('--output-format <format>', 'output format').choices(['table', 'tree']).default('tree'))
.addOption(new Option('--output-dest <dest>', 'where to send task info').choices(['screen', 'file']).default('screen'))
.addOption(new Option('--output-file-name <name>', 'file name to store task info in').default(''))
.addOption(new Option('--output-file-format <format>', 'file type/format').choices(['excel', 'csv', 'json']).default('excel'))
.option('--output-file-overwrite', 'overwrite output file without asking')
.addOption(new Option('--text-color <show>', 'use colored text in task views').choices(['yes', 'no']).default('yes'))
.option('--tree-icons', 'display task status icons in tree view')
.addOption(
new Option('--tree-details [detail...]', 'display details for each task in tree view')
.choices(['taskid', 'laststart', 'laststop', 'nextstart', 'appname', 'appstream'])
.default('')
)
.addOption(
new Option(
'--table-details [detail...]',
'which aspects of tasks should be included in table view. Not choosing any details will show all'
)
.choices([
'common',
'extprogram',
'lastexecution',
'tag',
'customproperty',
'schematrigger',
'compositetrigger',
'comptimeconstraint',
'comprule',
])
.default('')
);
// Set custom property on tasks command
program
.command('task-custom-property-set')
.description('update a custom property of one or more tasks')
.action(async (options) => {
await sharedParamAssertOptions(options);
setTaskCustomPropertyAssertOptions(options);
await setTaskCustomProperty(options);
})
.addOption(
new Option('--log-level <level>', 'log level').choices(['error', 'warn', 'info', 'verbose', 'debug', 'silly']).default('info')
)
.requiredOption('--host <host>', 'Qlik Sense server IP/FQDN')
.option('--port <port>', 'Qlik Sense repository service (QRS) port', '4242')
.option('--schema-version <string>', 'Qlik Sense engine schema version', '12.612.0')
.requiredOption('--virtual-proxy <prefix>', 'Qlik Sense virtual proxy prefix', '')
.requiredOption('--secure <true|false>', 'connection to Qlik Sense engine is via https', true)
.requiredOption('--auth-user-dir <directory>', 'user directory for user to connect with')
.requiredOption('--auth-user-id <userid>', 'user ID for user to connect with')
.addOption(new Option('-a, --auth-type <type>', 'authentication type').choices(['cert']).default('cert'))
.option('--auth-cert-file <file>', 'Qlik Sense certificate file (exported from QMC)', './cert/client.pem')
.option('--auth-cert-key-file <file>', 'Qlik Sense certificate key file (exported from QMC)', './cert/client_key.pem')
.option('--auth-root-cert-file <file>', 'Qlik Sense root certificate file (exported from QMC)', './cert/root.pem')
.addOption(
new Option('--task-type <type...>', 'type of tasks to list').choices(['reload']).default(['reload'])
// .choices(['reload', 'ext-program'])
// .default(['reload', 'ext-program'])
)
.option('--task-id <ids...>', 'use task IDs to select which tasks to retrieve')
.option('--task-tag <tags...>', 'use tags to select which tasks to retrieve')
.requiredOption('--custom-property-name <name>', 'name of custom property that will be updated')
.requiredOption('--custom-property-value <values...>', 'one or more values name of custom property that will be updated')
.option('--overwrite', 'overwrite existing custom property values without asking')
.addOption(
new Option('--update-mode <mode>', 'append or replace value(s) to existing custom property')
.choices(['append', 'replace'])
.default('append')
)
.option('--dry-run', 'do a dry run, i.e. do not modify any reload tasks - just show what would be updated');
// Import tasks from definitions in Excel/CSV file
program
.command('task-import')
.description('create tasks based on definitions in a file on disk, optionally also importing apps from QVF files.')
.action(async (options) => {
try {
await sharedParamAssertOptions(options);
taskImportAssertOptions(options);
importTaskFromFile(options);
} catch (err) {
logger.error(`IMPORT TASK: ${err}`);
}
})
.addOption(
new Option('--log-level <level>', 'log level').choices(['error', 'warn', 'info', 'verbose', 'debug', 'silly']).default('info')
)
.requiredOption('--host <host>', 'Qlik Sense server IP/FQDN')
.option('--port <port>', 'Qlik Sense server engine port', '4242')
.option('--schema-version <string>', 'Qlik Sense engine schema version', '12.612.0')
.requiredOption('--virtual-proxy <prefix>', 'Qlik Sense virtual proxy prefix', '')
.requiredOption('--secure <true|false>', 'connection to Qlik Sense engine is via https', true)
.requiredOption('--auth-user-dir <directory>', 'user directory for user to connect with')
.requiredOption('--auth-user-id <userid>', 'user ID for user to connect with')
.addOption(new Option('-a, --auth-type <type>', 'authentication type').choices(['cert']).default('cert'))
.option('--auth-cert-file <file>', 'Qlik Sense certificate file (exported from QMC)', './cert/client.pem')
.option('--auth-cert-key-file <file>', 'Qlik Sense certificate key file (exported from QMC)', './cert/client_key.pem')
.option('--auth-root-cert-file <file>', 'Qlik Sense root certificate file (exported from QMC)', './cert/root.pem')
.addOption(new Option('-t, --file-type <type>', 'source file type').choices(['excel', 'csv']).default('excel'))
.requiredOption('--file-name <filename>', 'file containing task definitions')
.option('--sheet-name <name>', 'name of Excel sheet where task info is found')
.addOption(new Option('--update-mode <mode>', 'create new or update existing tasks').choices(['create']).default('create'))
.requiredOption(
'--limit-import-count <number>',
'import at most x number of tasks from the source file. Defaults to 0 = no limit',
0
)
.requiredOption(
'--sleep-app-upload <milliseconds>',
'Wait this long before continuing after each app has been uploaded to Sense. Defaults to 1000 = 1 second',
1000
)
.option('--import-app', 'import Sense app QVFs from specified directory')
.option('--import-app-sheet-name <name>', 'name of Excel sheet where app definitions are found')
.option('--dry-run', 'do a dry run, i.e. do not create any reload tasks - just show what would be done');
// Import apps from definitions in Excel file
program
.command('app-import')
.description('import apps/upload QVF files on disk to Sense based on definitions in Excel file.')
.action(async (options) => {
try {
await sharedParamAssertOptions(options);
appImportAssertOptions(options);
importAppFromFile(options);
} catch (err) {
logger.error(`IMPORT APP: ${err}`);
}
})
.addOption(
new Option('--log-level <level>', 'log level').choices(['error', 'warn', 'info', 'verbose', 'debug', 'silly']).default('info')
)
.requiredOption('--host <host>', 'Qlik Sense server IP/FQDN')
.option('--port <port>', 'Qlik Sense server engine port', '4242')
.option('--schema-version <string>', 'Qlik Sense engine schema version', '12.612.0')
.requiredOption('--virtual-proxy <prefix>', 'Qlik Sense virtual proxy prefix', '')
.requiredOption('--secure <true|false>', 'connection to Qlik Sense engine is via https', true)
.requiredOption('--auth-user-dir <directory>', 'user directory for user to connect with')
.requiredOption('--auth-user-id <userid>', 'user ID for user to connect with')
.addOption(new Option('-a, --auth-type <type>', 'authentication type').choices(['cert']).default('cert'))
.option('--auth-cert-file <file>', 'Qlik Sense certificate file (exported from QMC)', './cert/client.pem')
.option('--auth-cert-key-file <file>', 'Qlik Sense certificate key file (exported from QMC)', './cert/client_key.pem')
.option('--auth-root-cert-file <file>', 'Qlik Sense root certificate file (exported from QMC)', './cert/root.pem')
.addOption(new Option('-t, --file-type <type>', 'source file type').choices(['excel']).default('excel'))
.requiredOption('--file-name <filename>', 'file containing app definitions')
.requiredOption('--sheet-name <name>', 'name of Excel sheet where app info is found')
.requiredOption('--limit-import-count <number>', 'import at most x number of apps. Defaults to 0 = no limit', 0)
.requiredOption(
'--sleep-app-upload <milliseconds>',
'Wait this long before continuing after each app has been uploaded to Sense. Defaults to 1000 = 1 second',
1000
)
.option('--dry-run', 'do a dry run, i.e. do not import any apps - just show what would be done');
// Export apps to QVF files
program
.command('app-export')
.description('export Qlik Sense apps to QVF files on disk.')
.action(async (options) => {
try {
await sharedParamAssertOptions(options);
await appExportAssertOptions(options);
exportAppToFile(options);
} catch (err) {
logger.error(`EXPORT APP: ${err}`);
}
})
.addOption(
new Option('--log-level <level>', 'log level').choices(['error', 'warn', 'info', 'verbose', 'debug', 'silly']).default('info')
)
.requiredOption('--host <host>', 'Qlik Sense server IP/FQDN')
.option('--port <port>', 'Qlik Sense server engine port', '4242')
.option('--schema-version <string>', 'Qlik Sense engine schema version', '12.612.0')
.requiredOption('--virtual-proxy <prefix>', 'Qlik Sense virtual proxy prefix', '')
.requiredOption('--secure <true|false>', 'connection to Qlik Sense engine is via https', true)
.requiredOption('--auth-user-dir <directory>', 'user directory for user to connect with')
.requiredOption('--auth-user-id <userid>', 'user ID for user to connect with')
.addOption(new Option('-a, --auth-type <type>', 'authentication type').choices(['cert']).default('cert'))
.option('--auth-cert-file <file>', 'Qlik Sense certificate file (exported from QMC)', './cert/client.pem')
.option('--auth-cert-key-file <file>', 'Qlik Sense certificate key file (exported from QMC)', './cert/client_key.pem')
.option('--auth-root-cert-file <file>', 'Qlik Sense root certificate file (exported from QMC)', './cert/root.pem')
.option('--app-id <ids...>', 'use app IDs to select which apps to export')
.option('--app-tag <tags...>', 'use app tags to select which apps to export')
.requiredOption('--output-dir <directory>', 'relative or absolut path in which QVF files should be stored.', 'qvf-export')
.addOption(
new Option('--qvf-name-format <format...>', 'structure of QVF file name format')
.choices(['app-id', 'app-name', 'export-date', 'export-time'])
.default(['app-name'])
)
.addOption(
new Option('--qvf-name-separator <separator>', 'character used to separate parts of the QVF file name')
.choices(['-', '--', '_', '__'])
.default('_')
)
.option('--qvf-overwrite', 'overwrite existing QVF files without asking')
.requiredOption('--exclude-app-data <true|false>', 'exclude or include app data in QVF file', true)
.requiredOption('--limit-export-count <number>', 'export at most x number of apps. Defaults to 0 = no limit', 0)
.requiredOption(
'--sleep-app-export <milliseconds>',
'Wait this long before continuing after each app has been exported. Defaults to 1000 = 1 second',
1000
)
// Export of app metadata
.option('--metadata-file-create', 'create a separate file with information about all exported apps')
.addOption(new Option('--metadata-file-name <name>', 'file name to store app metadata in').default('app_export.xlsx'))
.addOption(new Option('--metadata-file-format <format>', 'file type/format').choices(['excel']).default('excel'))
.option('--metadata-file-overwrite', 'overwrite app metadata file without asking')
.option('--dry-run', 'do a dry run, i.e. do not export any apps - just show what would be done');
// Test connection command
program
.command('connection-test')
.description('test connection to Qlik Sense server')
.action(async (options) => {
try {
await sharedParamAssertOptions(options);
testConnection(options);
} catch (err) {
logger.error(`CONNECTION TEST: ${err}`);
}
})
.addOption(
new Option('--log-level <level>', 'log level').choices(['error', 'warn', 'info', 'verbose', 'debug', 'silly']).default('info')
)
.requiredOption('--host <host>', 'Qlik Sense server IP/FQDN')
.option('--port <port>', 'Qlik Sense server engine port', '4242')
.option('--schema-version <string>', 'Qlik Sense engine schema version', '12.612.0')
.requiredOption('--virtual-proxy <prefix>', 'Qlik Sense virtual proxy prefix', '')
.requiredOption('--secure <true|false>', 'connection to Qlik Sense engine is via https', true)
.requiredOption('--auth-user-dir <directory>', 'user directory for user to connect with')
.requiredOption('--auth-user-id <userid>', 'user ID for user to connect with')
.addOption(new Option('-a, --auth-type <type>', 'authentication type').choices(['cert']).default('cert'))
.option('--auth-cert-file <file>', 'Qlik Sense certificate file (exported from QMC)', './cert/client.pem')
.option('--auth-cert-key-file <file>', 'Qlik Sense certificate key file (exported from QMC)', './cert/client_key.pem')
.option('--auth-root-cert-file <file>', 'Qlik Sense root certificate file (exported from QMC)', './cert/root.pem');
// Parse command line params
await program.parseAsync(process.argv);
})();