owasp-depscan 5.1.3__py3-none-any.whl → 5.1.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of owasp-depscan might be problematic. Click here for more details.

depscan/cli.py CHANGED
@@ -2,22 +2,17 @@
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
4
  import argparse
5
- from defusedxml.ElementTree import parse
6
5
  import json
7
6
  import os
8
- import shutil
9
- import subprocess
10
7
  import sys
11
- import tarfile
12
8
  import tempfile
13
9
 
14
- import oras.client
10
+ from defusedxml.ElementTree import parse
15
11
  from quart import Quart, request
16
12
  from rich.panel import Panel
17
13
  from rich.terminal_theme import DEFAULT_TERMINAL_THEME, MONOKAI
18
14
  from vdb.lib import config
19
15
  from vdb.lib import db as db_lib
20
- from vdb.lib.config import data_dir
21
16
  from vdb.lib.gha import GitHubSource
22
17
  from vdb.lib.nvd import NvdSource
23
18
  from vdb.lib.osv import OSVSource
@@ -45,12 +40,11 @@ from depscan.lib.config import (
45
40
  UNIVERSAL_SCAN_TYPE,
46
41
  license_data_dir,
47
42
  spdx_license_list,
48
- vdb_database_url,
49
- vdb_rafs_database_url,
50
43
  )
51
44
  from depscan.lib.csaf import export_csaf, write_toml
52
45
  from depscan.lib.license import build_license_data, bulk_lookup
53
46
  from depscan.lib.logger import DEBUG, LOG, console
47
+ from depscan.lib.orasclient import download_image
54
48
 
55
49
  try:
56
50
  os.environ["PYTHONIOENCODING"] = "utf-8"
@@ -497,68 +491,6 @@ def summarise(
497
491
  return summary, vdr_file, pkg_vulnerabilities, pkg_group_rows
498
492
 
499
493
 
500
- def download_rafs_based_image():
501
- rafs_image_downloaded, paths_list = False, None
502
- nydus_image_command = shutil.which("nydus-image", mode=os.X_OK)
503
- if nydus_image_command is not None:
504
- LOG.info(
505
- "About to download the vulnerability database from %s. This might take a while ...",
506
- vdb_rafs_database_url,
507
- )
508
-
509
- try:
510
- oras_client = oras.client.OrasClient()
511
- rafs_data_dir = tempfile.TemporaryDirectory()
512
- paths_list = oras_client.pull(
513
- target=vdb_rafs_database_url, outdir=rafs_data_dir.name
514
- )
515
-
516
- if (
517
- paths_list
518
- and os.path.exists(
519
- os.path.join(rafs_data_dir.name, "data.rafs")
520
- )
521
- and os.path.exists(
522
- os.path.join(rafs_data_dir.name, "meta.rafs")
523
- )
524
- ):
525
- nydus_download_command = [
526
- f"{nydus_image_command}",
527
- "unpack",
528
- "--blob",
529
- os.path.join(rafs_data_dir.name, "data.rafs"),
530
- "--output",
531
- os.path.join(data_dir, "vdb.tar"),
532
- "--bootstrap",
533
- os.path.join(rafs_data_dir.name, "meta.rafs"),
534
- ]
535
- _ = subprocess.run(
536
- nydus_download_command,
537
- check=True,
538
- stdout=subprocess.DEVNULL,
539
- )
540
- if os.path.exists(os.path.join(data_dir, "vdb.tar")):
541
- rafs_image_downloaded = True
542
- with tarfile.open(
543
- os.path.join(data_dir, "vdb.tar"), "r"
544
- ) as tar:
545
- tar.extractall(path=data_dir)
546
- os.remove(os.path.join(data_dir, "vdb.tar"))
547
- else:
548
- raise FileNotFoundError("vdb.tar not found")
549
- else:
550
- raise FileNotFoundError("data.rafs or meta.rafs not found")
551
-
552
- except Exception:
553
- LOG.info(
554
- "Unable to pull the vulnerability database (rafs image) from %s. Trying to pull the non-rafs-based VDB image.",
555
- vdb_rafs_database_url,
556
- )
557
- rafs_image_downloaded = False
558
-
559
- return rafs_image_downloaded, data_dir
560
-
561
-
562
494
  @app.get("/")
563
495
  async def index():
564
496
  """
@@ -576,18 +508,17 @@ async def cache():
576
508
  """
577
509
  db = db_lib.get()
578
510
  if not db_lib.index_count(db["index_file"]):
579
- rafs_image_downloaded, _ = download_rafs_based_image()
580
- if not rafs_image_downloaded:
581
- LOG.info(
582
- "About to download the vulnerability database from %s. This might take a while ...",
583
- vdb_database_url,
584
- )
585
- oras_client = oras.client.OrasClient()
586
- oras_client.pull(target=vdb_database_url, outdir=data_dir)
511
+ paths_list = download_image()
512
+ if paths_list:
587
513
  return {
588
514
  "error": "false",
589
515
  "message": "vulnerability database cached successfully",
590
516
  }
517
+ else:
518
+ return {
519
+ "error": "true",
520
+ "message": "vulnerability database was not cached",
521
+ }
591
522
  return {
592
523
  "error": "false",
593
524
  "message": "vulnerability database already exists",
@@ -1035,17 +966,7 @@ def main():
1035
966
  except Exception:
1036
967
  pass
1037
968
  if run_cacher:
1038
- rafs_image_downloaded, paths_list = download_rafs_based_image()
1039
- if not rafs_image_downloaded:
1040
- LOG.info(
1041
- "About to download the vulnerability database from %s. This might take a while ...",
1042
- vdb_database_url,
1043
- )
1044
- oras_client = oras.client.OrasClient()
1045
- paths_list = oras_client.pull(
1046
- target=vdb_database_url, outdir=data_dir
1047
- )
1048
-
969
+ paths_list = download_image()
1049
970
  LOG.debug("VDB data is stored at: %s", paths_list)
1050
971
  run_cacher = False
1051
972
  db = db_lib.get()
@@ -1100,12 +1021,10 @@ def main():
1100
1021
  # CSAF VEX export
1101
1022
  if args.csaf:
1102
1023
  export_csaf(
1103
- results,
1024
+ pkg_vulnerabilities,
1104
1025
  src_dir,
1105
1026
  reports_dir,
1106
- vdr_file,
1107
- direct_purls=direct_purls,
1108
- reached_purls=reached_purls,
1027
+ bom_file,
1109
1028
  )
1110
1029
  console.save_html(
1111
1030
  html_file,