diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2022-02-10 15:13:03 +0000 |
|---|---|---|
| committer | Aleksandr Nogikh <wp32pw@gmail.com> | 2022-02-25 18:57:42 +0100 |
| commit | aa3dbd72ed6726be5bf1bec14a2ceaca369a8063 (patch) | |
| tree | a9d05b9e5b20fc512c4f0b62c444302e7e496a4c /pkg/config/merge.go | |
| parent | dbfe5869946787d945f1e52f9a435c5284c9edd3 (diff) | |
tools/syz-testbed: don't parse configs
It's not practical to parse configs from tools/syz-testbed because it
limits the tool to using only those configuration options, which are
supported by the syzkaller version at the moment of tools/syz-testbed
compilation.
Operate with manager configs as if they were just some JSON objects.
Introduce a PatchJSON method to update their fields in a convenient way.
Diffstat (limited to 'pkg/config/merge.go')
| -rw-r--r-- | pkg/config/merge.go | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/pkg/config/merge.go b/pkg/config/merge.go index 49a7254de..3d8193c02 100644 --- a/pkg/config/merge.go +++ b/pkg/config/merge.go @@ -9,7 +9,7 @@ import ( // Unfortunately, if we want to apply a JSON patch to some configuration, we cannot just unmarshal // it twice - in that case json.RawMessage objects will be completely replaced, but not merged. -func MergeJSONData(left, right []byte) ([]byte, error) { +func MergeJSONs(left, right []byte) ([]byte, error) { vLeft, err := parseFragment(left) if err != nil { return nil, err @@ -18,8 +18,17 @@ func MergeJSONData(left, right []byte) ([]byte, error) { if err != nil { return nil, err } - merged := mergeRecursive(vLeft, vRight) - return json.Marshal(merged) + return json.Marshal(mergeRecursive(vLeft, vRight)) +} + +// Recursively apply a patch to a raw JSON data. +// Patch is supposed to be a map, which possibly nests other map objects. +func PatchJSON(left []byte, patch map[string]interface{}) ([]byte, error) { + vLeft, err := parseFragment(left) + if err != nil { + return nil, err + } + return json.Marshal(mergeRecursive(vLeft, patch)) } func parseFragment(input []byte) (parsed interface{}, err error) { |
