worker: ns detectors now support VersionFormat
This also filters unknown namespaces from the generic lsb-release and osrelease detectors.
This commit is contained in:
parent
9e39a26f26
commit
8bedd0a367
@ -48,7 +48,10 @@ func (d *detector) Detect(data map[string][]byte) *database.Namespace {
|
|||||||
match := versionRegexp.FindStringSubmatch(line)
|
match := versionRegexp.FindStringSubmatch(line)
|
||||||
if len(match) > 0 {
|
if len(match) > 0 {
|
||||||
versionNumbers := strings.Split(match[0], ".")
|
versionNumbers := strings.Split(match[0], ".")
|
||||||
return &database.Namespace{Name: osName + ":" + "v" + versionNumbers[0] + "." + versionNumbers[1]}
|
return &database.Namespace{
|
||||||
|
Name: osName + ":" + "v" + versionNumbers[0] + "." + versionNumbers[1],
|
||||||
|
VersionFormat: "dpkg",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,10 @@ func (detector *AptSourcesNamespaceDetector) Detect(data map[string][]byte) *dat
|
|||||||
}
|
}
|
||||||
|
|
||||||
if OS != "" && version != "" {
|
if OS != "" && version != "" {
|
||||||
return &database.Namespace{Name: OS + ":" + version}
|
return &database.Namespace{
|
||||||
|
Name: OS + ":" + version,
|
||||||
|
VersionFormat: "dpkg",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -69,8 +69,22 @@ func (detector *LsbReleaseNamespaceDetector) Detect(data map[string][]byte) *dat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determine the VersionFormat.
|
||||||
|
var versionFormat string
|
||||||
|
switch OS {
|
||||||
|
case "debian", "ubuntu":
|
||||||
|
versionFormat = "dpkg"
|
||||||
|
case "centos", "rhel", "fedora", "amzn", "ol", "oracle":
|
||||||
|
versionFormat = "rpm"
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if OS != "" && version != "" {
|
if OS != "" && version != "" {
|
||||||
return &database.Namespace{Name: OS + ":" + version}
|
return &database.Namespace{
|
||||||
|
Name: OS + ":" + version,
|
||||||
|
VersionFormat: versionFormat,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -72,8 +72,22 @@ func (detector *OsReleaseNamespaceDetector) Detect(data map[string][]byte) *data
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determine the VersionFormat.
|
||||||
|
var versionFormat string
|
||||||
|
switch OS {
|
||||||
|
case "debian", "ubuntu":
|
||||||
|
versionFormat = "dpkg"
|
||||||
|
case "centos", "rhel", "fedora", "amzn", "ol", "oracle":
|
||||||
|
versionFormat = "rpm"
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if OS != "" && version != "" {
|
if OS != "" && version != "" {
|
||||||
return &database.Namespace{Name: OS + ":" + version}
|
return &database.Namespace{
|
||||||
|
Name: OS + ":" + version,
|
||||||
|
VersionFormat: versionFormat,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -58,20 +58,29 @@ func (detector *RedhatReleaseNamespaceDetector) Detect(data map[string][]byte) *
|
|||||||
// try for Oracle Linux
|
// try for Oracle Linux
|
||||||
r = oracleReleaseRegexp.FindStringSubmatch(string(f))
|
r = oracleReleaseRegexp.FindStringSubmatch(string(f))
|
||||||
if len(r) == 4 {
|
if len(r) == 4 {
|
||||||
return &database.Namespace{Name: strings.ToLower(r[1]) + ":" + r[3]}
|
return &database.Namespace{
|
||||||
|
Name: strings.ToLower(r[1]) + ":" + r[3],
|
||||||
|
VersionFormat: "rpm",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// try for RHEL
|
// try for RHEL
|
||||||
r = redhatReleaseRegexp.FindStringSubmatch(string(f))
|
r = redhatReleaseRegexp.FindStringSubmatch(string(f))
|
||||||
if len(r) == 4 {
|
if len(r) == 4 {
|
||||||
// TODO(vbatts) this is a hack until https://github.com/coreos/clair/pull/193
|
// TODO(vbatts) this is a hack until https://github.com/coreos/clair/pull/193
|
||||||
return &database.Namespace{Name: "centos" + ":" + r[3]}
|
return &database.Namespace{
|
||||||
|
Name: "centos" + ":" + r[3],
|
||||||
|
VersionFormat: "rpm",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// then try centos first
|
// then try centos first
|
||||||
r = centosReleaseRegexp.FindStringSubmatch(string(f))
|
r = centosReleaseRegexp.FindStringSubmatch(string(f))
|
||||||
if len(r) == 4 {
|
if len(r) == 4 {
|
||||||
return &database.Namespace{Name: strings.ToLower(r[1]) + ":" + r[3]}
|
return &database.Namespace{
|
||||||
|
Name: strings.ToLower(r[1]) + ":" + r[3],
|
||||||
|
VersionFormat: "rpm",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,7 @@ func TestProcessWithDistUpgrade(t *testing.T) {
|
|||||||
|
|
||||||
for _, nufv := range nonUpgradedFeatureVersions {
|
for _, nufv := range nonUpgradedFeatureVersions {
|
||||||
nufv.Feature.Namespace.Name = "debian:7"
|
nufv.Feature.Namespace.Name = "debian:7"
|
||||||
|
nufv.Feature.Namespace.VersionFormat = "dpkg"
|
||||||
assert.Contains(t, wheezy.Features, nufv)
|
assert.Contains(t, wheezy.Features, nufv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,10 +102,12 @@ func TestProcessWithDistUpgrade(t *testing.T) {
|
|||||||
|
|
||||||
for _, nufv := range nonUpgradedFeatureVersions {
|
for _, nufv := range nonUpgradedFeatureVersions {
|
||||||
nufv.Feature.Namespace.Name = "debian:7"
|
nufv.Feature.Namespace.Name = "debian:7"
|
||||||
|
nufv.Feature.Namespace.VersionFormat = "dpkg"
|
||||||
assert.Contains(t, jessie.Features, nufv)
|
assert.Contains(t, jessie.Features, nufv)
|
||||||
}
|
}
|
||||||
for _, nufv := range nonUpgradedFeatureVersions {
|
for _, nufv := range nonUpgradedFeatureVersions {
|
||||||
nufv.Feature.Namespace.Name = "debian:8"
|
nufv.Feature.Namespace.Name = "debian:8"
|
||||||
|
nufv.Feature.Namespace.VersionFormat = "dpkg"
|
||||||
assert.NotContains(t, jessie.Features, nufv)
|
assert.NotContains(t, jessie.Features, nufv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user