Compare commits

...

1 Commits

Author SHA1 Message Date
Mateusz Gruszczyński
e134ee2692 app 2026-02-14 10:04:53 +01:00

View File

@@ -505,30 +505,77 @@ class CVEHandler:
logger.info(f"Total unique CVEs after deduplication: {len(unique_cves)}") logger.info(f"Total unique CVEs after deduplication: {len(unique_cves)}")
new_count = 0
updated_count = 0
with self.get_db_connection() as conn: with self.get_db_connection() as conn:
cursor = conn.cursor() cursor = conn.cursor()
for cve_id, cve in unique_cves.items(): for cve_id, cve in unique_cves.items():
cursor.execute(""" cursor.execute("""
INSERT OR REPLACE INTO cve_cache SELECT discord_notified FROM cve_cache WHERE cve_id = ?
(cve_id, vendor_code, description, published_date, last_modified, """, (cve_id,))
cvss_score, cvss_vector, severity, refs, cwe_ids,
affected_products, raw_data, updated_at) existing = cursor.fetchone()
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
""", ( if not existing:
cve_id, cursor.execute("""
vendor_code, INSERT INTO cve_cache
cve.get('description'), (cve_id, vendor_code, description, published_date, last_modified,
cve.get('published_date'), cvss_score, cvss_vector, severity, refs, cwe_ids,
cve.get('last_modified'), affected_products, raw_data, discord_notified,
cve.get('cvss_score'), created_at, updated_at)
cve.get('cvss_vector'), VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
cve.get('severity'), """, (
cve.get('references'), cve_id,
cve.get('cwe_ids'), vendor_code,
None, cve.get('description'),
cve.get('raw_data') cve.get('published_date'),
)) cve.get('last_modified'),
cve.get('cvss_score'),
cve.get('cvss_vector'),
cve.get('severity'),
cve.get('references'),
cve.get('cwe_ids'),
None,
cve.get('raw_data')
))
new_count += 1
else:
old_notified = existing[0]
cursor.execute("""
UPDATE cve_cache SET
vendor_code = ?,
description = ?,
published_date = ?,
last_modified = ?,
cvss_score = ?,
cvss_vector = ?,
severity = ?,
refs = ?,
cwe_ids = ?,
affected_products = ?,
raw_data = ?,
discord_notified = ?,
updated_at = CURRENT_TIMESTAMP
WHERE cve_id = ?
""", (
vendor_code,
cve.get('description'),
cve.get('published_date'),
cve.get('last_modified'),
cve.get('cvss_score'),
cve.get('cvss_vector'),
cve.get('severity'),
cve.get('references'),
cve.get('cwe_ids'),
None,
cve.get('raw_data'),
old_notified,
cve_id
))
updated_count += 1
cursor.execute(""" cursor.execute("""
INSERT OR REPLACE INTO cve_metadata INSERT OR REPLACE INTO cve_metadata
@@ -540,11 +587,16 @@ class CVEHandler:
list(unique_cves.keys())[0] if unique_cves else None list(unique_cves.keys())[0] if unique_cves else None
)) ))
logger.info(f"✓ Successfully updated {len(unique_cves)} CVEs for {vendor['name']}") if new_count > 0:
logger.info(f"Added {new_count} new CVEs for {vendor['name']}")
if updated_count > 0:
logger.info(f"Updated {updated_count} existing CVEs for {vendor['name']}")
logger.info(f"Successfully processed {len(unique_cves)} CVEs for {vendor['name']}")
return True return True
except Exception as e: except Exception as e:
logger.error(f"Error updating vendor cache for {vendor_code}: {e}", exc_info=True) logger.error(f"Error updating vendor cache for {vendor_code}: {e}", exc_info=True)
try: try:
with self.get_db_connection() as conn: with self.get_db_connection() as conn:
@@ -559,6 +611,7 @@ class CVEHandler:
return False return False
def get_vendor_cves(self, vendor_code: str, limit: int = None, offset: int = 0, def get_vendor_cves(self, vendor_code: str, limit: int = None, offset: int = 0,
severity: str = None, year: int = None) -> List[Dict]: severity: str = None, year: int = None) -> List[Dict]:
with self.get_db_connection() as conn: with self.get_db_connection() as conn: