mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
47 lines
939 B
Go
47 lines
939 B
Go
package scope
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/anchore/stereoscope/pkg/image"
|
|
"github.com/anchore/stereoscope/pkg/tree"
|
|
)
|
|
|
|
type Scope struct {
|
|
Option Option
|
|
Trees []tree.FileTreeReader
|
|
Image *image.Image
|
|
}
|
|
|
|
func NewScope(img *image.Image, option Option) (Scope, error) {
|
|
var trees = make([]tree.FileTreeReader, 0)
|
|
|
|
if img == nil {
|
|
return Scope{}, fmt.Errorf("no image given")
|
|
}
|
|
|
|
switch option {
|
|
case SquashedScope:
|
|
if img.SquashedTree == nil {
|
|
return Scope{}, fmt.Errorf("the image does not have have a squashed tree")
|
|
}
|
|
trees = append(trees, img.SquashedTree)
|
|
|
|
case AllLayersScope:
|
|
if len(img.Layers) == 0 {
|
|
return Scope{}, fmt.Errorf("the image does not contain any layers")
|
|
}
|
|
for _, layer := range img.Layers {
|
|
trees = append(trees, layer.Tree)
|
|
}
|
|
default:
|
|
return Scope{}, fmt.Errorf("bad option provided: %+v", option)
|
|
}
|
|
|
|
return Scope{
|
|
Option: option,
|
|
Trees: trees,
|
|
Image: img,
|
|
}, nil
|
|
}
|