-
Notifications
You must be signed in to change notification settings - Fork 518
/
distribution.go
47 lines (40 loc) · 1.24 KB
/
distribution.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
package models
import (
"github.com/anchore/grype/grype/distro"
"github.com/anchore/grype/internal/log"
"github.com/anchore/syft/syft/linux"
)
// distribution provides information about a detected Linux distribution.
type distribution struct {
Name string `json:"name"` // Name of the Linux distribution
Version string `json:"version"` // Version of the Linux distribution (major or major.minor version)
IDLike []string `json:"idLike"` // the ID_LIKE field found within the /etc/os-release file
}
// newDistribution creates a struct with the Linux distribution to be represented in JSON.
func newDistribution(r *linux.Release) distribution {
if r == nil {
return distribution{}
}
// attempt to use the strong distro type (like the matchers do)
d, err := distro.NewFromRelease(*r)
if err != nil {
log.Warnf("unable to determine linux distribution: %+v", err)
// as a fallback use the raw release information
return distribution{
Name: r.ID,
Version: r.VersionID,
IDLike: cleanIDLike(r.IDLike),
}
}
return distribution{
Name: d.Name(),
Version: d.FullVersion(),
IDLike: cleanIDLike(d.IDLike),
}
}
func cleanIDLike(idLike []string) []string {
if idLike == nil {
return make([]string, 0)
}
return idLike
}