mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
feat: haproxy binary matcher (#1591)
Signed-off-by: Benji Visser <benji@093b.org>
This commit is contained in:
parent
0c05855131
commit
abfec62219
@ -207,6 +207,42 @@ func Test_Cataloger_DefaultClassifiers_PositiveCases(t *testing.T) {
|
|||||||
Metadata: metadata("perl-binary"),
|
Metadata: metadata("perl-binary"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "positive-haproxy-1.5.14",
|
||||||
|
fixtureDir: "test-fixtures/classifiers/positive/haproxy-1.5.14",
|
||||||
|
expected: pkg.Package{
|
||||||
|
Name: "haproxy",
|
||||||
|
Version: "1.5.14",
|
||||||
|
Type: "binary",
|
||||||
|
PURL: "pkg:generic/haproxy@1.5.14",
|
||||||
|
Locations: locations("haproxy"),
|
||||||
|
Metadata: metadata("haproxy-binary"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "positive-haproxy-1.8.22",
|
||||||
|
fixtureDir: "test-fixtures/classifiers/positive/haproxy-1.8.22",
|
||||||
|
expected: pkg.Package{
|
||||||
|
Name: "haproxy",
|
||||||
|
Version: "1.8.22",
|
||||||
|
Type: "binary",
|
||||||
|
PURL: "pkg:generic/haproxy@1.8.22",
|
||||||
|
Locations: locations("haproxy"),
|
||||||
|
Metadata: metadata("haproxy-binary"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "positive-haproxy-2.7.3",
|
||||||
|
fixtureDir: "test-fixtures/classifiers/positive/haproxy-2.7.3",
|
||||||
|
expected: pkg.Package{
|
||||||
|
Name: "haproxy",
|
||||||
|
Version: "2.7.3",
|
||||||
|
Type: "binary",
|
||||||
|
PURL: "pkg:generic/haproxy@2.7.3",
|
||||||
|
Locations: locations("haproxy"),
|
||||||
|
Metadata: metadata("haproxy-binary"),
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "positive-redis-2.8.23",
|
name: "positive-redis-2.8.23",
|
||||||
fixtureDir: "test-fixtures/classifiers/positive/redis-server-2.8.23",
|
fixtureDir: "test-fixtures/classifiers/positive/redis-server-2.8.23",
|
||||||
|
|||||||
@ -51,6 +51,21 @@ type classifier struct {
|
|||||||
// evidenceMatcher is a function called to catalog Packages that match some sort of evidence
|
// evidenceMatcher is a function called to catalog Packages that match some sort of evidence
|
||||||
type evidenceMatcher func(classifier classifier, reader source.LocationReadCloser) ([]pkg.Package, error)
|
type evidenceMatcher func(classifier classifier, reader source.LocationReadCloser) ([]pkg.Package, error)
|
||||||
|
|
||||||
|
func evidenceMatchers(matchers ...evidenceMatcher) evidenceMatcher {
|
||||||
|
return func(classifier classifier, reader source.LocationReadCloser) ([]pkg.Package, error) {
|
||||||
|
for _, matcher := range matchers {
|
||||||
|
match, err := matcher(classifier, reader)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if match != nil {
|
||||||
|
return match, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func fileNameTemplateVersionMatcher(fileNamePattern string, contentTemplate string) evidenceMatcher {
|
func fileNameTemplateVersionMatcher(fileNamePattern string, contentTemplate string) evidenceMatcher {
|
||||||
pat := regexp.MustCompile(fileNamePattern)
|
pat := regexp.MustCompile(fileNamePattern)
|
||||||
return func(classifier classifier, reader source.LocationReadCloser) ([]pkg.Package, error) {
|
return func(classifier classifier, reader source.LocationReadCloser) ([]pkg.Package, error) {
|
||||||
|
|||||||
@ -120,6 +120,17 @@ var defaultClassifiers = []classifier{
|
|||||||
Package: "busybox",
|
Package: "busybox",
|
||||||
CPEs: singleCPE("cpe:2.3:a:busybox:busybox:*:*:*:*:*:*:*:*"),
|
CPEs: singleCPE("cpe:2.3:a:busybox:busybox:*:*:*:*:*:*:*:*"),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Class: "haproxy-binary",
|
||||||
|
FileGlob: "**/haproxy",
|
||||||
|
EvidenceMatcher: evidenceMatchers(
|
||||||
|
fileContentsVersionMatcher(`(?m)HA-Proxy version (?P<version>[0-9]+\.[0-9]+\.[0-9]+)`),
|
||||||
|
fileContentsVersionMatcher(`(?m)(?P<version>[0-9]+\.[0-9]+\.[0-9]+)-[0-9a-zA-Z]{7}.+HAProxy version`),
|
||||||
|
),
|
||||||
|
Package: "haproxy",
|
||||||
|
PURL: mustPURL("pkg:generic/haproxy@version"),
|
||||||
|
CPEs: singleCPE("cpe:2.3:a:haproxy:haproxy:*:*:*:*:*:*:*:*"),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Class: "perl-binary",
|
Class: "perl-binary",
|
||||||
FileGlob: "**/perl",
|
FileGlob: "**/perl",
|
||||||
|
|||||||
@ -0,0 +1 @@
|
|||||||
|
HA-Proxy version 1.5.14 2015/07/02Copyright 2000-2015 Willy Tarreau <willy@haproxy.org>
|
||||||
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user