Skip to content

Commit 8e02fc5

Browse files
authored
Doug/fix run issue (#26)
* Fixed issue where diff scan was running when there were no changed manifest files * Fixes for run time detection of changed files
1 parent dcb9b12 commit 8e02fc5

File tree

5 files changed

+47
-29
lines changed

5 files changed

+47
-29
lines changed

socketsecurity/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
__author__ = 'socket.dev'
2-
__version__ = '1.0.24'
2+
__version__ = '1.0.30'

socketsecurity/core/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,6 @@ def find_files(path: str) -> list:
410410
Globs the path for supported manifest files.
411411
Note: Might move the source to a JSON file
412412
:param path: Str - path to where the manifest files are located
413-
:param files: override finding the manifest files using the glob matcher
414413
:return:
415414
"""
416415
log.debug("Starting Find Files")
@@ -750,10 +749,11 @@ def create_issue_alerts(package: Package, alerts: dict, packages: dict) -> dict:
750749
if alert.type in security_policy:
751750
action = security_policy[alert.type]['action']
752751
setattr(issue_alert, action, True)
753-
if issue_alert.key not in alerts:
754-
alerts[issue_alert.key] = [issue_alert]
755-
else:
756-
alerts[issue_alert.key].append(issue_alert)
752+
if issue_alert.type != 'licenseSpdxDisj':
753+
if issue_alert.key not in alerts:
754+
alerts[issue_alert.key] = [issue_alert]
755+
else:
756+
alerts[issue_alert.key].append(issue_alert)
757757
return alerts
758758

759759
@staticmethod

socketsecurity/core/classes.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,15 @@ def __init__(self, **kwargs):
161161

162162
if hasattr(self, "created_at"):
163163
self.created_at = self.created_at.strip(" (Coordinated Universal Time)")
164-
if not hasattr(self, "introduced_by"):
165-
self.introduced_by = []
166164
if not hasattr(self, "manifests"):
167165
self.manifests = ""
166+
if not hasattr(self, "introduced_by"):
167+
self.introduced_by = []
168+
else:
169+
for item in self.introduced_by:
170+
pkg, manifest = item
171+
self.manifests += f"{manifest};"
172+
self.manifests = self.manifests.rstrip(";")
168173
if not hasattr(self, "error"):
169174
self.error = False
170175
if not hasattr(self, "warn"):

socketsecurity/core/github.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ def check_event_type() -> str:
116116
else:
117117
event_type = "diff"
118118
elif github_event_name.lower() == "pull_request":
119-
if event_action is not None and event_action != "" and event_action.lower() == "opened":
119+
if event_action is not None and event_action != "" and (
120+
event_action.lower() == "opened" or event_action.lower() == 'synchronize'):
120121
event_type = "diff"
121122
else:
122123
log.info(f"Pull Request Action {event_action} is not a supported type")

socketsecurity/socketcli.py

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -163,25 +163,34 @@
163163

164164

165165
def output_console_comments(diff_report: Diff, sbom_file_name: str = None) -> None:
166-
console_security_comment = Messages.create_console_security_alert_table(diff_report)
167-
save_sbom_file(diff_report, sbom_file_name)
168-
log.info(f"Socket Full Scan ID: {diff_report.id}")
169-
if not report_pass(diff_report):
170-
log.info("Security issues detected by Socket Security")
171-
msg = f"\n{console_security_comment}"
172-
log.info(msg)
173-
if not blocking_disabled:
174-
sys.exit(1)
175-
else:
176-
log.info("No New Security issues detected by Socket Security")
166+
if diff_report.id != "NO_DIFF_RAN":
167+
console_security_comment = Messages.create_console_security_alert_table(diff_report)
168+
save_sbom_file(diff_report, sbom_file_name)
169+
log.info(f"Socket Full Scan ID: {diff_report.id}")
170+
if len(diff_report.new_alerts) > 0:
171+
log.info("Security issues detected by Socket Security")
172+
msg = f"\n{console_security_comment}"
173+
log.info(msg)
174+
if not report_pass(diff_report) and not blocking_disabled:
175+
sys.exit(1)
176+
else:
177+
# Means only warning alerts with no blocked
178+
if not blocking_disabled:
179+
sys.exit(5)
180+
else:
181+
log.info("No New Security issues detected by Socket Security")
177182

178183

179184
def output_console_json(diff_report: Diff, sbom_file_name: str = None) -> None:
180-
console_security_comment = Messages.create_security_comment_json(diff_report)
181-
save_sbom_file(diff_report, sbom_file_name)
182-
print(json.dumps(console_security_comment))
183-
if not report_pass(diff_report) and not blocking_disabled:
184-
sys.exit(1)
185+
if diff_report.id != "NO_DIFF_RAN":
186+
console_security_comment = Messages.create_security_comment_json(diff_report)
187+
save_sbom_file(diff_report, sbom_file_name)
188+
print(json.dumps(console_security_comment))
189+
if not report_pass(diff_report) and not blocking_disabled:
190+
sys.exit(1)
191+
elif len(diff_report.new_alerts) > 0 and not blocking_disabled:
192+
# Means only warning alerts with no blocked
193+
sys.exit(5)
185194

186195

187196
def report_pass(diff_report: Diff) -> bool:
@@ -299,11 +308,12 @@ def main_code():
299308
default_branch = scm.is_default_branch
300309

301310
base_api_url = os.getenv("BASE_API_URL") or None
302-
core = Core(token=api_token, request_timeout=1200, base_api_url=base_api_url)
311+
core = Core(token=api_token, request_timeout=1200, base_api_url=base_api_url, allow_unverified=allow_unverified)
303312
no_change = True
304313
if ignore_commit_files:
305314
no_change = False
306315
elif is_repo and files is not None and len(files) > 0:
316+
log.info(files)
307317
no_change = core.match_supported_files(files)
308318

309319
set_as_pending_head = False
@@ -319,7 +329,8 @@ def main_code():
319329
make_default_branch=default_branch,
320330
set_as_pending_head=set_as_pending_head
321331
)
322-
diff = None
332+
diff = Diff()
333+
diff.id = "NO_DIFF_RAN"
323334
if scm is not None and scm.check_event_type() == "comment":
324335
log.info("Comment initiated flow")
325336
log.debug(f"Getting comments for Repo {scm.repository} for PR {scm.pr_number}")
@@ -329,10 +340,11 @@ def main_code():
329340
elif scm is not None and scm.check_event_type() != "comment":
330341
log.info("Push initiated flow")
331342
diff: Diff
332-
diff = core.create_new_diff(target_path, params, workspace=target_path, no_change=no_change)
333343
if no_change:
334-
log.info("No dependency changes")
344+
log.info("No manifest files changes, skipping scan")
345+
# log.info("No dependency changes")
335346
elif scm.check_event_type() == "diff":
347+
diff = core.create_new_diff(target_path, params, workspace=target_path, no_change=no_change)
336348
log.info("Starting comment logic for PR/MR event")
337349
log.debug(f"Getting comments for Repo {scm.repository} for PR {scm.pr_number}")
338350
comments = scm.get_comments_for_pr(repo, str(pr_number))

0 commit comments

Comments
 (0)