diff --git a/Makefile b/Makefile index 8d4a6b8f5..3f620be55 100644 --- a/Makefile +++ b/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 # 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)" \ No newline at end of file + -X main.buildTime="$(date --rfc-3339=seconds --utc)" diff --git a/imgbom/analyzer/analyzer.go b/imgbom/analyzer/analyzer.go new file mode 100644 index 000000000..4d5ff3ec3 --- /dev/null +++ b/imgbom/analyzer/analyzer.go @@ -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 +} diff --git a/imgbom/analyzer/controller.go b/imgbom/analyzer/controller.go new file mode 100644 index 000000000..e144d0e97 --- /dev/null +++ b/imgbom/analyzer/controller.go @@ -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) +} \ No newline at end of file diff --git a/imgbom/pkg/catalog.go b/imgbom/pkg/catalog.go new file mode 100644 index 000000000..0504a6888 --- /dev/null +++ b/imgbom/pkg/catalog.go @@ -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) +} \ No newline at end of file diff --git a/imgbom/pkg/package.go b/imgbom/pkg/package.go new file mode 100644 index 000000000..bfaec824b --- /dev/null +++ b/imgbom/pkg/package.go @@ -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... \ No newline at end of file diff --git a/imgbom/pkg/type.go b/imgbom/pkg/type.go new file mode 100644 index 000000000..912a8829e --- /dev/null +++ b/imgbom/pkg/type.go @@ -0,0 +1,17 @@ +package pkg + +const ( + UnknownPkg uint = iota + ApkPkg + DebPkg + JavaPkg + NodePkg + PacmanPkg + PythonPkg + RpmPkg + RubyPkg +) + +type Type uint + +// TODO: stringer... \ No newline at end of file diff --git a/imgbom/scope/scope.go b/imgbom/scope/scope.go index f5833a6f2..a1cbff097 100644 --- a/imgbom/scope/scope.go +++ b/imgbom/scope/scope.go @@ -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 }