@@ -24,8 +24,8 @@ class A1000(object):
24
24
25
25
__TOKEN_ENDPOINT = "/api-token-auth/"
26
26
__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}"
29
29
__RESULTS_ENDPOINT = "/api/samples/list/"
30
30
__SUMMARY_REPORT_ENDPOINT_V2 = "/api/samples/v2/list/"
31
31
__DETAILED_REPORT_ENDPOINT_V2 = "/api/samples/v2/list/details/"
@@ -161,8 +161,9 @@ def test_connection(self):
161
161
"""Creates a request towards the A1000 Check Status API to test the connection
162
162
with A1000.
163
163
"""
164
- _ = self .__analysis_is_finished (
165
- sample_hashes = ["0000000000000000000000000000000000000000" ]
164
+ self .file_analysis_status (
165
+ sample_hashes = ["0000000000000000000000000000000000000000" ],
166
+ sample_status = "processed"
166
167
)
167
168
168
169
return
@@ -295,6 +296,35 @@ def upload_sample_from_url(self, file_url, crawler=None, archive_password=None,
295
296
296
297
return response
297
298
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
+
298
328
def check_submitted_url_status (self , task_id ):
299
329
"""Accepts a task ID returned by the upload sample from url
300
330
:param task_id: ID of the submitted sample
@@ -305,7 +335,7 @@ def check_submitted_url_status(self, task_id):
305
335
if not isinstance (task_id , str ):
306
336
raise WrongInputError ("task_id parameter must be a string." )
307
337
308
- endpoint = self .__CHECK_URL_STATUS_ENDPOINT .format (task_id = task_id )
338
+ endpoint = self .__URL_ANALYSIS_STATUS_ENDPOINT .format (task_id = task_id )
309
339
310
340
url = self ._url .format (endpoint = endpoint )
311
341
@@ -426,8 +456,11 @@ def get_summary_report_v2(self, sample_hashes, retry=True, fields=None, include_
426
456
if iteration :
427
457
time .sleep (self ._wait_time_seconds )
428
458
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
+
431
464
break
432
465
433
466
if not analysis_is_finished :
@@ -564,8 +597,11 @@ def get_detailed_report_v2(self, sample_hashes, retry=False, fields=None, skip_r
564
597
if iteration :
565
598
time .sleep (self ._wait_time_seconds )
566
599
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
+
569
605
break
570
606
571
607
if not analysis_is_finished :
@@ -2218,31 +2254,6 @@ def __create_post_payload(custom_filename=None, file_url=None, crawler=None, ar
2218
2254
2219
2255
return data
2220
2256
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
-
2246
2257
def __get_request (self , url , params = None ):
2247
2258
"""A generic GET request method for all A1000 methods.
2248
2259
:param url: request URL
0 commit comments