-
Notifications
You must be signed in to change notification settings - Fork 599
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cataloger for Erlang OTP applications
Signed-off-by: Laurent Goderre <[email protected]>
- Loading branch information
1 parent
6fb153e
commit b3535e9
Showing
14 changed files
with
200 additions
and
6 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
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,47 @@ | ||
package erlang | ||
|
||
import ( | ||
"github.com/anchore/syft/syft/artifact" | ||
"github.com/anchore/syft/syft/file" | ||
"github.com/anchore/syft/syft/pkg" | ||
"github.com/anchore/syft/syft/pkg/cataloger/generic" | ||
) | ||
|
||
// parseRebarLock parses a rebar.lock and returns the discovered Elixir packages. | ||
// | ||
//nolint:funlen | ||
func parseOTPApp(_ file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) { | ||
doc, err := parseErlang(reader) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
var packages []pkg.Package | ||
|
||
root := doc.Get(0) | ||
|
||
name := root.Get(1).String() | ||
|
||
keys := root.Get(2) | ||
|
||
for _, key := range keys.Slice() { | ||
if key.Get(0).String() == "vsn" { | ||
version := key.Get(1).String() | ||
|
||
p := newPackageFromOTP( | ||
pkg.ErlangOTPApplication{ | ||
Name: name, | ||
Version: version, | ||
}, | ||
reader.Location.WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation), | ||
) | ||
|
||
packages = append(packages, p) | ||
} | ||
} | ||
|
||
return packages, nil, nil | ||
} | ||
|
||
// integrity check | ||
var _ generic.Parser = parseOTPApp |
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,47 @@ | ||
package erlang | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/anchore/syft/syft/artifact" | ||
"github.com/anchore/syft/syft/file" | ||
"github.com/anchore/syft/syft/pkg" | ||
"github.com/anchore/syft/syft/pkg/cataloger/internal/pkgtest" | ||
) | ||
|
||
func TestParseOTPApplication(t *testing.T) { | ||
tests := []struct { | ||
fixture string | ||
expected []pkg.Package | ||
}{ | ||
{ | ||
fixture: "test-fixtures/rabbitmq.app", | ||
expected: []pkg.Package{ | ||
{ | ||
Name: "rabbit", | ||
Version: "3.12.10", | ||
Language: pkg.Erlang, | ||
Type: pkg.UnknownPkg, | ||
PURL: "pkg:generic/[email protected]", | ||
Metadata: pkg.ErlangOTPApplication{ | ||
Name: "rabbit", | ||
Version: "3.12.10", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.fixture, func(t *testing.T) { | ||
// TODO: relationships are not under test | ||
var expectedRelationships []artifact.Relationship | ||
|
||
for idx := range test.expected { | ||
test.expected[idx].Locations = file.NewLocationSet(file.NewLocation(test.fixture)) | ||
} | ||
|
||
pkgtest.TestFileParser(t, test.fixture, parseOTPApp, test.expected, expectedRelationships) | ||
}) | ||
} | ||
} |
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
1 change: 1 addition & 0 deletions
1
syft/pkg/cataloger/erlang/test-fixtures/glob-paths/src/rabbitmq.app
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 @@ | ||
bogus erlang file |
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,18 @@ | ||
{application, 'rabbit', [ | ||
{description, "RabbitMQ"}, | ||
{vsn, "3.12.10"}, | ||
{id, "v3.12.9-9-g1f61ca8"}, | ||
{modules, ['amqqueue','background_gc']}, | ||
{optional_applications, []}, | ||
{env, [ | ||
{memory_monitor_interval, 2500}, | ||
{disk_free_limit, 50000000}, %% 50MB | ||
{msg_store_index_module, rabbit_msg_store_ets_index}, | ||
{backing_queue_module, rabbit_variable_queue}, | ||
%% 0 ("no limit") would make a better default, but that | ||
%% breaks the QPid Java client | ||
{frame_max, 131072}, | ||
%% see rabbitmq-server#1593 | ||
{channel_max, 2047} | ||
]} | ||
]}. |
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