mirror of
https://github.com/anchore/syft.git
synced 2026-11-01 15:06:36 +01:00
migrate scope option to image metadata (from source)
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import "github.com/anchore/stereoscope/pkg/image"
|
||||
|
||||
type ImageMetadata struct {
|
||||
UserInput string `json:"userInput"`
|
||||
Scope Scope `json:"scope"` // specific perspective to catalog
|
||||
Layers []LayerMetadata `json:"layers"`
|
||||
Size int64 `json:"size"`
|
||||
Digest string `json:"digest"`
|
||||
@@ -17,7 +18,7 @@ type LayerMetadata struct {
|
||||
Size int64 `json:"size"`
|
||||
}
|
||||
|
||||
func NewImageMetadata(img *image.Image, userInput string) ImageMetadata {
|
||||
func NewImageMetadata(img *image.Image, userInput string, scope Scope) ImageMetadata {
|
||||
// populate artifacts...
|
||||
tags := make([]string, len(img.Metadata.Tags))
|
||||
for idx, tag := range img.Metadata.Tags {
|
||||
@@ -25,6 +26,7 @@ func NewImageMetadata(img *image.Image, userInput string) ImageMetadata {
|
||||
}
|
||||
theImg := ImageMetadata{
|
||||
UserInput: userInput,
|
||||
Scope: scope,
|
||||
Digest: img.Metadata.Digest,
|
||||
Size: img.Metadata.Size,
|
||||
MediaType: string(img.Metadata.MediaType),
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package source
|
||||
|
||||
type Metadata struct {
|
||||
Scope Scope // specific perspective to catalog
|
||||
Scheme Scheme // the source data scheme type (directory or image)
|
||||
ImageMetadata ImageMetadata // all image info (image only)
|
||||
Path string // the root path to be cataloged (directory only)
|
||||
|
||||
@@ -85,12 +85,12 @@ func NewFromDirectory(path string) (Source, error) {
|
||||
|
||||
// NewFromImage creates a new source object tailored to catalog a given container image, relative to the
|
||||
// option given (e.g. all-layers, squashed, etc)
|
||||
func NewFromImage(img *image.Image, option Scope, userImageStr string) (Source, error) {
|
||||
func NewFromImage(img *image.Image, scope Scope, userImageStr string) (Source, error) {
|
||||
if img == nil {
|
||||
return Source{}, fmt.Errorf("no image given")
|
||||
}
|
||||
|
||||
resolver, err := getImageResolver(img, option)
|
||||
resolver, err := getImageResolver(img, scope)
|
||||
if err != nil {
|
||||
return Source{}, fmt.Errorf("could not determine file resolver: %w", err)
|
||||
}
|
||||
@@ -99,9 +99,8 @@ func NewFromImage(img *image.Image, option Scope, userImageStr string) (Source,
|
||||
Resolver: resolver,
|
||||
Image: img,
|
||||
Metadata: Metadata{
|
||||
Scope: option,
|
||||
Scheme: ImageScheme,
|
||||
ImageMetadata: NewImageMetadata(img, userImageStr),
|
||||
ImageMetadata: NewImageMetadata(img, userImageStr, scope),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user