add first distro support

This commit is contained in:
Alex Goodman
2020-06-01 10:46:06 -04:00
parent 1f272c2bda
commit 45fbd05cf9
9 changed files with 116 additions and 17 deletions
+31
View File
@@ -0,0 +1,31 @@
package distro
import (
"fmt"
hashiVer "github.com/hashicorp/go-version"
)
type Distro struct {
Type Type
Version *hashiVer.Version
}
func NewDistro(t Type, ver string) (Distro, error) {
verObj, err := hashiVer.NewVersion(ver)
if err != nil {
return Distro{}, fmt.Errorf("could not create distro version: %w", err)
}
return Distro{
Type: t,
Version: verObj,
}, nil
}
func (d Distro) MajorVersion() int {
return d.Version.Segments()[0]
}
func (d Distro) String() string {
return fmt.Sprintf("%s %s", d.Type, d.Version)
}
+11
View File
@@ -0,0 +1,11 @@
package distro
import (
"github.com/anchore/stereoscope/pkg/image"
)
func Identify(img *image.Image) (Distro, error) {
// TODO: implement me based off of https://github.com/anchore/anchore-engine/blob/78b23d7e8f007005c070673405b5e23730a660e0/anchore_engine/analyzers/utils.py#L131
return NewDistro(UnknownDistro, "0.0.0")
}
+52
View File
@@ -0,0 +1,52 @@
package distro
const (
UnknownDistro Type = iota
Debian
// Ubuntu
// RedHat
// CentOS
// Fedora
// Alpine
// Busybox
// AmazonLinux
// OracleLinux
// ArchLinux
)
type Type int
var distroStr = []string{
"UnknownDistro",
"Debian",
// "Ubuntu",
// "RedHat",
// "CentOS",
// "Fedora",
// "Alpine",
// "Busybox",
// "AmazonLinux",
// "OracleLinux",
// "ArchLinux",
}
var All = []Type{
Debian,
// Ubuntu,
// RedHat,
// CentOS,
// Fedora,
// Alpine,
// Busybox,
// AmazonLinux,
// OracleLinux,
// ArchLinux,
}
func (t Type) String() string {
if int(t) >= len(distroStr) || t < 0 {
return distroStr[0]
}
return distroStr[t]
}