Skip to content

Commit

Permalink
Merge pull request #610 from mountaindude/227
Browse files Browse the repository at this point in the history
227
  • Loading branch information
mountaindude authored Nov 10, 2024
2 parents 7dad6f6 + 5b41c30 commit 00dd973
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 146 deletions.
1 change: 1 addition & 0 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# Source code

96 changes: 40 additions & 56 deletions src/lib/cloud/cloud-collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,66 +135,50 @@ const qscloudListCollections = async (options) => {
}
};

const qscloudVerifyCollectionExists = (options) =>
new Promise((resolve, reject) => {
try {
logger.debug('Checking if QS Cloud collection already exists');
const qscloudVerifyCollectionExists = async (options) => {
try {
logger.debug('Checking if QS Cloud collection already exists');

const cloudConfig = {
url: options.tenanturl,
token: options.apikey,
// version: X, // optional. default is: 1
};
const cloudConfig = {
url: options.tenanturl,
token: options.apikey,
// version: X, // optional. default is: 1
};

const saasInstance = new QlikSaas(cloudConfig);

// Get all available collections
saasInstance
.Get('collections')
.then((allCollections) => {
logger.debug(
`COLLECTION EXISTS: Collections:\n${JSON.stringify(
allCollections,
null,
2
)}`
);

// Get index of specified collection among the existin ones.
const index = allCollections.map((e) => e.id).indexOf(options.collectionid);

if (index === -1) {
// Content library mpt found
resolve(false);
} else {
// Collection found
resolve(true);
}
})
.catch((err) => {
// Return error msg
if (err.stack) {
logger.error(`CLOUD COLLECTION EXISTS 1 (stack): ${err.stack}`);
} else if (err.message) {
logger.error(`CLOUD COLLECTION EXISTS 1 (message): ${err.message}`);
} else {
logger.error(`CLOUD COLLECTION EXISTS 1: ${err}`);
}

reject(new Error(`COLLECTION EXISTS 1: ${err}`));
});
} catch (err) {
if (err.stack) {
logger.error(`CLOUD COLLECTION EXISTS 2 (stack): ${err.stack}`);
} else if (err.message) {
logger.error(`CLOUD COLLECTION EXISTS 2 (stack): ${err.message}`);
} else {
logger.error(`CLOUD COLLECTION EXISTS 2: ${JSON.stringify(err, null, 2)}`);
}
const saasInstance = new QlikSaas(cloudConfig);

reject(new Error(`COLLECTION EXISTS: ${err}`));
// Get all available collections
const allCollections = await saasInstance.Get('collections');
logger.debug(
`COLLECTION EXISTS: Collections:\n${JSON.stringify(
allCollections,
null,
2
)}`
);

// Get index of specified collection among the existing ones.
const index = allCollections.map((e) => e.id).indexOf(options.collectionid);

if (index === -1) {
// Collection not found
return false;
} else {
// Collection found
return true;
}
} catch (err) {
if (err.stack) {
logger.error(`CLOUD COLLECTION EXISTS 1 (stack): ${err.stack}`);
} else if (err.message) {
logger.error(`CLOUD COLLECTION EXISTS 1 (message): ${err.message}`);
} else {
logger.error(`CLOUD COLLECTION EXISTS 1: ${err}`);
}
});

throw new Error(`COLLECTION EXISTS 1: ${err}`);
}
};

module.exports = {
qscloudListCollections,
Expand Down
76 changes: 37 additions & 39 deletions src/lib/qseow/qseow-certificates.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,52 +22,50 @@ async function exists(pathToCheck) {
* @param {*} options
* @returns
*/
const qseowVerifyCertificatesExist = (options) =>
// eslint-disable-next-line no-unused-vars
new Promise(async (resolve, reject) => {
try {
logger.debug('Checking if QSEoW certificates exists');

const certFile = upath.isAbsolute(options.certfile)
? options.certfile
: upath.join(bsiExecutablePath, options.certfile);
const certKeyFile = upath.isAbsolute(options.certkeyfile)
? options.certkeyfile
: upath.join(bsiExecutablePath, options.certkeyfile);
const qseowVerifyCertificatesExist = async (options) => {
try {
logger.debug('Checking if QSEoW certificates exists');

logger.debug(`Path to Qlik Sense certificate file: ${certFile}`);
logger.debug(`Path to Qlik Sense certificate key file: ${certKeyFile}`);
const certFile = upath.isAbsolute(options.certfile)
? options.certfile
: upath.join(bsiExecutablePath, options.certfile);
const certKeyFile = upath.isAbsolute(options.certkeyfile)
? options.certkeyfile
: upath.join(bsiExecutablePath, options.certkeyfile);

const certExists = await exists(certFile);
const certKeyExists = await exists(certKeyFile);
logger.debug(`Path to Qlik Sense certificate file: ${certFile}`);
logger.debug(`Path to Qlik Sense certificate key file: ${certKeyFile}`);

if (certExists === true) {
logger.verbose(`Certificate file ${certFile} exists`);
} else {
logger.error(`Certificate file ${certFile} missing`);
resolve(false);
}
const certExists = await exists(certFile);
const certKeyExists = await exists(certKeyFile);

if (certKeyExists === true) {
logger.verbose(`Certificate key file ${certKeyFile} exists`);
} else {
logger.error(`Certificate key file ${certKeyFile} missing`);
resolve(false);
}
if (certExists) {
logger.verbose(`Certificate file ${certFile} exists`);
} else {
logger.error(`Certificate file ${certFile} missing`);
return false;
}

resolve(true);
} catch (err) {
if (err.stack) {
logger.error(`QSEOW CERT CHECK (stack): ${err.stack}`);
} else if (err.message) {
logger.error(`QSEOW CERT CHECK (message): ${err.message}`);
} else {
logger.error(`QSEOW CERT CHECK: ${JSON.stringify(err, null, 2)}`);
}
if (certKeyExists) {
logger.verbose(`Certificate key file ${certKeyFile} exists`);
} else {
logger.error(`Certificate key file ${certKeyFile} missing`);
return false;
}

resolve(false);
return true;
} catch (err) {
if (err.stack) {
logger.error(`QSEOW CERT CHECK (stack): ${err.stack}`);
} else if (err.message) {
logger.error(`QSEOW CERT CHECK (message): ${err.message}`);
} else {
logger.error(`QSEOW CERT CHECK: ${JSON.stringify(err, null, 2)}`);
}
});

return false;
}
};

module.exports = {
qseowVerifyCertificatesExist,
Expand Down
87 changes: 36 additions & 51 deletions src/lib/qseow/qseow-contentlibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,58 +7,43 @@ const { setupQseowQrsConnection } = require('./qseow-qrs');
*
* @param {*} options
*/
const qseowVerifyContentLibraryExists = (options) =>
new Promise((resolve, reject) => {
try {
logger.debug('Checking if QSEoW content library already exists');

const qseowConfigQrs = setupQseowQrsConnection(options);
// eslint-disable-next-line new-cap
const qrsInteractInstance = new qrsInteract(qseowConfigQrs);

const { contentlibrary } = options;

const apiUrl = `/contentlibrary?filter=name eq '${contentlibrary}'`;
logger.debug(`API URL: ${apiUrl}`);

// Test if content library already exists
qrsInteractInstance
.Get(apiUrl)
.then((result) => {
if (result.statusCode === 200 && result.body.length > 0) {
// Content library found
logger.debug(`Content library '${contentlibrary}' exists`);
resolve(true);
} else {
// Content library mpt found
logger.debug(`Content library '${contentlibrary}' does not exist`);
resolve(false);
}
})
.catch((err) => {
// Return error msg
if (err.stack) {
logger.error(`QSEOW CONTENT LIBRARY 1 (stack): ${err.stack}`);
} else if (err.message) {
logger.error(`QSEOW CONTENT LIBRARY 1 (message): ${err.message}`);
} else {
logger.error(`QSEOW CONTENT LIBRARY 1: ${err}`);
}

reject(new Error(`CONTENT LIBRARY 1: ${err}`));
});
} catch (err) {
if (err.stack) {
logger.error(`QSEOW CONTENT LIBRARY 2 (stack): ${err.stack}`);
} else if (err.message) {
logger.error(`QSEOW CONTENT LIBRARY 2 (message): ${err.message}`);
} else {
logger.error(`QSEOW CONTENT LIBRARY 2: ${JSON.stringify(err, null, 2)}`);
}

reject(new Error(`CONTENT LIBRARY 2: ${err}`));
const qseowVerifyContentLibraryExists = async (options) => {
try {
logger.debug('Checking if QSEoW content library already exists');

const qseowConfigQrs = setupQseowQrsConnection(options);
// eslint-disable-next-line new-cap
const qrsInteractInstance = new qrsInteract(qseowConfigQrs);

const { contentlibrary } = options;

const apiUrl = `/contentlibrary?filter=name eq '${contentlibrary}'`;
logger.debug(`API URL: ${apiUrl}`);

// Test if content library already exists
const result = await qrsInteractInstance.Get(apiUrl);

if (result.statusCode === 200 && result.body.length > 0) {
// Content library found
logger.debug(`Content library '${contentlibrary}' exists`);
return true;
} else {
// Content library not found
logger.debug(`Content library '${contentlibrary}' does not exist`);
return false;
}
} catch (err) {
if (err.stack) {
logger.error(`QSEOW CONTENT LIBRARY 1 (stack): ${err.stack}`);
} else if (err.message) {
logger.error(`QSEOW CONTENT LIBRARY 1 (message): ${err.message}`);
} else {
logger.error(`QSEOW CONTENT LIBRARY 1: ${err}`);
}
});

throw new Error(`CONTENT LIBRARY 1: ${err}`);
}
};

module.exports = {
qseowVerifyContentLibraryExists,
Expand Down

0 comments on commit 00dd973

Please sign in to comment.