"""HIVE API Client.""" import config import httpx import httpx_retries # https://docs.thehive.ai/reference/submit-a-task-synchronously API_BASE_URL = "https://api.thehive.ai/api/v2" def run_task(url: str) -> dict: """Run a task in The Hive.""" headers = { "accept": "application/json", "authorization": f"token {config.HIVE_CREDENTIALS}", } transport = httpx_retries.RetryTransport( retry=httpx_retries.Retry( total=config.HIVE_RETRIES, backoff_factor=2, # httpx-retries skips non-idempotent methods unless listed; without # POST here the whole Retry config is inert. 500 is included because # Hive 500s are mostly transient (CDAM-4096: ~55% recover on retry). allowed_methods=["POST"], status_forcelist=[429, 500, 502, 503, 504], # a Retry-After sleep may otherwise run to 120s per attempt, # spending the Lambda's 300s budget on billed idle time max_backoff_wait=15, ) ) with httpx.Client(transport=transport) as client: response = client.post( f"{API_BASE_URL}/task/sync", headers=headers, json={"url": url}, timeout=config.HIVE_TIMEOUT, ) response.raise_for_status() return response.json()