diff --git a/alpine/distributionscanner.go b/alpine/distributionscanner.go index b8ad4e8d4..1f95bc020 100644 --- a/alpine/distributionscanner.go +++ b/alpine/distributionscanner.go @@ -26,11 +26,10 @@ const ( scannerName = "alpine" scannerVersion = "3" scannerKind = "distribution" -) -const ( issuePath = `etc/issue` + edgeVersion = `edge` edgePrettyName = `Alpine Linux edge` ) @@ -114,7 +113,7 @@ func readOSRelease(ctx context.Context, sys fs.FS) (*claircore.Distribution, err } v := vid[:idx] if m[`PRETTY_NAME`] == edgePrettyName { - v = "edge" + v = edgeVersion } return &claircore.Distribution{ Name: m[`NAME`], @@ -147,7 +146,7 @@ func readIssue(ctx context.Context, sys fs.FS) (*claircore.Distribution, error) return &claircore.Distribution{ Name: `Alpine Linux`, DID: `alpine`, - Version: `edge`, + Version: edgeVersion, PrettyName: edgePrettyName, }, nil } diff --git a/alpine/parser_test.go b/alpine/parser_test.go index c13df0f6a..c03cf30ed 100644 --- a/alpine/parser_test.go +++ b/alpine/parser_test.go @@ -13,7 +13,7 @@ import ( "github.com/quay/claircore" ) -var dist310 = release{3, 10}.Distribution() +var dist310 = stableRelease{3, 10}.Distribution() var v3_10CommunityTruncatedVulns = []*claircore.Vulnerability{ { @@ -136,7 +136,7 @@ func TestParser(t *testing.T) { expected []*claircore.Vulnerability }{ { - release: release{3, 10}, + release: stableRelease{3, 10}, repo: "community", testFile: "fetch/v3.10/community.json", expected: v3_10CommunityTruncatedVulns, diff --git a/alpine/release.go b/alpine/release.go index a5f103a43..83a98eb03 100644 --- a/alpine/release.go +++ b/alpine/release.go @@ -12,8 +12,22 @@ import ( // to normalize detected distributions into major.minor releases and // parse vulnerabilities into major.minor releases -// release is a particular release of the Alpine linux distribution -type release [2]int +// release represents a particular release of the Alpine Linux distribution +type release interface { + Distribution() *claircore.Distribution + String() string +} + +var ( + _ release = (*edgeRelease)(nil) + _ release = (*stableRelease)(nil) +) + +// edgeRelease is the Alpine Linux edge distribution. +type edgeRelease struct{} + +// stableRelease is a particular stable release of the Alpine Linux distribution. +type stableRelease [2]int // Common os-release fields applicable for *claircore.Distribution usage. const ( @@ -21,9 +35,26 @@ const ( distID = "alpine" ) -var relMap sync.Map +var ( + relMap sync.Map + + edgeDist = &claircore.Distribution{ + Name: distName, + DID: distID, + VersionID: edgeVersion, + PrettyName: edgePrettyName, + } +) + +func (edgeRelease) Distribution() *claircore.Distribution { + return edgeDist +} + +func (edgeRelease) String() string { + return edgeVersion +} -func (r release) Distribution() *claircore.Distribution { +func (r stableRelease) Distribution() *claircore.Distribution { // Dirty hack to keyify the release structure. k := int64(r[0]<<32) | int64(r[1]) v, ok := relMap.Load(k) @@ -38,4 +69,4 @@ func (r release) Distribution() *claircore.Distribution { return v.(*claircore.Distribution) } -func (r release) String() string { return fmt.Sprintf("v%d.%d", r[0], r[1]) } +func (r stableRelease) String() string { return fmt.Sprintf("v%d.%d", r[0], r[1]) } diff --git a/alpine/updater.go b/alpine/updater.go index 1dc9706f1..c5951cb9a 100644 --- a/alpine/updater.go +++ b/alpine/updater.go @@ -122,7 +122,7 @@ Major: } Minor: for ; ; min++ { - r := release{maj, min} + r := stableRelease{maj, min} u, err := f.base.Parse(r.String() + "/") if err != nil { return s, fmt.Errorf("alpine: unable to construct request: %w", err) @@ -153,7 +153,7 @@ Major: } } } - for _, r := range todo { + for _, r := range append(todo, edgeRelease{}) { for _, n := range []string{`main`, `community`} { u, err := f.base.Parse(path.Join(r.String(), n+".json")) if err != nil { @@ -182,7 +182,7 @@ Major: } s.Add(&updater{ repo: n, - release: r, // NB: Safe to copy because it's an array. + release: r, // NB: Safe to copy because it's an array or empty struct. url: u.String(), }) }