-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from mountaindude/63-typos
63 typos
- Loading branch information
Showing
12 changed files
with
706 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* eslint-disable no-await-in-loop */ | ||
const { getAllSpaces } = require('./space'); | ||
|
||
// Function to get all apps and their associated metadata | ||
// Parameters: | ||
// qlik: authentication object | ||
// | ||
// Return | ||
// Success: An array of app objects | ||
// Failure: false | ||
async function getAllApps(qlik) { | ||
let allItems = []; | ||
try { | ||
const items = await qlik.items.getItems({ resourceType: 'app', limit: 100 }); | ||
|
||
// Paginate through the results | ||
// eslint-disable-next-line no-restricted-syntax | ||
for await (const item of items.pagination) { | ||
allItems.push(item); | ||
} | ||
} catch (error) { | ||
allItems = false; | ||
} | ||
|
||
// Return the apps' metadata | ||
return allItems; | ||
} | ||
|
||
// Function to look up apo IDs given app names, colletion names or managed space names | ||
// Parameters: | ||
// node: node object | ||
// qlik: authentication object | ||
// lookupSource: object containing entities to look up and translate into app IDs | ||
// | ||
// Return | ||
// Success: An object containing an array of unique app IDs and an array of unique app objects | ||
// Failure: false | ||
async function lookupAppId(node, qlik, lookupSource) { | ||
const allAppIds = []; | ||
const allAppObjects = []; | ||
|
||
// Get all apps. | ||
const allApps = await getAllApps(qlik); | ||
|
||
// Did we get any apps? If not, report error and return | ||
// Also make sure we got an array | ||
if (!allApps || !Array.isArray(allApps)) { | ||
node.log('Error getting apps in lookupAppId'); | ||
node.status({ fill: 'red', shape: 'ring', text: 'error getting apps' }); | ||
return false; | ||
} | ||
|
||
// Qlik SaaS APIs don't have a good filtering mechanism, so we'll have to filter the results ourselves. | ||
|
||
// lookupSource.appName is an array of app names. | ||
// We'll iterate through the array and look for apps with matching names. | ||
// Save the app IDs to the allAppIds array. | ||
if (lookupSource.appName) { | ||
try { | ||
// Iterate through the array of app names | ||
lookupSource.appName.forEach((appName) => { | ||
// Iterate through the array of apps | ||
allApps.forEach((app) => { | ||
// Does the app name match? | ||
if (app.name === appName) { | ||
// Yes. Save the app ID to the allAppIds array | ||
allAppIds.push(app.id); | ||
allAppObjects.push(app); | ||
} | ||
}); | ||
}); | ||
} catch (error) { | ||
node.log(`Error looking up app name: ${error}`); | ||
node.status({ fill: 'red', shape: 'ring', text: 'error looking up app name' }); | ||
return false; | ||
} | ||
} | ||
|
||
// lookupSource.spaceName is an array of space names. | ||
// We'll iterate through the array and look for apps that are in the spaces. | ||
// Save the app IDs to the allAppIds array. | ||
if (lookupSource.spaceName) { | ||
try { | ||
// Get all spaces | ||
const allSpaces = await getAllSpaces(node, qlik); | ||
|
||
// Did we get any spaces? If not, report error and return | ||
// Also make sure we got an array | ||
if (!allSpaces || !Array.isArray(allSpaces)) { | ||
node.log('Error getting spaces in lookupAppId'); | ||
node.status({ fill: 'red', shape: 'ring', text: 'error getting spaces' }); | ||
return false; | ||
} | ||
|
||
// Iterate through the array of space names | ||
lookupSource.spaceName.forEach(async (spaceName) => { | ||
// Iterate through the array of spaces | ||
allSpaces.forEach(async (space) => { | ||
// Does the space name match? | ||
if (space.name === spaceName) { | ||
// Yes. Get the ID of this space | ||
const spaceId = space.id; | ||
|
||
// Get all apps in this space | ||
// Each app object has an attribute called resourceAttributes.spaceId | ||
// that is set to the space ID if the app is part of a space | ||
const appsInSpace = allApps.filter((app) => app.resourceAttributes.spaceId === spaceId); | ||
|
||
// Save the app IDs to the allAppIds array | ||
appsInSpace.forEach((app) => { | ||
allAppIds.push(app.id); | ||
allAppObjects.push(app); | ||
}); | ||
} | ||
}); | ||
}); | ||
} catch (error) { | ||
node.log(`Error looking up space name: ${error}`); | ||
node.status({ fill: 'red', shape: 'ring', text: 'error looking up space name' }); | ||
return false; | ||
} | ||
} | ||
|
||
// Remove duplicates from the allAppIds array | ||
const uniqueAppIds = [...new Set(allAppIds)]; | ||
|
||
// Get the app objects for the unique app IDs | ||
const uniqueAppObjects = []; | ||
|
||
// Make sure we got an array | ||
if (!uniqueAppIds || !Array.isArray(uniqueAppIds)) { | ||
node.log('Error getting unique app IDs in lookupAppId'); | ||
node.status({ fill: 'red', shape: 'ring', text: 'error getting unique app IDs' }); | ||
return false; | ||
} | ||
|
||
uniqueAppIds.forEach((appId) => { | ||
const appObject = allAppObjects.find((app) => app.id === appId); | ||
uniqueAppObjects.push(appObject); | ||
}); | ||
|
||
return { uniqueAppIds, uniqueAppObjects }; | ||
} | ||
|
||
// Make the function available to other files | ||
module.exports = { | ||
lookupAppId, | ||
getAllApps, | ||
}; |
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,84 @@ | ||
/* eslint-disable no-await-in-loop */ | ||
|
||
// Function to get all spaces and their associated metadata | ||
// Parameters: | ||
// node: node object | ||
// qlik: authentication object | ||
// | ||
// Return | ||
// Success: An array of space objects | ||
// Failure: false | ||
async function getAllSpaces(node, qlik) { | ||
let allItems = []; | ||
try { | ||
const items = await qlik.spaces.getSpaces({ limit: 100 }); | ||
|
||
// eslint-disable-next-line no-restricted-syntax | ||
for await (const item of items.pagination) { | ||
allItems.push(item); | ||
} | ||
} catch (error) { | ||
node.log(`Error getting spaces: ${error}`); | ||
allItems = false; | ||
} | ||
|
||
// Return the spaces' metadata | ||
return allItems; | ||
} | ||
|
||
// Function to get all apps that are in a space | ||
// Parameters: | ||
// auth: authentication object | ||
// spaceId: the ID of the space | ||
|
||
// Return | ||
// Success: An array of app objects | ||
// Failure: false | ||
async function getAppsInSpace(auth, spaceId) { | ||
let allItems = []; | ||
let path = `/items?resourceType=app&spaceId=${spaceId}`; | ||
|
||
// Loop until there are no more pages of results | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
try { | ||
// Parameters for the /items endpoint | ||
const params = { | ||
limit: 100, | ||
}; | ||
|
||
const response = await auth.rest(path, params); | ||
const allApps = await response.json(); | ||
|
||
// Push all objects to the allItems array | ||
// eslint-disable-next-line no-loop-func | ||
allApps.data.forEach((app) => { | ||
allItems.push(app); | ||
}); | ||
|
||
// Are there more pages of results? | ||
if (!allApps.links.next || allApps.links.next === null) { | ||
// No more pages. Break out of the loop | ||
break; | ||
} | ||
|
||
// Build the path for the next page of results | ||
// Only use the path after the ..../api/v1 part | ||
// eslint-disable-next-line prefer-destructuring | ||
path = allApps.links.next.href.split('/api/v1')[1]; | ||
// console.log(`next path: ${path}`); | ||
} catch (error) { | ||
allItems = false; | ||
break; | ||
} | ||
} | ||
|
||
// Return the apps' metadata | ||
return allItems; | ||
} | ||
|
||
// Make the function available to other files | ||
module.exports = { | ||
getAllSpaces, | ||
getAppsInSpace, | ||
}; |
Oops, something went wrong.