Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(connection-test): Add command to test connection to Sense server
Implements #328
- Loading branch information
Göran Sander
committed
Oct 26, 2023
1 parent
1bddb6a
commit 328886e
Showing
4 changed files
with
169 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const { logger, setLoggingLevel, isPkg, execPath } = require('../../globals'); | ||
const { getAboutFromQseow } = require('../util/about'); | ||
|
||
const testConnection = async (options) => { | ||
try { | ||
// Set log level | ||
setLoggingLevel(options.logLevel); | ||
|
||
logger.verbose(`Ctrl-Q was started as a stand-alone binary: ${isPkg}`); | ||
logger.verbose(`Ctrl-Q was started from ${execPath}`); | ||
|
||
logger.info(`Testing connection to Qlik Sense server ${options.host} on port ${options.port}`); | ||
logger.debug(`Options: ${JSON.stringify(options, null, 2)}`); | ||
|
||
const aboutInfo = await getAboutFromQseow(options); | ||
|
||
if (!aboutInfo) { | ||
logger.error(`Could not get about info from QSEoW`); | ||
return false; | ||
} | ||
|
||
logger.info(`Successfully connected to Qlik Sense server ${options.host} on port ${options.port}`); | ||
logger.info(`Qlik Sense build version: ${aboutInfo.buildVersion}`); | ||
logger.info(`Qlik Sense build date: ${aboutInfo.buildDate}`); | ||
return true; | ||
} catch (err) { | ||
logger.error(`EXPORT APP: ${err.stack}`); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
testConnection, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const axios = require('axios'); | ||
const path = require('path'); | ||
|
||
const { logger, execPath } = require('../../globals'); | ||
const { setupQRSConnection } = require('./qrs'); | ||
|
||
function getAboutFromQseow(options) { | ||
return new Promise((resolve, reject) => { | ||
logger.verbose(`Getting about info from QSEoW...`); | ||
|
||
// Make sure certificates exist | ||
const fileCert = path.resolve(execPath, options.authCertFile); | ||
const fileCertKey = path.resolve(execPath, options.authCertKeyFile); | ||
|
||
const axiosConfig = setupQRSConnection(options, { | ||
method: 'get', | ||
fileCert, | ||
fileCertKey, | ||
path: '/qrs/about', | ||
// headers: { | ||
// 'Accept': 'application/json', | ||
// 'Content-Type': 'application/json; charset=utf-8', | ||
// }, | ||
}); | ||
|
||
logger.debug(`About to get about info from QSEoW`); | ||
|
||
axios | ||
.request(axiosConfig) | ||
.then((result) => { | ||
if (result.status === 200) { | ||
const response = JSON.parse(result.data); | ||
logger.debug(`Successfully retrieved about info from QSEoW`); | ||
// Yes, the tag exists | ||
resolve(response); | ||
} | ||
resolve(false); | ||
}) | ||
.catch((err) => { | ||
logger.error(`GET ABOUT INFO: ${err}`); | ||
}); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
getAboutFromQseow, | ||
}; |