From fd659ab59df0c4e6d38443251d4aa08799dd3cde Mon Sep 17 00:00:00 2001 From: "George M. Dias" Date: Tue, 27 Feb 2024 23:51:23 -0600 Subject: [PATCH] Fix update controls for delta process (#2313) * Removed wait logger debug, added logger listener Signed-off-by: George M Dias * Fix deepsource findings Signed-off-by: George M Dias --------- Signed-off-by: George M Dias Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- package.json | 34 +++++++++---------- .../generate/update_controls4delta.ts | 34 +++++++++---------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/package.json b/package.json index 90a117e71..f6a4285e5 100644 --- a/package.json +++ b/package.json @@ -184,23 +184,23 @@ } }, "repository": "mitre/saf", -"scripts": { - "lint": "eslint \"src/**/*.ts\" --fix", - "lint:ci": "eslint \"src/**/*.ts\" --max-warnings 0", - "dev": "rm -rf lib && tsc && node bin/run", - "prepack": "run-script-os", - "test": "npm run test:mocha && npm run test:jest", - "tests": "npm run test", - "test:mocha": "NODE_ENV=test ts-mocha --timeout 8500 --forbid-only \"test/**/*.test.ts\"", - "test:mocha:one": "NODE_ENV=test ts-mocha --timeout 8500 --forbid-only", - "test:jest": "NODE_ENV=test jest", - "test:jest:one": "NODE_ENV=test jest --findRelatedTests", - "prepack:win32": "(IF EXIST lib rmdir /s /q lib) && tsc", - "prepack:darwin:linux": "rm -rf lib && tsc", - "pack-hdf-converters": "run-script-os", - "pack-hdf-converters:win32": "pack-hdf-converters.bat", - "pack-hdf-converters:darwin:linux": "./pack-hdf-converters.sh" -}, + "scripts": { + "lint": "eslint \"src/**/*.ts\" --fix", + "lint:ci": "eslint \"src/**/*.ts\" --max-warnings 0", + "dev": "rm -rf lib && tsc && node bin/run", + "test": "npm run test:mocha && npm run test:jest", + "tests": "npm run test", + "test:mocha": "ts-mocha --timeout 8500 --forbid-only \"test/**/*.test.ts\"", + "test:mocha:one": "ts-mocha --timeout 8500 --forbid-only", + "test:jest": "jest", + "test:jest:one": "jest --findRelatedTests", + "prepack": "run-script-os", + "prepack:win32": "(IF EXIST lib rmdir /s /q lib) && tsc", + "prepack:darwin:linux": "rm -rf lib && tsc", + "pack-hdf-converters": "run-script-os", + "pack-hdf-converters:win32": "pack-hdf-converters.bat", + "pack-hdf-converters:darwin:linux": "./pack-hdf-converters.sh" + }, "types": "lib/index.d.ts", "jest": { "preset": "ts-jest", diff --git a/src/commands/generate/update_controls4delta.ts b/src/commands/generate/update_controls4delta.ts index 1f336c324..e32bed5fd 100644 --- a/src/commands/generate/update_controls4delta.ts +++ b/src/commands/generate/update_controls4delta.ts @@ -198,8 +198,8 @@ export default class GenerateUpdateControls extends Command { const files = await readdir(controlsDir) // Iterate trough all files processing ony control files, have a .rb extension - const skippedControls = [] - const skippedFormatting = [] + const skippedControls: string[] = [] + const skippedFormatting: string[] = [] const isCorrectControlMap = new Map() const controlsProcessedMap = new Map() @@ -270,7 +270,7 @@ export default class GenerateUpdateControls extends Command { } let newControls = 0 - const newControlsFound = [] + const newControlsFound: any[] = [] for (const newControl of xccdfControlsMap.values()) { if (!controlsProcessedMap.has(newControl) && !isCorrectControlMap.has(newControl)) { newControls++ @@ -278,23 +278,23 @@ export default class GenerateUpdateControls extends Command { } } - await new Promise(resolve => { - setTimeout(resolve, Math.floor(Math.random() * 100)) - }) + logger.on('finish', () => { + console.log(colors.yellow('\n Total skipped files - no mapping to new control Id:'), colors.green(`${skipped.toString().padStart(4)}`)) + console.log(colors.yellow('Total processed files - found mapping to new control Id: '), colors.green(`${processed.toString().padStart(3)}`)) - console.log(colors.yellow('\n Total skipped files - no mapping to new control Id:'), colors.green(`${skipped.toString().padStart(4)}`)) - console.log(colors.yellow('Total processed files - found mapping to new control Id: '), colors.green(`${processed.toString().padStart(3)}`)) + console.log(colors.yellow('\n Total controls with correct identification: '), colors.green(`${isCorrectControl.toString().padStart(3)}`)) + console.log(colors.yellow('Total new controls found in the XCCDF guidance: '), colors.green(`${newControls.toString().padStart(3)}`)) - console.log(colors.yellow('\n Total controls with correct identification: '), colors.green(`${isCorrectControl.toString().padStart(3)}`)) - console.log(colors.yellow('Total new controls found in the XCCDF guidance: '), colors.green(`${newControls.toString().padStart(3)}`)) + console.log(colors.yellow('\nSkipped control(s) - not included in XCCDF guidance: '), `${colors.green(skippedControls.toString())}`) + console.log(colors.yellow('\n New control(s) found - included in XCCDF guidance: '), `${colors.green(newControlsFound.toString())}`) - console.log(colors.yellow('\nSkipped control(s) - not included in XCCDF guidance: '), `${colors.green(skippedControls.toString())}`) - console.log(colors.yellow('\n New control(s) found - included in XCCDF guidance: '), `${colors.green(newControlsFound.toString())}`) + if (flags.formatControls && notInProfileJSON > 0) { + console.log(colors.bold.red('\nTotal skipped formatting - not found in the profile json: '), colors.green(`${notInProfileJSON.toString().padStart(3)}`)) + console.log(colors.bold.red('Control(s) skipped formatting: '), colors.green(`${skippedFormatting.toString()}`)) + } + }) - if (flags.formatControls && notInProfileJSON > 0) { - console.log(colors.bold.red('\nTotal skipped formatting - not found in the profile json: '), colors.green(`${notInProfileJSON.toString().padStart(3)}`)) - console.log(colors.bold.red('Control(s) skipped formatting: '), colors.green(`${skippedFormatting.toString()}`)) - } + logger.end() } } @@ -323,7 +323,7 @@ function saveControl(filePath: string, newXCCDFControlNumber: string, currentCon fs.copyFileSync(filePath, destFilePath) } - // Deleted processed (old) file + // Delete processed (old) file } else if (renamedControl) { fs.unlinkSync(filePath) }