mirror of
https://github.com/anchore/syft.git
synced 2025-11-19 17:33:18 +01:00
export event monitor structs but not behavior
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
parent
1279bd0b08
commit
3308079158
@ -4,16 +4,16 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/anchore/syft/internal/bus"
|
||||||
|
"github.com/anchore/syft/syft/event"
|
||||||
|
"github.com/wagoodman/go-partybus"
|
||||||
|
"github.com/wagoodman/go-progress"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/anchore/client-go/pkg/external"
|
"github.com/anchore/client-go/pkg/external"
|
||||||
"github.com/anchore/stereoscope/pkg/image"
|
"github.com/anchore/stereoscope/pkg/image"
|
||||||
"github.com/anchore/syft/internal/bus"
|
|
||||||
"github.com/anchore/syft/syft/event"
|
|
||||||
"github.com/anchore/syft/syft/sbom"
|
"github.com/anchore/syft/syft/sbom"
|
||||||
"github.com/antihax/optional"
|
"github.com/antihax/optional"
|
||||||
"github.com/wagoodman/go-partybus"
|
|
||||||
"github.com/wagoodman/go-progress"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ImportConfig struct {
|
type ImportConfig struct {
|
||||||
|
|||||||
@ -1,28 +0,0 @@
|
|||||||
package monitor
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/anchore/syft/internal/bus"
|
|
||||||
"github.com/anchore/syft/syft/event"
|
|
||||||
"github.com/wagoodman/go-partybus"
|
|
||||||
"github.com/wagoodman/go-progress"
|
|
||||||
)
|
|
||||||
|
|
||||||
func FileDigesterMonitor(locations int64) (*progress.Stage, *progress.Manual) {
|
|
||||||
stage := &progress.Stage{}
|
|
||||||
prog := &progress.Manual{
|
|
||||||
Total: locations,
|
|
||||||
}
|
|
||||||
|
|
||||||
bus.Publish(partybus.Event{
|
|
||||||
Type: event.FileDigestsCatalogerStarted,
|
|
||||||
Value: struct {
|
|
||||||
progress.Stager
|
|
||||||
progress.Progressable
|
|
||||||
}{
|
|
||||||
Stager: progress.Stager(stage),
|
|
||||||
Progressable: prog,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
return stage, prog
|
|
||||||
}
|
|
||||||
@ -1,9 +1,6 @@
|
|||||||
package monitor
|
package monitor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/anchore/syft/internal/bus"
|
|
||||||
"github.com/anchore/syft/syft/event"
|
|
||||||
"github.com/wagoodman/go-partybus"
|
|
||||||
"github.com/wagoodman/go-progress"
|
"github.com/wagoodman/go-progress"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -12,18 +9,3 @@ type PackageCatalogerMonitor struct {
|
|||||||
FilesProcessed progress.Monitorable // the number of files selected and contents analyzed from all registered catalogers
|
FilesProcessed progress.Monitorable // the number of files selected and contents analyzed from all registered catalogers
|
||||||
PackagesDiscovered progress.Monitorable // the number of packages discovered from all registered catalogers
|
PackagesDiscovered progress.Monitorable // the number of packages discovered from all registered catalogers
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPackageCatalogerMonitor creates a new PackageCatalogerMonitor object and publishes the object on the bus as a PackageCatalogerStarted event.
|
|
||||||
func NewPackageCatalogerMonitor() (*progress.Manual, *progress.Manual) {
|
|
||||||
filesProcessed := progress.Manual{}
|
|
||||||
packagesDiscovered := progress.Manual{}
|
|
||||||
|
|
||||||
bus.Publish(partybus.Event{
|
|
||||||
Type: event.PackageCatalogerStarted,
|
|
||||||
Value: PackageCatalogerMonitor{
|
|
||||||
FilesProcessed: progress.Monitorable(&filesProcessed),
|
|
||||||
PackagesDiscovered: progress.Monitorable(&packagesDiscovered),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
return &filesProcessed, &packagesDiscovered
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,9 +1,6 @@
|
|||||||
package monitor
|
package monitor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/anchore/syft/internal/bus"
|
|
||||||
"github.com/anchore/syft/syft/event"
|
|
||||||
"github.com/wagoodman/go-partybus"
|
|
||||||
"github.com/wagoodman/go-progress"
|
"github.com/wagoodman/go-progress"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -12,23 +9,3 @@ type SecretsCatalogerMonitor struct {
|
|||||||
SecretsDiscovered progress.Monitorable
|
SecretsDiscovered progress.Monitorable
|
||||||
progress.Progressable
|
progress.Progressable
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSecretsCatalogerMonitor(locations int64) (*progress.Stage, *progress.Manual, *progress.Manual) {
|
|
||||||
stage := &progress.Stage{}
|
|
||||||
secretsDiscovered := &progress.Manual{}
|
|
||||||
prog := &progress.Manual{
|
|
||||||
Total: locations,
|
|
||||||
}
|
|
||||||
|
|
||||||
bus.Publish(partybus.Event{
|
|
||||||
Type: event.SecretsCatalogerStarted,
|
|
||||||
Source: secretsDiscovered,
|
|
||||||
Value: SecretsCatalogerMonitor{
|
|
||||||
Stager: progress.Stager(stage),
|
|
||||||
SecretsDiscovered: secretsDiscovered,
|
|
||||||
Progressable: prog,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
return stage, prog, secretsDiscovered
|
|
||||||
}
|
|
||||||
|
|||||||
@ -5,7 +5,10 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/anchore/syft/internal"
|
"github.com/anchore/syft/internal"
|
||||||
"github.com/anchore/syft/syft/event/monitor"
|
"github.com/anchore/syft/internal/bus"
|
||||||
|
"github.com/anchore/syft/syft/event"
|
||||||
|
"github.com/wagoodman/go-partybus"
|
||||||
|
"github.com/wagoodman/go-progress"
|
||||||
"hash"
|
"hash"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
@ -29,7 +32,7 @@ func NewDigestsCataloger(hashes []crypto.Hash) (*DigestsCataloger, error) {
|
|||||||
func (i *DigestsCataloger) Catalog(resolver source.FileResolver) (map[source.Coordinates][]Digest, error) {
|
func (i *DigestsCataloger) Catalog(resolver source.FileResolver) (map[source.Coordinates][]Digest, error) {
|
||||||
results := make(map[source.Coordinates][]Digest)
|
results := make(map[source.Coordinates][]Digest)
|
||||||
locations := allRegularFiles(resolver)
|
locations := allRegularFiles(resolver)
|
||||||
stage, prog := monitor.FileDigesterMonitor(int64(len(locations)))
|
stage, prog := digestsCatalogingProgress(int64(len(locations)))
|
||||||
for _, location := range locations {
|
for _, location := range locations {
|
||||||
stage.Current = location.RealPath
|
stage.Current = location.RealPath
|
||||||
result, err := i.catalogLocation(resolver, location)
|
result, err := i.catalogLocation(resolver, location)
|
||||||
@ -101,3 +104,23 @@ func (i *DigestsCataloger) catalogLocation(resolver source.FileResolver, locatio
|
|||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func digestsCatalogingProgress(locations int64) (*progress.Stage, *progress.Manual) {
|
||||||
|
stage := &progress.Stage{}
|
||||||
|
prog := &progress.Manual{
|
||||||
|
Total: locations,
|
||||||
|
}
|
||||||
|
|
||||||
|
bus.Publish(partybus.Event{
|
||||||
|
Type: event.FileDigestsCatalogerStarted,
|
||||||
|
Value: struct {
|
||||||
|
progress.Stager
|
||||||
|
progress.Progressable
|
||||||
|
}{
|
||||||
|
Stager: progress.Stager(stage),
|
||||||
|
Progressable: prog,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return stage, prog
|
||||||
|
}
|
||||||
|
|||||||
@ -3,8 +3,12 @@ package file
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/anchore/syft/internal/bus"
|
||||||
"github.com/anchore/syft/internal/file"
|
"github.com/anchore/syft/internal/file"
|
||||||
|
"github.com/anchore/syft/syft/event"
|
||||||
"github.com/anchore/syft/syft/event/monitor"
|
"github.com/anchore/syft/syft/event/monitor"
|
||||||
|
"github.com/wagoodman/go-partybus"
|
||||||
|
"github.com/wagoodman/go-progress"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -56,7 +60,7 @@ func NewSecretsCataloger(config SecretsCatalogerConfig) (*SecretsCataloger, erro
|
|||||||
func (i *SecretsCataloger) Catalog(resolver source.FileResolver) (map[source.Coordinates][]SearchResult, error) {
|
func (i *SecretsCataloger) Catalog(resolver source.FileResolver) (map[source.Coordinates][]SearchResult, error) {
|
||||||
results := make(map[source.Coordinates][]SearchResult)
|
results := make(map[source.Coordinates][]SearchResult)
|
||||||
locations := allRegularFiles(resolver)
|
locations := allRegularFiles(resolver)
|
||||||
stage, prog, secretsDiscovered := monitor.NewSecretsCatalogerMonitor(int64(len(locations)))
|
stage, prog, secretsDiscovered := newSecretsCatalogerMonitor(int64(len(locations)))
|
||||||
for _, location := range locations {
|
for _, location := range locations {
|
||||||
stage.Current = location.RealPath
|
stage.Current = location.RealPath
|
||||||
result, err := i.catalogLocation(resolver, location)
|
result, err := i.catalogLocation(resolver, location)
|
||||||
@ -143,3 +147,23 @@ func extractValue(resolver source.FileResolver, location source.Location, start,
|
|||||||
|
|
||||||
return buf.String(), nil
|
return buf.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newSecretsCatalogerMonitor(locations int64) (*progress.Stage, *progress.Manual, *progress.Manual) {
|
||||||
|
stage := &progress.Stage{}
|
||||||
|
secretsDiscovered := &progress.Manual{}
|
||||||
|
prog := &progress.Manual{
|
||||||
|
Total: locations,
|
||||||
|
}
|
||||||
|
|
||||||
|
bus.Publish(partybus.Event{
|
||||||
|
Type: event.SecretsCatalogerStarted,
|
||||||
|
Source: secretsDiscovered,
|
||||||
|
Value: monitor.SecretsCatalogerMonitor{
|
||||||
|
Stager: progress.Stager(stage),
|
||||||
|
SecretsDiscovered: secretsDiscovered,
|
||||||
|
Progressable: prog,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return stage, prog, secretsDiscovered
|
||||||
|
}
|
||||||
|
|||||||
@ -2,14 +2,18 @@ package packages
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/anchore/syft/internal/bus"
|
||||||
"github.com/anchore/syft/internal/log"
|
"github.com/anchore/syft/internal/log"
|
||||||
"github.com/anchore/syft/syft/artifact"
|
"github.com/anchore/syft/syft/artifact"
|
||||||
"github.com/anchore/syft/syft/cpe"
|
"github.com/anchore/syft/syft/cpe"
|
||||||
|
"github.com/anchore/syft/syft/event"
|
||||||
"github.com/anchore/syft/syft/event/monitor"
|
"github.com/anchore/syft/syft/event/monitor"
|
||||||
"github.com/anchore/syft/syft/linux"
|
"github.com/anchore/syft/syft/linux"
|
||||||
"github.com/anchore/syft/syft/pkg"
|
"github.com/anchore/syft/syft/pkg"
|
||||||
"github.com/anchore/syft/syft/source"
|
"github.com/anchore/syft/syft/source"
|
||||||
"github.com/hashicorp/go-multierror"
|
"github.com/hashicorp/go-multierror"
|
||||||
|
"github.com/wagoodman/go-partybus"
|
||||||
|
"github.com/wagoodman/go-progress"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Catalog a given source (container image or filesystem) with the given catalogers, returning all discovered packages.
|
// Catalog a given source (container image or filesystem) with the given catalogers, returning all discovered packages.
|
||||||
@ -20,7 +24,7 @@ func Catalog(resolver source.FileResolver, release *linux.Release, catalogers ..
|
|||||||
catalog := pkg.NewCatalog()
|
catalog := pkg.NewCatalog()
|
||||||
var allRelationships []artifact.Relationship
|
var allRelationships []artifact.Relationship
|
||||||
|
|
||||||
filesProcessed, packagesDiscovered := monitor.NewPackageCatalogerMonitor()
|
filesProcessed, packagesDiscovered := newPackageCatalogerMonitor()
|
||||||
|
|
||||||
// perform analysis, accumulating errors for each failed analysis
|
// perform analysis, accumulating errors for each failed analysis
|
||||||
var errs error
|
var errs error
|
||||||
@ -104,3 +108,18 @@ func packageFileOwnershipRelationships(p pkg.Package, resolver source.FilePathRe
|
|||||||
|
|
||||||
return relationships, nil
|
return relationships, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// newPackageCatalogerMonitor creates a new PackageCatalogerMonitor object and publishes the object on the bus as a PackageCatalogerStarted event.
|
||||||
|
func newPackageCatalogerMonitor() (*progress.Manual, *progress.Manual) {
|
||||||
|
filesProcessed := progress.Manual{}
|
||||||
|
packagesDiscovered := progress.Manual{}
|
||||||
|
|
||||||
|
bus.Publish(partybus.Event{
|
||||||
|
Type: event.PackageCatalogerStarted,
|
||||||
|
Value: monitor.PackageCatalogerMonitor{
|
||||||
|
FilesProcessed: progress.Monitorable(&filesProcessed),
|
||||||
|
PackagesDiscovered: progress.Monitorable(&packagesDiscovered),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return &filesProcessed, &packagesDiscovered
|
||||||
|
}
|
||||||
|
|||||||
@ -11,10 +11,9 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/anchore/syft/internal"
|
|
||||||
|
|
||||||
"github.com/anchore/stereoscope/pkg/file"
|
"github.com/anchore/stereoscope/pkg/file"
|
||||||
"github.com/anchore/stereoscope/pkg/filetree"
|
"github.com/anchore/stereoscope/pkg/filetree"
|
||||||
|
"github.com/anchore/syft/internal"
|
||||||
"github.com/anchore/syft/internal/bus"
|
"github.com/anchore/syft/internal/bus"
|
||||||
"github.com/anchore/syft/internal/log"
|
"github.com/anchore/syft/internal/log"
|
||||||
"github.com/anchore/syft/syft/event"
|
"github.com/anchore/syft/syft/event"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user