@@ -62,16 +62,21 @@ def get_project_info(self, download_url):
6262 return scan_info .get ("results" )[0 ]
6363
6464 def submit_scan (self , uri , user_uuid , dataspace_uuid ):
65+ """
66+ Submit package scan request to ScanCode.io.
67+ An unique ID for the user is set as a project label, available for filtering.
68+ """
69+ webhook_url = get_webhook_url ("notifications:send_scan_notification" , user_uuid )
70+
6571 data = {
66- "name" : get_project_name (uri , user_uuid , dataspace_uuid ),
72+ "name" : get_project_name (uri , dataspace_uuid ),
6773 "input_urls" : uri ,
6874 "pipeline" : "scan_single_package" ,
6975 "execute_now" : True ,
76+ "webhook_url" : webhook_url ,
77+ "labels" : [get_hash_uid (user_uuid )],
7078 }
7179
72- webhook_url = get_webhook_url ("notifications:send_scan_notification" , user_uuid )
73- data ["webhook_url" ] = webhook_url
74-
7580 logger .debug (f'{ self .label } : submit scan uri="{ uri } " webhook_url="{ webhook_url } "' )
7681 return self .request_post (url = self .project_api_url , json = data )
7782
@@ -102,14 +107,11 @@ def start_pipeline(self, run_url):
102107 start_pipeline_url = run_url + "start_pipeline/"
103108 return self .request_post (url = start_pipeline_url )
104109
105- def fetch_scan_list (self , user = None , dataspace = None , ** extra_payload ):
106- payload = {}
107-
108- if dataspace :
109- payload ["name__contains" ] = get_hash_uid (dataspace .uuid )
110+ def fetch_scan_list (self , user = None , ** extra_payload ):
111+ payload = {"name__contains" : get_hash_uid (self .dataspace .uuid )}
110112
111113 if user :
112- payload ["name__endswith " ] = get_hash_uid (user .uuid )
114+ payload ["label " ] = get_hash_uid (user .uuid )
113115
114116 payload .update (extra_payload )
115117 if not payload :
@@ -131,15 +133,11 @@ def find_project(self, **kwargs):
131133 if response .get ("count" ) == 1 :
132134 return response .get ("results" )[0 ]
133135
134- def fetch_scan_info (self , uri , user = None ):
136+ def fetch_scan_info (self , uri ):
135137 payload = {
136138 "name__startswith" : get_hash_uid (uri ),
137139 "name__contains" : get_hash_uid (self .dataspace .uuid ),
138140 }
139-
140- if user :
141- payload ["name__endswith" ] = get_hash_uid (user .uuid )
142-
143141 logger .debug (f'{ self .label } : fetch scan info uri="{ uri } "' )
144142 return self .request_get (url = self .project_api_url , params = payload )
145143
@@ -491,18 +489,16 @@ def get_hash_uid(value):
491489 return md5 (str (value ).encode ("utf-8" ), usedforsecurity = False ).hexdigest ()[:10 ]
492490
493491
494- def get_project_name (uri , user_uuid , dataspace_uuid ):
492+ def get_project_name (uri , dataspace_uuid ):
495493 """
496494 Return a project name based on a hash of the provided `uri` combined with a hash
497- of the `user_uuid` and ` dataspace_uuid`.
495+ of the `dataspace_uuid`.
498496
499- project_name = "uri_hash.dataspace_uuid_hash.user_uuid_hash "
497+ project_name = "uri_hash.dataspace_uuid_hash"
500498 """
501499 uri_hash = get_hash_uid (uri )
502500 dataspace_hash = get_hash_uid (dataspace_uuid )
503- user_hash = get_hash_uid (user_uuid )
504-
505- return f"{ uri_hash } .{ dataspace_hash } .{ user_hash } "
501+ return f"{ uri_hash } .{ dataspace_hash } "
506502
507503
508504def get_webhook_url (view_name , user_uuid ):
0 commit comments