Skip to content

Commit 9743f96

Browse files
committed
fixed SARIF regression
1 parent 44020e6 commit 9743f96

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

socketsecurity/config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ def create_argument_parser() -> argparse.ArgumentParser:
217217
config_group.add_argument(
218218
"--default_branch",
219219
dest="default_branch",
220+
action="store_true",
220221
help=argparse.SUPPRESS
221222
)
222223
config_group.add_argument(
@@ -228,6 +229,7 @@ def create_argument_parser() -> argparse.ArgumentParser:
228229
config_group.add_argument(
229230
"--pending_head",
230231
dest="pending_head",
232+
action="store_true",
231233
help=argparse.SUPPRESS
232234
)
233235

@@ -242,6 +244,7 @@ def create_argument_parser() -> argparse.ArgumentParser:
242244
output_group.add_argument(
243245
"--generate_license",
244246
dest="generate_license",
247+
action="store_true",
245248
help=argparse.SUPPRESS
246249
)
247250
output_group.add_argument(
@@ -253,6 +256,7 @@ def create_argument_parser() -> argparse.ArgumentParser:
253256
output_group.add_argument(
254257
"--enable_debug",
255258
dest="enable_debug",
259+
action="store_true",
256260
help=argparse.SUPPRESS
257261
)
258262
output_group.add_argument(
@@ -276,6 +280,7 @@ def create_argument_parser() -> argparse.ArgumentParser:
276280
output_group.add_argument(
277281
"--disable_overview",
278282
dest="disable_overview",
283+
action="store_true",
279284
help=argparse.SUPPRESS
280285
)
281286

@@ -295,6 +300,7 @@ def create_argument_parser() -> argparse.ArgumentParser:
295300
security_group.add_argument(
296301
"--disable_security_issue",
297302
dest="disable_security_issue",
303+
action="store_true",
298304
help=argparse.SUPPRESS
299305
)
300306

@@ -309,6 +315,7 @@ def create_argument_parser() -> argparse.ArgumentParser:
309315
advanced_group.add_argument(
310316
"--ignore_commit_files",
311317
dest="ignore_commit_files",
318+
action="store_true",
312319
help=argparse.SUPPRESS
313320
)
314321
advanced_group.add_argument(
@@ -320,6 +327,7 @@ def create_argument_parser() -> argparse.ArgumentParser:
320327
advanced_group.add_argument(
321328
"--disable_blocking",
322329
dest="disable_blocking",
330+
action="store_true",
323331
help=argparse.SUPPRESS
324332
)
325333
advanced_group.add_argument(

socketsecurity/core/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,15 +427,15 @@ def create_new_diff(
427427
428428
no_change: If True, return empty diff
429429
"""
430-
print(f"starting create_new_diff with no_change: {no_change}")
430+
log.debug(f"starting create_new_diff with no_change: {no_change}")
431431
if no_change:
432432
return Diff(id="no_diff_id")
433433

434434
# Find manifest files
435435
files = self.find_files(path)
436436
files_for_sending = self.load_files_for_sending(files, path)
437437

438-
print(f"files: {files} found at path {path}")
438+
log.debug(f"files: {files} found at path {path}")
439439
if not files:
440440
return Diff(id="no_diff_id")
441441

socketsecurity/core/messages.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@ def create_security_comment_sarif(diff) -> dict:
192192
Create SARIF-compliant output from the diff report, including dynamic URL generation
193193
based on manifest type and improved <br/> formatting for GitHub SARIF display.
194194
"""
195+
scan_failed = False
196+
if len(diff.new_alerts) == 0:
197+
for alert in diff.new_alerts:
198+
alert: Issue
199+
if alert.error:
200+
scan_failed = True
201+
break
195202
sarif_data = {
196203
"$schema": "https://json.schemastore.org/sarif-2.1.0.json",
197204
"version": "2.1.0",

socketsecurity/output.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ def handle_output(self, diff_report: Diff) -> None:
2828
self.save_sbom_file(diff_report, self.config.sbom_file)
2929

3030
def return_exit_code(self, diff_report: Diff) -> int:
31-
if not self.report_pass(diff_report) and not self.config.disable_blocking:
31+
if self.config.disable_blocking:
32+
return 0
33+
34+
if not self.report_pass(diff_report):
3235
return 1
33-
elif len(diff_report.new_alerts) > 0 and not self.config.disable_blocking:
36+
37+
if len(diff_report.new_alerts) > 0:
3438
# 5 means warning alerts but no blocking alerts
3539
return 5
36-
else:
37-
return 0
40+
return 0
3841

3942
def output_console_comments(self, diff_report: Diff, sbom_file_name: Optional[str] = None) -> None:
4043
"""Outputs formatted console comments"""
@@ -49,6 +52,7 @@ def output_console_comments(self, diff_report: Diff, sbom_file_name: Optional[st
4952
def output_console_json(self, diff_report: Diff, sbom_file_name: Optional[str] = None) -> None:
5053
"""Outputs JSON formatted results"""
5154
console_security_comment = Messages.create_security_comment_json(diff_report)
55+
self.save_sbom_file(diff_report, sbom_file_name)
5256
self.logger.info(json.dumps(console_security_comment))
5357

5458
def output_console_sarif(self, diff_report: Diff, sbom_file_name: Optional[str] = None) -> None:
@@ -58,9 +62,9 @@ def output_console_sarif(self, diff_report: Diff, sbom_file_name: Optional[str]
5862
if diff_report.id != "NO_DIFF_RAN":
5963
# Generate the SARIF structure using Messages
6064
console_security_comment = Messages.create_security_comment_sarif(diff_report)
61-
65+
self.save_sbom_file(diff_report, sbom_file_name)
6266
# Print the SARIF output to the console in JSON format
63-
self.logger.info(json.dumps(console_security_comment, indent=2))
67+
print(json.dumps(console_security_comment, indent=2))
6468

6569
def report_pass(self, diff_report: Diff) -> bool:
6670
"""Determines if the report passes security checks"""

socketsecurity/socketcli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def main_code():
135135
should_skip_scan = False # Force scan if ignoring commit files
136136
elif files_to_check: # If we have any files to check
137137
should_skip_scan = not core.has_manifest_files(list(files_to_check))
138-
print(f"in elif, should_skip_scan: {should_skip_scan}")
138+
log.debug(f"in elif, should_skip_scan: {should_skip_scan}")
139139

140140
if should_skip_scan:
141141
log.debug("No manifest files found in changes, skipping scan")

0 commit comments

Comments
 (0)