Skip to content

Commit

Permalink
alpine: support edge vulnerabilities
Browse files Browse the repository at this point in the history
Signed-off-by: RTann <[email protected]>
  • Loading branch information
RTann committed Nov 29, 2023
1 parent 25d5e29 commit faffb8e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 14 deletions.
7 changes: 3 additions & 4 deletions alpine/distributionscanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ const (
scannerName = "alpine"
scannerVersion = "3"
scannerKind = "distribution"
)

const (
issuePath = `etc/issue`

edgeVersion = `edge`
edgePrettyName = `Alpine Linux edge`
)

Expand Down Expand Up @@ -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`],
Expand Down Expand Up @@ -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,

Check warning on line 149 in alpine/distributionscanner.go

View check run for this annotation

Codecov / codecov/patch

alpine/distributionscanner.go#L149

Added line #L149 was not covered by tests
PrettyName: edgePrettyName,
}, nil
}
Expand Down
4 changes: 2 additions & 2 deletions alpine/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand Down Expand Up @@ -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,
Expand Down
41 changes: 36 additions & 5 deletions alpine/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,49 @@ 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 (
distName = "Alpine Linux"
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

Check warning on line 50 in alpine/release.go

View check run for this annotation

Codecov / codecov/patch

alpine/release.go#L49-L50

Added lines #L49 - L50 were not covered by tests
}

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)
Expand All @@ -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]) }
6 changes: 3 additions & 3 deletions alpine/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
})
}
Expand Down

0 comments on commit faffb8e

Please sign in to comment.