Skip to content

Commit

Permalink
refactor to better support coming QS Cloud commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Göran Sander committed Oct 24, 2024
1 parent b74df00 commit f21f4f9
Show file tree
Hide file tree
Showing 69 changed files with 1,393 additions and 1,100 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

32 changes: 0 additions & 32 deletions .eslintrc.yml

This file was deleted.

3 changes: 0 additions & 3 deletions .jshintrc

This file was deleted.

37 changes: 37 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import prettier from 'eslint-plugin-prettier';
import globals from 'globals';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import js from '@eslint/js';
import { FlatCompat } from '@eslint/eslintrc';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

// export default [...compat.extends("airbnb-base", "prettier"), {
export default [
...compat.extends('prettier'),
{
plugins: {
prettier,
},

languageOptions: {
globals: {
...globals.node,
},

ecmaVersion: 12,
sourceType: 'module',
},

rules: {
'prettier/prettier': 'error',
},
},
];
1,045 changes: 89 additions & 956 deletions src/ctrl-q.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/lib/app/class_allapps.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import fs2 from 'fs';
import { v4 as uuidv4, validate } from 'uuid';
import yesno from 'yesno';
import { logger, execPath, mergeDirFilePath, verifyFileExists, sleep, isPkg } from '../../globals.js';
import setupQRSConnection from '../util/qrs.js';
import { getAppColumnPosFromHeaderRow } from '../util/lookups.js';
import setupQRSConnection from '../util/qseow/qrs.js';
import { getAppColumnPosFromHeaderRow } from '../util/qseow/lookups.js';
import QlikSenseApp from './class_app.js';
import { getTagIdByName } from '../util/tag.js';
import { getAppById, deleteAppById } from '../util/app.js';
import { getCustomPropertyDefinitionByName, doesCustomPropertyValueExist } from '../util/customproperties.js';
import { getTagIdByName } from '../util/qseow/tag.js';
import { getAppById, deleteAppById } from '../util/qseow/app.js';
import { getCustomPropertyDefinitionByName, doesCustomPropertyValueExist } from '../util/qseow/customproperties.js';
import { catchLog } from '../util/log.js';

class QlikSenseApps {
Expand Down
37 changes: 37 additions & 0 deletions src/lib/cli/qscloud-test-connection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Option } from 'commander';

import { catchLog } from '../util/log.js';
import { qscloudSharedParamAssertOptions } from '../util/qscloud/assert-options.js';
import qscloudTestConnection from '../cmd/qscloud/testconnection.js';

export function setupQscloudTestConnectionCommand(qsCloud) {
qsCloud
.command('connection-test')
.description('test connection to Qlik Sense Cloud.')
.action(async (options) => {
// SHow app version
logger.info(`App version: ${appVersion}`);

try {
await qscloudSharedParamAssertOptions(options);
const res = qscloudTestConnection(options);
logger.debug(`QS CLOUD CONNECTION TEST: Result: ${res}`);
} catch (err) {
catchLog('QS CLOUD CONNECTION TEST', err);
}
})
.addOption(
new Option('--log-level <level>', 'log level').choices(['error', 'warn', 'info', 'verbose', 'debug', 'silly']).default('info')
)
.requiredOption(
'--tenant-url <url>',
'URL or host of Qlik Sense cloud tenant. Example: "https://tenant.eu.qlikcloud.com" or "tenant.eu.qlikcloud.com"'
)
.addOption(new Option('-a, --auth-type <type>', 'authentication type').choices(['apikey']).default('apikey'))
.requiredOption('--apikey <key>', 'API key used to access the Sense APIs')

.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('--auth-jwt <jwt>', 'JSON Web Token (JWT) to use for authentication with Qlik Sense server');
}
59 changes: 59 additions & 0 deletions src/lib/cli/qseow-cp-user-activity-bucket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Option } from 'commander';

import { catchLog } from '../util/log.js';
// import { qseowSharedParamAssertOptions, customPropertyUserActivityBucketsAssertOptions } from '../util/qseow/assert-options.js';
// import customPropertyUserActivityBuckets from '../cmd/qseow/custom-property-user-activity-buckets.js';

export function setupQseowUserActivityCustomPropertyCommand(qseow) {
//
}

// 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 qseowSharedParamAssertOptions(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>', 'https connection to Qlik Sense must use correct certificate. Invalid certificates will result in rejected/failed connection.', 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',
// ]);
43 changes: 43 additions & 0 deletions src/lib/cli/qseow-delete-master-dimension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Option } from 'commander';

import { catchLog } from '../util/log.js';
import { qseowSharedParamAssertOptions, masterItemDimDeleteAssertOptions } from '../util/qseow/assert-options.js';
import deleteMasterDimension from '../cmd/qseow/getdim.js';

export function setupQseowDeleteMasterDimensionCommand(qseow) {
qseow
.command('master-item-dim-delete')
.description('delete master dimension(s)')
.action(async (options) => {
await qseowSharedParamAssertOptions(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 (usually 4747 for cert auth, 443 for jwt auth)', '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>',
'https connection to Qlik Sense must use correct certificate. Invalid certificates will result in rejected/failed connection.',
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', '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('--auth-jwt <jwt>', 'JSON Web Token (JWT) to use for authentication with Qlik Sense server')

.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');
}
43 changes: 43 additions & 0 deletions src/lib/cli/qseow-delete-master-measure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Option } from 'commander';

import { catchLog } from '../util/log.js';
import { qseowSharedParamAssertOptions, masterItemMeasureDeleteAssertOptions } from '../util/qseow/assert-options.js';
import deleteMasterMeasure from '../cmd/qseow/deletemeasure.js';

export function setupQseowDeleteMasterMeasureCommand(qseow) {
qseow
.command('master-item-measure-delete')
.description('delete master measure(s)')
.action(async (options) => {
await qseowSharedParamAssertOptions(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 (usually 4747 for cert auth, 443 for jwt auth)', '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>',
'https connection to Qlik Sense must use correct certificate. Invalid certificates will result in rejected/failed connection.',
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', '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('--auth-jwt <jwt>', 'JSON Web Token (JWT) to use for authentication with Qlik Sense server')

.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');
}
45 changes: 45 additions & 0 deletions src/lib/cli/qseow-delete-proxy-session.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Option } from 'commander';

import { catchLog } from '../util/log.js';
import { qseowSharedParamAssertOptions, deleteSessionsAssertOptions } from '../util/qseow/assert-options.js';
import deleteSessions from '../cmd/qseow/deletesessions.js';

export function setupQseowDeleteProxySessionsCommand(qseow) {
qseow
.command('session-delete')
.description('delete proxy session(s) on a specific virtual proxy and proxy service')
.action(async (options) => {
await qseowSharedParamAssertOptions(options);
await deleteSessionsAssertOptions(options);

deleteSessions(options);
})
.addOption(
new Option('--log-level <level>', 'log level').choices(['error', 'warn', 'info', 'verbose', 'debug', 'silly']).default('info')
)

.requiredOption('--host <host>', 'Qlik Sense host (IP/FQDN) where Qlik Repository Service (QRS) is running')
.option('--qrs-port <port>', 'Qlik Sense repository service (QRS) port (usually 4242)', '4242')
.requiredOption('--virtual-proxy <prefix>', 'Qlik Sense virtual proxy prefix to access QRS via', '')
.requiredOption(
'--secure <true|false>',
'https connection to Qlik Sense must use correct certificate. Invalid certificates will result in rejected/failed connection.',
true
)

.option('--session-id <id...>', 'session IDs to delete')
.requiredOption('--session-virtual-proxy <prefix>', 'Qlik Sense virtual proxy (prefix) to delete proxy session(s) on', '')
.requiredOption(
'--host-proxy <host>',
'Qlik Sense proxy (IP/FQDN) where sessions should be deleted. Must match the host name of a Sense node'
)
.option('--qps-port <port>', 'Qlik Sense proxy service (QPS) port (usually 4243)', '4243')

.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');
}
47 changes: 47 additions & 0 deletions src/lib/cli/qseow-delete-variable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Option } from 'commander';

import { catchLog } from '../util/log.js';
import { qseowSharedParamAssertOptions, variableDeleteAssertOptions } from '../util/qseow/assert-options.js';
import deleteVariable from '../cmd/qseow/deletevariable.js';

export function setupQseowDeleteVariableCommand(qseow) {
qseow
.command('variable-delete')
.description('delete one or more variables in one or more apps')
.action(async (options) => {
await qseowSharedParamAssertOptions(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 (usually 4747 for cert auth, 443 for jwt auth)', '4747')
.option('--qrs-port <port>', 'Qlik Sense repository service (QRS) port (usually 4242 for cert auth, 443 for jwt auth)', '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>',
'https connection to Qlik Sense must use correct certificate. Invalid certificates will result in rejected/failed connection.',
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', '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('--auth-jwt <jwt>', 'JSON Web Token (JWT) to use for authentication with Qlik Sense server')

.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');
}
Loading

0 comments on commit f21f4f9

Please sign in to comment.