mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-10 09:56:55 +00:00
* cherry-pick fix attestation checks https://github.com/kyverno/kyverno/pull/3999 Signed-off-by: Jim Bugwadia <jim@nirmata.com> * remove TUF initialization from main (#4098) Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix imageVerify validation checks and conversion logic (#4038) Signed-off-by: Jim Bugwadia <jim@nirmata.com> Co-authored-by: Vyankatesh Kudtarkar <vyankateshkd@gmail.com> * release event memory (#4138) Signed-off-by: Jim Bugwadia <jim@nirmata.com> Co-authored-by: Vyankatesh Kudtarkar <vyankateshkd@gmail.com> * fix merge of image verify and mutate patches Signed-off-by: Jim Bugwadia <jim@nirmata.com> * fix patch join Signed-off-by: Jim Bugwadia <jim@nirmata.com> * handle embedded strings with spaces Signed-off-by: Jim Bugwadia <jim@nirmata.com> Co-authored-by: Prateek Pandey <prateek.pandey@nirmata.com> Co-authored-by: Vyankatesh Kudtarkar <vyankateshkd@gmail.com>
37 lines
797 B
Go
37 lines
797 B
Go
package json
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
// JoinPatches joins array of serialized JSON patches to the single JSONPatch array
|
|
// It accepts patch operations and patches (arrays of patch operations) and returns
|
|
// a single combined patch.
|
|
func JoinPatches(patches ...[]byte) []byte {
|
|
if len(patches) == 0 {
|
|
return nil
|
|
}
|
|
|
|
var patchOperations []string
|
|
for _, patch := range patches {
|
|
str := strings.TrimSpace(string(patch))
|
|
if len(str) == 0 {
|
|
continue
|
|
}
|
|
|
|
if strings.HasPrefix(str, "[") {
|
|
str = strings.TrimPrefix(str, "[")
|
|
str = strings.TrimSuffix(str, "]")
|
|
str = strings.TrimSpace(str)
|
|
}
|
|
|
|
patchOperations = append(patchOperations, str)
|
|
}
|
|
|
|
if len(patchOperations) == 0 {
|
|
return nil
|
|
}
|
|
|
|
result := "[" + strings.Join(patchOperations, ",\n") + "]"
|
|
return []byte(result)
|
|
}
|