Skip to content

Commit

Permalink
guess tool orientation from only one label
Browse files Browse the repository at this point in the history
Signed-off-by: Will Murphy <[email protected]>
  • Loading branch information
willmurphyscode committed Sep 17, 2024
1 parent e327852 commit 5f5925d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
13 changes: 12 additions & 1 deletion src/yardstick/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,18 @@ def one(
if request.profile:
profile_obj = profiles.get(scan_config.tool_name, {}).get(request.profile, {})
if not profile_obj:
raise RuntimeError(f"no profile found for tool {scan_config.tool_name}")
profile_obj = profiles.get(scan_config.tool_name.replace("-", "_"), {}).get(
request.profile, {}
)

if not profile_obj:
profile_obj = profiles.get(scan_config.tool_name.replace("_", "-"), {}).get(
request.profile, {}
)
if not profile_obj:
raise RuntimeError(
f"no profile found for tool {scan_config.tool_name} profile {request.profile}, have {profiles}"
)

match_results, raw_json = run_scan(config=scan_config, profile=profile_obj)
store.scan_result.save(
Expand Down
19 changes: 11 additions & 8 deletions src/yardstick/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,23 +378,26 @@ def validate_image(
show_summaries=True,
)

reference_tool, candidate_tool = None, None
for r in results:
if r.config.tool_label == gate_config.reference_tool_label:
reference_tool = r.config.tool
if r.config.tool_label == gate_config.candidate_tool_label:
candidate_tool = r.config.tool
if len(results) != 2:
raise RuntimeError(f"expected 2 results but found {len(results)}")

if reference_tool is None or candidate_tool is None:
reference_tool, candidate_tool = None, None
if not gate_config.candidate_tool_label:
reference_tool, candidate_tool = guess_tool_orientation(
[r.config.tool for r in results]
[r.config.tool for r in results],
)
logging.warning(
f"guessed tool orientation reference:{reference_tool} candidate:{candidate_tool}"
)
logging.warning(
"to avoid guessing, specify reference_tool_label and candidate_tool_label in validation config and re-capture result set"
)
if results[0].config.tool_label == gate_config.candidate_tool_label:
candidate_tool = results[0].config.tool
reference_tool = results[1].config.tool
elif results[1].config.tool_label == gate_config.candidate_tool_label:
candidate_tool = results[1].config.tool
reference_tool = results[0].config.tool

# keep a list of differences between tools to summarize
deltas = []
Expand Down

0 comments on commit 5f5925d

Please sign in to comment.