update sterescope + add json presenter

This commit is contained in:
Alex Goodman
2020-05-20 18:29:06 -04:00
parent 28cc9b3dc1
commit 17b4b26fbb
21 changed files with 372 additions and 67 deletions
+31 -5
View File
@@ -4,19 +4,45 @@ package pkg
type Catalog struct {
// TODO: catalog by package ID for potential indexing
Packages map[Type][]Package
packages map[Type][]Package
}
func NewCatalog() Catalog {
return Catalog{
Packages: make(map[Type][]Package),
packages: make(map[Type][]Package),
}
}
func (c *Catalog) Add(p Package) {
_, ok := c.Packages[p.Type]
_, ok := c.packages[p.Type]
if !ok {
c.Packages[p.Type] = make([]Package, 0)
c.packages[p.Type] = make([]Package, 0)
}
c.Packages[p.Type] = append(c.Packages[p.Type], p)
c.packages[p.Type] = append(c.packages[p.Type], p)
}
func (c *Catalog) Enumerate(types ...Type) <-chan Package {
channel := make(chan Package)
go func() {
defer close(channel)
for ty, packages := range c.packages {
if len(types) != 0 {
found := false
typeCheck:
for _, t := range types {
if t == ty {
found = true
break typeCheck
}
}
if !found {
continue
}
}
for _, p := range packages {
channel <- p
}
}
}()
return channel
}
-6
View File
@@ -1,6 +0,0 @@
package pkg
// TODO: delete me
type DummyPackage struct {
Extra string
}
+1
View File
@@ -4,6 +4,7 @@ import "github.com/anchore/stereoscope/pkg/file"
// TODO: add package ID (random/incremental)
// TODO: add field to trace which analyzer detected this
type Package struct {
Name string
Version string
+18 -1
View File
@@ -14,4 +14,21 @@ const (
type Type uint
// TODO: stringer...
var typeStr = []string{
"UnknownPackage",
"apk",
"deb",
"java",
"node",
"pacman",
"python",
"rpm",
"ruby",
}
func (t Type) String() string {
if int(t) >= len(typeStr) {
return typeStr[0]
}
return typeStr[t]
}