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

fix(request.json): version with subpath #2136

Merged
Show file tree
Hide file tree
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
11 changes: 9 additions & 2 deletions atomic_reactor/utils/cachi2.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,25 @@ def gen_dependency_from_sbom_component(sbom_dep: Dict[str, Any]) -> Dict[str, Op
heuristic_type = request_type
break

pkg_dot_path = ("golang", "gem")

version = (
# for non-registry dependencies cachito uses URL as version
purl.qualifiers.get("vcs_url") or
purl.qualifiers.get("download_url") or
# for local dependencies Cachito uses path as version
(f"./{purl.subpath}" if purl.subpath and purl.type == "golang" else None) or
(f"file:{purl.subpath}" if purl.subpath and purl.type != "golang" else None) or
(f"./{purl.subpath}" if purl.subpath and purl.type in pkg_dot_path else None) or
(f"file:{purl.subpath}" if purl.subpath and purl.type not in pkg_dot_path else None) or
chmeliik marked this conversation as resolved.
Show resolved Hide resolved
# version is mainly for dependencies from pkg registries
sbom_dep.get("version")
# returns None if version cannot be determined
)

if version and purl.subpath and not version.endswith(purl.subpath):
# include subpath into vcs or download url to get exact location of dependency
# used mainly for vendored deps
version = f"{version}#{purl.subpath}"

res = {
"name": sbom_dep["name"],
"replaces": None, # it's always None, replacements aren't supported by cachi2
Expand Down
19 changes: 17 additions & 2 deletions tests/utils/test_cachi2.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def test_convert_SBOM_to_ICM(sbom, expected_icm):
"type": "npm",
"version": (
"git+https://github.com/cachito-testing/cachito-npm-without-deps.git@"
"2f0ce1d7b1f8b35572d919428b965285a69583f6"),
"2f0ce1d7b1f8b35572d919428b965285a69583f6#path"),
},
id="version_vsc_url"
),
Expand All @@ -308,7 +308,7 @@ def test_convert_SBOM_to_ICM(sbom, expected_icm):
"name": "cachito-npm-without-deps",
"replaces": None,
"type": "npm",
"version": "https://example.com/pkg",
"version": "https://example.com/pkg#path",
},
id="version_download_url"
),
Expand Down Expand Up @@ -378,6 +378,21 @@ def test_convert_SBOM_to_ICM(sbom, expected_icm):
},
id="npm_dev"
),
pytest.param(
{
"name": "validate_url",
"version": "1.0.5",
"purl": "pkg:gem/validate_url#subpath",
"type": "library"
},
{
"name": "validate_url",
"replaces": None,
"type": "rubygems",
"version": "./subpath"
},
id="type_rubygem_subpath_only"
),
])
def test_gen_dependency_from_sbom_component(sbom_comp, expected):
"""Test generating request.json dependency from sbom component"""
Expand Down
Loading