Skip to content

Commit

Permalink
Add namespace from distro-id
Browse files Browse the repository at this point in the history
Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
  • Loading branch information
AyanSinhaMahapatra committed Mar 25, 2024
1 parent fb481be commit 3a912f8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
21 changes: 21 additions & 0 deletions scanpipe/pipes/rootfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import fnmatch
import logging
import os
from collections import Counter

from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Q
Expand Down Expand Up @@ -263,10 +264,30 @@ def scan_rootfs_for_system_packages(project, rootfs):
logger.info(f"rootfs location: {rootfs.location}")

installed_packages = rootfs.get_installed_packages(package_getter)

created_system_packages = []
seen_namespaces = []
for index, (purl, package) in enumerate(installed_packages):
logger.info(f"Creating package #{index}: {purl}")
created_system_packages.append(package)
seen_namespaces.append(package.namespace)
_create_system_package(project, purl, package)

namespace_counts = Counter(seen_namespaces)
# we overwite namespace only when there are multiple
# namespaces in the packages
if not len(namespace_counts.keys()) > 1:
return

most_seen_namespace = max(namespace_counts)
# if the distro_id is different from the namespace
# most seen in packages, we update all the package
# namespaces to the distro_id
if most_seen_namespace != distro_id:
for package in created_system_packages:
if package.namespace != distro_id:
package.update(namespace=distro_id)


def get_resource_with_md5(project, status):
"""
Expand Down
Binary file modified scanpipe/tests/data/basic-rootfs.tar.gz
Binary file not shown.
32 changes: 17 additions & 15 deletions scanpipe/tests/data/basic-rootfs_root_filesystems.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,26 @@
"distro": {
"os": "linux",
"architecture": null,
"name": "Debian GNU/Linux",
"version": "9 (stretch)",
"identifier": "debian",
"id_like": null,
"version_codename": null,
"version_id": "9",
"pretty_name": "Debian GNU/Linux 9 (stretch)",
"name": "Ubuntu",
"version": "22.04.3 LTS (Jammy Jellyfish)",
"identifier": "ubuntu",
"id_like": "debian",
"version_codename": "jammy",
"version_id": "22.04",
"pretty_name": "Ubuntu 22.04.3 LTS",
"cpe_name": null,
"home_url": "https://www.debian.org/",
"home_url": "https://www.ubuntu.com/",
"documentation_url": null,
"support_url": "https://www.debian.org/support",
"bug_report_url": "https://bugs.debian.org/",
"privacy_policy_url": null,
"support_url": "https://help.ubuntu.com/",
"bug_report_url": "https://bugs.launchpad.net/ubuntu/",
"privacy_policy_url": "https://www.ubuntu.com/legal/terms-and-policies/privacy-policy",
"build_id": null,
"variant": null,
"variant_id": null,
"logo": null,
"extra_data": {}
"extra_data": {
"UBUNTU_CODENAME": "jammy"
}
}
}
]
Expand Down Expand Up @@ -355,9 +357,9 @@
"status": "ignored-not-interesting",
"tag": "",
"extension": "",
"md5": "8589b473401e7ebcca5d97204405c887",
"sha1": "29420ee3cb176f64209d5beddc5713133fa7c2d4",
"sha256": "aa6ccd5b1ade06c11f679cc781bdd3158f1007266ea391ed98a1bbf365641fd4",
"md5": "fd30c92c61acbdebbd205e33534ac9bc",
"sha1": "46d2cadf740c18ed8a1b30dbd7f5eeee521e1e8f",
"sha256": "4bde2c39f541afb5ac413a03c8e5f57aa99b8fab304a62386dc0b16044cc0e2d",
"sha512": "",
"programming_language": "",
"is_binary": false,
Expand Down

0 comments on commit 3a912f8

Please sign in to comment.