From f9e09aef196a6b1ce4056a8d0987220bcf20a388 Mon Sep 17 00:00:00 2001 From: Keith Zantow Date: Wed, 6 Mar 2024 14:25:37 -0500 Subject: [PATCH] docs: add simplest example from regsitry (#2691) Signed-off-by: Keith Zantow --- examples/source_from_registry/main.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 examples/source_from_registry/main.go diff --git a/examples/source_from_registry/main.go b/examples/source_from_registry/main.go new file mode 100644 index 000000000..158731259 --- /dev/null +++ b/examples/source_from_registry/main.go @@ -0,0 +1,20 @@ +package main + +import ( + "context" + "os" + + "github.com/anchore/syft/syft" + "github.com/anchore/syft/syft/format/syftjson" +) + +// This example demonstrates how to create an SBOM, pulling only from "registry", with error handling omitted +func main() { + image := "alpine:3.19" + + src, _ := syft.GetSource(context.Background(), image, syft.DefaultGetSourceConfig().WithSources("registry")) + + sbom, _ := syft.CreateSBOM(context.Background(), src, syft.DefaultCreateSBOMConfig()) + + _ = syftjson.NewFormatEncoder().Encode(os.Stdout, *sbom) +}