Skip to content

Commit

Permalink
refactor to use shorthand properties
Browse files Browse the repository at this point in the history
  • Loading branch information
csmig committed Jun 10, 2024
1 parent 78b7a04 commit 866c882
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions lib/cargo.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function writer ( taskAsset ) {
const component = 'writer'
try {
logger.debug({
component: component,
component,
message: `${taskAsset.assetProps.name} started`
})

Expand Down Expand Up @@ -50,7 +50,7 @@ async function writer ( taskAsset ) {
if (reviews.length > 0) {
const r = await api.postReviews(options.collectionId, taskAsset.assetProps.assetId, reviews)
logger.info({
component: component,
component,
message: `posted reviews`,
asset: { name: taskAsset.assetProps.name, id: taskAsset.assetProps.assetId },
rejected: r.rejected,
Expand All @@ -59,7 +59,7 @@ async function writer ( taskAsset ) {
}
else {
logger.warn({
component: component,
component,
message: `no reviews to post`,
asset: { name: taskAsset.assetProps.name, id: taskAsset.assetProps.assetId },
})
Expand Down Expand Up @@ -94,31 +94,30 @@ async function writer ( taskAsset ) {
}

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})
logger.info({component, message: `batch started`, batchId, size: parsedResults.length})
const apiAssets = await api.getCollectionAssets(
{
collectionId: options.collectionId,
targets: parsedResults.map(pr=>pr.target)
}
)
logger.info({component: component, message: `asset data received`, batchId: batchId, size: apiAssets.length})
logger.info({component, message: `asset data received`, batchId, size: apiAssets.length})
const apiStigs = await api.getInstalledStigs()
logger.info({component: component, message: `stig data received`, batchId: batchId, size: apiStigs.length})
const tasks = new TaskObject ({ parsedResults, apiAssets, apiStigs, options:options })
logger.info({component, message: `stig data received`, batchId, size: apiStigs.length})
const tasks = new TaskObject ({ parsedResults, apiAssets, apiStigs, options })
isModeScan && tasks.errors.length && addToHistory(tasks.errors.map(e => e.sourceRef))
for ( const taskAsset of tasks.taskAssets.values() ) {
const success = await writer( taskAsset )
isModeScan && success && addToHistory(taskAsset.sourceRefs)
}
logger.info({component, message: 'batch ended with success', batchId: batchId})
logger.info({component, message: 'batch ended', batchId})
cb()
}
catch (e) {
logger.error({component, message: 'batch ended with error', error: serializeError(e), batchId: batchId})
logger.error({component, message: 'batch ended', error: serializeError(e), batchId})
cb( e, undefined)
}
}
Expand Down

0 comments on commit 866c882

Please sign in to comment.