Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dakaneye
Copy link
Contributor

Fixes #48
Fixes #49
Signed-off-by: Samuel Dacanay [email protected]

@dakaneye dakaneye force-pushed the add-distro-mappings-arch-and-opensuseleap branch 2 times, most recently from 4e01cf7 to 2d47b69 Compare September 12, 2020 00:00
// 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)
Copy link
Contributor

@wagoodman wagoodman Sep 13, 2020

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

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 used it for some local debugging but wasn't sure if it'd be useful later on for troubleshooting! Will remove.

hashiVer "github.com/hashicorp/go-version"
)

const VersionUnknown = "(version unknown)"
Copy link
Contributor

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.

Copy link
Contributor

@wagoodman wagoodman left a 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.

verObj, err := hashiVer.NewVersion(ver)
if err != nil {
return Distro{}, fmt.Errorf("could not create distro version: %w", err)
var verObj *hashiVer.Version
Copy link
Contributor

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,
}, nil

Copy link
Contributor Author

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]>
@dakaneye dakaneye force-pushed the add-distro-mappings-arch-and-opensuseleap branch from 2d47b69 to 329b080 Compare September 13, 2020 20:51
Copy link
Contributor

@luhring luhring left a comment

Choose a reason for hiding this comment

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

Nice!

@dakaneye dakaneye merged commit 22dfcb2 into main Sep 14, 2020
@dakaneye dakaneye deleted the add-distro-mappings-arch-and-opensuseleap branch September 14, 2020 16:02
GijsCalis pushed a commit to GijsCalis/syft that referenced this pull request Feb 19, 2024
…and-opensuseleap

Add support for Arch (which doesnt return a version) and Open Suse Leap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add arch distro identification Add suse distro identification

3 participants