-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
expected int | ||
v2 string | ||
}{ | ||
|
There was a problem hiding this comment.
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") | ||
} | ||
*/ |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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"` |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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;`) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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}, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as before?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
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:
Fixes #222