@@ -24,8 +24,8 @@ class A1000(object):
2424
2525 __TOKEN_ENDPOINT = "/api-token-auth/"
2626 __UPLOAD_ENDPOINT = "/api/uploads/"
27- __CHECK_STATUS_ENDPOINT = "/api/samples/status/"
28- __CHECK_URL_STATUS_ENDPOINT = "/api/uploads/v2/url-samples/{task_id}"
27+ __FILE_ANALYSIS_STATUS_ENDPOINT = "/api/samples/status/"
28+ __URL_ANALYSIS_STATUS_ENDPOINT = "/api/uploads/v2/url-samples/{task_id}"
2929 __RESULTS_ENDPOINT = "/api/samples/list/"
3030 __SUMMARY_REPORT_ENDPOINT_V2 = "/api/samples/v2/list/"
3131 __DETAILED_REPORT_ENDPOINT_V2 = "/api/samples/v2/list/details/"
@@ -161,8 +161,9 @@ def test_connection(self):
161161 """Creates a request towards the A1000 Check Status API to test the connection
162162 with A1000.
163163 """
164- _ = self .__analysis_is_finished (
165- sample_hashes = ["0000000000000000000000000000000000000000" ]
164+ self .file_analysis_status (
165+ sample_hashes = ["0000000000000000000000000000000000000000" ],
166+ sample_status = "processed"
166167 )
167168
168169 return
@@ -295,6 +296,35 @@ def upload_sample_from_url(self, file_url, crawler=None, archive_password=None,
295296
296297 return response
297298
299+ def file_analysis_status (self , sample_hashes , sample_status = None ):
300+ """Accepts a list of file hashes and returns their analysis completion information.
301+ :param sample_hashes: list of hash strings
302+ :type sample_hashes: list[str]
303+ :param sample_status: return only samples with this classification;
304+ supported values are 'processed' and 'not_found'
305+ :type sample_status: str
306+ :return: :class:`Response <Response>` object
307+ :rtype: requests.Response
308+ """
309+ data = {"hash_values" : sample_hashes }
310+
311+ params = {}
312+
313+ if sample_status :
314+ params ["status" ] = sample_status
315+
316+ url = self ._url .format (endpoint = self .__FILE_ANALYSIS_STATUS_ENDPOINT )
317+
318+ response = self .__post_request (
319+ url = url ,
320+ data = data ,
321+ params = params
322+ )
323+
324+ self .__raise_on_error (response )
325+
326+ return response
327+
298328 def check_submitted_url_status (self , task_id ):
299329 """Accepts a task ID returned by the upload sample from url
300330 :param task_id: ID of the submitted sample
@@ -305,7 +335,7 @@ def check_submitted_url_status(self, task_id):
305335 if not isinstance (task_id , str ):
306336 raise WrongInputError ("task_id parameter must be a string." )
307337
308- endpoint = self .__CHECK_URL_STATUS_ENDPOINT .format (task_id = task_id )
338+ endpoint = self .__URL_ANALYSIS_STATUS_ENDPOINT .format (task_id = task_id )
309339
310340 url = self ._url .format (endpoint = endpoint )
311341
@@ -426,8 +456,11 @@ def get_summary_report_v2(self, sample_hashes, retry=True, fields=None, include_
426456 if iteration :
427457 time .sleep (self ._wait_time_seconds )
428458
429- analysis_is_finished = self .__analysis_is_finished (sample_hashes )
430- if analysis_is_finished :
459+ analysis_status = self .file_analysis_status (sample_hashes = sample_hashes , sample_status = "processed" )
460+
461+ if len (analysis_status .json ().get ("results" )) == len (sample_hashes ):
462+ analysis_is_finished = True
463+
431464 break
432465
433466 if not analysis_is_finished :
@@ -564,8 +597,11 @@ def get_detailed_report_v2(self, sample_hashes, retry=False, fields=None, skip_r
564597 if iteration :
565598 time .sleep (self ._wait_time_seconds )
566599
567- analysis_is_finished = self .__analysis_is_finished (sample_hashes )
568- if analysis_is_finished :
600+ analysis_status = self .file_analysis_status (sample_hashes = sample_hashes , sample_status = "processed" )
601+
602+ if len (analysis_status .json ().get ("results" )) == len (sample_hashes ):
603+ analysis_is_finished = True
604+
569605 break
570606
571607 if not analysis_is_finished :
@@ -2218,31 +2254,6 @@ def __create_post_payload(custom_filename=None, file_url=None, crawler=None, ar
22182254
22192255 return data
22202256
2221- def __analysis_is_finished (self , sample_hashes ):
2222- """Accepts a list of hashes and returns boolean.
2223- :param sample_hashes: list of hash strings
2224- :type sample_hashes: list[str]
2225- :return: boolean for processing status.
2226- :rtype: bool
2227- """
2228- data = {"hash_values" : sample_hashes }
2229- params = {"status" : "processed" }
2230-
2231- url = self ._url .format (endpoint = self .__CHECK_STATUS_ENDPOINT )
2232-
2233- response = self .__post_request (
2234- url = url ,
2235- data = data ,
2236- params = params
2237- )
2238-
2239- self .__raise_on_error (response )
2240-
2241- if len (response .json ().get ("results" )) == len (sample_hashes ):
2242- return True
2243-
2244- return False
2245-
22462257 def __get_request (self , url , params = None ):
22472258 """A generic GET request method for all A1000 methods.
22482259 :param url: request URL
0 commit comments