Skip to content

Commit

Permalink
allow for using grype-db from path (#250)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Goodman <[email protected]>
  • Loading branch information
wagoodman authored Mar 7, 2024
1 parent 82b2f07 commit b4e2769
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions manager/src/grype_db_manager/grypedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,12 @@ def list_dbs(self) -> list[DBInfo]:

class GrypeDB:
def __init__(self, bin_path: str, config_path: str = ""):
self.version = os.path.basename(bin_path).removeprefix("grype-db-")
if bin_path:
self.version = os.path.basename(bin_path).removeprefix("grype-db-")
else:
logging.info("using existing grype-db that is on path")
self.version = ""

self.bin_path = bin_path
self.config_path = config_path

Expand All @@ -383,11 +388,14 @@ def list_installed(cls, root_dir: str) -> list[GrypeDB]:

@classmethod
def install(cls, version: str, config_path: str, root_dir: str) -> GrypeDB:
bin_path = _install_grype_db(
input_version=version,
bin_dir=os.path.join(root_dir, BIN_DIR),
clone_dir=os.path.join(root_dir, CLONE_DIR),
)
bin_path = None
if version != "disabled":
bin_path = _install_grype_db(
input_version=version,
bin_dir=os.path.join(root_dir, BIN_DIR),
clone_dir=os.path.join(root_dir, CLONE_DIR),
)

return cls(bin_path=bin_path, config_path=config_path)

def build_and_package(self, schema_version: int, provider_root_dir: str, root_dir: str) -> str:
Expand Down Expand Up @@ -443,7 +451,7 @@ def package_db(self, build_dir: str, provider_root_dir: str) -> None:
)

def run(self, *args, provider_root_dir: str, config: str) -> int:
cmd = " ".join([self.bin_path, *args])
cmd = " ".join([self.bin_path, *args]) if self.bin_path else " ".join(["grype-db", *args])
level = logging.getLevelName(logging.getLogger().getEffectiveLevel())
if level == "TRACE":
# trace is not supported in grype-db yet
Expand Down

0 comments on commit b4e2769

Please sign in to comment.