33from typing import TYPE_CHECKING , Optional , Union
44from uuid import UUID
55
6+ import requests
67from requests import Response
78
89from cycode .cli import consts
@@ -25,6 +26,7 @@ def __init__(
2526 self .scan_config = scan_config
2627
2728 self ._SCAN_SERVICE_CLI_CONTROLLER_PATH = 'api/v1/cli-scan'
29+ self ._SCAN_SERVICE_V2_CLI_CONTROLLER_PATH = 'api/v2/cli-scan'
2830 self ._DETECTIONS_SERVICE_CLI_CONTROLLER_PATH = 'api/v1/detections/cli'
2931 self ._POLICIES_SERVICE_CONTROLLER_PATH_V3 = 'api/v3/policies'
3032
@@ -56,6 +58,10 @@ def get_scan_aggregation_report_url(self, aggregation_id: str, scan_type: str) -
5658 )
5759 return models .ScanReportUrlResponseSchema ().build_dto (response .json ())
5860
61+ def get_scan_service_v2_url_path (self , scan_type : str ) -> str :
62+ service_path = self .scan_config .get_service_name (scan_type )
63+ return f'{ service_path } /{ self ._SCAN_SERVICE_V2_CLI_CONTROLLER_PATH } '
64+
5965 def get_zipped_file_scan_async_url_path (self , scan_type : str , should_use_sync_flow : bool = False ) -> str :
6066 async_scan_type = self .scan_config .get_async_scan_type (scan_type )
6167 async_entity_type = self .scan_config .get_async_entity_type (scan_type )
@@ -123,6 +129,39 @@ def zipped_file_scan_async(
123129 )
124130 return models .ScanInitializationResponseSchema ().load (response .json ())
125131
132+ def get_upload_link (self , scan_type : str ) -> models .UploadLinkResponse :
133+ async_scan_type = self .scan_config .get_async_scan_type (scan_type )
134+ url_path = f'{ self .get_scan_service_v2_url_path (scan_type )} /{ async_scan_type } /upload-link'
135+ response = self .scan_cycode_client .get (url_path = url_path , hide_response_content_log = self ._hide_response_log )
136+ return models .UploadLinkResponseSchema ().load (response .json ())
137+
138+ def upload_to_presigned_post (self , url : str , fields : dict [str , str ], zip_file : 'InMemoryZip' ) -> None :
139+ multipart = {key : (None , value ) for key , value in fields .items ()}
140+ multipart ['file' ] = (None , zip_file .read ())
141+ response = requests .post (url , files = multipart , timeout = self .scan_cycode_client .timeout )
142+ response .raise_for_status ()
143+
144+ def scan_repository_from_upload_id (
145+ self ,
146+ scan_type : str ,
147+ upload_id : str ,
148+ scan_parameters : dict ,
149+ is_git_diff : bool = False ,
150+ is_commit_range : bool = False ,
151+ ) -> models .ScanInitializationResponse :
152+ async_scan_type = self .scan_config .get_async_scan_type (scan_type )
153+ url_path = f'{ self .get_scan_service_v2_url_path (scan_type )} /{ async_scan_type } /repository'
154+ response = self .scan_cycode_client .post (
155+ url_path = url_path ,
156+ data = {
157+ 'upload_id' : upload_id ,
158+ 'is_git_diff' : is_git_diff ,
159+ 'is_commit_range' : is_commit_range ,
160+ 'scan_parameters' : json .dumps (scan_parameters ),
161+ },
162+ )
163+ return models .ScanInitializationResponseSchema ().load (response .json ())
164+
126165 def commit_range_scan_async (
127166 self ,
128167 from_commit_zip_file : InMemoryZip ,
0 commit comments