-
Notifications
You must be signed in to change notification settings - Fork 82
/
certificates.js
59 lines (49 loc) · 2.18 KB
/
certificates.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
const enigma = require('enigma.js');
const WebSocket = require('ws');
const path = require('path');
const fs = require('fs');
const schema = require('enigma.js/schemas/12.20.0.json');
// Your Sense Enterprise installation hostname:
const engineHost = 'localhost';
// Make sure the port below is accessible from the machine where this example
// is executed. If you changed the QIX Engine port in your installation, change this:
const enginePort = 4747;
// 'engineData' is a special "app id" that indicates you only want to use the global
// QIX interface or session apps, change this to an existing app guid if you intend
// to open that app:
const appId = 'engineData';
// The Sense Enterprise-configured user directory for the user you want to identify
// as:
const userDirectory = 'your-sense-user-directory';
// The user to use when creating the session:
const userId = 'your-sense-user';
// Path to a local folder containing the Sense Enterprise exported certificates:
const certificatesPath = './';
// Helper function to read the contents of the certificate files:
const readCert = (filename) => fs.readFileSync(path.resolve(__dirname, certificatesPath, filename));
const session = enigma.create({
schema,
url: `wss://${engineHost}:${enginePort}/app/${appId}`,
// Notice the non-standard second parameter here, this is how you pass in
// additional configuration to the 'ws' npm library, if you use a different
// library you may configure this differently:
createSocket: (url) => new WebSocket(url, {
ca: [readCert('root.pem')],
key: readCert('client_key.pem'),
cert: readCert('client.pem'),
headers: {
'X-Qlik-User': `UserDirectory=${encodeURIComponent(userDirectory)}; UserId=${encodeURIComponent(userId)}`,
},
}),
});
session.open().then((global) => {
console.log('Session was opened successfully');
return global.getDocList().then((list) => {
const apps = list.map((app) => `${app.qDocId} (${app.qTitle || 'No title'})`).join(', ');
console.log(`Apps on this Engine that the configured user can open: ${apps}`);
session.close();
});
}).catch((error) => {
console.log('Failed to open session and/or retrieve the app list:', error);
process.exit(1);
});