Skip to content

Commit

Permalink
cve_feed: manage http request and add request log
Browse files Browse the repository at this point in the history
  • Loading branch information
kledo-lyft committed Dec 13, 2024
1 parent e68522e commit b99eb60
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cartography/intel/cve/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand All @@ -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"]
Expand Down

0 comments on commit b99eb60

Please sign in to comment.