Skip to content

Commit

Permalink
Clean up code for interacting with engine
Browse files Browse the repository at this point in the history
  • Loading branch information
mountaindude committed Nov 15, 2024
1 parent c050445 commit 39d5aec
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/lib/util/qseow/enigma_util.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import SenseUtilities from 'enigma.js/sense-utilities.js';
import WebSocket from 'ws';
import path from 'node:path';
import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import upath from 'upath';
import sea from 'node:sea';

import { logger, execPath, readCert } from '../../../globals.js';
import { logger, readCert } from '../../../globals.js';
import { getCertFilePaths } from '../../util/qseow/cert.js';

// Function to get Enigma.js schema file
const getEnigmaSchema = (processPkgFlag, seaFlag, options) => {
Expand Down Expand Up @@ -90,15 +90,8 @@ export const setupEnigmaConnection = (options, sessionId) => {
if (options.authType === 'cert') {
logger.verbose(`Using certificates for authentication with Enigma`);

logger.verbose('Verify that cert files exists');
const fileCert = path.resolve(execPath, options.authCertFile);
const fileCertKey = path.resolve(execPath, options.authCertKeyFile);
const fileCa = path.resolve(execPath, options.authRootCertFile);

if (!fileCert || !fileCertKey || !fileCa) {
logger.error(`Certificate file(s) not found when setting up Enigma connection`);
process.exit(1);
}
// Get certificate paths
const { fileCert, fileCertKey, fileCertCA } = getCertFilePaths(options);

// Set up Enigma configuration
// buildUrl docs: https://github.com/qlik-oss/enigma.js/blob/master/docs/api.md#senseutilitiesbuildurlconfig
Expand All @@ -116,9 +109,11 @@ export const setupEnigmaConnection = (options, sessionId) => {
new WebSocket(url, {
key: readCert(fileCertKey),
cert: readCert(fileCert),
ca: [readCert(fileCa)],
ca: [readCert(fileCertCA)],
headers: {
'X-Qlik-User': `UserDirectory=${encodeURIComponent(options.authUserDir)};UserId=${encodeURIComponent(options.authUserId)}`,
'X-Qlik-User': `UserDirectory=${encodeURIComponent(options.authUserDir)};UserId=${encodeURIComponent(
options.authUserId
)}`,
},
rejectUnauthorized: false,
}),
Expand Down

0 comments on commit 39d5aec

Please sign in to comment.