mirror of
https://github.com/anchore/syft.git
synced 2026-03-30 13:43:25 +02:00
* chore(deps): update tools to latest versions Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * chore(lint): fix errors in new golangci-lint Two fixes: First, replace sb.WriteString(fmt.Sprintf(...)) with fmt.Fprintf(&sb, ...) Second, suppress errors where we read from the local file system at a user provided path. This is a CLI tool, and reads from user provided paths on the local file system by design. Signed-off-by: Will Murphy <willmurphyscode@users.noreply.github.com> --------- Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Signed-off-by: Will Murphy <willmurphyscode@users.noreply.github.com> Co-authored-by: spiffcs <32073428+spiffcs@users.noreply.github.com> Co-authored-by: Will Murphy <willmurphyscode@users.noreply.github.com>
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
_ "embed"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/anchore/syft/syft/format"
|
|
)
|
|
|
|
//go:embed alpine.syft.json
|
|
var sbomContents string
|
|
|
|
func main() {
|
|
// decode the SBOM
|
|
fmt.Println("decoding SBOM...")
|
|
sbom, sbomFormat, formatVersion, err := format.Decode(sbomReader())
|
|
if err != nil {
|
|
fmt.Printf("failed to decode sbom: %+v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
fmt.Printf("SBOM format: %s@%s\n", sbomFormat, formatVersion)
|
|
|
|
// print packages found...
|
|
fmt.Println("\nPackages found:")
|
|
for _, pkg := range sbom.Artifacts.Packages.Sorted() {
|
|
fmt.Printf(" %s : %s@%s (%s)\n", pkg.ID(), pkg.Name, pkg.Version, pkg.Type)
|
|
}
|
|
|
|
// print files found...
|
|
fmt.Println("\nFiles found:")
|
|
for c, f := range sbom.Artifacts.FileMetadata {
|
|
fmt.Printf(" %s : %s\n", c.ID(), f.Path)
|
|
}
|
|
}
|
|
|
|
func sbomReader() io.Reader {
|
|
// read file from sys args (or use the default)
|
|
var reader io.Reader
|
|
if len(os.Args) < 2 {
|
|
reader = strings.NewReader(sbomContents)
|
|
} else {
|
|
var err error
|
|
// suppress gosec error: reads from local file system by design
|
|
reader, err = os.Open(os.Args[1]) //nolint:gosec
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
return reader
|
|
}
|