Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add registrable version formats #298

Merged
merged 8 commits into from Jan 3, 2017
Merged

Add registrable version formats #298

merged 8 commits into from Jan 3, 2017

Conversation

jzelinskie
Copy link
Contributor

@jzelinskie jzelinskie commented Dec 29, 2016

Version Formats are a new registrable interface for validating and comparing version strings.
Namespaces enforce that all Features use the same Version Format.

This PR adds the following formats:

  • dpkg
  • rpm

Fixes #222

@jzelinskie jzelinskie added component/database kind/bug things are not as they seem kind/design relates to the fundamental design of a component labels Dec 29, 2016
expected int
v2 string
}{

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to get rid of these newlines

if !unicode.IsDigit(rune(v.version[0])) {
return version{}, errors.New("version does not start with digit")
}
*/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to remove this comment.


// newVersionUnsafe is just a wrapper around NewVersion that ignore potentiel
// parsing error. Useful for test purposes
func newVersionUnsafe(str string) version {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I can delete this func

Since we only ever used dpkg, this change shims everything into using
dpkg.
This also filters unknown namespaces from the generic lsb-release and
osrelease detectors.
)

var log = capnslog.NewPackageLogger("github.com/coreos/clair", "v1")

type Error struct {
Message string `json:"Layer`
Message string `json:"Layer"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tag name?

@@ -1,4 +1,4 @@
// Copyright 2015 clair authors
// Copyright 2016 clair authors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should revert these and make a separated PR for 2017.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than spamming the codebase, I'd rather just update them whenever the files are touched.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm

func (pgSQL *pgSQL) insertFeatureVersion(fv database.FeatureVersion) (id int, err error) {
err = versionfmt.Valid(fv.Feature.Namespace.VersionFormat, fv.Version)
if err != nil {
fmt.Println(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover.

if featureVersion.Version.Compare(affect.fixedInVersion) < 0 {
cmp, err := versionfmt.Compare(featureVersion.Feature.Namespace.VersionFormat, featureVersion.Version, affect.fixedInVersion)
if err != nil {
return handleError("searchVulnerabilityVersionComparison", err)
Copy link
Contributor

@Quentin-M Quentin-M Jan 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handleError is specifically for SQL errors, it does a bunch of stuff including adding entries to Prometheus. So it'll show as a pgsql error while it's really..

return err
}

rows, err := tx.Query(`SELECT name FROM Namespace FOR UPDATE;`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though I was pretty excited to use Go migrations, we could actually do it serve-side this time.

UPDATE Namespace SET version_format = 'rpm' WHERE name LIKE 'RHEL%' OR name LIKE 'centos'%' ...

With a slightly smarter query, we might even update both dpkg and rpm using a single pass.

{"1.0~rc1~git123", LESS, "1.0~rc1"},
{"1.0~rc1", GREATER, "1.0~rc1~git123"},

// These are included here to document current, arguably buggy behaviors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add note that these are imported as is from the rpm sources (arguably buggy = upstream)

@@ -235,7 +239,7 @@ func parse33YAML(r io.Reader) (vulns []database.Vulnerability, err error) {
Namespace: database.Namespace{Name: "alpine:" + file.Distro},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing VersionFormat? Do we need it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also in parse34YAML, debian, etc.

},
Version: types.NewVersionUnsafe("3.1.1-7.el7_1"),
Version: "0:3.1.1-7.el7_1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why changing the test? The 0 epoch is optional. Can do some tests with but some without but we should ensure it still works without.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm

},
Version: types.NewVersionUnsafe("3.1.1-7.el7_1"),
Version: "0:3.1.1-7.el7_1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here is that we're comparing the objects with testify. It's doing a straight up string comparison. I think it's best to leave the epoch on because that's how it was presented in the source.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm

@@ -74,28 +78,34 @@ func (detector *DpkgFeaturesDetector) Detect(data map[string][]byte) ([]database

pkg.Feature.Name = md["name"]
if md["version"] != "" {
pkg.Version, err = types.NewVersion(md["version"])
version := md["version"]
err = versionfmt.Valid("dpkg", version)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems we hardcore "dpkg" and "rpm" everyone. Should it be a constant in the parser?

@Quentin-M
Copy link
Contributor

@jzelinskie jzelinskie merged commit ab33f8c into quay:master Jan 3, 2017
@jzelinskie jzelinskie deleted the versions branch January 3, 2017 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug things are not as they seem kind/design relates to the fundamental design of a component
Development

Successfully merging this pull request may close these issues.

None yet

2 participants