Skip to content

Commit

Permalink
Add prospector run parameters in JSON report. Add cli option to exclu…
Browse files Browse the repository at this point in the history
…de diff.
  • Loading branch information
matteogreek authored and lauraschauer committed Jul 25, 2023
1 parent ad204dd commit d76510c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 19 deletions.
35 changes: 19 additions & 16 deletions prospector/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,26 @@ def main(argv): # noqa: C901

logger.debug("Vulnerability ID: " + config.vuln_id)

results, advisory_record = prospector(
vulnerability_id=config.vuln_id,
repository_url=config.repository,
publication_date=config.pub_date,
vuln_descr=config.description,
version_interval=config.version_interval,
modified_files=config.modified_files,
advisory_keywords=config.keywords,
use_nvd=config.use_nvd,
params = {
"vulnerability_id": config.vuln_id,
"repository_url": config.repository,
"publication_date": config.pub_date,
"vuln_descr": config.description,
"version_interval": config.version_interval,
"modified_files": config.modified_files,
"advisory_keywords": config.keywords,
"use_nvd": config.use_nvd,
# fetch_references=config.fetch_references,
backend_address=config.backend,
use_backend=config.use_backend,
git_cache=config.git_cache,
limit_candidates=config.max_candidates,
"backend_address": config.backend,
"use_backend": config.use_backend,
"git_cache": config.git_cache,
"limit_candidates": config.max_candidates,
# ignore_adv_refs=config.ignore_refs,
use_llm_repository_url=config.llm_service.use_llm_repository_url,
enabled_rules=config.enabled_rules,
)
"use_llm_repository_url": config.llm_service.use_llm_repository_url,
"enabled_rules": config.enabled_rules,
}

results, advisory_record = prospector(**params)

if config.preprocess_only:
return
Expand All @@ -115,6 +117,7 @@ def main(argv): # noqa: C901
advisory_record,
config.report,
config.report_filename,
params,
config.report_diff,
)

Expand Down
25 changes: 22 additions & 3 deletions prospector/core/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ def default(self, obj):
def json_(
results: List[Commit],
advisory_record: AdvisoryRecord,
params,
filename: str = "prospector-report.json",
no_diff: bool = False,
):
fn = filename if filename.endswith(".json") else f"{filename}.json"

data = {
"parameters": params,
"advisory_record": advisory_record.__dict__,
"commits": [
r.as_dict(no_hash=True, no_rules=False, no_diff=no_diff) for r in results
Expand Down Expand Up @@ -106,18 +108,35 @@ def format_annotations(commit: Commit) -> str:


def generate_report(
results, advisory_record, report_type, report_filename, report_diff=False
results,
advisory_record,
report_type,
report_filename,
prospector_params,
report_diff=False,
):
with ConsoleWriter("Generating report\n") as console:
match report_type:
case "console":
console_(results, advisory_record, get_level() < logging.INFO)
case "json":
json_(results, advisory_record, report_filename, report_diff)
json_(
results,
advisory_record,
prospector_params,
report_filename,
report_diff,
)
case "html":
html_(results, advisory_record, report_filename)
case "all":
json_(results, advisory_record, report_filename, report_diff)
json_(
results,
advisory_record,
prospector_params,
report_filename,
report_diff,
)
html_(results, advisory_record, report_filename)
case _:
logger.warning("Invalid report type specified, using 'console'")
Expand Down
6 changes: 6 additions & 0 deletions prospector/util/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ def parse_cli_args(args):
help="Get data from NVD",
)

parser.add_argument(
"--no-diff",
action="store_true",
help="Do not include diff field in JSON report",
)

parser.add_argument(
"--fetch-references",
action="store_true",
Expand Down

0 comments on commit d76510c

Please sign in to comment.