Skip to content

Commit

Permalink
Add ability to output json lists in metadata build file
Browse files Browse the repository at this point in the history
Signed-off-by: Laurent Goderre <[email protected]>
  • Loading branch information
LaurentGoderre committed Nov 4, 2024
1 parent bcac44f commit ce86a92
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,30 @@ func checkWarnedFlags(f *pflag.Flag) {
}
}

func writeMetadataFile(filename string, dt interface{}) error {
b, err := json.MarshalIndent(dt, "", " ")
func writeMetadataFile(filename string, response map[string]interface{}) error {
out := make(map[string]interface{})
for k, v := range response {
var dt []byte
j, ok := v.(string)
if ok {
d, err := base64.StdEncoding.DecodeString(string(j))
if err != nil {
out[k] = v
continue
}
dt = d
} else if d, ok := v.(json.RawMessage); ok {
dt = d
}

var raw interface{}
if err := json.Unmarshal(dt, &raw); err != nil {
out[k] = v
continue
}
out[k] = json.RawMessage(dt)
}
b, err := json.MarshalIndent(out, "", " ")
if err != nil {
return err
}
Expand Down

0 comments on commit ce86a92

Please sign in to comment.