From b99eb602a5c473e561bad4c1bfa35b029d8a80a7 Mon Sep 17 00:00:00 2001 From: Khanh Le Do Date: Fri, 13 Dec 2024 10:38:23 -0800 Subject: [PATCH] cve_feed: manage http request and add request log --- cartography/intel/cve/feed.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cartography/intel/cve/feed.py b/cartography/intel/cve/feed.py index 6d5c2859ae..c16de1fe90 100644 --- a/cartography/intel/cve/feed.py +++ b/cartography/intel/cve/feed.py @@ -86,11 +86,13 @@ def _call_cves_api(url: str, api_key: str | None, params: Dict[str, Any]) -> Dic results: Dict[Any, Any] = dict() while params["resultsPerPage"] > 0 or params["startIndex"] < totalResults: + logger.info(f"Calling NIST NVD API at {url} with params {params}") try: - res = requests.get( + with requests.get( url, params=params, headers=headers, timeout=CONNECT_AND_READ_TIMEOUT, - ) - res.raise_for_status() + ) as res: + res.raise_for_status() + data = res.json() except requests.exceptions.HTTPError: logger.error( f"Failed to get CVE data from NIST NVD API {res.status_code} : {res.text}", @@ -102,7 +104,6 @@ def _call_cves_api(url: str, api_key: str | None, params: Dict[str, Any]) -> Dic sleep_time *= 2 time.sleep(sleep_time) continue - data = res.json() _map_cve_dict(results, data) totalResults = data["totalResults"] params["resultsPerPage"] = data["resultsPerPage"]