add Version to fetchers

Signed-off-by: liang chenye <liangchenye@huawei.com>
This commit is contained in:
liang chenye 2016-05-03 14:42:28 +08:00
parent 27ebef5d90
commit 5ae8b26c58
6 changed files with 21 additions and 19 deletions

View File

@ -192,7 +192,8 @@ func parseDebianJSON(data *jsonData) (vulnerabilities []database.Vulnerability,
Feature: database.Feature{ Feature: database.Feature{
Name: pkgName, Name: pkgName,
Namespace: database.Namespace{ Namespace: database.Namespace{
Name: "debian:" + database.DebianReleasesMapping[releaseName], Name: "debian",
Version: types.NewVersionUnsafe(database.DebianReleasesMapping[releaseName]),
}, },
}, },
Version: version, Version: version,

View File

@ -41,14 +41,14 @@ func TestDebianParser(t *testing.T) {
expectedFeatureVersions := []database.FeatureVersion{ expectedFeatureVersions := []database.FeatureVersion{
{ {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{Name: "debian:8"}, Namespace: database.Namespace{Name: "debian", Version: types.NewVersionUnsafe("8")},
Name: "aptdaemon", Name: "aptdaemon",
}, },
Version: types.MaxVersion, Version: types.MaxVersion,
}, },
{ {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{Name: "debian:unstable"}, Namespace: database.Namespace{Name: "debian", Version: types.NewVersionUnsafe("unstable")},
Name: "aptdaemon", Name: "aptdaemon",
}, },
@ -67,21 +67,21 @@ func TestDebianParser(t *testing.T) {
expectedFeatureVersions := []database.FeatureVersion{ expectedFeatureVersions := []database.FeatureVersion{
{ {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{Name: "debian:8"}, Namespace: database.Namespace{Name: "debian", Version: types.NewVersionUnsafe("8")},
Name: "aptdaemon", Name: "aptdaemon",
}, },
Version: types.NewVersionUnsafe("0.7.0"), Version: types.NewVersionUnsafe("0.7.0"),
}, },
{ {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{Name: "debian:unstable"}, Namespace: database.Namespace{Name: "debian", Version: types.NewVersionUnsafe("unstable")},
Name: "aptdaemon", Name: "aptdaemon",
}, },
Version: types.NewVersionUnsafe("0.7.0"), Version: types.NewVersionUnsafe("0.7.0"),
}, },
{ {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{Name: "debian:8"}, Namespace: database.Namespace{Name: "debian", Version: types.NewVersionUnsafe("8")},
Name: "asterisk", Name: "asterisk",
}, },
Version: types.NewVersionUnsafe("0.5.56"), Version: types.NewVersionUnsafe("0.5.56"),
@ -99,7 +99,7 @@ func TestDebianParser(t *testing.T) {
expectedFeatureVersions := []database.FeatureVersion{ expectedFeatureVersions := []database.FeatureVersion{
{ {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{Name: "debian:8"}, Namespace: database.Namespace{Name: "debian", Version: types.NewVersionUnsafe("8")},
Name: "asterisk", Name: "asterisk",
}, },
Version: types.MinVersion, Version: types.MinVersion,

View File

@ -291,13 +291,14 @@ func toFeatureVersions(criteria criteria) []database.FeatureVersion {
} }
if osVersion > firstConsideredRHEL { if osVersion > firstConsideredRHEL {
featureVersion.Feature.Namespace.Name = "centos" + ":" + strconv.Itoa(osVersion) featureVersion.Feature.Namespace.Name = "centos"
featureVersion.Feature.Namespace.Version = types.NewVersionUnsafe(strconv.Itoa(osVersion))
} else { } else {
continue continue
} }
if featureVersion.Feature.Namespace.Name != "" && featureVersion.Feature.Name != "" && featureVersion.Version.String() != "" { if !featureVersion.Feature.Namespace.IsEmpty() && featureVersion.Feature.Name != "" && featureVersion.Version.String() != "" {
featureVersionParameters[featureVersion.Feature.Namespace.Name+":"+featureVersion.Feature.Name] = featureVersion featureVersionParameters[featureVersion.Feature.Namespace.Name+":"+featureVersion.Feature.Namespace.Version.String()+":"+featureVersion.Feature.Name] = featureVersion
} else { } else {
log.Warningf("could not determine a valid package from criterions: %v", criterions) log.Warningf("could not determine a valid package from criterions: %v", criterions)
} }

View File

@ -41,21 +41,21 @@ func TestRHELParser(t *testing.T) {
expectedFeatureVersions := []database.FeatureVersion{ expectedFeatureVersions := []database.FeatureVersion{
{ {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{Name: "centos:7"}, Namespace: database.Namespace{Name: "centos", Version: types.NewVersionUnsafe("7")},
Name: "xerces-c", Name: "xerces-c",
}, },
Version: types.NewVersionUnsafe("3.1.1-7.el7_1"), Version: types.NewVersionUnsafe("3.1.1-7.el7_1"),
}, },
{ {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{Name: "centos:7"}, Namespace: database.Namespace{Name: "centos", Version: types.NewVersionUnsafe("7")},
Name: "xerces-c-devel", Name: "xerces-c-devel",
}, },
Version: types.NewVersionUnsafe("3.1.1-7.el7_1"), Version: types.NewVersionUnsafe("3.1.1-7.el7_1"),
}, },
{ {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{Name: "centos:7"}, Namespace: database.Namespace{Name: "centos", Version: types.NewVersionUnsafe("7")},
Name: "xerces-c-doc", Name: "xerces-c-doc",
}, },
Version: types.NewVersionUnsafe("3.1.1-7.el7_1"), Version: types.NewVersionUnsafe("3.1.1-7.el7_1"),
@ -79,14 +79,14 @@ func TestRHELParser(t *testing.T) {
expectedFeatureVersions := []database.FeatureVersion{ expectedFeatureVersions := []database.FeatureVersion{
{ {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{Name: "centos:6"}, Namespace: database.Namespace{Name: "centos", Version: types.NewVersionUnsafe("6")},
Name: "firefox", Name: "firefox",
}, },
Version: types.NewVersionUnsafe("38.1.0-1.el6_6"), Version: types.NewVersionUnsafe("38.1.0-1.el6_6"),
}, },
{ {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{Name: "centos:7"}, Namespace: database.Namespace{Name: "centos", Version: types.NewVersionUnsafe("7")},
Name: "firefox", Name: "firefox",
}, },
Version: types.NewVersionUnsafe("38.1.0-1.el7_1"), Version: types.NewVersionUnsafe("38.1.0-1.el7_1"),

View File

@ -376,7 +376,7 @@ func parseUbuntuCVE(fileContent io.Reader) (vulnerability database.Vulnerability
// Create and add the new package. // Create and add the new package.
featureVersion := database.FeatureVersion{ featureVersion := database.FeatureVersion{
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{Name: "ubuntu:" + database.UbuntuReleasesMapping[md["release"]]}, Namespace: database.Namespace{Name: "ubuntu", Version: types.NewVersionUnsafe(database.UbuntuReleasesMapping[md["release"]])},
Name: md["package"], Name: md["package"],
}, },
Version: version, Version: version,

View File

@ -45,21 +45,21 @@ func TestUbuntuParser(t *testing.T) {
expectedFeatureVersions := []database.FeatureVersion{ expectedFeatureVersions := []database.FeatureVersion{
{ {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{Name: "ubuntu:14.04"}, Namespace: database.Namespace{Name: "ubuntu", Version: types.NewVersionUnsafe("14.04")},
Name: "libmspack", Name: "libmspack",
}, },
Version: types.MaxVersion, Version: types.MaxVersion,
}, },
{ {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{Name: "ubuntu:15.04"}, Namespace: database.Namespace{Name: "ubuntu", Version: types.NewVersionUnsafe("15.04")},
Name: "libmspack", Name: "libmspack",
}, },
Version: types.NewVersionUnsafe("0.4-3"), Version: types.NewVersionUnsafe("0.4-3"),
}, },
{ {
Feature: database.Feature{ Feature: database.Feature{
Namespace: database.Namespace{Name: "ubuntu:15.10"}, Namespace: database.Namespace{Name: "ubuntu", Version: types.NewVersionUnsafe("15.10")},
Name: "libmspack-anotherpkg", Name: "libmspack-anotherpkg",
}, },
Version: types.NewVersionUnsafe("0.1"), Version: types.NewVersionUnsafe("0.1"),