mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
cmd: do not default for images, handle it specifically
Signed-off-by: Alfredo Deza <adeza@anchore.com>
This commit is contained in:
parent
2f626bf9fd
commit
a6e1866cdb
49
cmd/root.go
49
cmd/root.go
@ -7,12 +7,10 @@ import (
|
|||||||
"github.com/anchore/imgbom/imgbom"
|
"github.com/anchore/imgbom/imgbom"
|
||||||
"github.com/anchore/imgbom/imgbom/event"
|
"github.com/anchore/imgbom/imgbom/event"
|
||||||
"github.com/anchore/imgbom/imgbom/presenter"
|
"github.com/anchore/imgbom/imgbom/presenter"
|
||||||
"github.com/anchore/imgbom/imgbom/scope"
|
|
||||||
"github.com/anchore/imgbom/internal"
|
"github.com/anchore/imgbom/internal"
|
||||||
"github.com/anchore/imgbom/internal/bus"
|
"github.com/anchore/imgbom/internal/bus"
|
||||||
"github.com/anchore/imgbom/internal/log"
|
"github.com/anchore/imgbom/internal/log"
|
||||||
"github.com/anchore/imgbom/internal/ui"
|
"github.com/anchore/imgbom/internal/ui"
|
||||||
"github.com/anchore/stereoscope"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/wagoodman/go-partybus"
|
"github.com/wagoodman/go-partybus"
|
||||||
)
|
)
|
||||||
@ -50,54 +48,31 @@ func startWorker(userInput string) <-chan error {
|
|||||||
errs := make(chan error)
|
errs := make(chan error)
|
||||||
go func() {
|
go func() {
|
||||||
defer close(errs)
|
defer close(errs)
|
||||||
protocol := imgbom.NewProtocol(userInput)
|
|
||||||
log.Debugf("protocol: %+v", protocol)
|
|
||||||
|
|
||||||
var s scope.Scope
|
s, cleanup, err := imgbom.NewScope(userInput, appConfig.ScopeOpt)
|
||||||
var err error
|
defer cleanup()
|
||||||
|
|
||||||
switch protocol.Type {
|
if err != nil {
|
||||||
case imgbom.DirProtocol:
|
log.Errorf("could not produce catalog: %w", err)
|
||||||
// populate the scope object for dir
|
|
||||||
s, err = imgbom.GetScopeFromDir(protocol.Value, appConfig.ScopeOpt)
|
|
||||||
if err != nil {
|
|
||||||
errs <- fmt.Errorf("could not populate scope from path (%s): %w", protocol.Value, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
log.Infof("Fetching image '%s'", userInput)
|
|
||||||
img, err := stereoscope.GetImage(userInput)
|
|
||||||
|
|
||||||
if err != nil || img == nil {
|
|
||||||
errs <- fmt.Errorf("could not fetch image '%s': %w", userInput, err)
|
|
||||||
|
|
||||||
// TODO: this needs to be handled better
|
|
||||||
bus.Publish(partybus.Event{
|
|
||||||
Type: event.CatalogerFinished,
|
|
||||||
Value: nil,
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer stereoscope.Cleanup()
|
|
||||||
|
|
||||||
// populate the scope object for image
|
|
||||||
s, err = imgbom.GetScopeFromImage(img, appConfig.ScopeOpt)
|
|
||||||
if err != nil {
|
|
||||||
errs <- fmt.Errorf("could not populate scope with image: %w", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("Identifying Distro")
|
log.Info("Identifying Distro")
|
||||||
distro := imgbom.IdentifyDistro(s)
|
distro := imgbom.IdentifyDistro(s)
|
||||||
|
|
||||||
if distro == nil {
|
if distro == nil {
|
||||||
log.Errorf("error identifying distro")
|
log.Errorf("error identifying distro")
|
||||||
} else {
|
} else {
|
||||||
log.Infof(" Distro: %s", distro)
|
log.Infof(" Distro: %s", distro)
|
||||||
}
|
}
|
||||||
|
log.Info("Creating the Catalog")
|
||||||
|
catalog, err := imgbom.Catalog(s)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("could not produce catalog: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
bus.Publish(partybus.Event{
|
bus.Publish(partybus.Event{
|
||||||
Type: event.CatalogerFinished,
|
Type: event.CatalogerFinished,
|
||||||
Value: presenter.GetPresenter(appConfig.PresenterOpt, s),
|
Value: presenter.GetPresenter(appConfig.PresenterOpt, s, catalog),
|
||||||
})
|
})
|
||||||
}()
|
}()
|
||||||
return errs
|
return errs
|
||||||
|
|||||||
@ -22,7 +22,6 @@ func Identify(s scope.Scope) *Distro {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for path, fn := range identityFiles {
|
for path, fn := range identityFiles {
|
||||||
// this is always a slice with a single ref, the API is odd because it was meant for images
|
|
||||||
refs, err := s.FilesByPath(path)
|
refs, err := s.FilesByPath(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("unable to get path refs from %s: %s", path, err)
|
log.Errorf("unable to get path refs from %s: %s", path, err)
|
||||||
@ -32,33 +31,34 @@ func Identify(s scope.Scope) *Distro {
|
|||||||
if len(refs) == 0 {
|
if len(refs) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ref := refs[0]
|
|
||||||
|
|
||||||
contents, err := s.MultipleFileContentsByRef(ref)
|
for _, ref := range refs {
|
||||||
log.Infof("contents are: %+v", contents)
|
contents, err := s.MultipleFileContentsByRef(ref)
|
||||||
content, ok := contents[ref]
|
content, ok := contents[ref]
|
||||||
// XXX is it possible to get a ref and no contents at all?
|
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
log.Infof("no content present for ref: %s", ref)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Debugf("unable to get contents from %s: %s", path, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if content == "" {
|
||||||
|
log.Debugf("no contents in file, skipping: %s", path)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
distro := fn(content)
|
||||||
|
|
||||||
|
if distro == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
return distro
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Debugf("unable to get contents from %s: %s", path, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if content == "" {
|
|
||||||
log.Debugf("no contents in file, skipping: %s", path)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
distro := fn(content)
|
|
||||||
|
|
||||||
if distro == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
return distro
|
|
||||||
}
|
}
|
||||||
// TODO: is it useful to know partially detected distros? where the ID is known but not the version (and viceversa?)
|
// TODO: is it useful to know partially detected distros? where the ID is known but not the version (and viceversa?)
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user