mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 08:23:15 +01:00
add analyzer interface/controller and supporting package/catalog
This commit is contained in:
parent
11b2b1ab45
commit
cb6555491c
4
Makefile
4
Makefile
@ -21,6 +21,8 @@ bootstrap:
|
|||||||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b .tmp/ v1.26.0
|
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b .tmp/ v1.26.0
|
||||||
# install go-acc
|
# install go-acc
|
||||||
GOPATH=$(shell realpath ${TEMPDIR}) GO111MODULE=off go get github.com/ory/go-acc
|
GOPATH=$(shell realpath ${TEMPDIR}) GO111MODULE=off go get github.com/ory/go-acc
|
||||||
|
# cleanup
|
||||||
|
rm -rf $(TEMPDIR)/src
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
@printf '$(TITLE)Running linters$(RESET)\n'
|
@printf '$(TITLE)Running linters$(RESET)\n'
|
||||||
@ -47,4 +49,4 @@ integration:
|
|||||||
build-release:
|
build-release:
|
||||||
go build -s -w -X main.version="$(git describe --tags --dirty --always)" \
|
go build -s -w -X main.version="$(git describe --tags --dirty --always)" \
|
||||||
-X main.commit="$(git describe --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)"
|
||||||
|
|||||||
14
imgbom/analyzer/analyzer.go
Normal file
14
imgbom/analyzer/analyzer.go
Normal 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
|
||||||
|
}
|
||||||
21
imgbom/analyzer/controller.go
Normal file
21
imgbom/analyzer/controller.go
Normal 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
18
imgbom/pkg/catalog.go
Normal 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
16
imgbom/pkg/package.go
Normal 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
17
imgbom/pkg/type.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package pkg
|
||||||
|
|
||||||
|
const (
|
||||||
|
UnknownPkg uint = iota
|
||||||
|
ApkPkg
|
||||||
|
DebPkg
|
||||||
|
JavaPkg
|
||||||
|
NodePkg
|
||||||
|
PacmanPkg
|
||||||
|
PythonPkg
|
||||||
|
RpmPkg
|
||||||
|
RubyPkg
|
||||||
|
)
|
||||||
|
|
||||||
|
type Type uint
|
||||||
|
|
||||||
|
// TODO: stringer...
|
||||||
@ -10,6 +10,7 @@ import (
|
|||||||
type Scope struct {
|
type Scope struct {
|
||||||
Option Option
|
Option Option
|
||||||
Trees []*tree.FileTree
|
Trees []*tree.FileTree
|
||||||
|
Image *image.Image
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewScope(img *image.Image, option Option) (Scope, error) {
|
func NewScope(img *image.Image, option Option) (Scope, error) {
|
||||||
@ -40,5 +41,6 @@ func NewScope(img *image.Image, option Option) (Scope, error) {
|
|||||||
return Scope{
|
return Scope{
|
||||||
Option: option,
|
Option: option,
|
||||||
Trees: trees,
|
Trees: trees,
|
||||||
|
Image: img,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user