mirror of
https://github.com/k8snetworkplumbingwg/whereabouts.git
synced 2025-06-03 06:42:26 +00:00
build(deps): bump gomodules.xyz/jsonpatch/v2 from 2.2.0 to 2.4.0
Bumps [gomodules.xyz/jsonpatch/v2](https://github.com/gomodules/jsonpatch) from 2.2.0 to 2.4.0. - [Release notes](https://github.com/gomodules/jsonpatch/releases) - [Changelog](https://github.com/gomodules/jsonpatch/blob/release-2.0/CHANGELOG.md) - [Commits](https://github.com/gomodules/jsonpatch/compare/v2.2.0...v2.4.0) --- updated-dependencies: - dependency-name: gomodules.xyz/jsonpatch/v2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
parent
c2e6c4d76b
commit
9630fb5382
2
go.mod
2
go.mod
@ -12,7 +12,7 @@ require (
|
|||||||
github.com/onsi/ginkgo v1.16.5
|
github.com/onsi/ginkgo v1.16.5
|
||||||
github.com/onsi/gomega v1.31.1
|
github.com/onsi/gomega v1.31.1
|
||||||
github.com/pkg/errors v0.9.1
|
github.com/pkg/errors v0.9.1
|
||||||
gomodules.xyz/jsonpatch/v2 v2.2.0
|
gomodules.xyz/jsonpatch/v2 v2.4.0
|
||||||
k8s.io/api v0.24.0
|
k8s.io/api v0.24.0
|
||||||
k8s.io/apimachinery v0.24.0
|
k8s.io/apimachinery v0.24.0
|
||||||
k8s.io/client-go v0.24.0
|
k8s.io/client-go v0.24.0
|
||||||
|
6
go.sum
6
go.sum
@ -99,7 +99,6 @@ github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5y
|
|||||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ=
|
github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ=
|
||||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||||
github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ=
|
|
||||||
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||||
github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||||
github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCvpL6mnFh5mB2/l16U=
|
github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCvpL6mnFh5mB2/l16U=
|
||||||
@ -246,7 +245,6 @@ github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:
|
|||||||
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
||||||
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
|
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
|
||||||
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
|
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
|
||||||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
|
||||||
github.com/jonboulle/clockwork v0.4.0 h1:p4Cf1aMWXnXAUh8lVfewRBx1zaTSYKrKMF2g3ST4RZ4=
|
github.com/jonboulle/clockwork v0.4.0 h1:p4Cf1aMWXnXAUh8lVfewRBx1zaTSYKrKMF2g3ST4RZ4=
|
||||||
github.com/jonboulle/clockwork v0.4.0/go.mod h1:xgRqUGwRcjKCO1vbZUEtSLrqKoPSsUpK7fnezOII0kc=
|
github.com/jonboulle/clockwork v0.4.0/go.mod h1:xgRqUGwRcjKCO1vbZUEtSLrqKoPSsUpK7fnezOII0kc=
|
||||||
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
||||||
@ -618,8 +616,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
|
|||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
gomodules.xyz/jsonpatch/v2 v2.2.0 h1:4pT439QV83L+G9FkcCriY6EkpcK6r6bK+A5FBUMI7qY=
|
gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw=
|
||||||
gomodules.xyz/jsonpatch/v2 v2.2.0/go.mod h1:WXp+iVDkoLQqPudfQ9GBlwB2eZ5DKOnjQZCYdOS8GPY=
|
gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY=
|
||||||
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
|
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
|
||||||
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
|
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
|
||||||
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
|
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
|
||||||
|
160
vendor/gomodules.xyz/jsonpatch/v2/jsonpatch.go
vendored
160
vendor/gomodules.xyz/jsonpatch/v2/jsonpatch.go
vendored
@ -24,21 +24,28 @@ func (j *Operation) Json() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (j *Operation) MarshalJSON() ([]byte, error) {
|
func (j *Operation) MarshalJSON() ([]byte, error) {
|
||||||
var b bytes.Buffer
|
// Ensure for add and replace we emit `value: null`
|
||||||
b.WriteString("{")
|
if j.Value == nil && (j.Operation == "replace" || j.Operation == "add") {
|
||||||
b.WriteString(fmt.Sprintf(`"op":"%s"`, j.Operation))
|
return json.Marshal(struct {
|
||||||
b.WriteString(fmt.Sprintf(`,"path":"%s"`, j.Path))
|
Operation string `json:"op"`
|
||||||
// Consider omitting Value for non-nullable operations.
|
Path string `json:"path"`
|
||||||
if j.Value != nil || j.Operation == "replace" || j.Operation == "add" {
|
Value interface{} `json:"value"`
|
||||||
v, err := json.Marshal(j.Value)
|
}{
|
||||||
if err != nil {
|
Operation: j.Operation,
|
||||||
return nil, err
|
Path: j.Path,
|
||||||
}
|
})
|
||||||
b.WriteString(`,"value":`)
|
|
||||||
b.Write(v)
|
|
||||||
}
|
}
|
||||||
b.WriteString("}")
|
// otherwise just marshal normally. We cannot literally do json.Marshal(j) as it would be recursively
|
||||||
return b.Bytes(), nil
|
// calling this function.
|
||||||
|
return json.Marshal(struct {
|
||||||
|
Operation string `json:"op"`
|
||||||
|
Path string `json:"path"`
|
||||||
|
Value interface{} `json:"value,omitempty"`
|
||||||
|
}{
|
||||||
|
Operation: j.Operation,
|
||||||
|
Path: j.Path,
|
||||||
|
Value: j.Value,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type ByPath []Operation
|
type ByPath []Operation
|
||||||
@ -58,6 +65,9 @@ func NewOperation(op, path string, value interface{}) Operation {
|
|||||||
//
|
//
|
||||||
// An error will be returned if any of the two documents are invalid.
|
// An error will be returned if any of the two documents are invalid.
|
||||||
func CreatePatch(a, b []byte) ([]Operation, error) {
|
func CreatePatch(a, b []byte) ([]Operation, error) {
|
||||||
|
if bytes.Equal(a, b) {
|
||||||
|
return []Operation{}, nil
|
||||||
|
}
|
||||||
var aI interface{}
|
var aI interface{}
|
||||||
var bI interface{}
|
var bI interface{}
|
||||||
err := json.Unmarshal(a, &aI)
|
err := json.Unmarshal(a, &aI)
|
||||||
@ -149,9 +159,6 @@ func makePath(path string, newPart interface{}) string {
|
|||||||
if path == "" {
|
if path == "" {
|
||||||
return "/" + key
|
return "/" + key
|
||||||
}
|
}
|
||||||
if strings.HasSuffix(path, "/") {
|
|
||||||
return path + key
|
|
||||||
}
|
|
||||||
return path + "/" + key
|
return path + "/" + key
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,22 +218,18 @@ func handleValues(av, bv interface{}, p string, patch []Operation) ([]Operation,
|
|||||||
}
|
}
|
||||||
case []interface{}:
|
case []interface{}:
|
||||||
bt := bv.([]interface{})
|
bt := bv.([]interface{})
|
||||||
if isSimpleArray(at) && isSimpleArray(bt) {
|
n := min(len(at), len(bt))
|
||||||
patch = append(patch, compareEditDistance(at, bt, p)...)
|
for i := len(at) - 1; i >= n; i-- {
|
||||||
} else {
|
patch = append(patch, NewOperation("remove", makePath(p, i), nil))
|
||||||
n := min(len(at), len(bt))
|
}
|
||||||
for i := len(at) - 1; i >= n; i-- {
|
for i := n; i < len(bt); i++ {
|
||||||
patch = append(patch, NewOperation("remove", makePath(p, i), nil))
|
patch = append(patch, NewOperation("add", makePath(p, i), bt[i]))
|
||||||
}
|
}
|
||||||
for i := n; i < len(bt); i++ {
|
for i := 0; i < n; i++ {
|
||||||
patch = append(patch, NewOperation("add", makePath(p, i), bt[i]))
|
var err error
|
||||||
}
|
patch, err = handleValues(at[i], bt[i], makePath(p, i), patch)
|
||||||
for i := 0; i < n; i++ {
|
if err != nil {
|
||||||
var err error
|
return nil, err
|
||||||
patch, err = handleValues(at[i], bt[i], makePath(p, i), patch)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -235,100 +238,9 @@ func handleValues(av, bv interface{}, p string, patch []Operation) ([]Operation,
|
|||||||
return patch, nil
|
return patch, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func isBasicType(a interface{}) bool {
|
|
||||||
switch a.(type) {
|
|
||||||
case string, float64, bool:
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func isSimpleArray(a []interface{}) bool {
|
|
||||||
for i := range a {
|
|
||||||
switch a[i].(type) {
|
|
||||||
case string, float64, bool:
|
|
||||||
default:
|
|
||||||
val := reflect.ValueOf(a[i])
|
|
||||||
if val.Kind() == reflect.Map {
|
|
||||||
for _, k := range val.MapKeys() {
|
|
||||||
av := val.MapIndex(k)
|
|
||||||
if av.Kind() == reflect.Ptr || av.Kind() == reflect.Interface {
|
|
||||||
if av.IsNil() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
av = av.Elem()
|
|
||||||
}
|
|
||||||
if av.Kind() != reflect.String && av.Kind() != reflect.Float64 && av.Kind() != reflect.Bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://en.wikipedia.org/wiki/Wagner%E2%80%93Fischer_algorithm
|
|
||||||
// Adapted from https://github.com/texttheater/golang-levenshtein
|
|
||||||
func compareEditDistance(s, t []interface{}, p string) []Operation {
|
|
||||||
m := len(s)
|
|
||||||
n := len(t)
|
|
||||||
|
|
||||||
d := make([][]int, m+1)
|
|
||||||
for i := 0; i <= m; i++ {
|
|
||||||
d[i] = make([]int, n+1)
|
|
||||||
d[i][0] = i
|
|
||||||
}
|
|
||||||
for j := 0; j <= n; j++ {
|
|
||||||
d[0][j] = j
|
|
||||||
}
|
|
||||||
|
|
||||||
for j := 1; j <= n; j++ {
|
|
||||||
for i := 1; i <= m; i++ {
|
|
||||||
if reflect.DeepEqual(s[i-1], t[j-1]) {
|
|
||||||
d[i][j] = d[i-1][j-1] // no op required
|
|
||||||
} else {
|
|
||||||
del := d[i-1][j] + 1
|
|
||||||
add := d[i][j-1] + 1
|
|
||||||
rep := d[i-1][j-1] + 1
|
|
||||||
d[i][j] = min(rep, min(add, del))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return backtrace(s, t, p, m, n, d)
|
|
||||||
}
|
|
||||||
|
|
||||||
func min(x int, y int) int {
|
func min(x int, y int) int {
|
||||||
if y < x {
|
if y < x {
|
||||||
return y
|
return y
|
||||||
}
|
}
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
func backtrace(s, t []interface{}, p string, i int, j int, matrix [][]int) []Operation {
|
|
||||||
if i > 0 && matrix[i-1][j]+1 == matrix[i][j] {
|
|
||||||
op := NewOperation("remove", makePath(p, i-1), nil)
|
|
||||||
return append([]Operation{op}, backtrace(s, t, p, i-1, j, matrix)...)
|
|
||||||
}
|
|
||||||
if j > 0 && matrix[i][j-1]+1 == matrix[i][j] {
|
|
||||||
op := NewOperation("add", makePath(p, i), t[j-1])
|
|
||||||
return append([]Operation{op}, backtrace(s, t, p, i, j-1, matrix)...)
|
|
||||||
}
|
|
||||||
if i > 0 && j > 0 && matrix[i-1][j-1]+1 == matrix[i][j] {
|
|
||||||
if isBasicType(s[0]) {
|
|
||||||
op := NewOperation("replace", makePath(p, i-1), t[j-1])
|
|
||||||
return append([]Operation{op}, backtrace(s, t, p, i-1, j-1, matrix)...)
|
|
||||||
}
|
|
||||||
|
|
||||||
p2, _ := handleValues(s[i-1], t[j-1], makePath(p, i-1), []Operation{})
|
|
||||||
return append(p2, backtrace(s, t, p, i-1, j-1, matrix)...)
|
|
||||||
}
|
|
||||||
if i > 0 && j > 0 && matrix[i-1][j-1] == matrix[i][j] {
|
|
||||||
return backtrace(s, t, p, i-1, j-1, matrix)
|
|
||||||
}
|
|
||||||
return []Operation{}
|
|
||||||
}
|
|
||||||
|
4
vendor/modules.txt
vendored
4
vendor/modules.txt
vendored
@ -252,8 +252,8 @@ golang.org/x/tools/internal/tokeninternal
|
|||||||
golang.org/x/tools/internal/typeparams
|
golang.org/x/tools/internal/typeparams
|
||||||
golang.org/x/tools/internal/typesinternal
|
golang.org/x/tools/internal/typesinternal
|
||||||
golang.org/x/tools/internal/versions
|
golang.org/x/tools/internal/versions
|
||||||
# gomodules.xyz/jsonpatch/v2 v2.2.0
|
# gomodules.xyz/jsonpatch/v2 v2.4.0
|
||||||
## explicit; go 1.12
|
## explicit; go 1.20
|
||||||
gomodules.xyz/jsonpatch/v2
|
gomodules.xyz/jsonpatch/v2
|
||||||
# google.golang.org/appengine v1.6.7
|
# google.golang.org/appengine v1.6.7
|
||||||
## explicit; go 1.11
|
## explicit; go 1.11
|
||||||
|
Loading…
Reference in New Issue
Block a user