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 namespace detection from distro IDs #3770

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
30 changes: 20 additions & 10 deletions src/packagedcode/distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,34 @@ class EtcOsReleaseHandler(models.NonAssemblableDatafileHandler):
@classmethod
def parse(cls, location, package_only=False):
distro = Distro.from_os_release_file(location)
distro_identifier = distro.identifier
distro_identifier = None
if distro:
distro_identifier = distro.identifier

if not distro_identifier:
return

pretty_name = distro.pretty_name and distro.pretty_name.lower() or ''

# TODO: It is misleading to use package data fields
# name and namespace to store distro/os infomration,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

infomration -> information

# we should consider using extra_data fields instead.

if distro_identifier == 'debian':
namespace = 'debian'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure there is no namespace?

name = 'debian'

if 'distroless' in pretty_name:
name = 'distroless'
elif pretty_name.startswith('debian'):
name = 'distroless'
namespace = 'distroless'
else:
namespace = 'debian'

elif distro_identifier == 'ubuntu' and distro.id_like == 'debian':
namespace = 'debian'
name = 'ubuntu'
namespace = 'ubuntu'
name = 'debian'

elif distro_identifier.startswith('fedora') or distro.id_like == 'fedora':
namespace = distro_identifier
name = distro.id_like or distro_identifier
elif distro_identifier.startswith('fedora') or distro.id_like == 'fedora':
name = distro_identifier or distro.id_like
namespace = distro.id_like

else:
# FIXME: this needs to be seriously updated
Expand Down
2 changes: 1 addition & 1 deletion src/packagedcode/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,7 @@ def get_distro_identifier_rootfs(cls, root_resource, codebase):
# there can be only one distro
distro = os_release_res.package_data and os_release_res.package_data[0]
if distro:
identifier = distro.get("name")
identifier = distro.get("namespace")
break

return identifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@
"package_data": [
{
"type": "linux-distro",
"namespace": "debian",
"name": "ubuntu",
"namespace": "ubuntu",
"name": "debian",
"version": "22.04",
"qualifiers": {},
"subpath": null,
Expand Down Expand Up @@ -393,7 +393,7 @@
"repository_download_url": null,
"api_data_url": null,
"datasource_id": "etc_os_release",
"purl": "pkg:linux-distro/debian/ubuntu@22.04"
"purl": "pkg:linux-distro/ubuntu/debian@22.04"
}
],
"for_packages": [],
Expand Down
34 changes: 17 additions & 17 deletions tests/packagedcode/data/plugin/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,41 @@ Package type: about
description: AboutCode ABOUT file
path_patterns: '*.ABOUT'
--------------------------------------------
Package type: alpine
Package type: android
datasource_id: android_apk
documentation URL: https://en.wikipedia.org/wiki/Apk_(file_format)
primary language: Java
description: Android application package
path_patterns: '*.apk'
--------------------------------------------
Package type: android_lib
datasource_id: android_aar_library
documentation URL: https://developer.android.com/studio/projects/android-library
primary language: Java
description: Android library archive
path_patterns: '*.aar'
--------------------------------------------
Package type: apk
datasource_id: alpine_apk_archive
documentation URL: https://wiki.alpinelinux.org/wiki/Alpine_package_format
primary language: None
description: Alpine Linux .apk package archive
path_patterns: '*.apk'
--------------------------------------------
Package type: alpine
Package type: apk
datasource_id: alpine_apkbuild
documentation URL: https://wiki.alpinelinux.org/wiki/APKBUILD_Reference
primary language: None
description: Alpine Linux APKBUILD package script
path_patterns: '*APKBUILD'
--------------------------------------------
Package type: alpine
Package type: apk
datasource_id: alpine_installed_db
documentation URL: None
primary language: None
description: Alpine Linux installed package database
path_patterns: '*lib/apk/db/installed'
--------------------------------------------
Package type: android
datasource_id: android_apk
documentation URL: https://en.wikipedia.org/wiki/Apk_(file_format)
primary language: Java
description: Android application package
path_patterns: '*.apk'
--------------------------------------------
Package type: android_lib
datasource_id: android_aar_library
documentation URL: https://developer.android.com/studio/projects/android-library
primary language: Java
description: Android library archive
path_patterns: '*.aar'
--------------------------------------------
Package type: autotools
datasource_id: autotools_configure
documentation URL: https://www.gnu.org/software/automake/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203694,8 +203694,8 @@
"package_data": [
{
"type": "linux-distro",
"namespace": "fedora-modular",
"name": "fedora",
"namespace": "fedora",
"name": "fedora-modular",
"version": "26",
"qualifiers": {},
"subpath": null,
Expand Down Expand Up @@ -203732,7 +203732,7 @@
"repository_download_url": null,
"api_data_url": null,
"datasource_id": "etc_os_release",
"purl": "pkg:linux-distro/fedora-modular/fedora@26"
"purl": "pkg:linux-distro/fedora/fedora-modular@26"
}
],
"for_packages": [
Expand Down
Loading