feat: add --from flag, refactor source providers (#2610)

Signed-off-by: Keith Zantow <kzantow@gmail.com>
This commit is contained in:
Keith Zantow
2024-02-27 16:44:37 -05:00
committed by GitHub
parent 928511ea0f
commit a978966cad
72 changed files with 1035 additions and 1080 deletions
+19 -10
View File
@@ -1,10 +1,15 @@
package main
import (
"context"
"encoding/json"
"os"
"github.com/anchore/go-collections"
"github.com/anchore/stereoscope"
"github.com/anchore/syft/syft"
"github.com/anchore/syft/syft/source"
"github.com/anchore/syft/syft/source/sourceproviders"
)
/*
@@ -28,18 +33,18 @@ import (
const defaultImage = "alpine:3.19"
func main() {
detection, err := source.Detect(
imageReference(),
source.DetectConfig{
DefaultImageSource: "docker",
},
)
userInput := imageReference()
if err != nil {
panic(err)
// parse the scheme against the known set of schemes
schemeSource, newUserInput := stereoscope.ExtractSchemeSource(userInput, allSourceTags()...)
// set up the GetSourceConfig
getSourceCfg := syft.DefaultGetSourceConfig()
if schemeSource != "" {
getSourceCfg = getSourceCfg.WithSources(schemeSource)
userInput = newUserInput
}
src, err := detection.NewSource(source.DefaultDetectionSourceConfig())
src, err := syft.GetSource(context.Background(), userInput, getSourceCfg)
if err != nil {
panic(err)
@@ -60,3 +65,7 @@ func imageReference() string {
}
return defaultImage
}
func allSourceTags() []string {
return collections.TaggedValueSet[source.Provider]{}.Join(sourceproviders.All("", nil)...).Tags()
}