-
Couldn't load subscription status.
- Fork 727
Add support for Arch (which doesnt return a version) and Open Suse Leap #170
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
Conversation
4e01cf7 to
2d47b69
Compare
syft/distro/identify.go
Outdated
| // Both distro and version must be present | ||
| if len(name) == 0 || len(version) == 0 { | ||
| if len(name) == 0 { | ||
| log.Debugf("Name (%s) not found", name) |
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.
nit: logging probably isn't necessary here
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 used it for some local debugging but wasn't sure if it'd be useful later on for troubleshooting! Will remove.
syft/distro/distro.go
Outdated
| hashiVer "github.com/hashicorp/go-version" | ||
| ) | ||
|
|
||
| const VersionUnknown = "(version unknown)" |
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'd vote removing this and leaving the version field blank.
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 MajorVersion and String functions should be updated to account for when the version is not included.
syft/distro/distro.go
Outdated
| verObj, err := hashiVer.NewVersion(ver) | ||
| if err != nil { | ||
| return Distro{}, fmt.Errorf("could not create distro version: %w", err) | ||
| var verObj *hashiVer.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.
This isn't a required change at all, just a subjective suggestion for making the implementation easier to follow and slightly less nested (and consequently, it cuts down on variables that are declared without defined values). Feel free to discard! 😄
Assuming we accept @wagoodman 's suggestion of using the zero value for RawVersion in this case (which I agree with), we can detect a lack of version early on and return a Distro accordingly.
if ver == "" {
return Distro{Type: t}, nil
}
verObj, err := hashiVer.NewVersion(ver)
if err != nil {
return Distro{}, fmt.Errorf("could not create distro version: %w", err)
}
return Distro{
Type: t,
Version: verObj,
RawVersion: ver,
}, nilThere 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.
great feedback! This is normally how I prefer to program things but I'm still getting my feet wet w/ go, so I missed this! It's funny how new contexts can be distracting this way. Updated to follow this format!
Signed-off-by: Samuel Dacanay <[email protected]> remove bad-version test fixture (no longer relevant since it is now an expected case) and add cases for arch and opensuse-leap Signed-off-by: Samuel Dacanay <[email protected]> Reduce nesting, simplify empty version logic Signed-off-by: Samuel Dacanay <[email protected]>
2d47b69 to
329b080
Compare
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.
Nice!
…and-opensuseleap Add support for Arch (which doesnt return a version) and Open Suse Leap
Fixes #48
Fixes #49
Signed-off-by: Samuel Dacanay [email protected]