Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: in scan mode, migrate addToHistory() calls to the queue handlers #93

Merged
merged 6 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/unit-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
node-version: 18
- name: Install app dependencies
run: npm ci
- name: Create .env file
run: echo -e "WATCHER_COLLECTION=1\nWATCHER_API_BASE=url\nWATCHER_AUTHORITY=auth\nWATCHER_CLIENT_ID=clientId\nWATCHER_CLIENT_SECRET=secret" > .env
- name: Run tests
run: npm test
- name: Upload coverage to github
Expand Down
8 changes: 7 additions & 1 deletion lib/cargo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Queue from 'better-queue'
import * as api from './api.js'
import { serializeError } from 'serialize-error'
import { TaskObject } from 'stig-manager-client-modules'
import { addToHistory } from './scan.js'

const component = 'cargo'
let batchId = 0
Expand Down Expand Up @@ -64,6 +65,7 @@ async function writer ( taskAsset ) {
})

}
return true
}
catch (error) {
const errorObj = {
Expand All @@ -87,19 +89,23 @@ async function writer ( taskAsset ) {
errorObj.error = serializeError(error)
}
logger.error(errorObj)
return false
}
}

async function resultsHandler( parsedResults, cb ) {
const component = 'batch'
try {
batchId++
const isModeScan = options.mode === 'scan'
logger.info({component: component, message: `batch started`, batchId: batchId, size: parsedResults.length})
const apiAssets = await api.getCollectionAssets(options.collectionId)
const apiStigs = await api.getInstalledStigs()
const tasks = new TaskObject ({ parsedResults, apiAssets, apiStigs, options:options })
isModeScan && tasks.errors.length && addToHistory(tasks.errors.map(e => e.sourceRef))
for ( const taskAsset of tasks.taskAssets.values() ) {
await writer( taskAsset )
const success = await writer( taskAsset )
isModeScan && success && addToHistory(taskAsset.sourceRefs)
}
logger.info({component: component, message: 'batch ended', batchId: batchId})
cb()
Expand Down
3 changes: 3 additions & 0 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { cargoQueue } from './cargo.js'
import { promises as fs } from 'fs'
import he from 'he'
import { reviewsFromCkl, reviewsFromScc, reviewsFromCklb } from 'stig-manager-client-modules'
import { addToHistory } from './scan.js'
import { options } from './args.js'

const valueProcessor = function (tagName, tagValue, jPath, hasAttributes, isLeafNode) {
he.decode(tagValue)
Expand Down Expand Up @@ -91,6 +93,7 @@ async function parseFileAndEnqueue (file, cb) {
}
catch (e) {
logger.warn({component: component, message: e.message, file: file})
options.mode === 'scan' && addToHistory(file)
cb(e, null)
}
}
Expand Down
1 change: 0 additions & 1 deletion lib/scan.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ async function startScanner() {
}
// if the file is not in the history, add it to the in memory history set.
else {
addToHistory(entry)
parseQueue.push(entry)
logger.info({component, message: `queued for parsing`, file: entry})
}
Expand Down
114 changes: 1 addition & 113 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"chai": "^5.0.3",
"esbuild": "^0.20.0",
"mocha": "^10.2.0",
"nodemon": "^3.0.3",
"sinon": "^17.0.1"
"nodemon": "^3.0.3"
}
}
Loading
Loading