-
Notifications
You must be signed in to change notification settings - Fork 79
/
release.go
72 lines (58 loc) · 1.68 KB
/
release.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package alpine
import (
"fmt"
"sync"
"github.com/quay/claircore"
)
// Alpine linux has patch releases but their security database
// aggregates security information by major release. We choose
// to normalize detected distributions into major.minor releases and
// parse vulnerabilities into major.minor releases
// 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
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 stableRelease) Distribution() *claircore.Distribution {
// Dirty hack to keyify the release structure.
k := int64(r[0]<<32) | int64(r[1])
v, ok := relMap.Load(k)
if !ok {
v, _ = relMap.LoadOrStore(k, &claircore.Distribution{
Name: distName,
DID: distID,
VersionID: fmt.Sprintf("%d.%d", r[0], r[1]),
PrettyName: fmt.Sprintf("Alpine Linux v%d.%d", r[0], r[1]),
})
}
return v.(*claircore.Distribution)
}
func (r stableRelease) String() string { return fmt.Sprintf("v%d.%d", r[0], r[1]) }