mirror of
https://github.com/anchore/syft.git
synced 2026-11-05 00:46:38 +01:00
Added the SWI Prolog (swipl) ecosystem (#3076)
* Add binary classifier for swipl Signed-off-by: Laurent Goderre <laurent.goderre@docker.com> * Added cataloger for SWI Prolog Pack packages Signed-off-by: Laurent Goderre <laurent.goderre@docker.com> --------- Signed-off-by: Laurent Goderre <laurent.goderre@docker.com>
This commit is contained in:
@@ -929,6 +929,17 @@ func Test_Cataloger_PositiveCases(t *testing.T) {
|
||||
Metadata: metadata("erlang-alpine-binary"),
|
||||
},
|
||||
},
|
||||
{
|
||||
logicalFixture: "swipl/9.3.8/linux-amd64",
|
||||
expected: pkg.Package{
|
||||
Name: "swipl",
|
||||
Version: "9.3.8",
|
||||
Type: "binary",
|
||||
PURL: "pkg:generic/swipl@9.3.8",
|
||||
Locations: locations("swipl"),
|
||||
Metadata: metadata("swipl-binary"),
|
||||
},
|
||||
},
|
||||
{
|
||||
logicalFixture: "nginx/1.25.1/linux-amd64",
|
||||
expected: pkg.Package{
|
||||
|
||||
@@ -428,6 +428,16 @@ func DefaultClassifiers() []Classifier {
|
||||
PURL: mustPURL("pkg:generic/erlang@version"),
|
||||
CPEs: singleCPE("cpe:2.3:a:erlang:erlang\\/otp:*:*:*:*:*:*:*:*"),
|
||||
},
|
||||
{
|
||||
Class: "swipl-binary",
|
||||
FileGlob: "**/swipl",
|
||||
EvidenceMatcher: FileContentsVersionMatcher(
|
||||
`(?m)swipl-(?P<version>[0-9]+\.[0-9]+\.[0-9]+)\/`,
|
||||
),
|
||||
Package: "swipl",
|
||||
PURL: mustPURL("pkg:generic/swipl@version"),
|
||||
CPEs: singleCPE("cpe:2.3:a:erlang:erlang\\/otp:*:*:*:*:*:*:*:*"),
|
||||
},
|
||||
{
|
||||
Class: "consul-binary",
|
||||
FileGlob: "**/consul",
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
name: beam.smp
|
||||
offset: 6378906
|
||||
length: 140
|
||||
snippetSha256: 186c882decc4160bfcfbdddaee08e8364675c795d3e85697422fbd7218452ee2
|
||||
fileSha256: f84f0ffc2e397abcf5f081b865e241017b1793c2ec38f5136bff4e5e21ffdad7
|
||||
|
||||
### byte snippet to follow ###
|
||||
ied by configure */
|
||||
#define ERTS_EMU_CMDLINE_FLAGS " -fno-strict-aliasing -fno-common -g -O2 -I/usr/src/otp_src_27.0/erts/x86_64-pc-linux-mu
|
||||
BIN
Binary file not shown.
@@ -71,6 +71,13 @@ from-images:
|
||||
paths:
|
||||
- /usr/local/lib/erlang/erts-15.0/bin/beam.smp
|
||||
|
||||
- version: 9.3.8
|
||||
images:
|
||||
- ref: swipl:9.3.8@sha256:6a15e6a03afe943228924a5502ba763e653ff28d9b3391e2b3e1fc3e991f37d4
|
||||
platform: linux/amd64
|
||||
paths:
|
||||
- /usr/lib/swipl/bin/x86_64-linux/swipl
|
||||
|
||||
- version: 1.21.3
|
||||
images:
|
||||
- ref: golang:1.21.3@sha256:3ce8313c3513515040870c55e0c041a2b94f3576a58cfd3948633604214aa811
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
Package swipl provides a Cataloger implementation relating to packages within the SWI Prolog language ecosystem.
|
||||
*/
|
||||
package swipl
|
||||
|
||||
import (
|
||||
"github.com/anchore/syft/syft/pkg"
|
||||
"github.com/anchore/syft/syft/pkg/cataloger/generic"
|
||||
)
|
||||
|
||||
// NewSwiplPackCataloger returns a new SWI Prolog Pack package manager cataloger object.
|
||||
func NewSwiplPackCataloger() pkg.Cataloger {
|
||||
return generic.NewCataloger("swipl-pack-cataloger").
|
||||
WithParserByGlobs(parsePackPackage, "**/pack.pl")
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package swipl
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/anchore/syft/syft/pkg/cataloger/internal/pkgtest"
|
||||
)
|
||||
|
||||
func Test_Cataloger_Globs(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
fixture string
|
||||
expected []string
|
||||
}{
|
||||
{
|
||||
name: "obtain swipl pack files",
|
||||
fixture: "test-fixtures/glob-paths",
|
||||
expected: []string{
|
||||
"pack.pl",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
pkgtest.NewCatalogTester().
|
||||
FromDirectory(t, test.fixture).
|
||||
ExpectsResolverContentQueries(test.expected).
|
||||
TestCataloger(t, NewSwiplPackCataloger())
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package swipl
|
||||
|
||||
import (
|
||||
// "strings"
|
||||
|
||||
"github.com/anchore/packageurl-go"
|
||||
"github.com/anchore/syft/syft/file"
|
||||
"github.com/anchore/syft/syft/pkg"
|
||||
)
|
||||
|
||||
func newSwiplPackPackage(m pkg.SwiplPackEntry, locations ...file.Location) pkg.Package {
|
||||
p := pkg.Package{
|
||||
Name: m.Name,
|
||||
Version: m.Version,
|
||||
PURL: swiplpackPackageURL(m.Name, m.Version),
|
||||
Locations: file.NewLocationSet(locations...),
|
||||
Type: pkg.SwiplPackPkg,
|
||||
Language: pkg.Swipl,
|
||||
Metadata: m,
|
||||
}
|
||||
|
||||
p.SetID()
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func swiplpackPackageURL(name, version string) string {
|
||||
var qualifiers packageurl.Qualifiers
|
||||
|
||||
return packageurl.NewPackageURL(
|
||||
"swiplpack",
|
||||
"",
|
||||
name,
|
||||
version,
|
||||
qualifiers,
|
||||
"",
|
||||
).ToString()
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package swipl
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_swiplpackPackageURL(t *testing.T) {
|
||||
type args struct {
|
||||
name string
|
||||
version string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "go case",
|
||||
args: args{
|
||||
name: "name",
|
||||
version: "v0.1.0",
|
||||
},
|
||||
want: "pkg:swiplpack/name@v0.1.0",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert.Equal(t, tt.want, swiplpackPackageURL(tt.args.name, tt.args.version))
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package swipl
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"regexp"
|
||||
|
||||
"github.com/anchore/syft/internal/log"
|
||||
"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"
|
||||
)
|
||||
|
||||
func parsePackPackage(_ context.Context, _ file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
|
||||
var pkgs []pkg.Package
|
||||
|
||||
nameRe := regexp.MustCompile(`name\(\s*'?([^')]+)'?\s*\)`)
|
||||
versionRe := regexp.MustCompile(`version\('([^']+)'\)`)
|
||||
homeRe := regexp.MustCompile(`home\(\s*'([^']+)'\s*\)`)
|
||||
authorRe := regexp.MustCompile(`(author|packager)\(\s*'([^']+)'\s*(?:,\s*'([^']+)'\s*)?\)`)
|
||||
|
||||
data, err := io.ReadAll(reader)
|
||||
if err != nil {
|
||||
log.WithFields("error", err).Trace("unable to parse Rockspec app")
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
name := nameRe.FindSubmatch(data)
|
||||
version := versionRe.FindSubmatch(data)
|
||||
|
||||
if name == nil || version == nil {
|
||||
log.Debugf("encountered pack.pl file without a name and/or version field, ignoring (path=%q)", reader.Path())
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
entry := pkg.SwiplPackEntry{
|
||||
Name: string(name[1]),
|
||||
Version: string(version[1]),
|
||||
}
|
||||
|
||||
home := homeRe.FindSubmatch(data)
|
||||
|
||||
if home != nil {
|
||||
entry.Homepage = string(home[1])
|
||||
}
|
||||
|
||||
authors := authorRe.FindAllSubmatch(data, -1)
|
||||
|
||||
for _, a := range authors {
|
||||
switch string(a[1]) {
|
||||
case "author":
|
||||
entry.Author = string(a[2])
|
||||
entry.AuthorEmail = string(a[3])
|
||||
case "packager":
|
||||
entry.Packager = string(a[2])
|
||||
entry.PackagerEmail = string(a[3])
|
||||
}
|
||||
}
|
||||
|
||||
pkgs = append(
|
||||
pkgs,
|
||||
newSwiplPackPackage(
|
||||
entry,
|
||||
reader.Location.WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation),
|
||||
),
|
||||
)
|
||||
|
||||
return pkgs, nil, nil
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package swipl
|
||||
|
||||
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 TestParsePackPackage(t *testing.T) {
|
||||
fixture := "test-fixtures/pack.pl"
|
||||
locations := file.NewLocationSet(file.NewLocation(fixture))
|
||||
expectedPkgs := []pkg.Package{
|
||||
{
|
||||
Name: "hdt",
|
||||
Version: "0.5.2",
|
||||
PURL: "pkg:swiplpack/hdt@0.5.2",
|
||||
Locations: locations,
|
||||
Language: pkg.Swipl,
|
||||
Type: pkg.SwiplPackPkg,
|
||||
Metadata: pkg.SwiplPackEntry{
|
||||
Name: "hdt",
|
||||
Version: "0.5.2",
|
||||
Author: "Jan Wielemaker",
|
||||
AuthorEmail: "J.Wielemaker@vu.nl",
|
||||
Packager: "Jan Wielemaker",
|
||||
PackagerEmail: "J.Wielemaker@vu.nl",
|
||||
Homepage: "https://github.com/JanWielemaker/hdt",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// TODO: no relationships are under test yet
|
||||
var expectedRelationships []artifact.Relationship
|
||||
|
||||
pkgtest.TestFileParser(t, fixture, parsePackPackage, expectedPkgs, expectedRelationships)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
bogus
|
||||
@@ -0,0 +1,10 @@
|
||||
name(hdt).
|
||||
version('0.5.2').
|
||||
% TODO: swipl_version([90121]).
|
||||
title('Access RDF HDT files').
|
||||
keywords(['RDF']).
|
||||
author( 'Jan Wielemaker', 'J.Wielemaker@vu.nl' ).
|
||||
packager( 'Jan Wielemaker', 'J.Wielemaker@vu.nl' ).
|
||||
maintainer( 'Jan Wielemaker', 'J.Wielemaker@vu.nl' ).
|
||||
home( 'https://github.com/JanWielemaker/hdt' ).
|
||||
download( 'https://github.com/JanWielemaker/hdt/archive/V*.zip' ).
|
||||
Reference in New Issue
Block a user