-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add BeamVM Hex support (#1073)
* feat: initial commit providing mix support Signed-off-by: cpendery <[email protected]> * feat: add rebar parser Signed-off-by: cpendery <[email protected]> * fix: add beam/hex everywhere else required for Syft runtime Signed-off-by: cpendery <[email protected]> * style: fix lints Signed-off-by: cpendery <[email protected]> * ci: fix failing tests Signed-off-by: cpendery <[email protected]> * docs: update with new supported languages Signed-off-by: cpendery <[email protected]> * chore: update elixir/erlang catalogers to generic cataloger Signed-off-by: Alex Goodman <[email protected]> Signed-off-by: cpendery <[email protected]> Signed-off-by: Alex Goodman <[email protected]> Co-authored-by: Alex Goodman <[email protected]>
- Loading branch information
Showing
27 changed files
with
894 additions
and
113 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
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
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
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,16 @@ | ||
/* | ||
Package elixir provides a concrete Cataloger implementation for elixir specific package manger files. | ||
*/ | ||
package elixir | ||
|
||
import ( | ||
"github.com/anchore/syft/syft/pkg/cataloger/generic" | ||
) | ||
|
||
const catalogerName = "elixir-mix-lock-cataloger" | ||
|
||
// NewMixLockCataloger returns parses mix.lock files and returns packages | ||
func NewMixLockCataloger() *generic.Cataloger { | ||
return generic.NewCataloger(catalogerName). | ||
WithParserByGlobs(parseMixLock, "**/mix.lock") | ||
} |
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,37 @@ | ||
package elixir | ||
|
||
import ( | ||
"github.com/anchore/packageurl-go" | ||
"github.com/anchore/syft/syft/pkg" | ||
"github.com/anchore/syft/syft/source" | ||
) | ||
|
||
func newPackage(d pkg.MixLockMetadata, locations ...source.Location) pkg.Package { | ||
p := pkg.Package{ | ||
Name: d.Name, | ||
Version: d.Version, | ||
Language: pkg.Elixir, | ||
Locations: source.NewLocationSet(locations...), | ||
PURL: packageURL(d), | ||
Type: pkg.HexPkg, | ||
MetadataType: pkg.MixLockMetadataType, | ||
Metadata: d, | ||
} | ||
|
||
p.SetID() | ||
|
||
return p | ||
} | ||
|
||
func packageURL(m pkg.MixLockMetadata) string { | ||
var qualifiers packageurl.Qualifiers | ||
|
||
return packageurl.NewPackageURL( | ||
packageurl.TypeHex, | ||
"", | ||
m.Name, | ||
m.Version, | ||
qualifiers, | ||
"", | ||
).ToString() | ||
} |
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,53 @@ | ||
package elixir | ||
|
||
import ( | ||
"bufio" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"regexp" | ||
|
||
"github.com/anchore/syft/internal/log" | ||
"github.com/anchore/syft/syft/artifact" | ||
"github.com/anchore/syft/syft/pkg" | ||
"github.com/anchore/syft/syft/pkg/cataloger/generic" | ||
"github.com/anchore/syft/syft/source" | ||
) | ||
|
||
// integrity check | ||
var _ generic.Parser = parseMixLock | ||
|
||
var mixLockDelimiter = regexp.MustCompile(`[%{}\n" ,:]+`) | ||
|
||
// parseMixLock parses a mix.lock and returns the discovered Elixir packages. | ||
func parseMixLock(_ source.FileResolver, _ *generic.Environment, reader source.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) { | ||
r := bufio.NewReader(reader) | ||
|
||
var packages []pkg.Package | ||
for { | ||
line, err := r.ReadString('\n') | ||
switch { | ||
case errors.Is(io.EOF, err): | ||
return packages, nil, nil | ||
case err != nil: | ||
return nil, nil, fmt.Errorf("failed to parse mix.lock file: %w", err) | ||
} | ||
tokens := mixLockDelimiter.Split(line, -1) | ||
if len(tokens) < 6 { | ||
continue | ||
} | ||
name, version, hash, hashExt := tokens[1], tokens[4], tokens[5], tokens[len(tokens)-2] | ||
|
||
if name == "" { | ||
log.WithFields("path", reader.RealPath).Debug("skipping empty package name from mix.lock file") | ||
continue | ||
} | ||
|
||
packages = append(packages, newPackage(pkg.MixLockMetadata{ | ||
Name: name, | ||
Version: version, | ||
PkgHash: hash, | ||
PkgHashExt: hashExt, | ||
})) | ||
} | ||
} |
Oops, something went wrong.