A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.
feat(enrichers): add delay on whoxy requests
dextmorgn517b342fc255
diff --git a/flowsint-enrichers/src/flowsint_enrichers/domain/to_history.py b/flowsint-enrichers/src/flowsint_enrichers/domain/to_history.pyindex 77db477e..fd900d32 100644--- a/flowsint-enrichers/src/flowsint_enrichers/domain/to_history.py+++ b/flowsint-enrichers/src/flowsint_enrichers/domain/to_history.py@@ -1,6 +1,7 @@import jsonimport osimport re+import timefrom typing import Any, Dict, List, Optional, Set, Unionfrom dotenv import load_dotenv@@ -79,7 +80,9 @@ class DomainToHistoryEnricher(Enricher):self._extracted_organizations = [] # Store extracted organizations for testingapi_key = self.get_secret("WHOXY_API_KEY", os.getenv("WHOXY_API_KEY"))- for domain in data:+ for i, domain in enumerate(data):+ if i > 0:+ time.sleep(1)infos_data = self.__get_infos_from_whoxy(domain.domain, api_key)if infos_data and "whois_records" in infos_data:Logger.info(diff --git a/flowsint-enrichers/src/tools/network/whoxy.py b/flowsint-enrichers/src/tools/network/whoxy.pyindex ca41af5a..2e31a77a 100644--- a/flowsint-enrichers/src/tools/network/whoxy.py+++ b/flowsint-enrichers/src/tools/network/whoxy.py@@ -1,13 +1,17 @@+import timefrom typing import Dictimport requests+from ..base import Toolclass WhoxyTool(Tool):-whoxy_api_endoint = "https://api.whoxy.com/"-++ MAX_RETRIES = 3+ INITIAL_DELAY = 2 # seconds+@classmethoddef name(cls) -> str:return "whoxy"@@ -25,20 +29,43 @@ class WhoxyTool(Tool):return "Network intelligence"def launch(self, params: Dict[str, str] = {}) -> list[Dict]:- try:- resp = requests.get(- self.whoxy_api_endoint,- params=params,- timeout=10,- )- resp.raise_for_status()- data = resp.json()- if data.get("status") != 1:- raise RuntimeError(- f"Error querying Whoxy API: {str(data.get("status_reason") )}"+ last_exception = None++ for attempt in range(self.MAX_RETRIES):+ try:+ resp = requests.get(+ self.whoxy_api_endoint,+ params=params,+ timeout=10,)- if data.get("total_results") == 0:- raise ValueError(f"No match found for Whoxy search.")- return data- except Exception as e:- raise RuntimeError(f"{str(e)}")++ if resp.status_code == 429:+ delay = self.INITIAL_DELAY * (2 ** attempt)+ time.sleep(delay)+ continue++ resp.raise_for_status()+ data = resp.json()+ if data.get("status") != 1:+ raise RuntimeError(+ f"Error querying Whoxy API: {str(data.get('status_reason'))}"+ )+ if data.get("total_results") == 0:+ raise ValueError("No match found for Whoxy search.")+ return data+ except requests.exceptions.HTTPError as e:+ if resp.status_code in (429, 502, 503, 504):+ last_exception = e+ delay = self.INITIAL_DELAY * (2 ** attempt)+ time.sleep(delay)+ continue+ raise RuntimeError(f"{str(e)}")+ except (ValueError, RuntimeError):+ raise+ except Exception as e:+ last_exception = e+ delay = self.INITIAL_DELAY * (2 ** attempt)+ time.sleep(delay)+ continue++ raise RuntimeError(f"Whoxy API failed after {self.MAX_RETRIES} retries: {str(last_exception)}")