From aeb99858bd17c8ae69ec60c12b0ddf88ad56f03c Mon Sep 17 00:00:00 2001 From: almogch Date: Mon, 30 Sep 2024 15:25:44 +0300 Subject: [PATCH 1/2] feature(analyses-history) - add url and scanned_url filters to history query --- CHANGES | 4 ++++ intezer_sdk/__init__.py | 2 +- intezer_sdk/analyses_history.py | 8 ++++++++ intezer_sdk/analysis.py | 9 +++------ test_requirements.txt | 2 +- tests/unit/test_results.py | 2 +- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/CHANGES b/CHANGES index b8c25bc..179ce03 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +1.21.5 +_______ +- Add url and scanned_url to url analyses history filters + 1.21.4 _______ - Always refresh access token on 'unauthorized' http status diff --git a/intezer_sdk/__init__.py b/intezer_sdk/__init__.py index 6ec049f..97e3f85 100644 --- a/intezer_sdk/__init__.py +++ b/intezer_sdk/__init__.py @@ -1 +1 @@ -__version__ = '1.21.4' +__version__ = '1.21.5' diff --git a/intezer_sdk/analyses_history.py b/intezer_sdk/analyses_history.py index dfa7e63..70ce522 100644 --- a/intezer_sdk/analyses_history.py +++ b/intezer_sdk/analyses_history.py @@ -112,6 +112,8 @@ def query_url_analyses_history(*, sub_verdicts: List[str] = None, did_download_file: bool = None, submitted_url: str = None, + scanned_url: str = None, + url: str = None, aggregated_view: bool = False, limit: int = DEFAULT_LIMIT, offset: int = DEFAULT_OFFSET @@ -127,6 +129,8 @@ def query_url_analyses_history(*, :param sub_verdicts: Filter by the analysis's verdict :param did_download_file: Should the result be aggregated by latest url. :param submitted_url: Filter by specific url + :param scanned_url: Filter by specific scanned_url + :param url: Filter by submitted url or scanned url :param aggregated_view: Should the result be aggregated by latest url. :param limit: Number of analyses returned by the query. :param offset: Number of analyses to skips the before beginning to return the analyses. @@ -148,6 +152,10 @@ def query_url_analyses_history(*, filters['did_download_file'] = did_download_file if submitted_url: filters['submitted_url'] = submitted_url + if scanned_url: + filters['scanned_url'] = scanned_url + if url: + filters['url'] = url if sub_verdicts: filters['sub_verdicts'] = sub_verdicts diff --git a/intezer_sdk/analysis.py b/intezer_sdk/analysis.py index b0378fd..1e112a4 100644 --- a/intezer_sdk/analysis.py +++ b/intezer_sdk/analysis.py @@ -401,18 +401,15 @@ def from_latest_analysis(cls, now = datetime.datetime.now() yesterday = now - datetime.timedelta(days=days_threshold_for_latest_analysis) + url = _clean_url(url) if exact_match else url analysis_history_url_result = query_url_analyses_history(start_date=yesterday, end_date=now, + url=url, aggregated_view=True, api=api) all_analyses_reports = analysis_history_url_result.all() - - analyses_ids = [report['analysis_id'] for report in all_analyses_reports - if url in (report.get('scanned_url'), report.get('submitted_url'))] - if not analyses_ids and not exact_match: - analyses_ids = [report['analysis_id'] for report in all_analyses_reports - if _clean_url(url) in (_clean_url(report.get('scanned_url', '')), _clean_url(report.get('submitted_url', '')))] + analyses_ids = [report['analysis_id'] for report in all_analyses_reports] if not analyses_ids: return None diff --git a/test_requirements.txt b/test_requirements.txt index 277ce36..1901004 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -1,4 +1,4 @@ # This is not used by the project, but is used by the CI/CD pipeline to install dependencies, update setup.py for package dependencies. requests>=2.29.0,<3 responses==0.25.0 -pytest==8.0.1 +pytest==8.1.1 diff --git a/tests/unit/test_results.py b/tests/unit/test_results.py index 5a8dc2f..c8aefcd 100644 --- a/tests/unit/test_results.py +++ b/tests/unit/test_results.py @@ -190,7 +190,7 @@ def test_url_analyses_history_happy_flow(self): verdicts=['malicious'], sub_verdicts=['phishing'], did_download_file=True, - submitted_url='https://example_trusted.com' + url='https://example_trusted.com' ) for result in results: assert result From f47c4fc94c18dae5cc8b153083f4d41ebc930667 Mon Sep 17 00:00:00 2001 From: almogch Date: Mon, 30 Sep 2024 15:30:01 +0300 Subject: [PATCH 2/2] feature(analyses-history) - add url and scanned_url filters to history query --- intezer_sdk/analysis.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/intezer_sdk/analysis.py b/intezer_sdk/analysis.py index 1e112a4..99bb8e8 100644 --- a/intezer_sdk/analysis.py +++ b/intezer_sdk/analysis.py @@ -407,9 +407,7 @@ def from_latest_analysis(cls, url=url, aggregated_view=True, api=api) - all_analyses_reports = analysis_history_url_result.all() - - analyses_ids = [report['analysis_id'] for report in all_analyses_reports] + analyses_ids = [report['analysis_id'] for report in analysis_history_url_result.all()] if not analyses_ids: return None