Skip to content

feat: add message about mirror when nvd is down #5023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions cve_bin_tool/data_sources/nvd_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,15 +413,24 @@ async def fetch_cves(self):
self.nist_fetch_using_api(),
)
else:
nvd_metadata = await asyncio.create_task(
self.nist_scrape(self.session),
)
try:
nvd_metadata = await asyncio.create_task(
self.nist_scrape(self.session),
)

tasks = [
self.cache_update(self.session, url, meta["sha256"])
for url, meta in nvd_metadata.items()
if meta is not None
]
except Exception as e:
self.nvd_type = "api2"
self.feed = self.FEED_MIRROR
self.LOGGER.info("NVD appears to be down, falling back to mirror")
self.all_cve_entries = await asyncio.create_task(
self.nist_fetch_using_api(),
)

tasks = [
self.cache_update(self.session, url, meta["sha256"])
for url, meta in nvd_metadata.items()
if meta is not None
]

total_tasks = len(tasks)

Expand Down Expand Up @@ -464,14 +473,17 @@ async def nist_fetch_using_api(self) -> list:
api_key=self.nvd_api_key,
api_version=api_version,
)
if self.incremental_update:
await nvd_api.get_nvd_params(
time_of_last_update=datetime.datetime.fromtimestamp(
db.get_db_update_date()
try:
if self.incremental_update:
await nvd_api.get_nvd_params(
time_of_last_update=datetime.datetime.fromtimestamp(
db.get_db_update_date()
)
)
)
else:
await nvd_api.get_nvd_params()
else:
await nvd_api.get_nvd_params()
except Exception as e:
self.LOGGER.debug(f"{e}")
await nvd_api.get()
await nvd_api.session.close()
nvd_api.session = None
Expand Down
Loading