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

Allow custom report templates via CLI #4800

Merged
merged 1 commit into from
Sep 5, 2022
Merged
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
48 changes: 38 additions & 10 deletions cli/src/main/java/org/owasp/dependencycheck/CliParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ private void validateArgs() throws FileNotFoundException, ParseException {
throw new ParseException("Invalid Setting: cveStartYear must be a number greater than or equal to 2002.");
}
}

}
if (isRunScan()) {
validatePathExists(getScanFiles(), ARGUMENT.SCAN);
Expand All @@ -146,16 +145,13 @@ private void validateArgs() throws FileNotFoundException, ParseException {
validatePathExists(pathToCore, ARGUMENT.PATH_TO_CORE);
}
if (line.hasOption(ARGUMENT.OUTPUT_FORMAT)) {
String validating = null;
try {
for (String format : getReportFormat()) {
validating = format;
Format.valueOf(format);
for (String validating : getReportFormat()) {
if (!isValidFormat(validating)
&& !isValidFilePath(validating, "format")) {
final String msg = String.format("An invalid 'format' of '%s' was specified. "
+ "Supported output formats are %s, and custom template files.", validating, SUPPORTED_FORMATS);
throw new ParseException(msg);
}
} catch (IllegalArgumentException ex) {
final String msg = String.format("An invalid 'format' of '%s' was specified. "
+ "Supported output formats are " + SUPPORTED_FORMATS, validating);
throw new ParseException(msg);
}
}
final String base = getStringArgument(ARGUMENT.CVE_BASE_URL);
Expand All @@ -177,6 +173,38 @@ private void validateArgs() throws FileNotFoundException, ParseException {
}
}

/**
* Validates the format to be one of the known Formats.
*
* @param format the format to validate
* @return true, if format is known in Format; false otherwise
* @see Format
*/
private boolean isValidFormat(String format) {
try {
Format.valueOf(format);
return true;
} catch (IllegalArgumentException ex) {
return false;
}
}

/**
* Validates the path to point at an existing file.
*
* @param path the path to validate if it exists
* @param argumentName the argument being validated (e.g. scan, out, etc.)
* @return true, if path exists; false otherwise
*/
private boolean isValidFilePath(String path, String argumentName) {
try {
validatePathExists(path, argumentName);
return true;
} catch (FileNotFoundException ex) {
return false;
}
}

/**
* Validates whether or not the path(s) points at a file that exists; if the
* path(s) does not point to an existing file a FileNotFoundException is
Expand Down