tag v0.142.0 Tagger: imagebuilder-bot <imagebuilder-bots+imagebuilder-bot@redhat.com> Changes with 0.142.0 ---------------- * distro: move `kernelOptions` into `ImageConfig` (osbuild/images#1470) * Author: Michael Vogt, Reviewers: Achilleas Koutsou, Tomáš Hozza * manifest: register insights to template on boot (HMS-5994) (osbuild/images#1443) * Author: rverdile, Reviewers: Achilleas Koutsou, Tomáš Hozza * many: add custom unmarshalers for osbuild, platform (osbuild/images#1477) * Author: Michael Vogt, Reviewers: Achilleas Koutsou, Tomáš Hozza — Somewhere on the Internet, 2025-05-05 --- tag v0.143.0 Tagger: imagebuilder-bot <imagebuilder-bots+imagebuilder-bot@redhat.com> Changes with 0.143.0 ---------------- * distro/rhel9/azure: drop net.ifnames=0 kernel arg (RHEL-89440) (osbuild/images#1487) * Author: Achilleas Koutsou, Reviewers: Michael Vogt, Sanne Raymaekers * github: don't run manifest checksum validation on the merge queue (osbuild/images#1478) * Author: Achilleas Koutsou, Reviewers: Brian C. Lane, Florian Schüller * repositories: Set 6h expire on main repo, use default for updates (osbuild/images#1482) * Author: Brian C. Lane, Reviewers: Achilleas Koutsou, Neal Gompa (ニール・ゴンパ), Simon de Vlieger — Somewhere on the Internet, 2025-05-05 ---
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package disk
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
"reflect"
|
|
)
|
|
|
|
func unmarshalJSONPayload(data []byte) (PayloadEntity, error) {
|
|
var payload struct {
|
|
Payload json.RawMessage `json:"payload"`
|
|
PayloadType string `json:"payload_type,omitempty"`
|
|
}
|
|
if err := json.Unmarshal(data, &payload); err != nil {
|
|
return nil, fmt.Errorf("cannot peek payload: %w", err)
|
|
}
|
|
if payload.PayloadType == "" {
|
|
if len(payload.Payload) > 0 {
|
|
return nil, fmt.Errorf("cannot build payload: empty payload type but payload is: %q", payload.Payload)
|
|
}
|
|
return nil, nil
|
|
}
|
|
entType := payloadEntityMap[payload.PayloadType]
|
|
if entType == nil {
|
|
return nil, fmt.Errorf("cannot build payload from %q: unknown payload type %q", data, payload.PayloadType)
|
|
}
|
|
entValP := reflect.New(entType).Elem().Addr()
|
|
ent := entValP.Interface()
|
|
if err := jsonUnmarshalStrict(payload.Payload, &ent); err != nil {
|
|
return nil, fmt.Errorf("cannot decode payload for %q: %w", data, err)
|
|
}
|
|
return ent.(PayloadEntity), nil
|
|
}
|
|
|
|
func jsonUnmarshalStrict(data []byte, v any) error {
|
|
dec := json.NewDecoder(bytes.NewBuffer(data))
|
|
dec.DisallowUnknownFields()
|
|
return dec.Decode(&v)
|
|
}
|