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/event"
|
||||
"github.com/anchore/imgbom/imgbom/presenter"
|
||||
"github.com/anchore/imgbom/imgbom/scope"
|
||||
"github.com/anchore/imgbom/internal"
|
||||
"github.com/anchore/imgbom/internal/bus"
|
||||
"github.com/anchore/imgbom/internal/log"
|
||||
"github.com/anchore/imgbom/internal/ui"
|
||||
"github.com/anchore/stereoscope"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/wagoodman/go-partybus"
|
||||
)
|
||||
@ -50,54 +48,31 @@ func startWorker(userInput string) <-chan error {
|
||||
errs := make(chan error)
|
||||
go func() {
|
||||
defer close(errs)
|
||||
protocol := imgbom.NewProtocol(userInput)
|
||||
log.Debugf("protocol: %+v", protocol)
|
||||
|
||||
var s scope.Scope
|
||||
var err error
|
||||
s, cleanup, err := imgbom.NewScope(userInput, appConfig.ScopeOpt)
|
||||
defer cleanup()
|
||||
|
||||
switch protocol.Type {
|
||||
case imgbom.DirProtocol:
|
||||
// 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)
|
||||
}
|
||||
if err != nil {
|
||||
log.Errorf("could not produce catalog: %w", err)
|
||||
}
|
||||
|
||||
log.Info("Identifying Distro")
|
||||
distro := imgbom.IdentifyDistro(s)
|
||||
|
||||
if distro == nil {
|
||||
log.Errorf("error identifying distro")
|
||||
} else {
|
||||
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{
|
||||
Type: event.CatalogerFinished,
|
||||
Value: presenter.GetPresenter(appConfig.PresenterOpt, s),
|
||||
Value: presenter.GetPresenter(appConfig.PresenterOpt, s, catalog),
|
||||
})
|
||||
}()
|
||||
return errs
|
||||
|
||||
@ -22,7 +22,6 @@ func Identify(s scope.Scope) *Distro {
|
||||
}
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
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 {
|
||||
continue
|
||||
}
|
||||
ref := refs[0]
|
||||
|
||||
contents, err := s.MultipleFileContentsByRef(ref)
|
||||
log.Infof("contents are: %+v", contents)
|
||||
content, ok := contents[ref]
|
||||
// XXX is it possible to get a ref and no contents at all?
|
||||
if !ok {
|
||||
continue
|
||||
for _, ref := range refs {
|
||||
contents, err := s.MultipleFileContentsByRef(ref)
|
||||
content, ok := contents[ref]
|
||||
|
||||
if !ok {
|
||||
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?)
|
||||
return nil
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user