1414
1515def execute (args ) -> int :
1616 # NEW: Create structured config from legacy args (strangler fig pattern)
17- from entrypoint .data_model import ScanConfig , ArtifactType
17+ from entrypoint .data_model import ScanConfig , ArtifactType , OutputConfig
1818 config = ScanConfig .from_args (args )
19+ output_config = OutputConfig .from_args (args )
1920 logging .info (f"Created config: artifact_type={ config .artifact_type .value } , artifact_path={ config .artifact_path } , sbomgen_version={ config .sbomgen_version } , timeout={ config .timeout } s" )
21+ logging .info (f"Created output_config: display_findings={ output_config .display_vulnerability_findings } , sbom_path={ output_config .output_sbom_path } " )
2022
21- # OLD: Keep existing logic unchanged for now
23+ # Use structured configs for type-safe, maintainable code
2224 logging .info (f"downloading and installing inspector-sbomgen version { config .sbomgen_version } " )
2325 ret = install_sbomgen (config .sbomgen_version )
2426 require_true ((ret == 0 ), "unable to download and install inspector-sbomgen" )
2527
2628 logging .info ("generating SBOM from artifact" )
27- ret = invoke_sbomgen (args , config )
29+ ret = invoke_sbomgen (args , config , output_config )
2830 require_true (ret == 0 , "unable to generate SBOM with inspector-sbomgen" )
2931
3032 logging .info ("scanning SBOM contents with Amazon Inspector" )
31- ret = invoke_inspector_scan (args . out_sbom , args . out_scan )
33+ ret = invoke_inspector_scan (output_config . output_sbom_path , output_config . output_inspector_scan_path )
3234 require_true (ret == 0 , "unable to scan SBOM contents with Amazon Inspector" )
33- set_github_actions_output ('inspector_scan_results' , args . out_scan )
35+ set_github_actions_output ('inspector_scan_results' , output_config . output_inspector_scan_path )
3436
3537 logging .info ("tallying vulnerabilities" )
36- succeeded , scan_result , fixed_vuln_counts = get_scan_result (args )
38+ succeeded , scan_result , fixed_vuln_counts = get_scan_result (args , config , output_config )
3739 require_true (succeeded , "unable to tally vulnerabilities" )
3840
3941 print_vuln_count_summary (scan_result )
4042
41- vuln_counts = fixed_vuln_counts if args .threshold_fixable_only else scan_result
42- set_env_var_if_vuln_threshold_exceeded (args , vuln_counts )
43+ vuln_counts = fixed_vuln_counts if output_config .threshold_fixable_only else scan_result
44+ set_env_var_if_vuln_threshold_exceeded (output_config , vuln_counts )
4345
44- write_pkg_vuln_report_csv (args . out_scan_csv , scan_result )
45- set_github_actions_output ('inspector_scan_results_csv' , args . out_scan_csv )
46+ write_pkg_vuln_report_csv (output_config . output_inspector_scan_path_csv , scan_result )
47+ set_github_actions_output ('inspector_scan_results_csv' , output_config . output_inspector_scan_path_csv )
4648
47- pkg_vuln_markdown = write_pkg_vuln_report_markdown (args . out_scan_markdown , scan_result )
48- post_pkg_vuln_github_actions_step_summary (args , pkg_vuln_markdown )
49- set_github_actions_output ('inspector_scan_results_markdown' , args . out_scan_markdown )
49+ pkg_vuln_markdown = write_pkg_vuln_report_markdown (output_config . output_inspector_scan_path_markdown , scan_result )
50+ post_pkg_vuln_github_actions_step_summary (output_config , pkg_vuln_markdown )
51+ set_github_actions_output ('inspector_scan_results_markdown' , output_config . output_inspector_scan_path_markdown )
5052
51- dockerfile .write_dockerfile_report_csv (args . out_scan , args . out_dockerfile_scan_csv )
52- set_github_actions_output ('inspector_dockerile_scan_results_csv' , args . out_dockerfile_scan_csv )
53+ dockerfile .write_dockerfile_report_csv (output_config . output_inspector_scan_path , output_config . output_dockerfile_scan_csv )
54+ set_github_actions_output ('inspector_dockerile_scan_results_csv' , output_config . output_dockerfile_scan_csv )
5355
54- dockerfile .write_dockerfile_report_md (args . out_scan , args . out_dockerfile_scan_md )
55- set_github_actions_output ('inspector_dockerile_scan_results_markdown' , args . out_dockerfile_scan_md )
56- post_dockerfile_step_summary (args , scan_result .total_vulns ())
56+ dockerfile .write_dockerfile_report_md (output_config . output_inspector_scan_path , output_config . output_dockerfile_scan_markdown )
57+ set_github_actions_output ('inspector_dockerile_scan_results_markdown' , output_config . output_dockerfile_scan_markdown )
58+ post_dockerfile_step_summary (output_config , scan_result .total_vulns ())
5759
5860 return 0
5961
6062
61- def post_dockerfile_step_summary (args , total_vulns ):
62- if args . display_vuln_findings == "enabled" and total_vulns > 0 :
63+ def post_dockerfile_step_summary (output_config , total_vulns ):
64+ if output_config . display_vulnerability_findings and total_vulns > 0 :
6365 logging .info ("posting Inspector Dockerfile scan findings to GitHub Actions step summary page" )
6466
6567 dockerfile_markdown = ""
6668 try :
67- with open (args . out_dockerfile_scan_md , "r" ) as f :
69+ with open (output_config . output_dockerfile_scan_markdown , "r" ) as f :
6870 dockerfile_markdown = f .read ()
6971 except Exception as e :
7072 logging .debug (e ) # can be spammy, so set as debug log
@@ -152,39 +154,40 @@ def get_sbomgen_arch(host_cpu):
152154 return None
153155
154156
155- def invoke_sbomgen (args , config ) -> int :
157+ def invoke_sbomgen (args , config , output_config ) -> int :
156158 sbomgen = installer .get_sbomgen_install_path ()
157159 if sbomgen == "" :
158160 logging .error ("expected path to inspector-sbomgen but received empty string" )
159161 return 1
160162
161163 # marshall arguments between action.yml and cli.py
162164 path_arg = ""
165+ sbom_artifact_type = ""
163166 if config .artifact_type == ArtifactType .REPOSITORY :
164- args . artifact_type = "directory"
167+ sbom_artifact_type = "directory"
165168 path_arg = "--path"
166169
167170 elif config .artifact_type == ArtifactType .CONTAINER :
168- args . artifact_type = "container"
171+ sbom_artifact_type = "container"
169172 path_arg = "--image"
170173
171174 elif config .artifact_type == ArtifactType .BINARY :
172- args . artifact_type = "binary"
175+ sbom_artifact_type = "binary"
173176 path_arg = "--path"
174177
175178 elif config .artifact_type == ArtifactType .ARCHIVE :
176- args . artifact_type = "archive"
179+ sbom_artifact_type = "archive"
177180 path_arg = "--path"
178181
179182 else :
180183 logging .error (
181- f"expected artifact type to be 'repository', 'container', 'binary' or 'archive' but received { args .artifact_type } " )
184+ f"expected artifact type to be 'repository', 'container', 'binary' or 'archive' but received { config .artifact_type . value } " )
182185 return 1
183186
184187 # invoke sbomgen with arguments
185- sbomgen_args = [args . artifact_type ,
188+ sbomgen_args = [sbom_artifact_type ,
186189 path_arg , config .artifact_path ,
187- "--outfile" , args . out_sbom ,
190+ "--outfile" , output_config . output_sbom_path ,
188191 "--disable-progress-bar" ,
189192 "--timeout" , str (config .timeout ),
190193 ]
@@ -223,9 +226,9 @@ def invoke_sbomgen(args, config) -> int:
223226
224227 # make scan results readable by any user so
225228 # github actions can upload the file as a job artifact
226- os .system (f"chmod 444 { args . out_sbom } " )
229+ os .system (f"chmod 444 { output_config . output_sbom_path } " )
227230
228- set_github_actions_output ('artifact_sbom' , args . out_sbom )
231+ set_github_actions_output ('artifact_sbom' , output_config . output_sbom_path )
229232
230233 return ret
231234
@@ -244,37 +247,37 @@ def invoke_inspector_scan(src_sbom, dst_scan):
244247 return ret
245248
246249
247- def get_scan_result (args ) -> tuple [bool , exporter .InspectorScanResult , fixed_vulns .FixedVulns ]:
250+ def get_scan_result (args , config , output_config ) -> tuple [bool , exporter .InspectorScanResult , fixed_vulns .FixedVulns ]:
248251 scan_result = exporter .InspectorScanResult (vulnerabilities = [pkg_vuln .Vulnerability ()])
249252 fixed_vulns_counts = fixed_vulns .FixedVulns (criticals = 0 , highs = 0 , mediums = 0 , lows = 0 , others = 0 )
250253
251254 succeeded , fixed_vulns_counts = get_fixed_vuln_counts (
252- args . out_scan )
255+ output_config . output_inspector_scan_path )
253256 if succeeded is False :
254257 return False , scan_result , fixed_vulns_counts
255258
256- succeeded , criticals , highs , mediums , lows , others = get_vuln_counts (args . out_scan )
259+ succeeded , criticals , highs , mediums , lows , others = get_vuln_counts (output_config . output_inspector_scan_path )
257260 if succeeded is False :
258261 return False , scan_result , fixed_vulns_counts
259262
260263 try :
261- with open (args . out_scan , "r" ) as f :
264+ with open (output_config . output_inspector_scan_path , "r" ) as f :
262265 inspector_scan = json .load (f )
263266 vulns = pkg_vuln .parse_inspector_scan_result (inspector_scan )
264267
265268 except Exception as e :
266269 logging .error (e )
267270 return False , scan_result , fixed_vulns_counts
268271
269- if args .show_only_fixable_vulns :
272+ if output_config .show_only_fixable_vulns :
270273 for vuln in vulns :
271274 if vuln .fixed_ver == "null" :
272275 vulns .remove (vuln )
273276
274277 scan_result = exporter .InspectorScanResult (
275278 vulnerabilities = vulns ,
276- artifact_name = args .artifact_path ,
277- artifact_type = args .artifact_type ,
279+ artifact_name = config .artifact_path ,
280+ artifact_type = config .artifact_type . value ,
278281 criticals = str (criticals ),
279282 highs = str (highs ),
280283 mediums = str (mediums ),
@@ -478,16 +481,16 @@ def write_pkg_vuln_report_markdown(out_scan_markdown, scan_result: exporter.Insp
478481 return markdown
479482
480483
481- def set_env_var_if_vuln_threshold_exceeded (args ,
484+ def set_env_var_if_vuln_threshold_exceeded (output_config ,
482485 vuln_counts : typing .Union [
483486 exporter .InspectorScanResult , fixed_vulns .FixedVulns ]):
484- is_exceeded = exceeds_threshold (vuln_counts .criticals , args . critical ,
485- vuln_counts .highs , args . high ,
486- vuln_counts .mediums , args . medium ,
487- vuln_counts .lows , args . low ,
488- vuln_counts .others , args . other )
487+ is_exceeded = exceeds_threshold (vuln_counts .criticals , output_config . critical_threshold ,
488+ vuln_counts .highs , output_config . high_threshold ,
489+ vuln_counts .mediums , output_config . medium_threshold ,
490+ vuln_counts .lows , output_config . low_threshold ,
491+ vuln_counts .others , output_config . other_threshold )
489492
490- if is_exceeded and args .thresholds :
493+ if is_exceeded and output_config .thresholds :
491494 set_github_actions_output ('vulnerability_threshold_exceeded' , 1 )
492495 else :
493496 set_github_actions_output ('vulnerability_threshold_exceeded' , 0 )
@@ -550,8 +553,8 @@ def get_summarized_findings(scan_result: exporter.InspectorScanResult):
550553 return results
551554
552555
553- def post_pkg_vuln_github_actions_step_summary (args , markdown ):
554- if args . display_vuln_findings == "enabled" :
556+ def post_pkg_vuln_github_actions_step_summary (output_config , markdown ):
557+ if output_config . display_vulnerability_findings :
555558 logging .info ("posting Inspector scan findings to GitHub Actions step summary page" )
556559 exporter .post_github_step_summary (markdown )
557560
0 commit comments