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
-4
View File
@@ -1,4 +0,0 @@
package imgbom
// note: must be a single word, all lowercase
const LibraryName = "imgbom"
+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]
}
+11 -3
View File
@@ -2,19 +2,27 @@ package imgbom
import (
"github.com/anchore/imgbom/imgbom/analyzer"
"github.com/anchore/imgbom/imgbom/distro"
"github.com/anchore/imgbom/imgbom/logger"
"github.com/anchore/imgbom/imgbom/pkg"
"github.com/anchore/imgbom/imgbom/scope"
"github.com/anchore/imgbom/internal/log"
"github.com/anchore/stereoscope/pkg/image"
)
// TODO: add os detection results as return value
func IdentifyDistro(img *image.Image) (distro.Distro, error) {
return distro.Identify(img)
}
func CatalogImage(img *image.Image, o scope.Option) (*pkg.Catalog, error) {
s, err := scope.NewScope(img, o)
if err != nil {
return nil, err
}
// TODO: add OS detection here...
return analyzer.Analyze(s)
}
func SetLogger(logger logger.Logger) {
log.Log = logger
}
-10
View File
@@ -1,10 +0,0 @@
package imgbom
import (
"github.com/anchore/imgbom/imgbom/logger"
"github.com/anchore/imgbom/internal/log"
)
func SetLogger(logger logger.Logger) {
log.Log = logger
}