1010from glob import glob
1111from io import BytesIO
1212from 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
1417from socketdev import socketdev
1518from socketdev .exceptions import APIFailure
1619from 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 """
0 commit comments