mirror of
https://github.com/anchore/syft.git
synced 2026-11-02 23:46:35 +01:00
add first distro support
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
package imgbom
|
||||
|
||||
// note: must be a single word, all lowercase
|
||||
const LibraryName = "imgbom"
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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")
|
||||
}
|
||||
@@ -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]
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user