-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement CLI abstract class (#2915)
* Reduce code complexity Signed-off-by: Joyce Quach <[email protected]> * Fix code smells for grype mapper Signed-off-by: Joyce Quach <[email protected]> * Fix code smells for other mappers Signed-off-by: Joyce Quach <[email protected]> * Run linter Signed-off-by: Joyce Quach <[email protected]> * added proper formatting for CLI, added oclif theme Signed-off-by: George M Dias <[email protected]> * Remove file CLI log file and added to gitignore Signed-off-by: George M Dias <[email protected]> * modified half of the CLIs adding the proper error catching Signed-off-by: George M Dias <[email protected]> * 60% completed - CLI to use abstract class Signed-off-by: George M Dias <[email protected]> * 85% completed - CLI to use abstract class Signed-off-by: George M Dias <[email protected]> * testing pack win - oclif was failing due to node 18 not supporting win32-arm64 Signed-off-by: George M Dias <[email protected]> * testing pack win - oclif was failing on win32-arm64 - change to node 20 Signed-off-by: George M Dias <[email protected]> * completed updates to CLI - use abstract class Signed-off-by: George M Dias <[email protected]> * fixed threshold test Signed-off-by: George M Dias <[email protected]> * fixed SonarCloud Code Analysis Signed-off-by: George M Dias <[email protected]> * removed xccdf_benchmark2inspec_stub in favor of inspec_profile Signed-off-by: George M Dias <[email protected]> * removed xccdf_benchmark2inspec_stub in favor of inspec_profile Signed-off-by: George M Dias <[email protected]> * updated inspect_profile to take given path, updated test Signed-off-by: George M Dias <[email protected]> * fixed inspec_profile test Signed-off-by: George M Dias <[email protected]> * fixed inspect_profile test Signed-off-by: George M Dias <[email protected]> * added generation of additon files Signed-off-by: George M Dias <[email protected]> * typo and grammar corrections * fixed inspect_profile test failing Signed-off-by: George M Dias <[email protected]> --------- Signed-off-by: Joyce Quach <[email protected]> Signed-off-by: George M Dias <[email protected]> Co-authored-by: George M Dias <[email protected]> Co-authored-by: Daniel Medina <[email protected]>
- Loading branch information
1 parent
df31f13
commit 3d0407c
Showing
82 changed files
with
4,063 additions
and
1,368 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
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 |
---|---|---|
|
@@ -16,4 +16,4 @@ out | |
**/saf-cli.log | ||
*.html | ||
saf-cli.log | ||
*.log | ||
CliProcessOutput.log |
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,26 @@ | ||
{ | ||
"bin": "yellow", | ||
"command": "yellow", | ||
"commandSummary": "green", | ||
"dollarSign": "yellow", | ||
"flag": "yellow", | ||
"flagDefaultValue": "blue", | ||
"flagOptions": "blue", | ||
"flagRequired": "red", | ||
"flagSeparator": "yellow", | ||
"json": { | ||
"brace": "magenta", | ||
"bracket": "magenta", | ||
"colon": "dim", | ||
"comma": "dim", | ||
"key": "yellow", | ||
"string": "green", | ||
"number": "green", | ||
"boolean": "green", | ||
"null": "red" | ||
}, | ||
"sectionDescription": "blue", | ||
"sectionHeader": "underline", | ||
"topic": "yellow", | ||
"version": "yellow" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,28 +1,51 @@ | ||
import {Command, Flags} from '@oclif/core' | ||
import {Flags} from '@oclif/core' | ||
import fs from 'fs' | ||
import {AnchoreGrypeMapper as Mapper} from '@mitre/hdf-converters' | ||
import {checkInput, checkSuffix} from '../../utils/global' | ||
import {BaseCommand} from '../../utils/oclif/baseCommand' | ||
|
||
export default class AnchoreGrype2HDF extends Command { | ||
static usage = 'convert anchoregrype2hdf -i <anchoregrype-json> -o <hdf-scan-results-json>' | ||
export default class AnchoreGrype2HDF extends BaseCommand<typeof AnchoreGrype2HDF> { | ||
static readonly usage = | ||
'<%= command.id %> -i <anchoregrype-json> -o <hdf-scan-results-json>'; | ||
|
||
static description = 'Translate a Anchore Grype output file into an HDF results set' | ||
static readonly description = | ||
'Translate an Anchore Grype output file into an HDF results set'; | ||
|
||
static examples = ['saf convert anchoregrype2hdf -i anchoregrype.json -o output-hdf-name.json'] | ||
static readonly examples = [ | ||
'<%= config.bin %> <%= command.id %> -i anchoregrype.json -o output-hdf-name.json', | ||
]; | ||
|
||
static flags = { | ||
help: Flags.help({char: 'h'}), | ||
input: Flags.string({char: 'i', required: true, description: 'Input Anchore Grype file'}), | ||
output: Flags.string({char: 'o', required: true, description: 'Output HDF file'}), | ||
'with-raw': Flags.boolean({char: 'w', required: false}), | ||
} | ||
static readonly flags = { | ||
input: Flags.string({ | ||
char: 'i', | ||
required: true, | ||
description: 'Input Anchore Grype file', | ||
}), | ||
output: Flags.string({ | ||
char: 'o', | ||
required: true, | ||
description: 'Output HDF file', | ||
}), | ||
includeRaw: Flags.boolean({ | ||
char: 'w', | ||
required: false, | ||
description: 'Include raw data from the input Anchore Grype file', | ||
}), | ||
}; | ||
|
||
async run() { | ||
const {flags} = await this.parse(AnchoreGrype2HDF) | ||
const input = fs.readFileSync(flags.input, 'utf8') | ||
checkInput({data: input, filename: flags.input}, 'grype', 'Anchore Grype JSON results file') | ||
checkInput( | ||
{data: input, filename: flags.input}, | ||
'grype', | ||
'Anchore Grype JSON results file', | ||
) | ||
|
||
const converter = new Mapper(input, flags['with-raw']) | ||
fs.writeFileSync(checkSuffix(flags.output), JSON.stringify(converter.toHdf(), null, 2)) | ||
const converter = new Mapper(input, flags.includeRaw) | ||
fs.writeFileSync( | ||
checkSuffix(flags.output), | ||
JSON.stringify(converter.toHdf(), null, 2), | ||
) | ||
} | ||
} |
Oops, something went wrong.