Skip to content

Commit

Permalink
Merge pull request #39 from Ostorlab/Fix/when_api_reach_the_rate_limi…
Browse files Browse the repository at this point in the history
…t_retry_after_60_seconds

Fix/when api reach the rate limit retry after 60 seconds.
  • Loading branch information
3asm authored Nov 2, 2023
2 parents b3baa14 + a9cedfa commit dca8786
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions agent/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ def get_file_content(message: m.Message) -> bytes | None:
content_url: str | None = message.data.get("content_url")
if content_url is not None:
return _download_file(content_url)

return None
1 change: 0 additions & 1 deletion agent/virustotal.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def get_scans(response: dict[str, Any]) -> dict[str, Any] | None:
VirusTotalApiError: In case the API request encountered problems.
"""
if response.get("response_code") == 204 and response.get("error") is not None:
logger.error("Exceeded the virustotal API rate limit.")
raise VirusTotalApiError()
elif response.get("response_code") == 0 or "results" not in response:
raise VirusTotalApiError()
Expand Down
2 changes: 2 additions & 0 deletions tests/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def testVirusTotalAgent_whenVirusTotalApiReturnsInvalidResponse_agentShouldNotCr
"""Unittest for the lifecyle of the virustotal agent :
Case where the Virus Total public API response is invalid.
"""
mocker.patch("time.sleep")

def virustotal_invalid_response(message: msg.Message) -> dict[str, Any]:
"""Method for mocking the virustotal public api invalid response."""
Expand Down Expand Up @@ -310,6 +311,7 @@ def testVirusTotalAgent_whenWhiteListTypesAreNotProvided_shouldNotCrash(
"""Unit test for the lifecyle of the virustotal agent:
Case when the whitelist_types arg not provided agent shouldn't crash
"""
mocker.patch("time.sleep")
get_file_content_mock = mocker.patch(
"agent.file.get_file_content", return_value=b""
)
Expand Down

0 comments on commit dca8786

Please sign in to comment.