mirror of
https://github.com/anchore/syft.git
synced 2026-11-01 15:06:36 +01:00
add source.Location + reorient Resolvers to use it
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package source
|
||||
|
||||
import (
|
||||
"github.com/anchore/syft/internal/log"
|
||||
|
||||
"github.com/anchore/stereoscope/pkg/file"
|
||||
"github.com/anchore/stereoscope/pkg/image"
|
||||
)
|
||||
|
||||
type Location struct {
|
||||
Path string `json:"path"`
|
||||
LayerIndex uint `json:"layerIndex"`
|
||||
LayerID string `json:"layerID"`
|
||||
ref file.Reference
|
||||
}
|
||||
|
||||
func newLocation(path string) Location {
|
||||
return Location{
|
||||
Path: path,
|
||||
}
|
||||
}
|
||||
|
||||
func newLocationFromRef(ref file.Reference) Location {
|
||||
return Location{
|
||||
Path: string(ref.Path),
|
||||
ref: ref,
|
||||
}
|
||||
}
|
||||
|
||||
func newLocationFromImage(ref file.Reference, img *image.Image) Location {
|
||||
entry, err := img.FileCatalog.Get(ref)
|
||||
if err != nil {
|
||||
log.Warnf("unable to find file catalog entry for ref=%+v", ref)
|
||||
return Location{
|
||||
Path: string(ref.Path),
|
||||
ref: ref,
|
||||
}
|
||||
}
|
||||
|
||||
return Location{
|
||||
Path: string(ref.Path),
|
||||
LayerIndex: entry.Source.Metadata.Index,
|
||||
LayerID: entry.Source.Metadata.Digest,
|
||||
ref: ref,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user