-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support for downloading precompiled image using oras Signed-off-by: Prabhu Subramanian <[email protected]> --------- Signed-off-by: Prabhu Subramanian <[email protected]>
- Loading branch information
Showing
7 changed files
with
126 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[project] | ||
name = "appthreat-vulnerability-db" | ||
version = "6.0.0" | ||
version = "6.0.1" | ||
description = "AppThreat's vulnerability database and package search library with a built-in sqlite based storage. OSV, CVE, GitHub, npm are the primary sources of vulnerabilities." | ||
authors = [ | ||
{name = "Team AppThreat", email = "[email protected]"}, | ||
|
@@ -51,6 +51,8 @@ dev = [ | |
"pytest", | ||
"pytest-cov" | ||
] | ||
oras = ["oras"] | ||
all = ["oras"] | ||
|
||
[tool.setuptools] | ||
packages = ["vdb", "vdb.lib", "vdb.lib.cve_model"] | ||
|
@@ -61,3 +63,4 @@ addopts="--showlocals -v --cov-report=term-missing --no-cov-on-fail --cov vdb" | |
[tool.pylint] | ||
disable = ["broad-exception-caught", "too-many-branches", "too-many-statements", "too-many-nested-blocks", "too-many-locals", "missing-function-docstring", "too-many-lines", "missing-module-docstring"] | ||
ignore-paths = ["vdb/lib/cve_model/*"] | ||
generated-member = ["orjson.loads", "orjson.dumps", "orjson.OPT_NAIVE_UTC"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import os | ||
import tarfile | ||
|
||
import oras.client | ||
import oras.provider | ||
from oras.logger import setup_logger | ||
|
||
|
||
setup_logger(quiet=True, debug=False) | ||
|
||
|
||
class VdbDistributionRegistry(oras.provider.Registry): | ||
""" | ||
We override the default registry to make things compatible with ghcr. Without this, the below error is thrown. | ||
jsonschema.exceptions.ValidationError: Additional properties are not allowed ('artifactType' was unexpected) | ||
""" | ||
|
||
def get_manifest(self, container, allowed_media_type=None, refresh_headers=True): | ||
""" | ||
Retrieve a manifest for a package. | ||
:param container: parsed container URI | ||
:type container: oras.container.Container or str | ||
:param allowed_media_type: one or more allowed media types | ||
:type allowed_media_type: str | ||
""" | ||
if not allowed_media_type: | ||
allowed_media_type = [oras.defaults.default_manifest_media_type] | ||
headers = {"Accept": ";".join(allowed_media_type)} | ||
|
||
get_manifest = f"{self.prefix}://{container.manifest_url()}" # type: ignore | ||
response = self.do_request(get_manifest, "GET", headers=headers) | ||
self._check_200_response(response) | ||
manifest = response.json() | ||
return manifest | ||
|
||
|
||
def download_image(target, outdir): | ||
""" | ||
Method to download vdb files from a oci registry | ||
""" | ||
oras_client = oras.client.OrasClient(registry=VdbDistributionRegistry()) | ||
paths_list = oras_client.pull( | ||
target=target, | ||
outdir=outdir, | ||
allowed_media_type=[], | ||
overwrite=True, | ||
) | ||
for apath in paths_list: | ||
if apath.endswith(".tar.gz") or apath.endswith(".tar.xz"): | ||
with tarfile.open(apath, "r") as tarf: | ||
tarf.extractall(path=outdir) | ||
try: | ||
os.remove(apath) | ||
except OSError: | ||
pass | ||
return paths_list |