@@ -409,19 +409,30 @@ async def fetch_cves(self):
409
409
tasks = []
410
410
LOGGER .info ("Getting NVD CVE data..." )
411
411
if self .nvd_type == "api2" :
412
+ self .LOGGER .info ("Using mirror, with nvd_type %s and feed %s" , self .nvd_type , self .feed )
412
413
self .all_cve_entries = await asyncio .create_task (
413
414
self .nist_fetch_using_api (),
414
415
)
415
416
else :
416
- nvd_metadata = await asyncio .create_task (
417
- self .nist_scrape (self .session ),
418
- )
417
+ self .LOGGER .info ("Using NVD, with nvd_type %s and feed %s" , self .nvd_type , self .feed )
418
+ try :
419
+ nvd_metadata = await asyncio .create_task (
420
+ self .nist_scrape (self .session ),
421
+ )
422
+
423
+ tasks = [
424
+ self .cache_update (self .session , url , meta ["sha256" ])
425
+ for url , meta in nvd_metadata .items ()
426
+ if meta is not None
427
+ ]
428
+ except Exception as e :
429
+ self .LOGGER .info (f"nvd_source.py 429 fetch_cves() { e } " )
430
+ self .nvd_type = "api2"
431
+ self .LOGGER .info ("Falling back to mirror, with nvd_type %s and feed %s" , self .nvd_type , self .feed )
432
+ self .all_cve_entries = await asyncio .create_task (
433
+ self .nist_fetch_using_api (),
434
+ )
419
435
420
- tasks = [
421
- self .cache_update (self .session , url , meta ["sha256" ])
422
- for url , meta in nvd_metadata .items ()
423
- if meta is not None
424
- ]
425
436
426
437
total_tasks = len (tasks )
427
438
@@ -464,14 +475,17 @@ async def nist_fetch_using_api(self) -> list:
464
475
api_key = self .nvd_api_key ,
465
476
api_version = api_version ,
466
477
)
467
- if self .incremental_update :
468
- await nvd_api .get_nvd_params (
469
- time_of_last_update = datetime .datetime .fromtimestamp (
470
- db .get_db_update_date ()
478
+ try :
479
+ if self .incremental_update :
480
+ await nvd_api .get_nvd_params (
481
+ time_of_last_update = datetime .datetime .fromtimestamp (
482
+ db .get_db_update_date ()
483
+ )
471
484
)
472
- )
473
- else :
474
- await nvd_api .get_nvd_params ()
485
+ else :
486
+ await nvd_api .get_nvd_params ()
487
+ except Exception as e :
488
+ self .LOGGER .info (f"nvd_source.py 488 nist_fetch_using_api() { e } " )
475
489
await nvd_api .get ()
476
490
await nvd_api .session .close ()
477
491
nvd_api .session = None
@@ -490,18 +504,21 @@ async def getmeta(
490
504
Returns:
491
505
tuple: A tuple containing the URL for the JSON data and a dictionary of metadata.
492
506
"""
493
- async with await session .get (meta_url ) as response :
494
- response .raise_for_status ()
495
- return (
496
- meta_url .replace (".meta" , ".json.gz" ),
497
- dict (
498
- [
499
- line .split (":" , maxsplit = 1 )
500
- for line in (await response .text ()).splitlines ()
501
- if ":" in line
502
- ]
503
- ),
504
- )
507
+ try :
508
+ async with await session .get (meta_url ) as response :
509
+ response .raise_for_status ()
510
+ return (
511
+ meta_url .replace (".meta" , ".json.gz" ),
512
+ dict (
513
+ [
514
+ line .split (":" , maxsplit = 1 )
515
+ for line in (await response .text ()).splitlines ()
516
+ if ":" in line
517
+ ]
518
+ ),
519
+ )
520
+ except Exception as e :
521
+ self .LOGGER .info (f"nvd_source.py 521 getmeta() { e } " )
505
522
506
523
async def nist_scrape (self , session : RateLimiter ):
507
524
"""
@@ -513,23 +530,26 @@ async def nist_scrape(self, session: RateLimiter):
513
530
Returns:
514
531
dict: A dictionary containing metadata links and their corresponding SHA values.
515
532
"""
516
- async with await session .get (self .feed ) as response :
517
- response .raise_for_status ()
518
- page = await response .text ()
519
- if self .nvd_type == "json-nvd" :
520
- json_meta_links = self .META_REGEX_NVD .findall (page )
521
- meta_host = self .META_LINK_NVD
522
- else :
523
- json_meta_links = self .META_REGEX_MIRROR .findall (page )
524
- meta_host = self .META_LINK_MIRROR
525
- return dict (
526
- await asyncio .gather (
527
- * (
528
- self .getmeta (session , f"{ meta_host } /{ meta_url } " )
529
- for meta_url in json_meta_links
533
+ try :
534
+ async with await session .get (self .feed ) as response :
535
+ response .raise_for_status ()
536
+ page = await response .text ()
537
+ if self .nvd_type == "json-nvd" :
538
+ json_meta_links = self .META_REGEX_NVD .findall (page )
539
+ meta_host = self .META_LINK_NVD
540
+ else :
541
+ json_meta_links = self .META_REGEX_MIRROR .findall (page )
542
+ meta_host = self .META_LINK_MIRROR
543
+ return dict (
544
+ await asyncio .gather (
545
+ * (
546
+ self .getmeta (session , f"{ meta_host } /{ meta_url } " )
547
+ for meta_url in json_meta_links
548
+ )
530
549
)
531
550
)
532
- )
551
+ except Exception as e :
552
+ self .LOGGER .info (f"nvd_source.py 552 nist_scrape() { e } " )
533
553
534
554
async def cache_update (
535
555
self ,
0 commit comments