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

Update osrelease and redhatrelease detectors to detect Rocky Linux as… #745

Merged
merged 1 commit into from
Oct 6, 2022
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
1 change: 1 addition & 0 deletions ext/featurens/osrelease/osrelease.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var (
"etc/fedora-release",
"etc/oracle-release",
"etc/redhat-release",
"etc/rocky-release",
"usr/lib/centos-release",
}

Expand Down
12 changes: 11 additions & 1 deletion ext/featurens/redhatrelease/redhatrelease.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ var (
oracleReleaseRegexp = regexp.MustCompile(`(?P<os>Oracle) (Linux Server release) (?P<version>[\d]+)`)
centosReleaseRegexp = regexp.MustCompile(`(?P<os>[^\s]*) (Linux release|release) (?P<version>[\d]+)`)
redhatReleaseRegexp = regexp.MustCompile(`(?P<os>Red Hat Enterprise Linux) (Client release|Server release|Workstation release|release) (?P<version>[\d]+)`)
rockyReleaseRegexp = regexp.MustCompile(`(?P<os>Rocky) (Linux release) (?P<version>[\d]+)`)

// RequiredFilenames defines the names of the files required to identify the RHEL-based release.
RequiredFilenames = []string{"etc/oracle-release", "etc/centos-release", "etc/redhat-release", "etc/system-release"}
RequiredFilenames = []string{"etc/oracle-release", "etc/centos-release", "etc/redhat-release", "etc/rocky-release", "etc/system-release"}
)

type detector struct{}
Expand Down Expand Up @@ -88,6 +89,15 @@ func (d detector) Detect(files analyzer.Files, opts *featurens.DetectorOptions)
return namespace
}

// Attempt to match Rocky.
r = rockyReleaseRegexp.FindStringSubmatch(string(f.Contents))
if len(r) == 4 {
return &database.Namespace{
Name: strings.ToLower(r[1]) + ":" + r[3],
VersionFormat: rpm.ParserName,
}
}

// Attempt to match CentOS.
r = centosReleaseRegexp.FindStringSubmatch(string(f.Contents))
if len(r) == 4 {
Expand Down
12 changes: 12 additions & 0 deletions ext/featurens/redhatrelease/redhatrelease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ func TestDetector(t *testing.T) {
"etc/system-release": {Contents: []byte(`CentOS Linux release 7.1.1503 (Core)`)},
}),
},
{
ExpectedNamespace: &database.Namespace{Name: "rocky:8", VersionFormat: rpm.ParserName},
Files: tarutil.CreateNewLayerFiles(map[string]analyzer.FileData{
"etc/rocky-release": {Contents: []byte(`Rocky Linux release 8.6 (Green Obsidian)`)},
}),
},
{
ExpectedNamespace: &database.Namespace{Name: "rocky:9", VersionFormat: rpm.ParserName},
Files: tarutil.CreateNewLayerFiles(map[string]analyzer.FileData{
"etc/rocky-release": {Contents: []byte(`Rocky Linux release 9.0 (Blue Onyx)`)},
}),
},
{
ExpectedNamespace: nil,
Files: tarutil.CreateNewLayerFiles(nil),
Expand Down