From c43479c082e23dbe54a4b79f62e1d6d5970d765f Mon Sep 17 00:00:00 2001 From: prabhu Date: Thu, 14 Dec 2023 22:09:05 +0000 Subject: [PATCH] Defer db load (#79) Signed-off-by: Prabhu Subramanian --- pyproject.toml | 2 +- vdb/lib/nvd.py | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a3aa8df..4b89267 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "appthreat-vulnerability-db" -version = "5.5.5" +version = "5.5.6" description = "AppThreat's vulnerability database and package search library with a built-in file based storage. OSV, CVE, GitHub, npm are the primary sources of vulnerabilities." authors = [ {name = "Team AppThreat", email = "cloud@appthreat.com"}, diff --git a/vdb/lib/nvd.py b/vdb/lib/nvd.py index d7b9f80..0d383bd 100644 --- a/vdb/lib/nvd.py +++ b/vdb/lib/nvd.py @@ -34,8 +34,6 @@ now = datetime.datetime.now() # Size of the stream to read and write to the file download_chunk_size = 128 -# Create database -db = dbLib.get() json_lib = orjson if ORJSON_AVAILABLE else json @@ -57,6 +55,8 @@ class NvdSource(VulnerabilitySource): def download_all(self, local_store=True): """Download all historic cve data""" + # Create database + self.db = dbLib.get() data_list = [] for y in range(now.year, int(start_year) - 1, -1): data = self.fetch(y) @@ -68,6 +68,8 @@ def download_all(self, local_store=True): def download_recent(self, local_store=True): """Method which downloads the recent CVE gzip from NVD""" + # Create database + self.db = dbLib.get() data = self.fetch("recent") if local_store: self.store(data) @@ -114,10 +116,10 @@ def refresh(self): def store(self, data, reindex=True): """Store data in the database""" - docs = dbLib.store(db, data, reindex) + docs = dbLib.store(self.db, data, reindex) return docs - def bulk_search(): + def bulk_search(self): """ Bulk search the resource instead of downloading the information :return: Vulnerability result