mirror of
https://github.com/anchore/syft.git
synced 2026-10-30 14:02:26 +01:00
* normalize the json image/dir source Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update json image presenter golden file Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
31 lines
539 B
Go
31 lines
539 B
Go
package json
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/anchore/syft/syft/scope"
|
|
)
|
|
|
|
type Source struct {
|
|
Type string `json:"type"`
|
|
Target interface{} `json:"target"`
|
|
}
|
|
|
|
func NewSource(s scope.Scope) (Source, error) {
|
|
srcObj := s.Source()
|
|
switch src := srcObj.(type) {
|
|
case scope.ImageSource:
|
|
return Source{
|
|
Type: "image",
|
|
Target: NewImage(src),
|
|
}, nil
|
|
case scope.DirSource:
|
|
return Source{
|
|
Type: "directory",
|
|
Target: s.DirSrc.Path,
|
|
}, nil
|
|
default:
|
|
return Source{}, fmt.Errorf("unsupported source: %T", src)
|
|
}
|
|
}
|