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

Please find a new home for the two exported functions that have 'nothing' to do with logging. #2187

Open
aaronlippold opened this issue Jan 14, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@aaronlippold
Copy link
Member

This can only lead to issues and indicates there is a need for something new in the /utils/ dir.

export type Summary = {
profileNames: string[];
controlCount: number;
passedCount: number;
failedCount: number;
notApplicableCount: number;
notReviewedCount: number;
errorCount: number;
}
export function createWinstonLogger(
mapperName: string,
level = 'debug',
): winston.Logger {
return winston.createLogger({
transports: [new winston.transports.Console()],
level: level, // skipcq: JS-0240
format: winston.format.combine(
winston.format.timestamp({
format: 'MMM-DD-YYYY HH:mm:ss Z',
}),
winston.format.printf(
info => `[${[info.timestamp]}] ${mapperName} ${info.message}`,
),
),
})
}
export function getHDFSummary(hdf: ExecJSON.Execution): string {
let summary = 'Execution<'
const summaryObject: Summary = {
profileNames: [],
controlCount: 0,
passedCount: 0,
failedCount: 0,
notApplicableCount: 0,
notReviewedCount: 0,
errorCount: 0,
}
const contextualizedEvaluation = contextualizeEvaluation(hdf)
contextualizedEvaluation.contains.forEach(profile => {
summaryObject.profileNames.push(profile.data.name)
})
const controls: readonly ContextualizedControl[] = contextualizedEvaluation.contains.flatMap(
profile => profile.contains,
)
controls.forEach(control => {
switch (control.hdf.status) {
case 'Passed': {
summaryObject.passedCount += 1
break
}
case 'Failed': {
summaryObject.failedCount += 1
break
}
case 'Not Applicable': {
summaryObject.notApplicableCount += 1
break
}
case 'Not Reviewed': {
summaryObject.notReviewedCount += 1
break
}
case 'Profile Error': {
summaryObject.errorCount += 1
break
}
default:
}
})
summary += `Profiles: [Profile<${summaryObject.profileNames.join('> Profile<')}>], Passed=${summaryObject.passedCount}, Failed=${summaryObject.failedCount}, Not Applicable=${summaryObject.notApplicableCount}, Not Reviewed=${summaryObject.notReviewedCount}>`
return summary

@aaronlippold aaronlippold added the bug Something isn't working label Jan 14, 2024
@aaronlippold
Copy link
Member Author

the getSummary method may be OBE now with this PR and we can just point the things that use it to the standard Summary class interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants