Skip to content

Commit a561074

Browse files
committed
Moved the Tier 1 reachability finalize logic to after the Full Scan instead of after the diff scan. This way if the diff scan fails for some reason the reachability status is still updated.
1 parent 2c714f2 commit a561074

File tree

4 files changed

+31
-30
lines changed

4 files changed

+31
-30
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
66

77
[project]
88
name = "socketsecurity"
9-
version = "2.2.39"
9+
version = "2.2.40"
1010
requires-python = ">= 3.10"
1111
license = {"file" = "LICENSE"}
1212
dependencies = [

socketsecurity/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
__author__ = 'socket.dev'
2-
__version__ = '2.2.39'
2+
__version__ = '2.2.40'
33
USER_AGENT = f'SocketPythonCLI/{__version__}'

socketsecurity/core/__init__.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
from glob import glob
1111
from io import BytesIO
1212
from pathlib import PurePath
13-
from typing import BinaryIO, Dict, List, Tuple, Set, Union
13+
from typing import BinaryIO, Dict, List, Tuple, Set, Union, TYPE_CHECKING, Optional
14+
15+
if TYPE_CHECKING:
16+
from socketsecurity.config import CliConfig
1417
from socketdev import socketdev
1518
from socketdev.exceptions import APIFailure
1619
from socketdev.fullscans import FullScanParams, SocketArtifact
@@ -59,11 +62,13 @@ class Core:
5962

6063
config: SocketConfig
6164
sdk: socketdev
65+
cli_config: Optional['CliConfig']
6266

63-
def __init__(self, config: SocketConfig, sdk: socketdev) -> None:
67+
def __init__(self, config: SocketConfig, sdk: socketdev, cli_config: Optional['CliConfig'] = None) -> None:
6468
"""Initialize Core with configuration and SDK instance."""
6569
self.config = config
6670
self.sdk = sdk
71+
self.cli_config = cli_config
6772
self.set_org_vars()
6873

6974
def set_org_vars(self) -> None:
@@ -507,7 +512,7 @@ def finalize_tier1_scan(self, full_scan_id: str, facts_file_path: str) -> bool:
507512
log.debug(f"Unable to finalize tier 1 scan: {e}")
508513
return False
509514

510-
def create_full_scan(self, files: List[str], params: FullScanParams, base_paths: List[str] = None) -> FullScan:
515+
def create_full_scan(self, files: List[str], params: FullScanParams, base_paths: Optional[List[str]] = None) -> FullScan:
511516
"""
512517
Creates a new full scan via the Socket API.
513518
@@ -532,16 +537,29 @@ def create_full_scan(self, files: List[str], params: FullScanParams, base_paths:
532537
total_time = create_full_end - create_full_start
533538
log.debug(f"New Full Scan created in {total_time:.2f} seconds")
534539

540+
# Finalize tier1 scan if reachability analysis was enabled
541+
if self.cli_config and self.cli_config.reach:
542+
facts_file_path = self.cli_config.reach_output_file or ".socket.facts.json"
543+
log.debug(f"Reachability analysis enabled, finalizing tier1 scan for full scan {full_scan.id}")
544+
try:
545+
success = self.finalize_tier1_scan(full_scan.id, facts_file_path)
546+
if success:
547+
log.debug(f"Successfully finalized tier1 scan for full scan {full_scan.id}")
548+
else:
549+
log.debug(f"Failed to finalize tier1 scan for full scan {full_scan.id}")
550+
except Exception as e:
551+
log.warning(f"Error finalizing tier1 scan for full scan {full_scan.id}: {e}")
552+
535553
return full_scan
536554

537555
def create_full_scan_with_report_url(
538556
self,
539557
paths: List[str],
540558
params: FullScanParams,
541559
no_change: bool = False,
542-
save_files_list_path: str = None,
543-
save_manifest_tar_path: str = None,
544-
base_paths: List[str] = None
560+
save_files_list_path: Optional[str] = None,
561+
save_manifest_tar_path: Optional[str] = None,
562+
base_paths: Optional[List[str]] = None
545563
) -> Diff:
546564
"""Create a new full scan and return with html_report_url.
547565
@@ -935,9 +953,9 @@ def create_new_diff(
935953
paths: List[str],
936954
params: FullScanParams,
937955
no_change: bool = False,
938-
save_files_list_path: str = None,
939-
save_manifest_tar_path: str = None,
940-
base_paths: List[str] = None
956+
save_files_list_path: Optional[str] = None,
957+
save_manifest_tar_path: Optional[str] = None,
958+
base_paths: Optional[List[str]] = None
941959
) -> Diff:
942960
"""Create a new diff using the Socket SDK.
943961
@@ -1184,6 +1202,7 @@ def create_purl(self, package_id: str, packages: dict[str, Package]) -> Purl:
11841202
)
11851203
return purl
11861204

1205+
11871206
@staticmethod
11881207
def get_source_data(package: Package, packages: dict) -> list:
11891208
"""

socketsecurity/socketcli.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def main_code():
8282
client = CliClient(socket_config)
8383
sdk.api.api_url = socket_config.api_url
8484
log.debug("loaded client")
85-
core = Core(socket_config, sdk)
85+
core = Core(socket_config, sdk, config)
8686
log.debug("loaded core")
8787

8888
# Check for required dependencies if reachability analysis is enabled
@@ -565,24 +565,6 @@ def main_code():
565565
)
566566
output_handler.handle_output(diff)
567567

568-
# Finalize tier 1 scan if reachability analysis was enabled
569-
if config.reach and diff.id not in ("NO_DIFF_RAN", "NO_SCAN_RAN"):
570-
facts_file_path = config.reach_output_file or ".socket.facts.json"
571-
# Use absolute path based on target directory
572-
if not os.path.isabs(facts_file_path):
573-
facts_file_path = os.path.join(config.target_path, facts_file_path)
574-
575-
log.info("Finalizing tier 1 reachability scan...")
576-
warning_message = "Failed to finalize tier 1 scan: The scan has still been created, but the Socket team may not have the assoicated analytics required to debug potential issues."
577-
try:
578-
finalize_result = core.finalize_tier1_scan(diff.id, facts_file_path)
579-
if finalize_result:
580-
log.debug("Tier 1 scan finalized successfully")
581-
else:
582-
log.warning(warning_message)
583-
except Exception as e:
584-
log.warning(f"{warning_message} {e}")
585-
586568
# Handle license generation
587569
if not should_skip_scan and diff.id != "NO_DIFF_RAN" and diff.id != "NO_SCAN_RAN" and config.generate_license:
588570
all_packages = {}

0 commit comments

Comments
 (0)