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 firmware versioned attribute compatibility #111

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions internal/inventory/component_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,21 @@ func componentAttributesFromJSON(byt []byte) (*rivets.ComponentAttributes, error
return ca, nil
}

// for historical reasons, alloy used to store firmware data like this using a different API
// we create this here to maintain compatibility with old data
type firmwareContainer struct {
Firmware *common.Firmware `json:"firmware,omitempty"`
}

func mustFirmwareJSON(fw *common.Firmware) []byte {
if fw == nil {
return nil
}
byt, err := json.Marshal(fw)

fwc := &firmwareContainer{
Firmware: fw,
}
byt, err := json.Marshal(fwc)
if err != nil {
panic("bad firmware payload")
}
Expand All @@ -44,12 +54,12 @@ func firmwareFromJSON(byt []byte) (*common.Firmware, error) {
if byt == nil {
return nil, nil
}
fw := &common.Firmware{}
err := json.Unmarshal(byt, fw)
fwc := &firmwareContainer{}
err := json.Unmarshal(byt, fwc)
if err != nil {
return nil, err
}
return fw, nil
return fwc.Firmware, nil
}

type statusContainer struct {
Expand Down
Loading