Skip to content

Commit 6bb686c

Browse files
committed
✨ Support rpm modules for AlmaLinux
Related to #6391 Signed-off-by: Christian Zunker <christian@mondoo.com>
1 parent 7f8e14b commit 6bb686c

File tree

3 files changed

+100
-2
lines changed

3 files changed

+100
-2
lines changed

providers/os/resources/packages/rpm_packages.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"strconv"
1414
"strings"
1515

16+
"go.mondoo.com/cnquery/v12/providers/core/resources/versions/semver"
1617
"go.mondoo.com/cnquery/v12/providers/os/resources/cpe"
1718
"go.mondoo.com/cnquery/v12/providers/os/resources/purl"
1819

@@ -374,12 +375,22 @@ func (spm *SusePkgManager) Available() (map[string]PackageUpdate, error) {
374375
// Not every rpm based distro supports modules.
375376
// E.g. SLES and Amazon Linux 2023 do not support modularity.
376377
// Amazon Linux 2 supports modularity.
378+
// No more modules starting with RHEL v10: https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/considerations_in_adopting_rhel_10/application-streams
377379
func modularitySupportedByPlatform(platform *inventory.Platform) bool {
378380
supported := false
379381

380382
switch platform.Name {
381-
case "oraclelinux":
382-
supported = true
383+
case "oraclelinux", "almalinux":
384+
vParser := semver.Parser{}
385+
cmp, err := vParser.Compare(platform.Version, "10")
386+
if err != nil {
387+
return false
388+
}
389+
if cmp < 0 {
390+
supported = true
391+
} else {
392+
supported = false
393+
}
383394
}
384395

385396
return supported

providers/os/resources/packages/rpm_packages_test.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,3 +428,75 @@ func TestOracleParser(t *testing.T) {
428428
fPkg = findPkg(m, p.Name)
429429
assert.Equal(t, p.PUrl, fPkg.PUrl)
430430
}
431+
432+
func TestAlmaLinuxParser(t *testing.T) {
433+
mock, err := mock.New(0, &inventory.Asset{}, mock.WithPath("./testdata/packages_almalinux.toml"))
434+
if err != nil {
435+
t.Fatal(err)
436+
}
437+
438+
pf := &inventory.Platform{
439+
Name: "almalinux",
440+
Version: "8.10",
441+
Arch: "x86_64",
442+
Family: []string{"redhat", "linux", "unix", "os"},
443+
Labels: map[string]string{
444+
"distro-id": "almalinux",
445+
},
446+
}
447+
448+
c, err := mock.RunCommand("rpm -qa --queryformat '%{NAME} %{EPOCHNUM}:%{VERSION}-%{RELEASE} %{ARCH}__%{VENDOR}__%{SUMMARY}__%{MODULARITYLABEL}\\n'")
449+
if err != nil {
450+
t.Fatal(err)
451+
}
452+
453+
m := ParseRpmPackages(pf, c.Stdout)
454+
require.Equal(t, 6, len(m))
455+
456+
p := Package{
457+
Name: "php-cli",
458+
PUrl: "pkg:rpm/almalinux/php-cli@7.4.33-2.module_el8.10.0%2B3935%2B28808425?arch=aarch64&distro=almalinux-8.10&rpmmod=php%3A7.4%3A8100020241212065510%3Aeb0869e2",
459+
}
460+
fPkg := findPkg(m, p.Name)
461+
assert.Equal(t, p.PUrl, fPkg.PUrl)
462+
}
463+
464+
func TestModularitySupportedByPlatform(t *testing.T) {
465+
tests := []struct {
466+
name string
467+
platform *inventory.Platform
468+
want bool
469+
}{
470+
{
471+
name: "AlmaLinux",
472+
platform: &inventory.Platform{Name: "almalinux", Version: "8.10", Arch: "x86_64"},
473+
want: true,
474+
},
475+
{
476+
name: "OracleLinux",
477+
platform: &inventory.Platform{Name: "oraclelinux", Version: "9", Arch: "x86_64"},
478+
want: true,
479+
},
480+
{
481+
name: "AlmaLinux",
482+
platform: &inventory.Platform{Name: "almalinux", Version: "10", Arch: "x86_64"},
483+
want: false,
484+
},
485+
{
486+
name: "OracleLinux",
487+
platform: &inventory.Platform{Name: "oraclelinux", Version: "10.1", Arch: "x86_64"},
488+
want: false,
489+
},
490+
{
491+
name: "AmazonLinux",
492+
platform: &inventory.Platform{Name: "amazonlinux", Version: "2", Arch: "x86_64"},
493+
want: false,
494+
},
495+
}
496+
497+
for _, tt := range tests {
498+
t.Run(tt.name, func(t *testing.T) {
499+
require.Equal(t, tt.want, modularitySupportedByPlatform(tt.platform))
500+
})
501+
}
502+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[commands."command -v rpm"]
2+
stdout="/usr/bin/rpm"
3+
4+
[commands."rpm -E '%{_dbpath}'"]
5+
stdout="/var/lib/rpm"
6+
7+
[commands."rpm -qa --queryformat '%{NAME} %{EPOCHNUM}:%{VERSION}-%{RELEASE} %{ARCH}__%{VENDOR}__%{SUMMARY}__%{MODULARITYLABEL}\\n'"]
8+
stdout="""
9+
php-xml 0:7.4.33-2.module_el8.10.0+3935+28808425 aarch64__AlmaLinux__A module for PHP applications which use XML__php:7.4:8100020241212065510:eb0869e2
10+
php-mbstring 0:7.4.33-2.module_el8.10.0+3935+28808425 aarch64__AlmaLinux__A module for PHP applications which need multi-byte string handling__php:7.4:8100020241212065510:eb0869e2
11+
php-common 0:7.4.33-2.module_el8.10.0+3935+28808425 aarch64__AlmaLinux__Common files for PHP__php:7.4:8100020241212065510:eb0869e2
12+
php-cli 0:7.4.33-2.module_el8.10.0+3935+28808425 aarch64__AlmaLinux__Command-line interface for PHP__php:7.4:8100020241212065510:eb0869e2
13+
php-fpm 0:7.4.33-2.module_el8.10.0+3935+28808425 aarch64__AlmaLinux__PHP FastCGI Process Manager__php:7.4:8100020241212065510:eb0869e2
14+
php-json 0:7.4.33-2.module_el8.10.0+3935+28808425 aarch64__AlmaLinux__JavaScript Object Notation extension for PHP__php:7.4:8100020241212065510:eb0869e2
15+
"""

0 commit comments

Comments
 (0)