Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/allow exact match search when searching for latest url analyses #115

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.19.1
------
- Add "exact_match option" to UrlAnalysis.from_latest_analysis.

1.19
------
- Change "received_by" label to "reported_by" in submit phishing alert.
Expand Down
2 changes: 1 addition & 1 deletion intezer_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.19'
__version__ = '1.19.1'
9 changes: 7 additions & 2 deletions intezer_sdk/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,14 @@ def from_analysis_id(cls, analysis_id: str, api: IntezerApiClient = None) -> Opt
def from_latest_analysis(cls,
url: str,
days_threshold_for_latest_analysis: int = 1,
api: IntezerApiClient = None) -> Optional['UrlAnalysis']:
api: IntezerApiClient = None,
exact_match=False) -> Optional['UrlAnalysis']:
"""
Returns a UrlAnalysis instance with the latest analysis of the given URL.
:param url: The URL to retrieve the latest analysis for.
:param days_threshold_for_latest_analysis: The number of days to look back for the latest analysis.
:param api: The API connection to Intezer.
:param exact_match: If True, the URL must match exactly. Otherwise, try to find similar URLs which were analyzed.
:return: A UrlAnalysis instance with the latest analysis of the given URL.
"""
now = datetime.datetime.now()
Expand All @@ -398,7 +400,10 @@ def from_latest_analysis(cls,
all_analyses_reports = analysis_history_url_result.all()

analyses_ids = [report['analysis_id'] for report in all_analyses_reports
if _clean_url(url) in (_clean_url(report['scanned_url']), _clean_url(report['submitted_url']))]
if url in (report['scanned_url'], report['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['scanned_url']), _clean_url(report['submitted_url']))]

if not analyses_ids:
return None
Expand Down