diff --git a/internal/redfishwrapper/firmware.go b/internal/redfishwrapper/firmware.go index 81c3f1a5..01f287aa 100644 --- a/internal/redfishwrapper/firmware.go +++ b/internal/redfishwrapper/firmware.go @@ -16,6 +16,7 @@ import ( "time" "github.com/pkg/errors" + "github.com/stmcginnis/gofish/redfish" "github.com/bmc-toolbox/bmclib/v2/constants" bmclibErrs "github.com/bmc-toolbox/bmclib/v2/errors" @@ -112,6 +113,16 @@ func (c *Client) FirmwareUpload(ctx context.Context, updateFile *os.File, params return taskIDFromLocationHeader(location) } + rfTask := &redfish.Task{} + if err := rfTask.UnmarshalJSON(response); err != nil { + // we got invalid JSON + return "", fmt.Errorf("unmarshaling redfish response: %w", err) + } + // it's possible to get well-formed JSON that isn't a Task (thanks SMC). Test that we have something sensible. + if strings.Contains(rfTask.ODataType, "Task") { + return rfTask.ID, nil + } + return taskIDFromResponseBody(response) } @@ -146,6 +157,15 @@ func (c *Client) StartUpdateForUploadedFirmware(ctx context.Context) (taskID str return taskIDFromLocationHeader(location) } + rfTask := &redfish.Task{} + if err := rfTask.UnmarshalJSON(response); err != nil { + // we got invalid JSON + return "", fmt.Errorf("unmarshaling redfish response: %w", err) + } + if strings.Contains(rfTask.ODataType, "Task") { + return rfTask.ID, nil + } + return taskIDFromResponseBody(response) }