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

Get source rpm from purl #1096

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
19 changes: 14 additions & 5 deletions doozer/doozerlib/backend/konflux_image_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from kubernetes.client import Configuration
from kubernetes.dynamic import DynamicClient, exceptions, resource
from ruamel.yaml import YAML
from packageurl import PackageURL

from artcommonlib.exectools import limit_concurrency
from doozerlib import constants
Expand Down Expand Up @@ -261,11 +262,19 @@ async def _get_for_arch(arch):
sbom_contents = json.loads(stdout)
source_rpms = set()
for x in sbom_contents["components"]:
if x["bom-ref"].startswith("pkg:rpm"):
for i in x["properties"]:
if i["name"] == "syft:metadata:sourceRpm":
source_rpms.add(i["value"].rstrip(".src.rpm"))
break
# konflux generates sbom in cyclonedx schema: https://cyclonedx.org
# sbom uses purl or package-url convention https://github.com/package-url/purl-spec
# example: pkg:rpm/rhel/[email protected]?arch=x86_64&upstream=coreutils-8.32-35.el9.src.rpm&distro=rhel-9.4
# https://github.com/package-url/packageurl-python does not support purl schemes other than "pkg"
# so filter them out
if x["purl"].startswith("pkg:"):
purl = PackageURL.from_string(x["purl"])
# right now, we only care about rpms
if purl.type == "rpm":
# get the source rpm
source_rpm = purl.qualifiers.get("upstream", None)
if source_rpm:
source_rpms.add(source_rpm.rstrip(".src.rpm"))
return source_rpms

results = await asyncio.gather(*(_get_for_arch(arch) for arch in arches))
Expand Down
1 change: 1 addition & 0 deletions doozer/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ aiohttp
jira>=3.4.1
ghapi
zipp>=3.19.1 # not directly required, pinned by Snyk to avoid a vulnerability
packageurl-python