-
Notifications
You must be signed in to change notification settings - Fork 574
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Patrik Beno <patrik.beno@greenhorn.sk>
- Loading branch information
1 parent
0aea55f
commit dbf7411
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package sbom | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"github.com/anchore/syft/internal/formats/cyclonedxjson" | ||
"github.com/anchore/syft/syft/artifact" | ||
"github.com/anchore/syft/syft/pkg" | ||
"github.com/anchore/syft/syft/pkg/cataloger/common" | ||
"io" | ||
) | ||
|
||
// NewSBOMCataloger returns a new SBOM cataloger object loaded from saved SBOM JSON. | ||
func NewSBOMCataloger() *common.GenericCataloger { | ||
globParsers := map[string]common.ParserFn{ | ||
"**/deps.json": parseSBOM, | ||
"**/sbom.json": parseSBOM, | ||
} | ||
|
||
return common.NewGenericCataloger(nil, globParsers, "sbom-cataloger") | ||
} | ||
|
||
func parseSBOM(path string, reader io.Reader) ([]*pkg.Package, []artifact.Relationship, error) { | ||
by, err := io.ReadAll(reader) | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("unable to read sbom: %w", err) | ||
} | ||
|
||
f := cyclonedxjson.Format() | ||
|
||
s, _ := f.Decode(bytes.NewReader(by)) | ||
|
||
var packages []*pkg.Package | ||
for _, p := range s.Artifacts.PackageCatalog.Sorted() { | ||
x := p //copy | ||
packages = append(packages, &x) | ||
} | ||
|
||
return packages, nil, nil | ||
} |