add analyzer interface/controller and supporting package/catalog

This commit is contained in:
Alex Goodman 2020-05-13 10:13:48 -04:00
parent 11b2b1ab45
commit cb6555491c
No known key found for this signature in database
GPG key ID: 86E2870463D5E890
7 changed files with 91 additions and 1 deletions

View file

@ -21,6 +21,8 @@ bootstrap:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b .tmp/ v1.26.0
# install go-acc
GOPATH=$(shell realpath ${TEMPDIR}) GO111MODULE=off go get github.com/ory/go-acc
# cleanup
rm -rf $(TEMPDIR)/src
lint:
@printf '$(TITLE)Running linters$(RESET)\n'
@ -47,4 +49,4 @@ integration:
build-release:
go build -s -w -X main.version="$(git describe --tags --dirty --always)" \
-X main.commit="$(git describe --dirty --always)" \
-X main.buildTime="$(date --rfc-3339=seconds --utc)"
-X main.buildTime="$(date --rfc-3339=seconds --utc)"

View file

@ -0,0 +1,14 @@
package analyzer
import (
"github.com/anchore/imgbom/imgbom/pkg"
"github.com/anchore/imgbom/imgbom/scope"
"github.com/anchore/stereoscope/pkg/file"
)
type Analyzer interface {
SelectFiles(scope.Scope) []file.Reference
// NOTE: one of the errors which is returned is "IterationNeeded", which indicates to the driver to
// continue with another Select/Analyze pass
Analyze(pkg.CatalogWriter, map[file.Reference]string) error
}

View file

@ -0,0 +1,21 @@
package analyzer
var controllerInstance controller
func init() {
controllerInstance = controller{
analyzers: make([]Analyzer, 0),
}
}
type controller struct {
analyzers []Analyzer
}
func (c *controller) add(a Analyzer) {
c.analyzers = append(c.analyzers, a)
}
func Add(a Analyzer) {
controllerInstance.add(a)
}

18
imgbom/pkg/catalog.go Normal file
View file

@ -0,0 +1,18 @@
package pkg
type Catalog struct {
// TODO: catalog by package ID for potential indexing
catalog map[Type][]Package
}
type CatalogWriter interface {
Add(Package) error
}
func (c *Catalog) Add(p Package) {
_, ok := c.catalog[p.Type]
if !ok {
c.catalog[p.Type] = make([]Package, 0)
}
c.catalog[p.Type] = append(c.catalog[p.Type], p)
}

16
imgbom/pkg/package.go Normal file
View file

@ -0,0 +1,16 @@
package pkg
import "github.com/anchore/stereoscope/pkg/file"
// TODO: add package ID (random/incremental)
type Package struct {
Name string
Version string
Source []file.Reference
Licenses []string
Type Type
Metadata interface{}
}
// TODO: stringer...

17
imgbom/pkg/type.go Normal file
View file

@ -0,0 +1,17 @@
package pkg
const (
UnknownPkg uint = iota
ApkPkg
DebPkg
JavaPkg
NodePkg
PacmanPkg
PythonPkg
RpmPkg
RubyPkg
)
type Type uint
// TODO: stringer...

View file

@ -10,6 +10,7 @@ import (
type Scope struct {
Option Option
Trees []*tree.FileTree
Image *image.Image
}
func NewScope(img *image.Image, option Option) (Scope, error) {
@ -40,5 +41,6 @@ func NewScope(img *image.Image, option Option) (Scope, error) {
return Scope{
Option: option,
Trees: trees,
Image: img,
}, nil
}