diff --git a/src/lib/service_uptime.js b/src/lib/service_uptime.js index fb21bdaf..99d25ad6 100644 --- a/src/lib/service_uptime.js +++ b/src/lib/service_uptime.js @@ -17,6 +17,7 @@ function serviceUptimeStart() { // eslint-disable-next-line no-extend-native Number.prototype.toTime = function (isSec) { const ms = isSec ? this * 1e3 : this; + // eslint-disable-next-line no-bitwise const lm = ~(4 * !!isSec); /* limit fraction */ const fmt = new Date(ms).toISOString().slice(11, lm); diff --git a/src/lib/slack_notification.js b/src/lib/slack_notification.js index cc9fb2ff..213a65c7 100644 --- a/src/lib/slack_notification.js +++ b/src/lib/slack_notification.js @@ -535,8 +535,8 @@ function sendReloadTaskFailureNotificationSlack(reloadParams) { // This is needed to avoid breaking the Slack message JSON const regExpSingle = /'/gm; const regExpDouble = /"/gm; - templateContext.scriptLogHead = templateContext.scriptLogHead.replace(regExpSingle, "\'").replace(regExpDouble, "\\'"); - templateContext.scriptLogTail = templateContext.scriptLogTail.replace(regExpSingle, "\'").replace(regExpDouble, "\\'"); + templateContext.scriptLogHead = templateContext.scriptLogHead.replace(regExpSingle, "'").replace(regExpDouble, "\\'"); + templateContext.scriptLogTail = templateContext.scriptLogTail.replace(regExpSingle, "'").replace(regExpDouble, "\\'"); // Replace all single and double quotes in executionDetailsConcatenated with escaped ditto // This is needed to avoid breaking the Slack message JSON diff --git a/src/lib/winsvc.js b/src/lib/winsvc.js index 5645820f..8d86bbc1 100644 --- a/src/lib/winsvc.js +++ b/src/lib/winsvc.js @@ -130,6 +130,9 @@ function status(serviceName, host = null) { // Get state name return resolve(stateName); }); + + // We should never arrive here, but if we do return null + return null; }, // Reject on error @@ -173,16 +176,17 @@ function details(serviceName, host = null) { // Run command to get service details with provided data exec(command, (err, stdout) => { let i = 0; - const startTypeRegex = new RegExp(/\d/); - const dependenciesRegex = new RegExp(/(?<=\s*DEPENDENCIES)(\s*:.*\r\n)*/); + const startTypeRegex = /\d/; + const dependenciesRegex = /(?<=\s*DEPENDENCIES)(\s*:.*\r\n)*/; const deps = dependenciesRegex.exec(stdout)[0].toString().split('\r\n'); - for (i = 0; i < deps.length; ++i) { + for (i = 0; i < deps.length; ) { deps[i] = deps[i].replace(/\s*: /, ''); if (deps[i] === '') { deps.splice(i, 1); } + i += 1; } // On error, reject and exit @@ -220,6 +224,9 @@ function details(serviceName, host = null) { dependencies: deps, }); }); + + // We should never arrive here, but if we do return null + return null; }, // Reject on error diff --git a/src/qrs_util/app_tag_util.js b/src/qrs_util/app_tag_util.js index b9ff49b0..ee935ef8 100644 --- a/src/qrs_util/app_tag_util.js +++ b/src/qrs_util/app_tag_util.js @@ -8,53 +8,51 @@ const globals = require('../globals'); * @param {*} appId * @returns */ -function getAppTags(appId) { - return new Promise(async (resolve, reject) => { - globals.logger.debug(`GETAPPTAGS: Retrieving all tags of app ${appId}`); - +async function getAppTags(appId) { + globals.logger.debug(`GETAPPTAGS: Retrieving all tags of app ${appId}`); + + try { + const qrsInstance = new QrsInteract({ + hostname: globals.configQRS.host, + portNumber: globals.configQRS.port, + headers: { + 'X-Qlik-User': 'UserDirectory=Internal; UserId=sa_repository', + }, + certificates: { + certFile: path.resolve(globals.configQRS.certPaths.certPath), + keyFile: path.resolve(globals.configQRS.certPaths.keyPath), + }, + }); + + // Get info about the task try { - const qrsInstance = new QrsInteract({ - hostname: globals.configQRS.host, - portNumber: globals.configQRS.port, - headers: { - 'X-Qlik-User': 'UserDirectory=Internal; UserId=sa_repository', - }, - certificates: { - certFile: path.resolve(globals.configQRS.certPaths.certPath), - keyFile: path.resolve(globals.configQRS.certPaths.keyPath), - }, - }); - - // Get info about the task - try { - globals.logger.debug(`GETAPPTAGS: app/full?filter=id eq ${appId}`); - - const result = await qrsInstance.Get(`app/full?filter=id eq ${appId}`); - globals.logger.debug(`GETAPPTAGS: Got response: ${result.statusCode}`); - - if (result.body.length === 1) { - // Yes, the task exists. Return all tags for this task - - // Get array of all values for this CP, for this task - const appTags1 = result.body[0].tags; - - // Get array of all CP values - const appTags2 = appTags1.map((item) => item.name); - - resolve(appTags2); - } else { - // The task does not exist - resolve([]); - } - } catch (err) { - globals.logger.error(`GETAPPTAGS: Error while getting tags: ${err.message}`); - resolve([]); + globals.logger.debug(`GETAPPTAGS: app/full?filter=id eq ${appId}`); + + const result = await qrsInstance.Get(`app/full?filter=id eq ${appId}`); + globals.logger.debug(`GETAPPTAGS: Got response: ${result.statusCode}`); + + if (result.body.length === 1) { + // Yes, the task exists. Return all tags for this task + + // Get array of all values for this CP, for this task + const appTags1 = result.body[0].tags; + + // Get array of all CP values + const appTags2 = appTags1.map((item) => item.name); + + return appTags2; } + + // The task does not exist + return []; } catch (err) { - globals.logger.error(`GETAPPTAGS: Error while getting tags: ${err}`); - reject(); + globals.logger.error(`GETAPPTAGS: Error while getting tags: ${err.message}`); + return []; } - }); + } catch (err) { + globals.logger.error(`GETAPPTAGS: Error while getting tags: ${err}`); + return false; + } } module.exports = { diff --git a/src/qrs_util/does_task_exist.js b/src/qrs_util/does_task_exist.js index e1dda2f4..ff7ee289 100644 --- a/src/qrs_util/does_task_exist.js +++ b/src/qrs_util/does_task_exist.js @@ -2,51 +2,49 @@ const QrsInteract = require('qrs-interact'); const globals = require('../globals'); // Function for getting info about owner of Qlik Sense apps -module.exports.doesTaskExist = (taskId) => +module.exports.doesTaskExist = async (taskId) => { // eslint-disable-next-line no-unused-vars - new Promise(async (resolve, reject) => { - try { - const qrsInstance = new QrsInteract({ - hostname: globals.configQRS.host, - portNumber: globals.configQRS.port, - headers: { - 'X-Qlik-User': 'UserDirectory=Internal; UserId=sa_repository', - }, - certificates: { - certFile: globals.configQRS.certPaths.certPath, - keyFile: globals.configQRS.certPaths.keyPath, - }, - }); + try { + const qrsInstance = new QrsInteract({ + hostname: globals.configQRS.host, + portNumber: globals.configQRS.port, + headers: { + 'X-Qlik-User': 'UserDirectory=Internal; UserId=sa_repository', + }, + certificates: { + certFile: globals.configQRS.certPaths.certPath, + keyFile: globals.configQRS.certPaths.keyPath, + }, + }); - // Get info about the task - try { - globals.logger.debug(`TASKEXISTS 1: task?filter=id eq ${taskId}`); + // Get info about the task + try { + globals.logger.debug(`TASKEXISTS 1: task?filter=id eq ${taskId}`); - const result = await qrsInstance.Get(`task?filter=id eq ${taskId}`); - globals.logger.debug(`TASKEXISTS: Got response: ${result.statusCode} for task ID ${taskId}`); + const result = await qrsInstance.Get(`task?filter=id eq ${taskId}`); + globals.logger.debug(`TASKEXISTS: Got response: ${result.statusCode} for task ID ${taskId}`); - if (result.statusCode === 200 && result.body.length > 0) { - // Task exists - resolve({ - exists: true, - task: { - taskId: result.body[0].id, - taskName: result.body[0].name, - }, - }); - } else { - // Task doesn't exist or other error (e.g. couldn't contact QRS) - resolve({ - exists: false, - task: {}, - }); - } - } catch (err) { - globals.logger.error(`TASKEXISTS: Error while getting task: ${err.message}`); - resolve(false); + if (result.statusCode === 200 && result.body.length > 0) { + // Task exists + return { + exists: true, + task: { + taskId: result.body[0].id, + taskName: result.body[0].name, + }, + }; } + // Task doesn't exist or other error (e.g. couldn't contact QRS) + return { + exists: false, + task: {}, + }; } catch (err) { - globals.logger.error(`TASKEXISTS: Error while checking if task exists: ${JSON.stringify(err, null, 2)}`); - resolve(false); + globals.logger.error(`TASKEXISTS: Error while getting task: ${err.message}`); + return false; } - }); + } catch (err) { + globals.logger.error(`TASKEXISTS: Error while checking if task exists: ${JSON.stringify(err, null, 2)}`); + return false; + } +}; diff --git a/src/qrs_util/get_app_owner.js b/src/qrs_util/get_app_owner.js index e68dbe1a..d1eac610 100644 --- a/src/qrs_util/get_app_owner.js +++ b/src/qrs_util/get_app_owner.js @@ -2,58 +2,58 @@ const QrsInteract = require('qrs-interact'); const globals = require('../globals'); // Function for getting info about owner of Qlik Sense apps -module.exports.getAppOwner = (appId) => - // eslint-disable-next-line no-unused-vars - new Promise(async (resolve, reject) => { - try { - const qrsInstance = new QrsInteract({ - hostname: globals.configQRS.host, - portNumber: globals.configQRS.port, - headers: { - 'X-Qlik-User': 'UserDirectory=Internal; UserId=sa_repository', - }, - certificates: { - certFile: globals.configQRS.certPaths.certPath, - keyFile: globals.configQRS.certPaths.keyPath, - }, - }); +module.exports.getAppOwner = async (appId) => { + try { + const qrsInstance = new QrsInteract({ + hostname: globals.configQRS.host, + portNumber: globals.configQRS.port, + headers: { + 'X-Qlik-User': 'UserDirectory=Internal; UserId=sa_repository', + }, + certificates: { + certFile: globals.configQRS.certPaths.certPath, + keyFile: globals.configQRS.certPaths.keyPath, + }, + }); - // Step 1: Get app owner's userdirectory and userid - let appOwner = null; - try { - globals.logger.debug(`APPOWNER 1: app/${appId}`); - const result = await qrsInstance.Get(`app/${appId}`); - globals.logger.debug(`APPOWNER: Got response: ${result.statusCode} for app ID ${appId}`); + // Step 1: Get app owner's userdirectory and userid + let appOwner = null; + try { + globals.logger.debug(`APPOWNER 1: app/${appId}`); + const result = await qrsInstance.Get(`app/${appId}`); + globals.logger.debug(`APPOWNER: Got response: ${result.statusCode} for app ID ${appId}`); - appOwner = result.body.owner; - } catch (err) { - globals.logger.error(`APPOWNER: Error while getting app owner: ${JSON.stringify(err, null, 2)}`); - throw 'Error while getting app owner'; - } + appOwner = result.body.owner; + } catch (err) { + globals.logger.error(`APPOWNER: Error while getting app owner: ${JSON.stringify(err, null, 2)}`); + throw new Error('Error while getting app owner'); + } - // Step 2: Get additional info about the user identified in step 1 - try { - globals.logger.debug(`APPOWNER 2: user/${appOwner.id}`); - const result = await qrsInstance.Get(`user/${appOwner.id}`); - globals.logger.debug(`APPOWNER: Got response: ${result.statusCode} for app owner ${appOwner.id}`); + // Step 2: Get additional info about the user identified in step 1 + try { + globals.logger.debug(`APPOWNER 2: user/${appOwner.id}`); + const result = await qrsInstance.Get(`user/${appOwner.id}`); + globals.logger.debug(`APPOWNER: Got response: ${result.statusCode} for app owner ${appOwner.id}`); - // Find email attribute - const emailAttributes = result.body.attributes.filter((attribute) => attribute.attributeType.toLowerCase() === 'email'); - const resultAttributes = emailAttributes.map((attribute) => attribute.attributeValue); + // Find email attribute + const emailAttributes = result.body.attributes.filter((attribute) => attribute.attributeType.toLowerCase() === 'email'); + const resultAttributes = emailAttributes.map((attribute) => attribute.attributeValue); - // if (resultAttributes.length > 0) { - resolve({ - id: appOwner.id, - directory: appOwner.userDirectory, - userId: appOwner.userId, - userName: appOwner.name, - emails: resultAttributes, - }); - // } - } catch (err) { - globals.logger.error(`APPOWNER: Error while getting app owner details 1: ${JSON.stringify(err, null, 2)}`); - } + // if (resultAttributes.length > 0) { + return { + id: appOwner.id, + directory: appOwner.userDirectory, + userId: appOwner.userId, + userName: appOwner.name, + emails: resultAttributes, + }; + // } } catch (err) { - globals.logger.error(`APPOWNER: Error while getting app owner details 2: ${JSON.stringify(err, null, 2)}`); + globals.logger.error(`APPOWNER: Error while getting app owner details 1: ${JSON.stringify(err, null, 2)}`); + return false; } - }); + } catch (err) { + globals.logger.error(`APPOWNER: Error while getting app owner details 2: ${JSON.stringify(err, null, 2)}`); + return false; + } +}; diff --git a/src/qrs_util/get_tasks.js b/src/qrs_util/get_tasks.js index 2b3a6313..f5335c9d 100644 --- a/src/qrs_util/get_tasks.js +++ b/src/qrs_util/get_tasks.js @@ -3,70 +3,70 @@ const globals = require('../globals'); // Function for getting info about owner of Qlik Sense apps // filter: { tag: 'abc', customProperty: { name: 'def', value: 'ghi' } } -module.exports.getTasks = (filter) => - // eslint-disable-next-line no-unused-vars - new Promise(async (resolve, reject) => { - try { - const qrsInstance = new QrsInteract({ - hostname: globals.configQRS.host, - portNumber: globals.configQRS.port, - headers: { - 'X-Qlik-User': 'UserDirectory=Internal; UserId=sa_repository', - }, - certificates: { - certFile: globals.configQRS.certPaths.certPath, - keyFile: globals.configQRS.certPaths.keyPath, - }, - }); +module.exports.getTasks = async (filter) => { + try { + const qrsInstance = new QrsInteract({ + hostname: globals.configQRS.host, + portNumber: globals.configQRS.port, + headers: { + 'X-Qlik-User': 'UserDirectory=Internal; UserId=sa_repository', + }, + certificates: { + certFile: globals.configQRS.certPaths.certPath, + keyFile: globals.configQRS.certPaths.keyPath, + }, + }); - const tasks = []; + const tasks = []; - try { - // Handle tag filter - if (filter.tag) { - globals.logger.debug(`GETTASKS 1: task/full?filter=tags.name eq '${filter.tag}'`); - const result = await qrsInstance.Get(`task/full?filter=tags.name eq '${filter.tag}'`); - globals.logger.debug(`GETTASKS: Got response: ${result.statusCode} for tag filter ${filter.tag}`); + try { + // Handle tag filter + if (filter.tag) { + globals.logger.debug(`GETTASKS 1: task/full?filter=tags.name eq '${filter.tag}'`); + const result = await qrsInstance.Get(`task/full?filter=tags.name eq '${filter.tag}'`); + globals.logger.debug(`GETTASKS: Got response: ${result.statusCode} for tag filter ${filter.tag}`); - if (result.statusCode === 200 && result.body.length > 0) { - // At least one task matches the tag - // eslint-disable-next-line no-restricted-syntax - for (const task of result.body) { - tasks.push({ taskId: task.id, taskName: task.name }); - } - } else { - // No task matches the tag + if (result.statusCode === 200 && result.body.length > 0) { + // At least one task matches the tag + // eslint-disable-next-line no-restricted-syntax + for (const task of result.body) { + tasks.push({ taskId: task.id, taskName: task.name }); } - resolve(tasks); + } else { + // No task matches the tag } + return tasks; + } - // Handle custom properties filter - if (filter.customProperty) { - globals.logger.debug( - `GETTASKS 2: task/full?filter=(customProperties.definition.name eq '${filter.customProperty.name}') and (customProperties.value eq '${filter.customProperty.value}')` - ); - const result = await qrsInstance.Get( - `task/full?filter=(customProperties.definition.name eq '${filter.customProperty.name}') and (customProperties.value eq '${filter.customProperty.value}')` - ); - globals.logger.debug(`GETTASKS: Got response: ${result.statusCode} for tag filter ${filter.customProperty.name}`); + // Handle custom properties filter + if (filter.customProperty) { + globals.logger.debug( + `GETTASKS 2: task/full?filter=(customProperties.definition.name eq '${filter.customProperty.name}') and (customProperties.value eq '${filter.customProperty.value}')` + ); + const result = await qrsInstance.Get( + `task/full?filter=(customProperties.definition.name eq '${filter.customProperty.name}') and (customProperties.value eq '${filter.customProperty.value}')` + ); + globals.logger.debug(`GETTASKS: Got response: ${result.statusCode} for tag filter ${filter.customProperty.name}`); - if (result.statusCode === 200 && result.body.length > 0) { - // At least one task matches the tag - // eslint-disable-next-line no-restricted-syntax - for (const task of result.body) { - tasks.push({ taskId: task.id, taskName: task.name }); - } - } else { - // No task matches the custom property + if (result.statusCode === 200 && result.body.length > 0) { + // At least one task matches the tag + // eslint-disable-next-line no-restricted-syntax + for (const task of result.body) { + tasks.push({ taskId: task.id, taskName: task.name }); } - resolve(tasks); + } else { + // No task matches the custom property } - } catch (err) { - globals.logger.error(`TASKEXISTS: Error while getting task: ${JSON.stringify(err, null, 2)}`); - resolve(false); + return tasks; } } catch (err) { - globals.logger.error(`TASKEXISTS: Error while checking if task exists: ${JSON.stringify(err, null, 2)}`); - resolve(false); + globals.logger.error(`TASKEXISTS: Error while getting task: ${JSON.stringify(err, null, 2)}`); + return false; } - }); + + return false; + } catch (err) { + globals.logger.error(`TASKEXISTS: Error while checking if task exists: ${JSON.stringify(err, null, 2)}`); + return false; + } +}; diff --git a/src/qrs_util/task_cp_util.js b/src/qrs_util/task_cp_util.js index 5c5ad591..9fc4e080 100644 --- a/src/qrs_util/task_cp_util.js +++ b/src/qrs_util/task_cp_util.js @@ -10,50 +10,48 @@ const globals = require('../globals'); * @param {*} cpValue * @returns */ -function isCustomPropertyValueSet(taskId, cpName, cpValue) { - return new Promise(async (resolve, reject) => { - globals.logger.debug(`Checking if value "${cpValue}" is set for custom property "${cpName}"`); +async function isCustomPropertyValueSet(taskId, cpName, cpValue) { + globals.logger.debug(`Checking if value "${cpValue}" is set for custom property "${cpName}"`); + try { + const qrsInstance = new QrsInteract({ + hostname: globals.configQRS.host, + portNumber: globals.configQRS.port, + headers: { + 'X-Qlik-User': 'UserDirectory=Internal; UserId=sa_repository', + }, + certificates: { + certFile: path.resolve(globals.configQRS.certPaths.certPath), + keyFile: path.resolve(globals.configQRS.certPaths.keyPath), + }, + }); + + // Get info about the task try { - const qrsInstance = new QrsInteract({ - hostname: globals.configQRS.host, - portNumber: globals.configQRS.port, - headers: { - 'X-Qlik-User': 'UserDirectory=Internal; UserId=sa_repository', - }, - certificates: { - certFile: path.resolve(globals.configQRS.certPaths.certPath), - keyFile: path.resolve(globals.configQRS.certPaths.keyPath), - }, - }); - - // Get info about the task - try { - globals.logger.debug( - `ISCPVALUESET: task/full?filter=id eq ${taskId} and customProperties.definition.name eq '${cpName}' and customProperties.value eq '${cpValue}'` - ); - - const result = await qrsInstance.Get( - `task/full?filter=id eq ${taskId} and customProperties.definition.name eq '${cpName}' and customProperties.value eq '${cpValue}'` - ); - globals.logger.debug(`ISCPVALUESET: Got response: ${result.statusCode} for CP ${cpName}`); - - if (result.body.length === 1) { - // Yes, the CP/value exists for this task - resolve(true); - } else { - // Value not set for the CP - resolve(false); - } - } catch (err) { - globals.logger.error(`ISCPVALUESET: Error while getting CP: ${err.message}`); - resolve(false); + globals.logger.debug( + `ISCPVALUESET: task/full?filter=id eq ${taskId} and customProperties.definition.name eq '${cpName}' and customProperties.value eq '${cpValue}'` + ); + + const result = await qrsInstance.Get( + `task/full?filter=id eq ${taskId} and customProperties.definition.name eq '${cpName}' and customProperties.value eq '${cpValue}'` + ); + globals.logger.debug(`ISCPVALUESET: Got response: ${result.statusCode} for CP ${cpName}`); + + if (result.body.length === 1) { + // Yes, the CP/value exists for this task + return true; } + + // Value not set for the CP + return false; } catch (err) { - globals.logger.error(`ISCPVALUESET: Error while getting CP: ${err}`); - reject(); + globals.logger.error(`ISCPVALUESET: Error while getting CP: ${err.message}`); + return false; } - }); + } catch (err) { + globals.logger.error(`ISCPVALUESET: Error while getting CP: ${err}`); + return false; + } } /** @@ -62,57 +60,51 @@ function isCustomPropertyValueSet(taskId, cpName, cpValue) { * @param {*} cpName * @returns */ -function getTaskCustomPropertyValues(taskId, cpName) { - return new Promise(async (resolve, reject) => { - globals.logger.debug(`GETTASKCPVALUE: Retrieving all values for custom property "${cpName}" of reload task ${taskId}`); +async function getTaskCustomPropertyValues(taskId, cpName) { + globals.logger.debug(`GETTASKCPVALUE: Retrieving all values for custom property "${cpName}" of reload task ${taskId}`); + + try { + const qrsInstance = new QrsInteract({ + hostname: globals.configQRS.host, + portNumber: globals.configQRS.port, + headers: { + 'X-Qlik-User': 'UserDirectory=Internal; UserId=sa_repository', + }, + certificates: { + certFile: path.resolve(globals.configQRS.certPaths.certPath), + keyFile: path.resolve(globals.configQRS.certPaths.keyPath), + }, + }); + // Get info about the task try { - const qrsInstance = new QrsInteract({ - hostname: globals.configQRS.host, - portNumber: globals.configQRS.port, - headers: { - 'X-Qlik-User': 'UserDirectory=Internal; UserId=sa_repository', - }, - certificates: { - certFile: path.resolve(globals.configQRS.certPaths.certPath), - keyFile: path.resolve(globals.configQRS.certPaths.keyPath), - }, - }); - - // Get info about the task - try { - globals.logger.debug( - `GETTASKCPVALUE: task/full?filter=id eq ${taskId} and customProperties.definition.name eq '${cpName}'` - ); - - const result = await qrsInstance.Get( - `task/full?filter=id eq ${taskId} and customProperties.definition.name eq '${cpName}'` - ); - globals.logger.debug(`GETTASKCPVALUE: Got response: ${result.statusCode} for CP ${cpName}`); - - if (result.body.length === 1) { - // Yes, the CP exists for this task. Return all values present for this CP - - // Get array of all values for this CP, for this task - const cpValues1 = result.body[0].customProperties.filter((cp) => cp.definition.name === cpName); - - // Get array of all CP values - const cpValues2 = cpValues1.map((item) => item.value); - - resolve(cpValues2); - } else { - // The task and/or the CP does not exist - resolve([]); - } - } catch (err) { - globals.logger.error(`GETTASKCPVALUE: Error while getting CP: ${err.message}`); - resolve([]); + globals.logger.debug(`GETTASKCPVALUE: task/full?filter=id eq ${taskId} and customProperties.definition.name eq '${cpName}'`); + + const result = await qrsInstance.Get(`task/full?filter=id eq ${taskId} and customProperties.definition.name eq '${cpName}'`); + globals.logger.debug(`GETTASKCPVALUE: Got response: ${result.statusCode} for CP ${cpName}`); + + if (result.body.length === 1) { + // Yes, the CP exists for this task. Return all values present for this CP + + // Get array of all values for this CP, for this task + const cpValues1 = result.body[0].customProperties.filter((cp) => cp.definition.name === cpName); + + // Get array of all CP values + const cpValues2 = cpValues1.map((item) => item.value); + + return cpValues2; } + + // The task and/or the CP does not exist + return []; } catch (err) { - globals.logger.error(`GETTASKCPVALUE: Error while getting CP: ${err}`); - reject(); + globals.logger.error(`GETTASKCPVALUE: Error while getting CP: ${err.message}`); + return []; } - }); + } catch (err) { + globals.logger.error(`GETTASKCPVALUE: Error while getting CP: ${err}`); + return false; + } } module.exports = { diff --git a/src/qrs_util/task_tag_util.js b/src/qrs_util/task_tag_util.js index 5a6d0343..8c5ce296 100644 --- a/src/qrs_util/task_tag_util.js +++ b/src/qrs_util/task_tag_util.js @@ -8,53 +8,50 @@ const globals = require('../globals'); * @param {*} taskId * @returns */ -function getTaskTags(taskId) { - return new Promise(async (resolve, reject) => { - globals.logger.debug(`GETTASKTAGS: Retrieving all tags of reload task ${taskId}`); - +async function getTaskTags(taskId) { + globals.logger.debug(`GETTASKTAGS: Retrieving all tags of reload task ${taskId}`); + + try { + const qrsInstance = new QrsInteract({ + hostname: globals.configQRS.host, + portNumber: globals.configQRS.port, + headers: { + 'X-Qlik-User': 'UserDirectory=Internal; UserId=sa_repository', + }, + certificates: { + certFile: path.resolve(globals.configQRS.certPaths.certPath), + keyFile: path.resolve(globals.configQRS.certPaths.keyPath), + }, + }); + + // Get info about the task try { - const qrsInstance = new QrsInteract({ - hostname: globals.configQRS.host, - portNumber: globals.configQRS.port, - headers: { - 'X-Qlik-User': 'UserDirectory=Internal; UserId=sa_repository', - }, - certificates: { - certFile: path.resolve(globals.configQRS.certPaths.certPath), - keyFile: path.resolve(globals.configQRS.certPaths.keyPath), - }, - }); - - // Get info about the task - try { - globals.logger.debug(`GETTASKTAGS: task/full?filter=id eq ${taskId}`); - - const result = await qrsInstance.Get(`task/full?filter=id eq ${taskId}`); - globals.logger.debug(`GETTASKTAGS: Got response: ${result.statusCode}`); - - if (result.body.length === 1) { - // Yes, the task exists. Return all tags for this task - - // Get array of all values for this CP, for this task - const taskTags1 = result.body[0].tags; - - // Get array of all CP values - const taskTags2 = taskTags1.map((item) => item.name); - - resolve(taskTags2); - } else { - // The task does not exist - resolve([]); - } - } catch (err) { - globals.logger.error(`GETTASKTAGS: Error while getting tags: ${err.message}`); - resolve([]); + globals.logger.debug(`GETTASKTAGS: task/full?filter=id eq ${taskId}`); + + const result = await qrsInstance.Get(`task/full?filter=id eq ${taskId}`); + globals.logger.debug(`GETTASKTAGS: Got response: ${result.statusCode}`); + + if (result.body.length === 1) { + // Yes, the task exists. Return all tags for this task + + // Get array of all values for this CP, for this task + const taskTags1 = result.body[0].tags; + + // Get array of all CP values + const taskTags2 = taskTags1.map((item) => item.name); + + return taskTags2; } + // The task does not exist + return []; } catch (err) { - globals.logger.error(`GETTASKTAGS: Error while getting tags: ${err}`); - reject(); + globals.logger.error(`GETTASKTAGS: Error while getting tags: ${err.message}`); + return []; } - }); + } catch (err) { + globals.logger.error(`GETTASKTAGS: Error while getting tags: ${err}`); + return false; + } } module.exports = {