migrate scope option to image metadata (from source)

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman
2020-11-17 12:37:12 -05:00
parent 91baabe5a1
commit f46de19c6b
14 changed files with 59 additions and 60 deletions
+3 -1
View File
@@ -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
View File
@@ -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)
+3 -4
View File
@@ -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
}