@@ -848,18 +848,18 @@ def list_extracted_files_v2(self, sample_hash, page_size=None, page=None):
848
848
849
849
return response
850
850
851
- def list_extracted_files_v2_aggregated (self , sample_hash , max_results = 5000 ):
851
+ def list_extracted_files_v2_aggregated (self , sample_hash , max_results = None ):
852
852
"""Get a list of all files TitaniumCore engine extracted from the requested sample during static analysis.
853
853
Paging is done automatically and results from individual responses aggregated into one list and returned.
854
854
The max_results parameter defines the maximum number of results to be returned to the list.
855
855
:param sample_hash: hash string
856
856
:type sample_hash: str
857
- :param max_results: maximum number of results to be returned
858
- :type max_results: int
857
+ :param max_results: number of results to be returned in the list;
858
+ set as integer to receive a defined number of results or leave as None to receive all available results
859
+ :type max_results: int or None
859
860
:return: list of results
860
861
:rtype: list
861
862
"""
862
- pass
863
863
result_list = []
864
864
next_page = 1
865
865
@@ -875,14 +875,16 @@ def list_extracted_files_v2_aggregated(self, sample_hash, max_results=5000):
875
875
results = response_json .get ("results" , [])
876
876
result_list .extend (results )
877
877
878
- if len (result_list ) > max_results :
879
- results = result_list [:max_results ]
880
- return results
881
-
882
878
next_page_url = response_json .get ("next" , None )
883
879
next_page = int (next_page_url .split ("?" )[1 ].split ("&" )[0 ].split ("=" )[1 ]) if next_page_url else None
884
880
885
- return result_list
881
+ if not max_results :
882
+ if not next_page :
883
+ return result_list
884
+
885
+ else :
886
+ if not next_page or len (result_list ) >= max_results :
887
+ return result_list [:max_results ]
886
888
887
889
def download_extracted_files (self , sample_hash ):
888
890
"""Accepts a single hash string and returns a downloadable archive file
@@ -1726,7 +1728,7 @@ def advanced_search_v2(self, query_string, ticloud=False, page_number=1, records
1726
1728
1727
1729
return response
1728
1730
1729
- def advanced_search_v2_aggregated (self , query_string , ticloud = False , max_results = 5000 , sorting_criteria = None ,
1731
+ def advanced_search_v2_aggregated (self , query_string , ticloud = False , max_results = None , sorting_criteria = None ,
1730
1732
sorting_order = "desc" ):
1731
1733
"""THIS METHOD IS DEPRECATED. Use advanced_search_v3_aggregated instead.
1732
1734
@@ -1744,8 +1746,9 @@ def advanced_search_v2_aggregated(self, query_string, ticloud=False, max_results
1744
1746
:type query_string: str
1745
1747
:param ticloud: show only cloud results
1746
1748
:type ticloud: bool
1747
- :param max_results: maximum results to be returned in a list; default value is 5000
1748
- :type max_results: int
1749
+ :param max_results: number of results to be returned in the list;
1750
+ set as integer to receive a defined number of results or leave as None to receive all available results
1751
+ :type max_results: int or None
1749
1752
:param sorting_criteria: define the criteria used in sorting; possible values are 'sha1', 'firstseen',
1750
1753
'threatname', 'sampletype', 'filecount', 'size'
1751
1754
:type sorting_criteria: str
@@ -1756,9 +1759,6 @@ def advanced_search_v2_aggregated(self, query_string, ticloud=False, max_results
1756
1759
"""
1757
1760
warn ("This method is deprecated. Use advanced_search_v3_aggregated instead." , DeprecationWarning )
1758
1761
1759
- if not isinstance (max_results , int ):
1760
- raise WrongInputError ("max_results parameter must be integer." )
1761
-
1762
1762
results = []
1763
1763
next_page = 1
1764
1764
more_pages = True
@@ -1778,14 +1778,16 @@ def advanced_search_v2_aggregated(self, query_string, ticloud=False, max_results
1778
1778
entries = response_json .get ("rl" ).get ("web_search_api" ).get ("entries" , [])
1779
1779
results .extend (entries )
1780
1780
1781
- if len (results ) > max_results :
1782
- results = results [:max_results ]
1783
- return results
1784
-
1785
1781
next_page = response_json .get ("rl" ).get ("web_search_api" ).get ("next_page" , None )
1786
1782
more_pages = response_json .get ("rl" ).get ("web_search_api" ).get ("more_pages" , False )
1787
1783
1788
- return results
1784
+ if not max_results :
1785
+ if not more_pages :
1786
+ return results
1787
+
1788
+ else :
1789
+ if not more_pages or len (results ) >= max_results :
1790
+ return results [:max_results ]
1789
1791
1790
1792
def advanced_search_v3 (self , query_string , ticloud = False , start_search_date = None , end_search_date = None ,
1791
1793
page_number = 1 , records_per_page = 20 , sorting_criteria = None , sorting_order = "desc" ):
@@ -1862,7 +1864,7 @@ def advanced_search_v3(self, query_string, ticloud=False, start_search_date=None
1862
1864
return response
1863
1865
1864
1866
def advanced_search_v3_aggregated (self , query_string , ticloud = False , start_search_date = None , end_search_date = None ,
1865
- records_per_page = 20 , max_results = 5000 , sorting_criteria = None ,
1867
+ records_per_page = 20 , max_results = None , sorting_criteria = None ,
1866
1868
sorting_order = "desc" ):
1867
1869
"""This method handles the paging automatically.
1868
1870
Sends a query string to the A1000 Advanced Search API v3.
@@ -1885,8 +1887,9 @@ def advanced_search_v3_aggregated(self, query_string, ticloud=False, start_searc
1885
1887
:type end_search_date: str
1886
1888
:param records_per_page: number of records returned per page; maximum value is 100
1887
1889
:type records_per_page: int
1888
- :param max_results: maximum number of returned results
1889
- :type max_results: int
1890
+ :param max_results: number of results to be returned in the list;
1891
+ set as integer to receive a defined number of results or leave as None to receive all available results
1892
+ :type max_results: int or None
1890
1893
:param sorting_criteria: define the criteria used in sorting; possible values are 'sha1', 'firstseen',
1891
1894
'threatname', 'sampletype', 'filecount', 'size'
1892
1895
:type sorting_criteria: str
@@ -1895,9 +1898,6 @@ def advanced_search_v3_aggregated(self, query_string, ticloud=False, start_searc
1895
1898
:return: list of results
1896
1899
:rtype: list
1897
1900
"""
1898
- if not isinstance (max_results , int ):
1899
- raise WrongInputError ("max_results parameter must be integer." )
1900
-
1901
1901
results = []
1902
1902
next_page = 1
1903
1903
more_pages = True
@@ -1922,10 +1922,13 @@ def advanced_search_v3_aggregated(self, query_string, ticloud=False, start_searc
1922
1922
next_page = response_json .get ("rl" ).get ("web_search_api" ).get ("next_page" , None )
1923
1923
more_pages = response_json .get ("rl" ).get ("web_search_api" ).get ("more_pages" )
1924
1924
1925
- if len (results ) >= max_results or not more_pages :
1926
- break
1925
+ if not max_results :
1926
+ if not more_pages :
1927
+ return results
1927
1928
1928
- return results [:max_results ]
1929
+ else :
1930
+ if not more_pages or len (results ) >= max_results :
1931
+ return results [:max_results ]
1929
1932
1930
1933
def list_containers_for_hashes (self , sample_hashes ):
1931
1934
"""Gets a list of all top-level containers from which the requested sample has been extracted during analysis.
@@ -2045,21 +2048,19 @@ def network_ip_to_domain(self, ip_addr, page=None, page_size=500):
2045
2048
2046
2049
return response
2047
2050
2048
- def network_ip_to_domain_aggregated (self , ip_addr , page_size = 500 , max_results = 5000 ):
2051
+ def network_ip_to_domain_aggregated (self , ip_addr , page_size = 500 , max_results = None ):
2049
2052
"""Accepts an IP address string and returns a list of IP-to-domain mappings.
2050
2053
This method performs the paging automatically and returns a specified maximum number of records.
2051
2054
:param ip_addr: requested IP address
2052
2055
:type ip_addr: str
2053
2056
:param page_size: number of records per page
2054
2057
:type page_size: int
2055
- :param max_results: maximum number of returned records
2056
- :type max_results: int
2058
+ :param max_results: number of results to be returned in the list;
2059
+ set as integer to receive a defined number of results or leave as None to receive all available results
2060
+ :type max_results: int or None
2057
2061
:return: list of results
2058
2062
:rtype: list
2059
2063
"""
2060
- if not isinstance (max_results , int ):
2061
- raise WrongInputError ("max_results parameter must be integer." )
2062
-
2063
2064
results = []
2064
2065
next_page = None
2065
2066
@@ -2077,10 +2078,13 @@ def network_ip_to_domain_aggregated(self, ip_addr, page_size=500, max_results=50
2077
2078
2078
2079
next_page = response_json .get ("next_page" , None )
2079
2080
2080
- if len (results ) >= max_results or not next_page :
2081
- break
2081
+ if not max_results :
2082
+ if not next_page :
2083
+ return results
2082
2084
2083
- return results [:max_results ]
2085
+ else :
2086
+ if not next_page or len (results ) >= max_results :
2087
+ return results [:max_results ]
2084
2088
2085
2089
def network_urls_from_ip (self , ip_addr , page = None , page_size = 500 ):
2086
2090
"""Accepts an IP address string and returns a list of URLs hosted on the requested IP address.
@@ -2112,21 +2116,19 @@ def network_urls_from_ip(self, ip_addr, page=None, page_size=500):
2112
2116
2113
2117
return response
2114
2118
2115
- def network_urls_from_ip_aggregated (self , ip_addr , page_size = 500 , max_results = 5000 ):
2119
+ def network_urls_from_ip_aggregated (self , ip_addr , page_size = 500 , max_results = None ):
2116
2120
"""Accepts an IP address string and returns a list of URLs hosted on the requested IP address.
2117
2121
This method performs the paging automatically and returns a specified maximum number of records.
2118
2122
:param ip_addr: requested IP address
2119
2123
:type ip_addr: str
2120
2124
:param page_size: number of records per page
2121
2125
:type page_size: int
2122
- :param max_results: maximum number of returned records
2123
- :type max_results: int
2126
+ :param max_results: number of results to be returned in the list;
2127
+ set as integer to receive a defined number of results or leave as None to receive all available results
2128
+ :type max_results: int or None
2124
2129
:return: list of results
2125
2130
:rtype: list
2126
2131
"""
2127
- if not isinstance (max_results , int ):
2128
- raise WrongInputError ("max_results parameter must be integer." )
2129
-
2130
2132
results = []
2131
2133
next_page = None
2132
2134
@@ -2144,10 +2146,13 @@ def network_urls_from_ip_aggregated(self, ip_addr, page_size=500, max_results=50
2144
2146
2145
2147
next_page = response_json .get ("next_page" , None )
2146
2148
2147
- if len (results ) >= max_results or not next_page :
2148
- break
2149
+ if not max_results :
2150
+ if not next_page :
2151
+ return results
2149
2152
2150
- return results [:max_results ]
2153
+ else :
2154
+ if not next_page or len (results ) >= max_results :
2155
+ return results [:max_results ]
2151
2156
2152
2157
def network_files_from_ip (self , ip_addr , extended_results = True , classification = None , page = None , page_size = 500 ):
2153
2158
"""Accepts an IP address string and returns a list of hashes and
@@ -2194,7 +2199,7 @@ def network_files_from_ip(self, ip_addr, extended_results=True, classification=N
2194
2199
return response
2195
2200
2196
2201
def network_files_from_ip_aggregated (self , ip_addr , extended_results = True , classification = None , page_size = 500 ,
2197
- max_results = 5000 ):
2202
+ max_results = None ):
2198
2203
"""Accepts an IP address string and returns a list of hashes and
2199
2204
classifications for files found on the requested IP address.
2200
2205
This method performs the paging automatically and returns a specified maximum number of records.
@@ -2206,14 +2211,12 @@ def network_files_from_ip_aggregated(self, ip_addr, extended_results=True, class
2206
2211
:type classification: str
2207
2212
:param page_size: number of records per page
2208
2213
:type page_size: int
2209
- :param max_results: maximum number of returned records
2210
- :type max_results: int
2214
+ :param max_results: number of results to be returned in the list;
2215
+ set as integer to receive a defined number of results or leave as None to receive all available results
2216
+ :type max_results: int or None
2211
2217
:return: list of results
2212
2218
:rtype: list
2213
2219
"""
2214
- if not isinstance (max_results , int ):
2215
- raise WrongInputError ("max_results parameter must be integer." )
2216
-
2217
2220
results = []
2218
2221
next_page = None
2219
2222
@@ -2233,10 +2236,13 @@ def network_files_from_ip_aggregated(self, ip_addr, extended_results=True, class
2233
2236
2234
2237
next_page = response_json .get ("next_page" , None )
2235
2238
2236
- if len (results ) >= max_results or not next_page :
2237
- break
2239
+ if not max_results :
2240
+ if not next_page :
2241
+ return results
2238
2242
2239
- return results [:max_results ]
2243
+ else :
2244
+ if not next_page or len (results ) >= max_results :
2245
+ return results [:max_results ]
2240
2246
2241
2247
def __ip_addr_endpoints (self , ip_addr , specific_endpoint , params = None ):
2242
2248
"""Private method for all IP related endpoints from the Network Threat Intelligence API.
0 commit comments