Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for using grype-db from path #250

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading