Skip to content

Commit 742e501

Browse files
refactor: replace get_scan_result tuple return with structured VulnScanOutput
- Change get_scan_result() to return VulnScanOutput instead of complex tuple - Consolidate vulnerability counts into structured output object - Add specific error messages for different failure scenarios - Include total vulnerability count and breakdown by severity - Add test to verify VulnScanOutput return type
1 parent 250d20c commit 742e501

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

entrypoint/entrypoint/orchestrator.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,18 +272,24 @@ def invoke_inspector_scan(src_sbom, dst_scan):
272272
)
273273

274274

275-
def get_scan_result(args, config, output_config) -> tuple[bool, exporter.InspectorScanResult, fixed_vulns.FixedVulns]:
275+
def get_scan_result(args, config, output_config):
276276
scan_result = exporter.InspectorScanResult(vulnerabilities=[pkg_vuln.Vulnerability()])
277277
fixed_vulns_counts = fixed_vulns.FixedVulns(criticals=0, highs=0, mediums=0, lows=0, others=0)
278278

279279
succeeded, fixed_vulns_counts = get_fixed_vuln_counts(
280280
output_config.output_inspector_scan_path)
281281
if succeeded is False:
282-
return False, scan_result, fixed_vulns_counts
282+
return VulnScanOutput(
283+
scan_success=False,
284+
error_message="unable to get fixed vulnerability counts"
285+
)
283286

284287
succeeded, criticals, highs, mediums, lows, others = get_vuln_counts(output_config.output_inspector_scan_path)
285288
if succeeded is False:
286-
return False, scan_result, fixed_vulns_counts
289+
return VulnScanOutput(
290+
scan_success=False,
291+
error_message="unable to get vulnerability counts"
292+
)
287293

288294
try:
289295
with open(output_config.output_inspector_scan_path, "r") as f:
@@ -292,7 +298,10 @@ def get_scan_result(args, config, output_config) -> tuple[bool, exporter.Inspect
292298

293299
except Exception as e:
294300
logging.error(e)
295-
return False, scan_result, fixed_vulns_counts
301+
return VulnScanOutput(
302+
scan_success=False,
303+
error_message=f"unable to parse scan results: {str(e)}"
304+
)
296305

297306
if output_config.show_only_fixable_vulns:
298307
for vuln in vulns:
@@ -310,7 +319,16 @@ def get_scan_result(args, config, output_config) -> tuple[bool, exporter.Inspect
310319
others=str(others)
311320
)
312321

313-
return succeeded, scan_result, fixed_vulns_counts
322+
return VulnScanOutput(
323+
scan_success=True,
324+
scan_results_file_path=output_config.output_inspector_scan_path,
325+
total_vulnerabilities=len(vulns),
326+
critical_count=criticals,
327+
high_count=highs,
328+
medium_count=mediums,
329+
low_count=lows,
330+
other_count=others
331+
)
314332

315333

316334
def set_github_actions_output(key, value):

entrypoint/tests/test_orchestrator.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,23 @@ def test_invoke_inspector_scan_returns_vuln_scan_output_type(self):
375375
self.assertIsInstance(result, VulnScanOutput)
376376
self.assertFalse(result.scan_success) # Should fail with return code 1
377377

378+
def test_get_scan_result_returns_vuln_scan_output_type(self):
379+
"""Verify get_scan_result returns VulnScanOutput instead of tuple"""
380+
from unittest.mock import patch, MagicMock
381+
from entrypoint.data_model import ScanConfig, OutputConfig, ArtifactType, VulnScanOutput
382+
383+
# Create test configs
384+
config = ScanConfig(artifact_type=ArtifactType.REPOSITORY, artifact_path="./test")
385+
output_config = OutputConfig(output_inspector_scan_path="/tmp/test_scan.json")
386+
387+
# Mock file operations to avoid needing real files
388+
with patch('entrypoint.orchestrator.get_fixed_vuln_counts', return_value=(False, None)), \
389+
patch('entrypoint.orchestrator.get_vuln_counts', return_value=(False, 0, 0, 0, 0, 0)):
390+
391+
result = orchestrator.get_scan_result(None, config, output_config)
392+
self.assertIsInstance(result, VulnScanOutput)
393+
self.assertFalse(result.scan_success) # Should fail when get_fixed_vuln_counts fails
394+
378395

379396
if __name__ == "__main__":
380397
unittest.main()

0 commit comments

Comments
 (0)