更新: 109 个文件 - 2026-03-18 10:55:52

这个提交包含在:
hao
2026-03-18 10:55:52 -07:00
父节点 1d5cb533e3
当前提交 1f9d9b1d16
修改 109 个文件,包含 10958 行新增1350 行删除

查看文件

@@ -1,6 +1,8 @@
from __future__ import annotations
import os
import threading
import time
from typing import Any, Dict, List
import requests
@@ -11,6 +13,30 @@ from intel.utils import unique
API_URL = "https://services.nvd.nist.gov/rest/json/cves/2.0"
PUBLIC_INTERVAL_SECONDS = 7.0
_NVD_RATE_LOCK = threading.Lock()
_NVD_LAST_REQUEST = 0.0
def _wait_for_slot() -> None:
global _NVD_LAST_REQUEST
if os.environ.get("NVD_API_KEY"):
return
with _NVD_RATE_LOCK:
elapsed = time.monotonic() - _NVD_LAST_REQUEST
if elapsed < PUBLIC_INTERVAL_SECONDS:
time.sleep(PUBLIC_INTERVAL_SECONDS - elapsed)
_NVD_LAST_REQUEST = time.monotonic()
def request_nvd(source: Dict[str, Any], headers: Dict[str, Any], params: Dict[str, Any]) -> requests.Response:
_wait_for_slot()
response = request("GET", API_URL, source=source, headers=headers, params=params)
if response.status_code == 429 and not os.environ.get("NVD_API_KEY"):
time.sleep(PUBLIC_INTERVAL_SECONDS)
_wait_for_slot()
response = request("GET", API_URL, source=source, headers=headers, params=params)
return response
def fetch(system: Dict[str, Any], source: Dict[str, Any]) -> List[Candidate]:
@@ -23,7 +49,7 @@ def fetch(system: Dict[str, Any], source: Dict[str, Any]) -> List[Candidate]:
if api_key:
headers["apiKey"] = api_key
response = request("GET", API_URL, source=source, headers=headers, params=params)
response = request_nvd(source, headers, params)
response.raise_for_status()
payload = response.json()