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

fix(lwcomponent): better JSON handling components #946

Merged
merged 1 commit into from
Oct 14, 2022
Merged

fix(lwcomponent): better JSON handling components #946

merged 1 commit into from
Oct 14, 2022

Conversation

hazedav
Copy link
Collaborator

@hazedav hazedav commented Oct 13, 2022

Summary

When attempting to json.Unmarshal the lwcomponent.Component object several quirks are present.

{
    "name": "abc",
    "description": "def",
    "type": "BINARY",
    "version": {},
    "artifacts": [
        {
            "os": "darwin",
            "arch": "amd64",
            "url": "",
            "signature": ""
        }
    ],
    "breadcrumbs": {},
    "command_name": ""
}
  1. Some items should be omitted if empty (i.e. url and command_name)
  2. version should be a string not a dict

How did you test this change?

Unit tests added

Issue

https://lacework.atlassian.net/browse/ALLY-1229

@@ -255,12 +255,45 @@ type Component struct {
Name string `json:"name"`
Description string `json:"description"`
Type Type `json:"type"`
LatestVersion semver.Version `json:"version"`
LatestVersion semver.Version `json:"-"`
Copy link
Contributor

Choose a reason for hiding this comment

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

We need this field.

Copy link
Collaborator Author

@hazedav hazedav Oct 14, 2022

Choose a reason for hiding this comment

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

Please see MarshalJSON() and UnmarshalJSON() methods for Component which properly handles this field via LatestVersionString. Also TestJSON shows this properly being marshaled and unmarshaled.

@@ -255,12 +255,45 @@ type Component struct {
Name string `json:"name"`
Description string `json:"description"`
Type Type `json:"type"`
LatestVersion semver.Version `json:"version"`
LatestVersion semver.Version `json:"-"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe:

Suggested change
LatestVersion semver.Version `json:"-"`
LatestVersion semver.Version `json:"version,omitempty"`

Copy link
Collaborator Author

@hazedav hazedav Oct 14, 2022

Choose a reason for hiding this comment

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

Please see MarshalJSON() and UnmarshalJSON() methods for Component which properly handles this field via LatestVersionString. Also TestJSON shows this properly being marshaled and unmarshaled.

Copy link
Contributor

Choose a reason for hiding this comment

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

You're way to smart!

@hazedav hazedav requested a review from afiune October 14, 2022 01:57
Copy link
Contributor

@afiune afiune left a comment

Choose a reason for hiding this comment

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

Way to smart!!

@afiune afiune merged commit 8edb92d into main Oct 14, 2022
@afiune afiune deleted the ALLY-1229 branch October 14, 2022 07:51
@hazedav
Copy link
Collaborator Author

hazedav commented Oct 14, 2022

Thanks for the speedy review @afiune

@lacework-releng lacework-releng mentioned this pull request Oct 18, 2022
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.

2 participants