|
9 | 9 | import requests |
10 | 10 | import time |
11 | 11 | from urllib import parse |
12 | | -from warnings import warn |
13 | 12 |
|
14 | 13 | from ReversingLabs.SDK.helper import ADVANCED_SEARCH_SORTING_CRITERIA, DEFAULT_USER_AGENT, RESPONSE_CODE_ERROR_MAP, \ |
15 | 14 | MD5, SHA1, SHA256, SHA512, \ |
@@ -1560,131 +1559,6 @@ def get_yara_cloud_retro_scan_status(self, ruleset_name): |
1560 | 1559 |
|
1561 | 1560 | return response |
1562 | 1561 |
|
1563 | | - def advanced_search_v2(self, query_string, ticloud=False, page_number=1, records_per_page=20, sorting_criteria=None, |
1564 | | - sorting_order="desc"): |
1565 | | - """THIS METHOD IS DEPRECATED. Use advanced_search_v3 instead. |
1566 | | -
|
1567 | | - Sends a query string to the A1000 Advanced Search API v2. |
1568 | | - The query string must be composed of key-value pairs separated by space. |
1569 | | - A key is separated from its value by a colon symbol and no spaces. |
1570 | | - For directions on how to write advanced search queries, consult the A1000 documentation. |
1571 | | - If a page number is not provided, the first page of results will be returned. |
1572 | | - Query string example: |
1573 | | - 'av-count:5 available:TRUE' |
1574 | | -
|
1575 | | - :param query_string: query string |
1576 | | - :type query_string: str |
1577 | | - :param ticloud: show only cloud results |
1578 | | - :type ticloud: bool |
1579 | | - :param page_number: page number |
1580 | | - :type page_number: int |
1581 | | - :param records_per_page: number of records returned per page; maximum value is 100 |
1582 | | - :type records_per_page: int |
1583 | | - :param sorting_criteria: define the criteria used in sorting; possible values are 'sha1', 'firstseen', |
1584 | | - 'threatname', 'sampletype', 'filecount', 'size' |
1585 | | - :type sorting_criteria: str |
1586 | | - :param sorting_order: sorting order; possible values are 'desc', 'asc' |
1587 | | - :type sorting_order: str |
1588 | | - :return: response |
1589 | | - :rtype: requests.Response |
1590 | | - """ |
1591 | | - warn("This method is deprecated. Use advanced_search_v3 instead.", DeprecationWarning) |
1592 | | - |
1593 | | - if not isinstance(query_string, str): |
1594 | | - raise WrongInputError("The search query must be a string.") |
1595 | | - |
1596 | | - if not isinstance(ticloud, bool): |
1597 | | - raise WrongInputError("ticloud parameter must be boolean.") |
1598 | | - |
1599 | | - if not isinstance(records_per_page, int) or not 1 <= records_per_page <= 100: |
1600 | | - raise WrongInputError("records_per_page parameter must be an integer with a value " |
1601 | | - "between 1 and 100 (included).") |
1602 | | - |
1603 | | - url = self._url.format(endpoint=self.__ADVANCED_SEARCH_ENDPOINT_V2) |
1604 | | - |
1605 | | - post_json = {"query": query_string, "ticloud": ticloud, "page": page_number, |
1606 | | - "records_per_page": records_per_page} |
1607 | | - |
1608 | | - if sorting_criteria: |
1609 | | - if sorting_criteria not in ADVANCED_SEARCH_SORTING_CRITERIA or sorting_order not in ("desc", "asc"): |
1610 | | - raise WrongInputError("Sorting criteria must be one of the following options: {criteria}. " |
1611 | | - "Sorting order needs to be 'desc' or 'asc'.".format( |
1612 | | - criteria=ADVANCED_SEARCH_SORTING_CRITERIA |
1613 | | - )) |
1614 | | - sorting_expression = "{criteria} {order}".format( |
1615 | | - criteria=sorting_criteria, |
1616 | | - order=sorting_order |
1617 | | - ) |
1618 | | - |
1619 | | - post_json["sort"] = sorting_expression |
1620 | | - |
1621 | | - response = self.__post_request(url=url, post_json=post_json) |
1622 | | - |
1623 | | - self.__raise_on_error(response) |
1624 | | - |
1625 | | - return response |
1626 | | - |
1627 | | - def advanced_search_v2_aggregated(self, query_string, ticloud=False, max_results=5000, sorting_criteria=None, |
1628 | | - sorting_order="desc"): |
1629 | | - """THIS METHOD IS DEPRECATED. Use advanced_search_v3_aggregated instead. |
1630 | | -
|
1631 | | - Sends a query string to the A1000 Advanced Search API v2. |
1632 | | - The query string must be composed of key-value pairs separated by space. |
1633 | | - A key is separated from its value by a colon symbol and no spaces. |
1634 | | - For directions on how to write advanced search queries, consult the A1000 documentation. |
1635 | | - Paging is done automatically and results from individual |
1636 | | - responses aggregated into one list and returned`. |
1637 | | - The 'max_results' parameter defines the maximum desired number of results to be returned. |
1638 | | - Query string example: |
1639 | | - 'av-count:5 available:TRUE' |
1640 | | -
|
1641 | | - :param query_string: search query - see API documentation for details on writing search queries |
1642 | | - :type query_string: str |
1643 | | - :param ticloud: show only cloud results |
1644 | | - :type ticloud: bool |
1645 | | - :param max_results: maximum results to be returned in a list; default value is 5000 |
1646 | | - :type max_results: int |
1647 | | - :param sorting_criteria: define the criteria used in sorting; possible values are 'sha1', 'firstseen', |
1648 | | - 'threatname', 'sampletype', 'filecount', 'size' |
1649 | | - :type sorting_criteria: str |
1650 | | - :param sorting_order: sorting order; possible values are 'desc', 'asc' |
1651 | | - :type sorting_order: str |
1652 | | - :return: list of results |
1653 | | - :rtype: list |
1654 | | - """ |
1655 | | - warn("This method is deprecated. Use advanced_search_v3_aggregated instead.", DeprecationWarning) |
1656 | | - |
1657 | | - if not isinstance(max_results, int): |
1658 | | - raise WrongInputError("max_results parameter must be integer.") |
1659 | | - |
1660 | | - results = [] |
1661 | | - next_page = 1 |
1662 | | - more_pages = True |
1663 | | - |
1664 | | - while more_pages: |
1665 | | - response = self.advanced_search_v2( |
1666 | | - query_string=query_string, |
1667 | | - ticloud=ticloud, |
1668 | | - page_number=next_page, |
1669 | | - records_per_page=100, |
1670 | | - sorting_criteria=sorting_criteria, |
1671 | | - sorting_order=sorting_order |
1672 | | - ) |
1673 | | - |
1674 | | - response_json = response.json() |
1675 | | - |
1676 | | - entries = response_json.get("rl").get("web_search_api").get("entries", []) |
1677 | | - results.extend(entries) |
1678 | | - |
1679 | | - if len(results) > max_results: |
1680 | | - results = results[:max_results] |
1681 | | - return results |
1682 | | - |
1683 | | - next_page = response_json.get("rl").get("web_search_api").get("next_page", None) |
1684 | | - more_pages = response_json.get("rl").get("web_search_api").get("more_pages", False) |
1685 | | - |
1686 | | - return results |
1687 | | - |
1688 | 1562 | def advanced_search_v3(self, query_string, ticloud=False, start_search_date=None, end_search_date=None, |
1689 | 1563 | page_number=1, records_per_page=20, sorting_criteria=None, sorting_order="desc"): |
1690 | 1564 | """Sends a query string to the A1000 Advanced Search API v3. |
@@ -2437,4 +2311,4 @@ def __raise_on_error(response): |
2437 | 2311 | exception = RESPONSE_CODE_ERROR_MAP.get(response.status_code, None) |
2438 | 2312 | if not exception: |
2439 | 2313 | return |
2440 | | - raise exception |
| 2314 | + raise exception(response_object=response) |
0 commit comments