diff --git a/pkg/engine/assert/assert.go b/pkg/engine/assert/assert.go index bac9d933..fa066ea0 100644 --- a/pkg/engine/assert/assert.go +++ b/pkg/engine/assert/assert.go @@ -8,10 +8,10 @@ import ( "k8s.io/apimachinery/pkg/util/validation/field" ) -func Assert(ctx context.Context, assertion Assertion, value interface{}, bindings binding.Bindings, opts ...template.Option) (field.ErrorList, error) { +func Assert(ctx context.Context, assertion Assertion, value any, bindings binding.Bindings, opts ...template.Option) (field.ErrorList, error) { return assert(ctx, nil, assertion, value, bindings, opts...) } -func assert(ctx context.Context, path *field.Path, assertion Assertion, value interface{}, bindings binding.Bindings, opts ...template.Option) (field.ErrorList, error) { +func assert(ctx context.Context, path *field.Path, assertion Assertion, value any, bindings binding.Bindings, opts ...template.Option) (field.ErrorList, error) { return assertion.assert(ctx, path, value, bindings, opts...) } diff --git a/pkg/engine/assert/assertion.go b/pkg/engine/assert/assertion.go index 3b36e905..e20f13eb 100644 --- a/pkg/engine/assert/assertion.go +++ b/pkg/engine/assert/assertion.go @@ -9,5 +9,5 @@ import ( ) type Assertion interface { - assert(context.Context, *field.Path, interface{}, binding.Bindings, ...template.Option) (field.ErrorList, error) + assert(context.Context, *field.Path, any, binding.Bindings, ...template.Option) (field.ErrorList, error) } diff --git a/pkg/engine/assert/binding.go b/pkg/engine/assert/binding.go index 922dec06..35bfd50f 100644 --- a/pkg/engine/assert/binding.go +++ b/pkg/engine/assert/binding.go @@ -9,7 +9,7 @@ import ( "k8s.io/apimachinery/pkg/util/validation/field" ) -func NewContextBindings(bindings binding.Bindings, value interface{}, entries ...v1alpha1.ContextEntry) binding.Bindings { +func NewContextBindings(bindings binding.Bindings, value any, entries ...v1alpha1.ContextEntry) binding.Bindings { var path *field.Path path = path.Child("context") for i, entry := range entries { @@ -18,9 +18,9 @@ func NewContextBindings(bindings binding.Bindings, value interface{}, entries .. return bindings } -func NewContextBinding(path *field.Path, bindings binding.Bindings, value interface{}, entry v1alpha1.ContextEntry) binding.Binding { +func NewContextBinding(path *field.Path, bindings binding.Bindings, value any, entry v1alpha1.ContextEntry) binding.Binding { return template.NewLazyBinding( - func() (interface{}, error) { + func() (any, error) { expression := parseExpression(context.TODO(), entry.Variable.Value) if expression != nil && expression.engine != "" { if expression.foreach { diff --git a/pkg/engine/assert/expression.go b/pkg/engine/assert/expression.go index 3d589cd8..d0372d1d 100644 --- a/pkg/engine/assert/expression.go +++ b/pkg/engine/assert/expression.go @@ -57,7 +57,7 @@ func parseExpressionRegex(ctx context.Context, in string) *expression { return expression } -func parseExpression(ctx context.Context, value interface{}) *expression { +func parseExpression(ctx context.Context, value any) *expression { if reflectutils.GetKind(value) != reflect.String { return nil } diff --git a/pkg/engine/assert/match.go b/pkg/engine/assert/match.go index db0290eb..c018f342 100644 --- a/pkg/engine/assert/match.go +++ b/pkg/engine/assert/match.go @@ -14,7 +14,7 @@ import ( // We should remove this dependency. // Either move the Match struct in this package or move this file in a more specific package. -func MatchAssert(ctx context.Context, path *field.Path, match *v1alpha1.Assert, actual interface{}, bindings binding.Bindings, opts ...template.Option) ([]error, error) { +func MatchAssert(ctx context.Context, path *field.Path, match *v1alpha1.Assert, actual any, bindings binding.Bindings, opts ...template.Option) ([]error, error) { if match == nil || (len(match.Any) == 0 && len(match.All) == 0) { return nil, field.Invalid(path, match, "an empty assert is not valid") } else { @@ -66,7 +66,7 @@ func MatchAssert(ctx context.Context, path *field.Path, match *v1alpha1.Assert, } } -func Match(ctx context.Context, path *field.Path, match *v1alpha1.Match, actual interface{}, bindings binding.Bindings, opts ...template.Option) (field.ErrorList, error) { +func Match(ctx context.Context, path *field.Path, match *v1alpha1.Match, actual any, bindings binding.Bindings, opts ...template.Option) (field.ErrorList, error) { if match == nil || (len(match.Any) == 0 && len(match.All) == 0) { return nil, field.Invalid(path, match, "an empty match is not valid") } else { @@ -89,7 +89,7 @@ func Match(ctx context.Context, path *field.Path, match *v1alpha1.Match, actual } } -func MatchAny(ctx context.Context, path *field.Path, assertions []v1alpha1.Any, actual interface{}, bindings binding.Bindings, opts ...template.Option) (field.ErrorList, error) { +func MatchAny(ctx context.Context, path *field.Path, assertions []v1alpha1.Any, actual any, bindings binding.Bindings, opts ...template.Option) (field.ErrorList, error) { var errs field.ErrorList for i, assertion := range assertions { _errs, err := assert(ctx, path.Index(i), Parse(ctx, assertion.Value), actual, bindings, opts...) @@ -104,7 +104,7 @@ func MatchAny(ctx context.Context, path *field.Path, assertions []v1alpha1.Any, return errs, nil } -func MatchAll(ctx context.Context, path *field.Path, assertions []v1alpha1.Any, actual interface{}, bindings binding.Bindings, opts ...template.Option) (field.ErrorList, error) { +func MatchAll(ctx context.Context, path *field.Path, assertions []v1alpha1.Any, actual any, bindings binding.Bindings, opts ...template.Option) (field.ErrorList, error) { var errs field.ErrorList for i, assertion := range assertions { _errs, err := assert(ctx, path.Index(i), Parse(ctx, assertion.Value), actual, bindings, opts...) diff --git a/pkg/engine/assert/parse.go b/pkg/engine/assert/parse.go index a5404131..0d005d88 100644 --- a/pkg/engine/assert/parse.go +++ b/pkg/engine/assert/parse.go @@ -13,7 +13,7 @@ import ( "k8s.io/apimachinery/pkg/util/validation/field" ) -func Parse(ctx context.Context, assertion interface{}) Assertion { +func Parse(ctx context.Context, assertion any) Assertion { switch reflectutils.GetKind(assertion) { case reflect.Slice: node := sliceNode{} @@ -36,9 +36,9 @@ func Parse(ctx context.Context, assertion interface{}) Assertion { // mapNode is the assertion type represented by a map. // it is responsible for projecting the analysed resource and passing the result to the descendant -type mapNode map[interface{}]Assertion +type mapNode map[any]Assertion -func (n mapNode) assert(ctx context.Context, path *field.Path, value interface{}, bindings binding.Bindings, opts ...template.Option) (field.ErrorList, error) { +func (n mapNode) assert(ctx context.Context, path *field.Path, value any, bindings binding.Bindings, opts ...template.Option) (field.ErrorList, error) { var errs field.ErrorList for k, v := range n { projection, err := project(ctx, k, value, bindings, opts...) @@ -97,7 +97,7 @@ func (n mapNode) assert(ctx context.Context, path *field.Path, value interface{} // if lengths match all descendants are evaluated with their corresponding items. type sliceNode []Assertion -func (n sliceNode) assert(ctx context.Context, path *field.Path, value interface{}, bindings binding.Bindings, opts ...template.Option) (field.ErrorList, error) { +func (n sliceNode) assert(ctx context.Context, path *field.Path, value any, bindings binding.Bindings, opts ...template.Option) (field.ErrorList, error) { var errs field.ErrorList if value == nil { errs = append(errs, field.Invalid(path, value, "value is null")) @@ -124,10 +124,10 @@ func (n sliceNode) assert(ctx context.Context, path *field.Path, value interface // it receives a value and compares it with an expected value. // the expected value can be the result of an expression. type scalarNode struct { - rhs interface{} + rhs any } -func (n *scalarNode) assert(ctx context.Context, path *field.Path, value interface{}, bindings binding.Bindings, opts ...template.Option) (field.ErrorList, error) { +func (n *scalarNode) assert(ctx context.Context, path *field.Path, value any, bindings binding.Bindings, opts ...template.Option) (field.ErrorList, error) { rhs := n.rhs expression := parseExpression(ctx, rhs) // we only project if the expression uses the engine syntax @@ -154,7 +154,7 @@ func (n *scalarNode) assert(ctx context.Context, path *field.Path, value interfa return errs, nil } -func expectValueMessage(value interface{}) string { +func expectValueMessage(value any) string { switch t := value.(type) { case int64, int32, float64, float32, bool: // use simple printer for simple types diff --git a/pkg/engine/assert/project.go b/pkg/engine/assert/project.go index b3cfa0f0..9c2b8771 100644 --- a/pkg/engine/assert/project.go +++ b/pkg/engine/assert/project.go @@ -13,10 +13,10 @@ type projection struct { foreach bool foreachName string binding string - result interface{} + result any } -func project(ctx context.Context, key interface{}, value interface{}, bindings binding.Bindings, opts ...template.Option) (*projection, error) { +func project(ctx context.Context, key any, value any, bindings binding.Bindings, opts ...template.Option) (*projection, error) { expression := parseExpression(ctx, key) if expression != nil { if expression.engine != "" { @@ -33,7 +33,7 @@ func project(ctx context.Context, key interface{}, value interface{}, bindings b } else { if reflectutils.GetKind(value) == reflect.Map { mapValue := reflect.ValueOf(value).MapIndex(reflect.ValueOf(expression.statement)) - var value interface{} + var value any if mapValue.IsValid() { value = mapValue.Interface() } @@ -48,7 +48,7 @@ func project(ctx context.Context, key interface{}, value interface{}, bindings b } if reflectutils.GetKind(value) == reflect.Map { mapValue := reflect.ValueOf(value).MapIndex(reflect.ValueOf(key)) - var value interface{} + var value any if mapValue.IsValid() { value = mapValue.Interface() } diff --git a/pkg/engine/assert/project_test.go b/pkg/engine/assert/project_test.go index ca164c10..7be70879 100644 --- a/pkg/engine/assert/project_test.go +++ b/pkg/engine/assert/project_test.go @@ -11,15 +11,15 @@ import ( func Test_project(t *testing.T) { tests := []struct { name string - key interface{} - value interface{} + key any + value any bindings binding.Bindings want *projection wantErr bool }{{ name: "map index not found", key: "foo", - value: map[string]interface{}{ + value: map[string]any{ "bar": 42, }, bindings: nil, diff --git a/pkg/engine/match/match.go b/pkg/engine/match/match.go index 7f4b9ca8..afb21f16 100644 --- a/pkg/engine/match/match.go +++ b/pkg/engine/match/match.go @@ -8,7 +8,7 @@ import ( reflectutils "github.com/kyverno/kyverno-json/pkg/utils/reflect" ) -func Match(ctx context.Context, expected, actual interface{}) (bool, error) { +func Match(ctx context.Context, expected, actual any) (bool, error) { if expected != nil { switch reflectutils.GetKind(expected) { case reflect.Slice: diff --git a/pkg/engine/template/binding.go b/pkg/engine/template/binding.go index dfd94ee2..51be6c32 100644 --- a/pkg/engine/template/binding.go +++ b/pkg/engine/template/binding.go @@ -6,24 +6,24 @@ import ( "github.com/jmespath-community/go-jmespath/pkg/binding" ) -type resolverFunc = func() (interface{}, error) +type resolverFunc = func() (any, error) type lazyBinding struct { resolver resolverFunc } -func (b *lazyBinding) Value() (interface{}, error) { +func (b *lazyBinding) Value() (any, error) { return b.resolver() } func NewLazyBinding(resolver resolverFunc) binding.Binding { binding := &lazyBinding{} lock := &sync.Mutex{} - binding.resolver = func() (interface{}, error) { + binding.resolver = func() (any, error) { lock.Lock() defer lock.Unlock() value, err := resolver() - binding.resolver = func() (interface{}, error) { + binding.resolver = func() (any, error) { return value, err } return binding.resolver() @@ -31,8 +31,8 @@ func NewLazyBinding(resolver resolverFunc) binding.Binding { return binding } -func NewLazyBindingWithValue(value interface{}) binding.Binding { - return NewLazyBinding(func() (interface{}, error) { +func NewLazyBindingWithValue(value any) binding.Binding { + return NewLazyBinding(func() (any, error) { return value, nil }) } diff --git a/pkg/engine/template/functions/at.go b/pkg/engine/template/functions/at.go index 80db8b44..bff7e252 100644 --- a/pkg/engine/template/functions/at.go +++ b/pkg/engine/template/functions/at.go @@ -4,8 +4,8 @@ import ( "errors" ) -func jpfAt(arguments []interface{}) (interface{}, error) { - if slice, ok := arguments[0].([]interface{}); !ok { +func jpfAt(arguments []any) (any, error) { + if slice, ok := arguments[0].([]any); !ok { return nil, errors.New("invalid type, first argument must be an array") } else if index, ok := arguments[1].(int); !ok { return nil, errors.New("invalid type, second argument must be an int") diff --git a/pkg/engine/template/functions/concat.go b/pkg/engine/template/functions/concat.go index f20ed456..9a832ac0 100644 --- a/pkg/engine/template/functions/concat.go +++ b/pkg/engine/template/functions/concat.go @@ -4,7 +4,7 @@ import ( "errors" ) -func jpfConcat(arguments []interface{}) (interface{}, error) { +func jpfConcat(arguments []any) (any, error) { if left, ok := arguments[0].(string); !ok { return nil, errors.New("invalid type, first argument must be a string") } else if right, ok := arguments[1].(string); !ok { diff --git a/pkg/engine/template/functions/json_parse.go b/pkg/engine/template/functions/json_parse.go index 935d82fe..7cf869a4 100644 --- a/pkg/engine/template/functions/json_parse.go +++ b/pkg/engine/template/functions/json_parse.go @@ -5,11 +5,11 @@ import ( "errors" ) -func jpfJsonParse(arguments []interface{}) (interface{}, error) { +func jpfJsonParse(arguments []any) (any, error) { if data, ok := arguments[0].(string); !ok { return nil, errors.New("invalid type, first argument must be a string") } else { - var result interface{} + var result any err := json.Unmarshal([]byte(data), &result) if err != nil { return nil, err diff --git a/pkg/engine/template/functions/wildcard.go b/pkg/engine/template/functions/wildcard.go index c6f1cea6..493c3480 100644 --- a/pkg/engine/template/functions/wildcard.go +++ b/pkg/engine/template/functions/wildcard.go @@ -6,7 +6,7 @@ import ( "github.com/kyverno/kyverno/ext/wildcard" ) -func jpfWildcard(arguments []interface{}) (interface{}, error) { +func jpfWildcard(arguments []any) (any, error) { if pattern, ok := arguments[0].(string); !ok { return nil, errors.New("invalid type, first argument must be a string") } else if name, ok := arguments[1].(string); !ok { diff --git a/pkg/engine/template/kyverno/arithmetic.go b/pkg/engine/template/kyverno/arithmetic.go index 2fbaac5e..99af5f59 100644 --- a/pkg/engine/template/kyverno/arithmetic.go +++ b/pkg/engine/template/kyverno/arithmetic.go @@ -11,11 +11,11 @@ import ( ) type operand interface { - Add(interface{}, string) (interface{}, error) - Subtract(interface{}) (interface{}, error) - Multiply(interface{}) (interface{}, error) - Divide(interface{}) (interface{}, error) - Modulo(interface{}) (interface{}, error) + Add(any, string) (any, error) + Subtract(any) (any, error) + Multiply(any) (any, error) + Divide(any) (any, error) + Modulo(any) (any, error) } type quantity struct { @@ -30,7 +30,7 @@ type scalar struct { float64 } -func parseArithemticOperand(arguments []interface{}, index int, operator string) (operand, error) { +func parseArithemticOperand(arguments []any, index int, operator string) (operand, error) { if tmp, err := validateArg(operator, arguments, index, reflect.Float64); err == nil { return scalar{float64: tmp.Float()}, nil } else if tmp, err = validateArg(operator, arguments, index, reflect.String); err == nil { @@ -43,7 +43,7 @@ func parseArithemticOperand(arguments []interface{}, index int, operator string) return nil, formatError(genericError, operator, "invalid operand") } -func parseArithemticOperands(arguments []interface{}, operator string) (operand, operand, error) { +func parseArithemticOperands(arguments []any, operator string) (operand, operand, error) { left, err := parseArithemticOperand(arguments, 0, operator) if err != nil { return nil, nil, err @@ -62,7 +62,7 @@ func parseArithemticOperands(arguments []interface{}, operator string) (operand, // Scalar +|- Scalar -> Scalar // Scalar +|- Quantity|Duration -> error -func (op1 quantity) Add(op2 interface{}, operator string) (interface{}, error) { +func (op1 quantity) Add(op2 any, operator string) (any, error) { switch v := op2.(type) { case quantity: op1.Quantity.Add(v.Quantity) @@ -72,7 +72,7 @@ func (op1 quantity) Add(op2 interface{}, operator string) (interface{}, error) { } } -func (op1 duration) Add(op2 interface{}, operator string) (interface{}, error) { +func (op1 duration) Add(op2 any, operator string) (any, error) { switch v := op2.(type) { case duration: return (op1.Duration + v.Duration).String(), nil @@ -81,7 +81,7 @@ func (op1 duration) Add(op2 interface{}, operator string) (interface{}, error) { } } -func (op1 scalar) Add(op2 interface{}, operator string) (interface{}, error) { +func (op1 scalar) Add(op2 any, operator string) (any, error) { switch v := op2.(type) { case scalar: return op1.float64 + v.float64, nil @@ -90,7 +90,7 @@ func (op1 scalar) Add(op2 interface{}, operator string) (interface{}, error) { } } -func (op1 quantity) Subtract(op2 interface{}) (interface{}, error) { +func (op1 quantity) Subtract(op2 any) (any, error) { switch v := op2.(type) { case quantity: op1.Quantity.Sub(v.Quantity) @@ -100,7 +100,7 @@ func (op1 quantity) Subtract(op2 interface{}) (interface{}, error) { } } -func (op1 duration) Subtract(op2 interface{}) (interface{}, error) { +func (op1 duration) Subtract(op2 any) (any, error) { switch v := op2.(type) { case duration: return (op1.Duration - v.Duration).String(), nil @@ -109,7 +109,7 @@ func (op1 duration) Subtract(op2 interface{}) (interface{}, error) { } } -func (op1 scalar) Subtract(op2 interface{}) (interface{}, error) { +func (op1 scalar) Subtract(op2 any) (any, error) { switch v := op2.(type) { case scalar: return op1.float64 - v.float64, nil @@ -128,7 +128,7 @@ func (op1 scalar) Subtract(op2 interface{}) (interface{}, error) { // Scalar * Quantity -> Quantity // Scalar * Duration -> Duration -func (op1 quantity) Multiply(op2 interface{}) (interface{}, error) { +func (op1 quantity) Multiply(op2 any) (any, error) { switch v := op2.(type) { case scalar: q, err := resource.ParseQuantity(fmt.Sprintf("%v", v.float64)) @@ -143,7 +143,7 @@ func (op1 quantity) Multiply(op2 interface{}) (interface{}, error) { } } -func (op1 duration) Multiply(op2 interface{}) (interface{}, error) { +func (op1 duration) Multiply(op2 any) (any, error) { switch v := op2.(type) { case scalar: seconds := op1.Seconds() * v.float64 @@ -153,7 +153,7 @@ func (op1 duration) Multiply(op2 interface{}) (interface{}, error) { } } -func (op1 scalar) Multiply(op2 interface{}) (interface{}, error) { +func (op1 scalar) Multiply(op2 any) (any, error) { switch v := op2.(type) { case scalar: return op1.float64 * v.float64, nil @@ -178,7 +178,7 @@ func (op1 scalar) Multiply(op2 interface{}) (interface{}, error) { // Scalar / Quantity -> error // Scalar / Duration -> error -func (op1 quantity) Divide(op2 interface{}) (interface{}, error) { +func (op1 quantity) Divide(op2 any) (any, error) { switch v := op2.(type) { case quantity: divisor := v.AsApproximateFloat64() @@ -204,7 +204,7 @@ func (op1 quantity) Divide(op2 interface{}) (interface{}, error) { } } -func (op1 duration) Divide(op2 interface{}) (interface{}, error) { +func (op1 duration) Divide(op2 any) (any, error) { switch v := op2.(type) { case duration: if v.Seconds() == 0 { @@ -222,7 +222,7 @@ func (op1 duration) Divide(op2 interface{}) (interface{}, error) { } } -func (op1 scalar) Divide(op2 interface{}) (interface{}, error) { +func (op1 scalar) Divide(op2 any) (any, error) { switch v := op2.(type) { case scalar: if v.float64 == 0 { @@ -243,7 +243,7 @@ func (op1 scalar) Divide(op2 interface{}) (interface{}, error) { // Scalar % Quantity|Duration -> error // Scalar % Scalar -> Scalar -func (op1 quantity) Modulo(op2 interface{}) (interface{}, error) { +func (op1 quantity) Modulo(op2 any) (any, error) { switch v := op2.(type) { case quantity: f1 := op1.ToDec().AsApproximateFloat64() @@ -265,7 +265,7 @@ func (op1 quantity) Modulo(op2 interface{}) (interface{}, error) { } } -func (op1 duration) Modulo(op2 interface{}) (interface{}, error) { +func (op1 duration) Modulo(op2 any) (any, error) { switch v := op2.(type) { case duration: if v.Duration == 0 { @@ -277,7 +277,7 @@ func (op1 duration) Modulo(op2 interface{}) (interface{}, error) { } } -func (op1 scalar) Modulo(op2 interface{}) (interface{}, error) { +func (op1 scalar) Modulo(op2 any) (any, error) { switch v := op2.(type) { case scalar: val1 := int64(op1.float64) diff --git a/pkg/engine/template/kyverno/arithmetic_test.go b/pkg/engine/template/kyverno/arithmetic_test.go index 80f64fc4..ec5b9267 100644 --- a/pkg/engine/template/kyverno/arithmetic_test.go +++ b/pkg/engine/template/kyverno/arithmetic_test.go @@ -11,7 +11,7 @@ package jmespath // testCases := []struct { // name string // test string -// expectedResult interface{} +// expectedResult any // err bool // retFloat bool // }{ @@ -110,7 +110,7 @@ package jmespath // testCases := []struct { // name string // test string -// expectedResult interface{} +// expectedResult any // err bool // retFloat bool // }{ @@ -256,7 +256,7 @@ package jmespath // testCases := []struct { // name string // test string -// expectedResult interface{} +// expectedResult any // err bool // retFloat bool // }{ @@ -355,7 +355,7 @@ package jmespath // testCases := []struct { // name string // test string -// expectedResult interface{} +// expectedResult any // err bool // retFloat bool // }{ @@ -454,7 +454,7 @@ package jmespath // testCases := []struct { // name string // test string -// expectedResult interface{} +// expectedResult any // err bool // retFloat bool // }{ @@ -616,7 +616,7 @@ package jmespath // testCases := []struct { // name string // test string -// expectedResult interface{} +// expectedResult any // err bool // retFloat bool // }{ @@ -772,7 +772,7 @@ package jmespath // testCases := []struct { // name string // test string -// expectedResult interface{} +// expectedResult any // err bool // retFloat bool // }{ @@ -842,13 +842,13 @@ package jmespath // float64 float64 // } // type args struct { -// op2 interface{} +// op2 any // } // tests := []struct { // name string // fields fields // args args -// want interface{} +// want any // wantErr bool // }{{ // fields: fields{ @@ -878,7 +878,7 @@ package jmespath // func TestParseArithemticOperands(t *testing.T) { // type args struct { -// arguments []interface{} +// arguments []any // operator string // } // tests := []struct { @@ -889,7 +889,7 @@ package jmespath // wantErr bool // }{{ // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // true, // 1.0, // }, @@ -897,7 +897,7 @@ package jmespath // wantErr: true, // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // 1.0, // true, // }, diff --git a/pkg/engine/template/kyverno/error.go b/pkg/engine/template/kyverno/error.go index 73808a5d..ee4e01f5 100644 --- a/pkg/engine/template/kyverno/error.go +++ b/pkg/engine/template/kyverno/error.go @@ -15,8 +15,8 @@ const ( nonIntRoundError = errorPrefix + "Non-integer argument(s) passed for round off" ) -func formatError(format string, function string, values ...interface{}) error { - args := []interface{}{function} +func formatError(format string, function string, values ...any) error { + args := []any{function} args = append(args, values...) return fmt.Errorf(format, args...) } diff --git a/pkg/engine/template/kyverno/functions.go b/pkg/engine/template/kyverno/functions.go index 5568e141..911b0fec 100644 --- a/pkg/engine/template/kyverno/functions.go +++ b/pkg/engine/template/kyverno/functions.go @@ -578,7 +578,7 @@ func GetFunctions() []FunctionEntry { }} } -func jpfCompare(arguments []interface{}) (interface{}, error) { +func jpfCompare(arguments []any) (any, error) { if a, err := validateArg(compare, arguments, 0, reflect.String); err != nil { return nil, err } else if b, err := validateArg(compare, arguments, 1, reflect.String); err != nil { @@ -588,7 +588,7 @@ func jpfCompare(arguments []interface{}) (interface{}, error) { } } -func jpfEqualFold(arguments []interface{}) (interface{}, error) { +func jpfEqualFold(arguments []any) (any, error) { if a, err := validateArg(equalFold, arguments, 0, reflect.String); err != nil { return nil, err } else if b, err := validateArg(equalFold, arguments, 1, reflect.String); err != nil { @@ -598,7 +598,7 @@ func jpfEqualFold(arguments []interface{}) (interface{}, error) { } } -func jpfReplace(arguments []interface{}) (interface{}, error) { +func jpfReplace(arguments []any) (any, error) { if str, err := validateArg(replace, arguments, 0, reflect.String); err != nil { return nil, err } else if old, err := validateArg(replace, arguments, 1, reflect.String); err != nil { @@ -612,7 +612,7 @@ func jpfReplace(arguments []interface{}) (interface{}, error) { } } -func jpfReplaceAll(arguments []interface{}) (interface{}, error) { +func jpfReplaceAll(arguments []any) (any, error) { if str, err := validateArg(replaceAll, arguments, 0, reflect.String); err != nil { return nil, err } else if old, err := validateArg(replaceAll, arguments, 1, reflect.String); err != nil { @@ -624,7 +624,7 @@ func jpfReplaceAll(arguments []interface{}) (interface{}, error) { } } -func jpfToUpper(arguments []interface{}) (interface{}, error) { +func jpfToUpper(arguments []any) (any, error) { if str, err := validateArg(toUpper, arguments, 0, reflect.String); err != nil { return nil, err } else { @@ -632,7 +632,7 @@ func jpfToUpper(arguments []interface{}) (interface{}, error) { } } -func jpfToLower(arguments []interface{}) (interface{}, error) { +func jpfToLower(arguments []any) (any, error) { if str, err := validateArg(toLower, arguments, 0, reflect.String); err != nil { return nil, err } else { @@ -640,7 +640,7 @@ func jpfToLower(arguments []interface{}) (interface{}, error) { } } -func jpfTrim(arguments []interface{}) (interface{}, error) { +func jpfTrim(arguments []any) (any, error) { var err error str, err := validateArg(trim, arguments, 0, reflect.String) if err != nil { @@ -655,7 +655,7 @@ func jpfTrim(arguments []interface{}) (interface{}, error) { return strings.Trim(str.String(), cutset.String()), nil } -func jpfTrimPrefix(arguments []interface{}) (interface{}, error) { +func jpfTrimPrefix(arguments []any) (any, error) { var err error str, err := validateArg(trimPrefix, arguments, 0, reflect.String) if err != nil { @@ -670,7 +670,7 @@ func jpfTrimPrefix(arguments []interface{}) (interface{}, error) { return strings.TrimPrefix(str.String(), prefix.String()), nil } -func jpfSplit(arguments []interface{}) (interface{}, error) { +func jpfSplit(arguments []any) (any, error) { var err error str, err := validateArg(split, arguments, 0, reflect.String) if err != nil { @@ -683,7 +683,7 @@ func jpfSplit(arguments []interface{}) (interface{}, error) { } split := strings.Split(str.String(), sep.String()) - arr := make([]interface{}, len(split)) + arr := make([]any, len(split)) for i, v := range split { arr[i] = v @@ -692,7 +692,7 @@ func jpfSplit(arguments []interface{}) (interface{}, error) { return arr, nil } -func jpRegexReplaceAll(arguments []interface{}) (interface{}, error) { +func jpRegexReplaceAll(arguments []any) (any, error) { var err error regex, err := validateArg(regexReplaceAll, arguments, 0, reflect.String) if err != nil { @@ -716,7 +716,7 @@ func jpRegexReplaceAll(arguments []interface{}) (interface{}, error) { return string(reg.ReplaceAll([]byte(src), []byte(repl))), nil } -func jpRegexReplaceAllLiteral(arguments []interface{}) (interface{}, error) { +func jpRegexReplaceAllLiteral(arguments []any) (any, error) { var err error regex, err := validateArg(regexReplaceAllLiteral, arguments, 0, reflect.String) if err != nil { @@ -740,7 +740,7 @@ func jpRegexReplaceAllLiteral(arguments []interface{}) (interface{}, error) { return string(reg.ReplaceAllLiteral([]byte(src), []byte(repl))), nil } -func jpRegexMatch(arguments []interface{}) (interface{}, error) { +func jpRegexMatch(arguments []any) (any, error) { var err error regex, err := validateArg(regexMatch, arguments, 0, reflect.String) if err != nil { @@ -755,7 +755,7 @@ func jpRegexMatch(arguments []interface{}) (interface{}, error) { return regexp.Match(regex.String(), []byte(src)) } -func jpPatternMatch(arguments []interface{}) (interface{}, error) { +func jpPatternMatch(arguments []any) (any, error) { pattern, err := validateArg(regexMatch, arguments, 0, reflect.String) if err != nil { return nil, err @@ -769,14 +769,14 @@ func jpPatternMatch(arguments []interface{}) (interface{}, error) { return wildcard.Match(pattern.String(), src), nil } -func jpLabelMatch(arguments []interface{}) (interface{}, error) { - labelMap, ok := arguments[0].(map[string]interface{}) +func jpLabelMatch(arguments []any) (any, error) { + labelMap, ok := arguments[0].(map[string]any) if !ok { return nil, formatError(invalidArgumentTypeError, labelMatch, 0, "Object") } - matchMap, ok := arguments[1].(map[string]interface{}) + matchMap, ok := arguments[1].(map[string]any) if !ok { return nil, formatError(invalidArgumentTypeError, labelMatch, 1, "Object") @@ -791,7 +791,7 @@ func jpLabelMatch(arguments []interface{}) (interface{}, error) { return true, nil } -func jpToBoolean(arguments []interface{}) (interface{}, error) { +func jpToBoolean(arguments []any) (any, error) { if input, err := validateArg(toBoolean, arguments, 0, reflect.String); err != nil { return nil, err } else { @@ -806,7 +806,7 @@ func jpToBoolean(arguments []interface{}) (interface{}, error) { } } -func _jpAdd(arguments []interface{}, operator string) (interface{}, error) { +func _jpAdd(arguments []any, operator string) (any, error) { op1, op2, err := parseArithemticOperands(arguments, operator) if err != nil { return nil, err @@ -814,12 +814,12 @@ func _jpAdd(arguments []interface{}, operator string) (interface{}, error) { return op1.Add(op2, operator) } -func jpAdd(arguments []interface{}) (interface{}, error) { +func jpAdd(arguments []any) (any, error) { return _jpAdd(arguments, add) } -func jpSum(arguments []interface{}) (interface{}, error) { - items, ok := arguments[0].([]interface{}) +func jpSum(arguments []any) (any, error) { + items, ok := arguments[0].([]any) if !ok { return nil, formatError(typeMismatchError, sum) } @@ -829,7 +829,7 @@ func jpSum(arguments []interface{}) (interface{}, error) { var err error result := items[0] for _, item := range items[1:] { - result, err = _jpAdd([]interface{}{result, item}, sum) + result, err = _jpAdd([]any{result, item}, sum) if err != nil { return nil, err } @@ -837,7 +837,7 @@ func jpSum(arguments []interface{}) (interface{}, error) { return result, nil } -func jpSubtract(arguments []interface{}) (interface{}, error) { +func jpSubtract(arguments []any) (any, error) { op1, op2, err := parseArithemticOperands(arguments, subtract) if err != nil { return nil, err @@ -846,7 +846,7 @@ func jpSubtract(arguments []interface{}) (interface{}, error) { return op1.Subtract(op2) } -func jpMultiply(arguments []interface{}) (interface{}, error) { +func jpMultiply(arguments []any) (any, error) { op1, op2, err := parseArithemticOperands(arguments, multiply) if err != nil { return nil, err @@ -855,7 +855,7 @@ func jpMultiply(arguments []interface{}) (interface{}, error) { return op1.Multiply(op2) } -func jpDivide(arguments []interface{}) (interface{}, error) { +func jpDivide(arguments []any) (any, error) { op1, op2, err := parseArithemticOperands(arguments, divide) if err != nil { return nil, err @@ -864,7 +864,7 @@ func jpDivide(arguments []interface{}) (interface{}, error) { return op1.Divide(op2) } -func jpModulo(arguments []interface{}) (interface{}, error) { +func jpModulo(arguments []any) (any, error) { op1, op2, err := parseArithemticOperands(arguments, modulo) if err != nil { return nil, err @@ -873,7 +873,7 @@ func jpModulo(arguments []interface{}) (interface{}, error) { return op1.Modulo(op2) } -func jpRound(arguments []interface{}) (interface{}, error) { +func jpRound(arguments []any) (any, error) { op, err := validateArg(round, arguments, 0, reflect.Float64) if err != nil { return nil, err @@ -894,7 +894,7 @@ func jpRound(arguments []interface{}) (interface{}, error) { return rounded, nil } -func jpBase64Decode(arguments []interface{}) (interface{}, error) { +func jpBase64Decode(arguments []any) (any, error) { var err error str, err := validateArg("", arguments, 0, reflect.String) if err != nil { @@ -909,7 +909,7 @@ func jpBase64Decode(arguments []interface{}) (interface{}, error) { return string(decodedStr), nil } -func jpBase64Encode(arguments []interface{}) (interface{}, error) { +func jpBase64Encode(arguments []any) (any, error) { var err error str, err := validateArg("", arguments, 0, reflect.String) if err != nil { @@ -919,7 +919,7 @@ func jpBase64Encode(arguments []interface{}) (interface{}, error) { return base64.StdEncoding.EncodeToString([]byte(str.String())), nil } -func jpPathCanonicalize(arguments []interface{}) (interface{}, error) { +func jpPathCanonicalize(arguments []any) (any, error) { var err error str, err := validateArg(pathCanonicalize, arguments, 0, reflect.String) if err != nil { @@ -929,7 +929,7 @@ func jpPathCanonicalize(arguments []interface{}) (interface{}, error) { return filepath.Join(str.String()), nil } -func jpTruncate(arguments []interface{}) (interface{}, error) { +func jpTruncate(arguments []any) (any, error) { var err error var normalizedLength float64 str, err := validateArg(truncate, arguments, 0, reflect.String) @@ -950,7 +950,7 @@ func jpTruncate(arguments []interface{}) (interface{}, error) { return trunc.Truncator(str.String(), int(normalizedLength), trunc.CutStrategy{}), nil } -func jpSemverCompare(arguments []interface{}) (interface{}, error) { +func jpSemverCompare(arguments []any) (any, error) { var err error v, err := validateArg(semverCompare, arguments, 0, reflect.String) if err != nil { @@ -974,17 +974,17 @@ func jpSemverCompare(arguments []interface{}) (interface{}, error) { return false, nil } -func jpParseJson(arguments []interface{}) (interface{}, error) { +func jpParseJson(arguments []any) (any, error) { input, err := validateArg(parseJson, arguments, 0, reflect.String) if err != nil { return nil, err } - var output interface{} + var output any err = json.Unmarshal([]byte(input.String()), &output) return output, err } -func jpParseYAML(arguments []interface{}) (interface{}, error) { +func jpParseYAML(arguments []any) (any, error) { input, err := validateArg(parseYAML, arguments, 0, reflect.String) if err != nil { return nil, err @@ -993,20 +993,20 @@ func jpParseYAML(arguments []interface{}) (interface{}, error) { if err != nil { return nil, err } - var output interface{} + var output any err = json.Unmarshal(jsonData, &output) return output, err } -func jpLookup(arguments []interface{}) (interface{}, error) { +func jpLookup(arguments []any) (any, error) { switch input := arguments[0].(type) { - case map[string]interface{}: + case map[string]any: key, ok := arguments[1].(string) if !ok { return nil, formatError(invalidArgumentTypeError, lookup, 2, "String") } return input[key], nil - case []interface{}: + case []any: key, ok := arguments[1].(float64) if !ok { return nil, formatError(invalidArgumentTypeError, lookup, 2, "Number") @@ -1027,7 +1027,7 @@ func jpLookup(arguments []interface{}) (interface{}, error) { } } -func jpItems(arguments []interface{}) (interface{}, error) { +func jpItems(arguments []any) (any, error) { keyName, ok := arguments[1].(string) if !ok { return nil, formatError(invalidArgumentTypeError, items, 2, "String") @@ -1037,25 +1037,25 @@ func jpItems(arguments []interface{}) (interface{}, error) { return nil, formatError(invalidArgumentTypeError, items, 3, "String") } switch input := arguments[0].(type) { - case map[string]interface{}: + case map[string]any: keys := make([]string, 0, len(input)) // Sort the keys so that the output is deterministic for key := range input { keys = append(keys, key) } sort.Strings(keys) - arrayOfObj := make([]map[string]interface{}, 0, len(input)) + arrayOfObj := make([]map[string]any, 0, len(input)) for _, key := range keys { - arrayOfObj = append(arrayOfObj, map[string]interface{}{ + arrayOfObj = append(arrayOfObj, map[string]any{ keyName: key, valName: input[key], }) } return arrayOfObj, nil - case []interface{}: - arrayOfObj := make([]map[string]interface{}, 0, len(input)) + case []any: + arrayOfObj := make([]map[string]any, 0, len(input)) for index, value := range input { - arrayOfObj = append(arrayOfObj, map[string]interface{}{ + arrayOfObj = append(arrayOfObj, map[string]any{ keyName: float64(index), valName: value, }) @@ -1066,17 +1066,17 @@ func jpItems(arguments []interface{}) (interface{}, error) { } } -func jpObjectFromLists(arguments []interface{}) (interface{}, error) { - keys, ok := arguments[0].([]interface{}) +func jpObjectFromLists(arguments []any) (any, error) { + keys, ok := arguments[0].([]any) if !ok { return nil, formatError(invalidArgumentTypeError, objectFromLists, 1, "Array") } - values, ok := arguments[1].([]interface{}) + values, ok := arguments[1].([]any) if !ok { return nil, formatError(invalidArgumentTypeError, objectFromLists, 2, "Array") } - output := map[string]interface{}{} + output := map[string]any{} for i, ikey := range keys { key, err := ifaceToString(ikey) @@ -1094,7 +1094,7 @@ func jpObjectFromLists(arguments []interface{}) (interface{}, error) { } // InterfaceToString casts an interface to a string type -func ifaceToString(iface interface{}) (string, error) { +func ifaceToString(iface any) (string, error) { switch i := iface.(type) { case int: return strconv.Itoa(i), nil @@ -1111,7 +1111,7 @@ func ifaceToString(iface interface{}) (string, error) { } } -func jpRandom(arguments []interface{}) (interface{}, error) { +func jpRandom(arguments []any) (any, error) { pattern := arguments[0].(string) if pattern == "" { return "", errors.New("no pattern provided") @@ -1130,20 +1130,20 @@ func jpRandom(arguments []interface{}) (interface{}, error) { return ans, nil } -func encode[T any](in T) (interface{}, error) { +func encode[T any](in T) (any, error) { buf := new(bytes.Buffer) enc := json.NewEncoder(buf) if err := enc.Encode(in); err != nil { return nil, err } - res := map[string]interface{}{} + res := map[string]any{} if err := json.Unmarshal(buf.Bytes(), &res); err != nil { return nil, err } return res, nil } -func jpX509Decode(arguments []interface{}) (interface{}, error) { +func jpX509Decode(arguments []any) (any, error) { parseSubjectPublicKeyInfo := func(data []byte) (*rsa.PublicKey, error) { spki := cryptobyte.String(data) if !spki.ReadASN1(&spki, cryptobyte_asn1.SEQUENCE) { diff --git a/pkg/engine/template/kyverno/functions_test.go b/pkg/engine/template/kyverno/functions_test.go index 08aef514..84d6a6e9 100644 --- a/pkg/engine/template/kyverno/functions_test.go +++ b/pkg/engine/template/kyverno/functions_test.go @@ -74,7 +74,7 @@ package jmespath // func Test_ParseJsonComplex(t *testing.T) { // testCases := []struct { // input string -// expectedResult interface{} +// expectedResult any // }{ // { // input: `parse_json('{"a": "b"}').a`, @@ -105,11 +105,11 @@ package jmespath // func Test_ParseYAML(t *testing.T) { // testCases := []struct { // input string -// output interface{} +// output any // }{ // { // input: `a: b`, -// output: map[string]interface{}{ +// output: map[string]any{ // "a": "b", // }, // }, @@ -119,11 +119,11 @@ package jmespath // - 2 // - 3 // - a: b`, -// output: []interface{}{ +// output: []any{ // 1.0, // 2.0, // 3.0, -// map[string]interface{}{ +// map[string]any{ // "a": "b", // }, // }, @@ -136,10 +136,10 @@ package jmespath // - 2 // - 3 // `, -// output: map[string]interface{}{ -// "spec": map[string]interface{}{ +// output: map[string]any{ +// "spec": map[string]any{ // "test": 1.0, -// "test2": []interface{}{2.0, 3.0}, +// "test2": []any{2.0, 3.0}, // }, // }, // }, @@ -150,7 +150,7 @@ package jmespath // spans more than // one line // see?`, -// output: map[string]interface{}{ +// output: map[string]any{ // "bar": "this is not a normal string it spans more than one line see?", // }, // }, @@ -160,7 +160,7 @@ package jmespath // foo: ~ // bar: null // `, -// output: map[string]interface{}{ +// output: map[string]any{ // "bar": nil, // "foo": nil, // }, @@ -339,19 +339,19 @@ package jmespath // func Test_TrimPrefix(t *testing.T) { // type args struct { -// arguments []interface{} +// arguments []any // } // tests := []struct { // name string // args args -// want interface{} +// want any // wantErr bool // }{ // { // name: "trims prefix", // args: args{ -// arguments: []interface{}{"¡¡¡Hello, Gophers!!!", "¡¡¡Hello, "}, +// arguments: []any{"¡¡¡Hello, Gophers!!!", "¡¡¡Hello, "}, // }, // want: "Gophers!!!", // wantErr: false, @@ -359,7 +359,7 @@ package jmespath // { // name: "does not trim prefix", // args: args{ -// arguments: []interface{}{"¡¡¡Hello, Gophers!!!", "¡¡¡Hola, "}, +// arguments: []any{"¡¡¡Hello, Gophers!!!", "¡¡¡Hola, "}, // }, // want: "¡¡¡Hello, Gophers!!!", // wantErr: false, @@ -367,7 +367,7 @@ package jmespath // { // name: "invalid first argument", // args: args{ -// arguments: []interface{}{1, "¡¡¡Hello, "}, +// arguments: []any{1, "¡¡¡Hello, "}, // }, // want: nil, // wantErr: true, @@ -375,7 +375,7 @@ package jmespath // { // name: "invalid first argument", // args: args{ -// arguments: []interface{}{"¡¡¡Hello, Gophers!!!", 1}, +// arguments: []any{"¡¡¡Hello, Gophers!!!", 1}, // }, // want: nil, // wantErr: true, @@ -403,7 +403,7 @@ package jmespath // result, err := jp.Search("") // assert.NilError(t, err) -// split, ok := result.([]interface{}) +// split, ok := result.([]any) // assert.Assert(t, ok) // assert.Equal(t, split[0], "Hello") // assert.Equal(t, split[1], "Gophers") @@ -434,7 +434,7 @@ package jmespath // } // func Test_RegexMatch(t *testing.T) { -// data := make(map[string]interface{}) +// data := make(map[string]any) // data["foo"] = "hgf'b1a2r'b12g" // query, err := newJMESPath(cfg, "regex_match('12.*', foo)") @@ -446,7 +446,7 @@ package jmespath // } // func Test_RegexMatchWithNumber(t *testing.T) { -// data := make(map[string]interface{}) +// data := make(map[string]any) // data["foo"] = -12.0 // query, err := newJMESPath(cfg, "regex_match('12.*', abs(foo))") @@ -458,7 +458,7 @@ package jmespath // } // func Test_PatternMatch(t *testing.T) { -// data := make(map[string]interface{}) +// data := make(map[string]any) // data["foo"] = "prefix-foo" // query, err := newJMESPath(cfg, "pattern_match('prefix-*', foo)") @@ -470,7 +470,7 @@ package jmespath // } // func Test_PatternMatchWithNumber(t *testing.T) { -// data := make(map[string]interface{}) +// data := make(map[string]any) // data["foo"] = -12.0 // query, err := newJMESPath(cfg, "pattern_match('12*', abs(foo))") @@ -497,7 +497,7 @@ package jmespath // `) // expected := "Glo world, Gworldlo" -// var resource interface{} +// var resource any // err := json.Unmarshal(resourceRaw, &resource) // assert.NilError(t, err) // query, err := newJMESPath(cfg, `regex_replace_all('([Hh]e|G)l', spec.field, '${2}G')`) @@ -527,7 +527,7 @@ package jmespath // `) // expected := "Glo world, Gworldlo" -// var resource interface{} +// var resource any // err := json.Unmarshal(resourceRaw, &resource) // assert.NilError(t, err) @@ -582,7 +582,7 @@ package jmespath // } // for i, tc := range testCases { // t.Run(fmt.Sprintf("case %d", i), func(t *testing.T) { -// var resource interface{} +// var resource any // err := json.Unmarshal(tc.resource, &resource) // assert.NilError(t, err) @@ -602,8 +602,8 @@ package jmespath // func Test_JpToBoolean(t *testing.T) { // testCases := []struct { -// input interface{} -// expected interface{} +// input any +// expected any // err bool // }{ // {"true", true, false}, @@ -616,7 +616,7 @@ package jmespath // {nil, nil, true}, // } // for _, tc := range testCases { -// res, err := jpToBoolean([]interface{}{tc.input}) +// res, err := jpToBoolean([]any{tc.input}) // if tc.err && err == nil { // t.Errorf("Expected an error but received nil") // } @@ -668,7 +668,7 @@ package jmespath // "example2": "Rm9vQmFy" // } // }`) -// var resource interface{} +// var resource any // err := json.Unmarshal(resourceRaw, &resource) // assert.NilError(t, err) @@ -998,7 +998,7 @@ package jmespath // result, err := query.Search("") // assert.NilError(t, err) -// var expectedResult interface{} +// var expectedResult any // err = json.Unmarshal([]byte(tc.expectedResult), &expectedResult) // assert.NilError(t, err) @@ -1083,10 +1083,10 @@ package jmespath // res, err := query.Search("") // assert.NilError(t, err) -// result, ok := res.([]map[string]interface{}) +// result, ok := res.([]map[string]any) // assert.Assert(t, ok) -// var resource []map[string]interface{} +// var resource []map[string]any // err = json.Unmarshal([]byte(tc.expectedResult), &resource) // assert.NilError(t, err) @@ -1099,12 +1099,12 @@ package jmespath // testCases := []struct { // keys string // values string -// expectedResult map[string]interface{} +// expectedResult map[string]any // }{ // { // keys: `["key1", "key2"]`, // values: `["1", "2"]`, -// expectedResult: map[string]interface{}{ +// expectedResult: map[string]any{ // "key1": "1", // "key2": "2", // }, @@ -1112,7 +1112,7 @@ package jmespath // { // keys: `["key1", "key2"]`, // values: `[1, "2"]`, -// expectedResult: map[string]interface{}{ +// expectedResult: map[string]any{ // "key1": 1.0, // "key2": "2", // }, @@ -1120,7 +1120,7 @@ package jmespath // { // keys: `["key1", "key2"]`, // values: `[1]`, -// expectedResult: map[string]interface{}{ +// expectedResult: map[string]any{ // "key1": 1.0, // "key2": nil, // }, @@ -1132,7 +1132,7 @@ package jmespath // assert.NilError(t, err) // res, err := query.Search("") // assert.NilError(t, err) -// result, ok := res.(map[string]interface{}) +// result, ok := res.(map[string]any) // assert.Assert(t, ok) // assert.DeepEqual(t, result, tc.expectedResult) // }) @@ -1208,14 +1208,14 @@ package jmespath // `{"Raw":"MIIDSjCCAjKgAwIBAgIUWxmj40l+TDVJq98Xy7c6Leo3np8wDQYJKoZIhvcNAQELBQAwPTELMAkGA1UEBhMCeHgxCjAIBgNVBAgTAXgxCjAIBgNVBAcTAXgxCjAIBgNVBAoTAXgxCjAIBgNVBAsTAXgwHhcNMTgwMjAyMTIzODAwWhcNMjMwMjAxMTIzODAwWjA9MQswCQYDVQQGEwJ4eDEKMAgGA1UECBMBeDEKMAgGA1UEBxMBeDEKMAgGA1UEChMBeDEKMAgGA1UECxMBeDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANHkqOmVf23KMXdaZU2eFUx1h4wb09JINBB8x/HL7UE0KFJcnOoVnNQB0gRukUopiYCzrzMFyGWWmB/pAEKool+ZiI2uMy6mcYBDtOi4pOm7U0TQQMV6L/5Yfi65xRz3RTMd/tYAoFi4aCZbJAGjxU6UWNYDzTy8E/cP6ZnlNbVHRiA6/wHsoWcXtWTXYP5yn9cf7EWQi1hOBM4BWmOIyB1f6LEgQipZWMOMPPHO3hsuSBn0rk7jovSt5XTlbgRrtxqAJiNjJUykWzIF+lLnZCioippGv5vkdGvE83JoACXvZTUwzA+MLu49fkw3bweqkbhrer8kacjfGlw3aJN37eECAwEAAaNCMEAwDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFKXcb52bv6oqnD+D9fTNFHZL8IWxMA0GCSqGSIb3DQEBCwUAA4IBAQADvKvv3ym0XAYwKxPLLl3Lc6sJYHDbTN0donduG7PXeb1dhuukJ2lfufUYp2IGSAxuLecTYeeByOVp1gaMb5LsIGt2BVDmlMMkiH29LUHsvbyi85CpJo7A5RJG6AWW2VBCiDjz5v8JFM6pMkBRFfXH+pwIge65CE+MTSQcfb1/aIIoQ226P7E/3uUGX4k4pDXG/O7GNvykF40v1DB5y7DDBTQ4JWiJfyGkT69TmdOGLFAmjwxUjWyvEey4qJex/EGEm5RQcMv9iy7tba1wK7sykNGn5uDELGPGIIEAa5rIHm1FUFOZZVoELaasWS559wy8og39Eq21dDMynb8Bndn/","RawTBSCertificate":"MIICMqADAgECAhRbGaPjSX5MNUmr3xfLtzot6jeenzANBgkqhkiG9w0BAQsFADA9MQswCQYDVQQGEwJ4eDEKMAgGA1UECBMBeDEKMAgGA1UEBxMBeDEKMAgGA1UEChMBeDEKMAgGA1UECxMBeDAeFw0xODAyMDIxMjM4MDBaFw0yMzAyMDExMjM4MDBaMD0xCzAJBgNVBAYTAnh4MQowCAYDVQQIEwF4MQowCAYDVQQHEwF4MQowCAYDVQQKEwF4MQowCAYDVQQLEwF4MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0eSo6ZV/bcoxd1plTZ4VTHWHjBvT0kg0EHzH8cvtQTQoUlyc6hWc1AHSBG6RSimJgLOvMwXIZZaYH+kAQqiiX5mIja4zLqZxgEO06Lik6btTRNBAxXov/lh+LrnFHPdFMx3+1gCgWLhoJlskAaPFTpRY1gPNPLwT9w/pmeU1tUdGIDr/AeyhZxe1ZNdg/nKf1x/sRZCLWE4EzgFaY4jIHV/osSBCKllYw4w88c7eGy5IGfSuTuOi9K3ldOVuBGu3GoAmI2MlTKRbMgX6UudkKKiKmka/m+R0a8TzcmgAJe9lNTDMD4wu7j1+TDdvB6qRuGt6vyRpyN8aXDdok3ft4QIDAQABo0IwQDAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUpdxvnZu/qiqcP4P19M0UdkvwhbE=","RawSubjectPublicKeyInfo":"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0eSo6ZV/bcoxd1plTZ4VTHWHjBvT0kg0EHzH8cvtQTQoUlyc6hWc1AHSBG6RSimJgLOvMwXIZZaYH+kAQqiiX5mIja4zLqZxgEO06Lik6btTRNBAxXov/lh+LrnFHPdFMx3+1gCgWLhoJlskAaPFTpRY1gPNPLwT9w/pmeU1tUdGIDr/AeyhZxe1ZNdg/nKf1x/sRZCLWE4EzgFaY4jIHV/osSBCKllYw4w88c7eGy5IGfSuTuOi9K3ldOVuBGu3GoAmI2MlTKRbMgX6UudkKKiKmka/m+R0a8TzcmgAJe9lNTDMD4wu7j1+TDdvB6qRuGt6vyRpyN8aXDdok3ft4QIDAQAB","RawSubject":"MD0xCzAJBgNVBAYTAnh4MQowCAYDVQQIEwF4MQowCAYDVQQHEwF4MQowCAYDVQQKEwF4MQowCAYDVQQLEwF4","RawIssuer":"MD0xCzAJBgNVBAYTAnh4MQowCAYDVQQIEwF4MQowCAYDVQQHEwF4MQowCAYDVQQKEwF4MQowCAYDVQQLEwF4","Signature":"A7yr798ptFwGMCsTyy5dy3OrCWBw20zdHaJ3bhuz13m9XYbrpCdpX7n1GKdiBkgMbi3nE2HngcjladYGjG+S7CBrdgVQ5pTDJIh9vS1B7L28ovOQqSaOwOUSRugFltlQQog48+b/CRTOqTJAURX1x/qcCIHuuQhPjE0kHH29f2iCKENtuj+xP97lBl+JOKQ1xvzuxjb8pBeNL9QwecuwwwU0OCVoiX8hpE+vU5nThixQJo8MVI1srxHsuKiXsfxBhJuUUHDL/Ysu7W2tcCu7MpDRp+bgxCxjxiCBAGuayB5tRVBTmWVaBC2mrFkuefcMvKIN/RKttXQzMp2/AZ3Z/w==","SignatureAlgorithm":4,"PublicKeyAlgorithm":1,"PublicKey":{"N":"26496562094779491076553211809422098021949952483515703281510813808490953126660362388109632773224118754702902108388229193869554055094778177099185065933983949693842239539154549752097759985799130804083586220803335221114269832081649712810220640441076536231140807229028981655981643835428138719795509959624793308640711388215921808921435203036357847686892066058381787405708754578605922703585581205444932036212009496723589206933777338978604488048677611723712498345752655171502746679687404543368933776929978831813434358099337112479727796701588293884856604804625411358577626503349165930794262171211166398339413648296787152727521","E":65537},"Version":3,"SerialNumber":520089955419326249038486015063014459614455897759,"Issuer":{"Country":["xx"],"Organization":["x"],"OrganizationalUnit":["x"],"Locality":["x"],"Province":["x"],"StreetAddress":null,"PostalCode":null,"SerialNumber":"","CommonName":"","Names":[{"Type":[2,5,4,6],"Value":"xx"},{"Type":[2,5,4,8],"Value":"x"},{"Type":[2,5,4,7],"Value":"x"},{"Type":[2,5,4,10],"Value":"x"},{"Type":[2,5,4,11],"Value":"x"}],"ExtraNames":null},"Subject":{"Country":["xx"],"Organization":["x"],"OrganizationalUnit":["x"],"Locality":["x"],"Province":["x"],"StreetAddress":null,"PostalCode":null,"SerialNumber":"","CommonName":"","Names":[{"Type":[2,5,4,6],"Value":"xx"},{"Type":[2,5,4,8],"Value":"x"},{"Type":[2,5,4,7],"Value":"x"},{"Type":[2,5,4,10],"Value":"x"},{"Type":[2,5,4,11],"Value":"x"}],"ExtraNames":null},"NotBefore":"2018-02-02T12:38:00Z","NotAfter":"2023-02-01T12:38:00Z","KeyUsage":96,"Extensions":[{"Id":[2,5,29,15],"Critical":true,"Value":"AwIBBg=="},{"Id":[2,5,29,19],"Critical":true,"Value":"MAMBAf8="},{"Id":[2,5,29,14],"Critical":false,"Value":"BBSl3G+dm7+qKpw/g/X0zRR2S/CFsQ=="}],"ExtraExtensions":null,"UnhandledCriticalExtensions":null,"ExtKeyUsage":null,"UnknownExtKeyUsage":null,"BasicConstraintsValid":true,"IsCA":true,"MaxPathLen":-1,"MaxPathLenZero":false,"SubjectKeyId":"pdxvnZu/qiqcP4P19M0UdkvwhbE=","AuthorityKeyId":null,"OCSPServer":null,"IssuingCertificateURL":null,"DNSNames":null,"EmailAddresses":null,"IPAddresses":null,"URIs":null,"PermittedDNSDomainsCritical":false,"PermittedDNSDomains":null,"ExcludedDNSDomains":null,"PermittedIPRanges":null,"ExcludedIPRanges":null,"PermittedEmailAddresses":null,"ExcludedEmailAddresses":null,"PermittedURIDomains":null,"ExcludedURIDomains":null,"CRLDistributionPoints":null,"PolicyIdentifiers":null}`, // `{"Attributes": null,"DNSNames": null,"EmailAddresses": null,"Extensions": null,"ExtraExtensions": null,"IPAddresses": null,"PublicKey": {"E": 65537,"N": "30788787775499084229626026724118719872973907471499649646184775670914346180312671906399223325409590948519743636184795333482381888453996128329396648505249062053283056069530767359210562374203250761551376585013181653210719557451154530514423713570995019036786795900989905655136970670786111875127185122973524433496741842862203002594125711406631836733656561027033024624302759714504708249269624951711291364305004897900464453081676928894280743798888738608709381777168414778329993619693869221517193116446955833233290395600921852333943656575398427367952052258926688943219100950267027328710138285403327192731641778165311310576291"},"PublicKeyAlgorithm": 1,"Raw": "MIICvDCCAaQCAQAwdzELMAkGA1UEBhMCVVMxDTALBgNVBAgMBFV0YWgxDzANBgNVBAcMBkxpbmRvbjEWMBQGA1UECgwNRGlnaUNlcnQgSW5jLjERMA8GA1UECwwIRGlnaUNlcnQxHTAbBgNVBAMMFGV4YW1wbGUuZGlnaWNlcnQuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA8+To7d+2kPWeBv/orU3LVbJwDrSQbeKamCmowp5bqDxIwV20zqRb7APUOKYoVEFFOEQs6T6gImnIolhbiH6m4zgZ/CPvWBOkZc+c1Po2EmvBz+AD5sBdT5kzGQA6NbWyZGldxRthNLOs1efOhdnWFuhI162qmcflgpiIWDuwq4C9f+YkeJhNn9dF5+owm8cOQmDrV8NNdiTqin8q3qYAHHJRW28glJUCZkTZwIaSR6crBQ8TbYNE0dc+Caa3DOIkz1EOsHWzTx+n0zKfqcbgXi4DJx+C1bjptYPRBPZL8DAeWuA8ebudVT44yEp82G96/Ggcf7F33xMxe0yc+Xa6owIDAQABoAAwDQYJKoZIhvcNAQEFBQADggEBAB0kcrFccSmFDmxox0Ne01UIqSsDqHgL+XmHTXJwre6DhJSZwbvEtOK0G3+dr4Fs11WuUNt5qcLsx5a8uk4G6AKHMzuhLsJ7XZjgmQXGECpYQ4mC3yT3ZoCGpIXbw+iP3lmEEXgaQL0Tx5LFl/okKbKYwIqNiyKWOMj7ZR/wxWg/ZDGRs55xuoeLDJ/ZRFf9bI+IaCUd1YrfYcHIl3G87Av+r49YVwqRDT0VDV7uLgqn29XI1PpVUNCPQGn9p/eX6Qo7vpDaPybRtA2R7XLKjQaF9oXWeCUqy1hvJac9QFO297Ob1alpHPoZ7mWiEuJwjBPii6a9M9G30nUo39lBi1w=","RawSubject": "MHcxCzAJBgNVBAYTAlVTMQ0wCwYDVQQIDARVdGFoMQ8wDQYDVQQHDAZMaW5kb24xFjAUBgNVBAoMDURpZ2lDZXJ0IEluYy4xETAPBgNVBAsMCERpZ2lDZXJ0MR0wGwYDVQQDDBRleGFtcGxlLmRpZ2ljZXJ0LmNvbQ==","RawSubjectPublicKeyInfo": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA8+To7d+2kPWeBv/orU3LVbJwDrSQbeKamCmowp5bqDxIwV20zqRb7APUOKYoVEFFOEQs6T6gImnIolhbiH6m4zgZ/CPvWBOkZc+c1Po2EmvBz+AD5sBdT5kzGQA6NbWyZGldxRthNLOs1efOhdnWFuhI162qmcflgpiIWDuwq4C9f+YkeJhNn9dF5+owm8cOQmDrV8NNdiTqin8q3qYAHHJRW28glJUCZkTZwIaSR6crBQ8TbYNE0dc+Caa3DOIkz1EOsHWzTx+n0zKfqcbgXi4DJx+C1bjptYPRBPZL8DAeWuA8ebudVT44yEp82G96/Ggcf7F33xMxe0yc+Xa6owIDAQAB","RawTBSCertificateRequest": "MIIBpAIBADB3MQswCQYDVQQGEwJVUzENMAsGA1UECAwEVXRhaDEPMA0GA1UEBwwGTGluZG9uMRYwFAYDVQQKDA1EaWdpQ2VydCBJbmMuMREwDwYDVQQLDAhEaWdpQ2VydDEdMBsGA1UEAwwUZXhhbXBsZS5kaWdpY2VydC5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDz5Ojt37aQ9Z4G/+itTctVsnAOtJBt4pqYKajCnluoPEjBXbTOpFvsA9Q4pihUQUU4RCzpPqAiaciiWFuIfqbjOBn8I+9YE6Rlz5zU+jYSa8HP4APmwF1PmTMZADo1tbJkaV3FG2E0s6zV586F2dYW6EjXraqZx+WCmIhYO7CrgL1/5iR4mE2f10Xn6jCbxw5CYOtXw012JOqKfyrepgAcclFbbyCUlQJmRNnAhpJHpysFDxNtg0TR1z4JprcM4iTPUQ6wdbNPH6fTMp+pxuBeLgMnH4LVuOm1g9EE9kvwMB5a4Dx5u51VPjjISnzYb3r8aBx/sXffEzF7TJz5drqjAgMBAAGgAA==","Signature": "HSRysVxxKYUObGjHQ17TVQipKwOoeAv5eYdNcnCt7oOElJnBu8S04rQbf52vgWzXVa5Q23mpwuzHlry6TgboAoczO6EuwntdmOCZBcYQKlhDiYLfJPdmgIakhdvD6I/eWYQReBpAvRPHksWX+iQpspjAio2LIpY4yPtlH/DFaD9kMZGznnG6h4sMn9lEV/1sj4hoJR3Vit9hwciXcbzsC/6vj1hXCpENPRUNXu4uCqfb1cjU+lVQ0I9Aaf2n95fpCju+kNo/JtG0DZHtcsqNBoX2hdZ4JSrLWG8lpz1AU7b3s5vVqWkc+hnuZaIS4nCME+KLpr0z0bfSdSjf2UGLXA==","SignatureAlgorithm": 3,"Subject": {"CommonName": "example.digicert.com","Country": ["US"],"ExtraNames": null,"Locality": ["Lindon"],"Names": [{"Type": [2,5,4,6],"Value": "US"},{"Type": [2,5,4,8],"Value": "Utah"},{"Type": [2,5,4,7],"Value": "Lindon"},{"Type": [2,5,4,10],"Value": "DigiCert Inc."},{"Type": [2,5,4,11],"Value": "DigiCert"},{"Type": [2,5,4,3],"Value": "example.digicert.com"}],"Organization": ["DigiCert Inc."],"OrganizationalUnit": ["DigiCert"],"PostalCode": null,"Province": ["Utah"],"SerialNumber": "","StreetAddress": null},"URIs": null,"Version": 0}`, // } -// resExpected := make([]map[string]interface{}, 3) +// resExpected := make([]map[string]any, 3) // for i, v := range resList { // err := json.Unmarshal([]byte(v), &resExpected[i]) // assert.NilError(t, err) // } // testCases := []struct { // jmesPath string -// expectedResult map[string]interface{} +// expectedResult map[string]any // }{{ // jmesPath: "x509_decode(base64_decode('" + certs[0] + "'))", // expectedResult: resExpected[0], @@ -1240,7 +1240,7 @@ package jmespath // }, // // { // // jmesPath: "x509_decode('xyz')", -// // expectedResult: map[string]interface{}{}, +// // expectedResult: map[string]any{}, // // } // } // for _, tc := range testCases { @@ -1253,7 +1253,7 @@ package jmespath // assert.NilError(t, err) // } -// res, ok := result.(map[string]interface{}) +// res, ok := result.(map[string]any) // assert.Assert(t, ok) // assert.DeepEqual(t, res, tc.expectedResult) // }) @@ -1262,36 +1262,36 @@ package jmespath // func Test_jpfCompare(t *testing.T) { // type args struct { -// arguments []interface{} +// arguments []any // } // tests := []struct { // name string // args args -// want interface{} +// want any // wantErr bool // }{{ // args: args{ -// arguments: []interface{}{"a", "b"}, +// arguments: []any{"a", "b"}, // }, // want: -1, // }, { // args: args{ -// arguments: []interface{}{"b", "a"}, +// arguments: []any{"b", "a"}, // }, // want: 1, // }, { // args: args{ -// arguments: []interface{}{"b", "b"}, +// arguments: []any{"b", "b"}, // }, // want: 0, // }, { // args: args{ -// arguments: []interface{}{1, "b"}, +// arguments: []any{1, "b"}, // }, // wantErr: true, // }, { // args: args{ -// arguments: []interface{}{"a", 1}, +// arguments: []any{"a", 1}, // }, // wantErr: true, // }} @@ -1311,31 +1311,31 @@ package jmespath // func Test_jpfEqualFold(t *testing.T) { // type args struct { -// arguments []interface{} +// arguments []any // } // tests := []struct { // name string // args args -// want interface{} +// want any // wantErr bool // }{{ // args: args{ -// arguments: []interface{}{"Go", "go"}, +// arguments: []any{"Go", "go"}, // }, // want: true, // }, { // args: args{ -// arguments: []interface{}{"a", "b"}, +// arguments: []any{"a", "b"}, // }, // want: false, // }, { // args: args{ -// arguments: []interface{}{1, "b"}, +// arguments: []any{1, "b"}, // }, // wantErr: true, // }, { // args: args{ -// arguments: []interface{}{"a", 1}, +// arguments: []any{"a", 1}, // }, // wantErr: true, // }} @@ -1355,16 +1355,16 @@ package jmespath // func Test_jpfReplace(t *testing.T) { // type args struct { -// arguments []interface{} +// arguments []any // } // tests := []struct { // name string // args args -// want interface{} +// want any // wantErr bool // }{{ // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "Lorem ipsum dolor sit amet", // "ipsum", // "muspi", @@ -1374,7 +1374,7 @@ package jmespath // want: "Lorem muspi dolor sit amet", // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "Lorem ipsum ipsum ipsum dolor sit amet", // "ipsum", // "muspi", @@ -1384,7 +1384,7 @@ package jmespath // want: "Lorem muspi muspi muspi dolor sit amet", // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "Lorem ipsum ipsum ipsum dolor sit amet", // "ipsum", // "muspi", @@ -1394,7 +1394,7 @@ package jmespath // want: "Lorem muspi ipsum ipsum dolor sit amet", // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // 1.0, // "ipsum", // "muspi", @@ -1404,7 +1404,7 @@ package jmespath // wantErr: true, // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "Lorem ipsum ipsum ipsum dolor sit amet", // 1.0, // "muspi", @@ -1414,7 +1414,7 @@ package jmespath // wantErr: true, // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "Lorem ipsum ipsum ipsum dolor sit amet", // "ipsum", // false, @@ -1424,7 +1424,7 @@ package jmespath // wantErr: true, // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "Lorem ipsum ipsum ipsum dolor sit amet", // "ipsum", // "muspi", @@ -1449,16 +1449,16 @@ package jmespath // func Test_jpfReplaceAll(t *testing.T) { // type args struct { -// arguments []interface{} +// arguments []any // } // tests := []struct { // name string // args args -// want interface{} +// want any // wantErr bool // }{{ // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "Lorem ipsum dolor sit amet", // "ipsum", // "muspi", @@ -1467,7 +1467,7 @@ package jmespath // want: "Lorem muspi dolor sit amet", // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "Lorem ipsum ipsum ipsum dolor sit amet", // "ipsum", // "muspi", @@ -1476,7 +1476,7 @@ package jmespath // want: "Lorem muspi muspi muspi dolor sit amet", // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // 1.0, // "ipsum", // "muspi", @@ -1485,7 +1485,7 @@ package jmespath // wantErr: true, // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "Lorem ipsum ipsum ipsum dolor sit amet", // 1.0, // "muspi", @@ -1494,7 +1494,7 @@ package jmespath // wantErr: true, // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "Lorem ipsum ipsum ipsum dolor sit amet", // "ipsum", // false, @@ -1518,37 +1518,37 @@ package jmespath // func Test_jpfToUpper(t *testing.T) { // type args struct { -// arguments []interface{} +// arguments []any // } // tests := []struct { // name string // args args -// want interface{} +// want any // wantErr bool // }{{ // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "abc", // }, // }, // want: "ABC", // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "123", // }, // }, // want: "123", // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "a#%&123Bc", // }, // }, // want: "A#%&123BC", // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // 32.0, // }, // }, @@ -1570,37 +1570,37 @@ package jmespath // func Test_jpfToLower(t *testing.T) { // type args struct { -// arguments []interface{} +// arguments []any // } // tests := []struct { // name string // args args -// want interface{} +// want any // wantErr bool // }{{ // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "ABC", // }, // }, // want: "abc", // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "123", // }, // }, // want: "123", // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "A#%&123BC", // }, // }, // want: "a#%&123bc", // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // 32.0, // }, // }, diff --git a/pkg/engine/template/kyverno/time.go b/pkg/engine/template/kyverno/time.go index 8f7ab841..2c4998a9 100644 --- a/pkg/engine/template/kyverno/time.go +++ b/pkg/engine/template/kyverno/time.go @@ -22,7 +22,7 @@ var ( timeTruncate = "time_truncate" ) -func getTimeArg(f string, arguments []interface{}, index int) (time.Time, error) { +func getTimeArg(f string, arguments []any, index int) (time.Time, error) { var empty time.Time arg, err := validateArg(f, arguments, index, reflect.String) if err != nil { @@ -31,7 +31,7 @@ func getTimeArg(f string, arguments []interface{}, index int) (time.Time, error) return time.Parse(time.RFC3339, arg.String()) } -func getDurationArg(f string, arguments []interface{}, index int) (time.Duration, error) { +func getDurationArg(f string, arguments []any, index int) (time.Duration, error) { var empty time.Duration arg, err := validateArg(f, arguments, index, reflect.String) if err != nil { @@ -40,7 +40,7 @@ func getDurationArg(f string, arguments []interface{}, index int) (time.Duration return time.ParseDuration(arg.String()) } -func jpTimeSince(arguments []interface{}) (interface{}, error) { +func jpTimeSince(arguments []any) (any, error) { var err error layout, err := validateArg(timeSince, arguments, 0, reflect.String) if err != nil { @@ -77,15 +77,15 @@ func jpTimeSince(arguments []interface{}) (interface{}, error) { return t2.Sub(t1).String(), nil } -func jpTimeNow(arguments []interface{}) (interface{}, error) { +func jpTimeNow(arguments []any) (any, error) { return time.Now().Format(time.RFC3339), nil } -func jpTimeNowUtc(arguments []interface{}) (interface{}, error) { +func jpTimeNowUtc(arguments []any) (any, error) { return time.Now().UTC().Format(time.RFC3339), nil } -func jpTimeToCron(arguments []interface{}) (interface{}, error) { +func jpTimeToCron(arguments []any) (any, error) { if t, err := getTimeArg(timeToCron, arguments, 0); err != nil { return nil, err } else { @@ -99,7 +99,7 @@ func jpTimeToCron(arguments []interface{}) (interface{}, error) { } } -func jpTimeAdd(arguments []interface{}) (interface{}, error) { +func jpTimeAdd(arguments []any) (any, error) { if t, err := getTimeArg(timeToCron, arguments, 0); err != nil { return nil, err } else if d, err := getDurationArg(timeToCron, arguments, 1); err != nil { @@ -109,7 +109,7 @@ func jpTimeAdd(arguments []interface{}) (interface{}, error) { } } -func jpTimeParse(arguments []interface{}) (interface{}, error) { +func jpTimeParse(arguments []any) (any, error) { if layout, err := validateArg(timeParse, arguments, 0, reflect.String); err != nil { return nil, err } else if ts, err := validateArg(timeParse, arguments, 1, reflect.String); err != nil { @@ -121,7 +121,7 @@ func jpTimeParse(arguments []interface{}) (interface{}, error) { } } -func jpTimeUtc(arguments []interface{}) (interface{}, error) { +func jpTimeUtc(arguments []any) (any, error) { if t, err := getTimeArg(timeUtc, arguments, 0); err != nil { return nil, err } else { @@ -129,7 +129,7 @@ func jpTimeUtc(arguments []interface{}) (interface{}, error) { } } -func jpTimeDiff(arguments []interface{}) (interface{}, error) { +func jpTimeDiff(arguments []any) (any, error) { if t1, err := getTimeArg(timeDiff, arguments, 0); err != nil { return nil, err } else if t2, err := getTimeArg(timeDiff, arguments, 1); err != nil { @@ -139,7 +139,7 @@ func jpTimeDiff(arguments []interface{}) (interface{}, error) { } } -func jpTimeBefore(arguments []interface{}) (interface{}, error) { +func jpTimeBefore(arguments []any) (any, error) { if t1, err := getTimeArg(timeBefore, arguments, 0); err != nil { return nil, err } else if t2, err := getTimeArg(timeBefore, arguments, 1); err != nil { @@ -149,7 +149,7 @@ func jpTimeBefore(arguments []interface{}) (interface{}, error) { } } -func jpTimeAfter(arguments []interface{}) (interface{}, error) { +func jpTimeAfter(arguments []any) (any, error) { if t1, err := getTimeArg(timeAfter, arguments, 0); err != nil { return nil, err } else if t2, err := getTimeArg(timeAfter, arguments, 1); err != nil { @@ -159,7 +159,7 @@ func jpTimeAfter(arguments []interface{}) (interface{}, error) { } } -func jpTimeBetween(arguments []interface{}) (interface{}, error) { +func jpTimeBetween(arguments []any) (any, error) { if t, err := getTimeArg(timeBetween, arguments, 0); err != nil { return nil, err } else if start, err := getTimeArg(timeBetween, arguments, 1); err != nil { @@ -171,7 +171,7 @@ func jpTimeBetween(arguments []interface{}) (interface{}, error) { } } -func jpTimeTruncate(arguments []interface{}) (interface{}, error) { +func jpTimeTruncate(arguments []any) (any, error) { if t, err := getTimeArg(timeTruncate, arguments, 0); err != nil { return nil, err } else if d, err := getDurationArg(timeTruncate, arguments, 1); err != nil { diff --git a/pkg/engine/template/kyverno/time_test.go b/pkg/engine/template/kyverno/time_test.go index 0e6ffe9b..44fe2432 100644 --- a/pkg/engine/template/kyverno/time_test.go +++ b/pkg/engine/template/kyverno/time_test.go @@ -195,7 +195,7 @@ package jmespath // } // type args struct { // f string -// arguments []interface{} +// arguments []any // index int // } // tests := []struct { @@ -206,7 +206,7 @@ package jmespath // }{{ // args: args{ // f: "test", -// arguments: []interface{}{ +// arguments: []any{ // "2021-01-02T15:04:05-07:00", // }, // index: 0, @@ -215,7 +215,7 @@ package jmespath // }, { // args: args{ // f: "test", -// arguments: []interface{}{ +// arguments: []any{ // "2021-01-02T15:04:05-07:00", // }, // index: 1, @@ -224,7 +224,7 @@ package jmespath // }, { // args: args{ // f: "test", -// arguments: []interface{}{ +// arguments: []any{ // 1, // }, // index: 0, @@ -233,7 +233,7 @@ package jmespath // }, { // args: args{ // f: "test", -// arguments: []interface{}{ +// arguments: []any{ // "", // }, // index: 0, @@ -264,7 +264,7 @@ package jmespath // } // type args struct { // f string -// arguments []interface{} +// arguments []any // index int // } // tests := []struct { @@ -275,7 +275,7 @@ package jmespath // }{{ // args: args{ // f: "test", -// arguments: []interface{}{ +// arguments: []any{ // "20s", // }, // index: 0, @@ -284,7 +284,7 @@ package jmespath // }, { // args: args{ // f: "test", -// arguments: []interface{}{ +// arguments: []any{ // "20s", // }, // index: 1, @@ -293,7 +293,7 @@ package jmespath // }, { // args: args{ // f: "test", -// arguments: []interface{}{ +// arguments: []any{ // 1, // }, // index: 0, @@ -302,7 +302,7 @@ package jmespath // }, { // args: args{ // f: "test", -// arguments: []interface{}{ +// arguments: []any{ // "", // }, // index: 0, @@ -325,16 +325,16 @@ package jmespath // func Test_jpTimeBefore(t *testing.T) { // type args struct { -// arguments []interface{} +// arguments []any // } // tests := []struct { // name string // args args -// want interface{} +// want any // wantErr bool // }{{ // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "2021-01-02T15:04:05-07:00", // "2021-01-02T16:04:05-07:00", // }, @@ -342,7 +342,7 @@ package jmespath // want: true, // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "2021-01-02T15:04:05-07:00", // "2021-01-02T15:04:05-07:00", // }, @@ -350,7 +350,7 @@ package jmespath // want: false, // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "2021-01-02T16:04:05-07:00", // "2021-01-02T15:04:05-07:00", // }, @@ -358,7 +358,7 @@ package jmespath // want: false, // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // 1, // "2021-01-02T15:04:05-07:00", // }, @@ -366,7 +366,7 @@ package jmespath // wantErr: true, // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "2021-01-02T15:04:05-07:00", // 1, // }, @@ -389,16 +389,16 @@ package jmespath // func Test_jpTimeAfter(t *testing.T) { // type args struct { -// arguments []interface{} +// arguments []any // } // tests := []struct { // name string // args args -// want interface{} +// want any // wantErr bool // }{{ // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "2021-01-02T15:04:05-07:00", // "2021-01-02T16:04:05-07:00", // }, @@ -406,7 +406,7 @@ package jmespath // want: false, // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "2021-01-02T15:04:05-07:00", // "2021-01-02T15:04:05-07:00", // }, @@ -414,7 +414,7 @@ package jmespath // want: false, // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "2021-01-02T16:04:05-07:00", // "2021-01-02T15:04:05-07:00", // }, @@ -422,7 +422,7 @@ package jmespath // want: true, // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // 1, // "2021-01-02T15:04:05-07:00", // }, @@ -430,7 +430,7 @@ package jmespath // wantErr: true, // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "2021-01-02T15:04:05-07:00", // 1, // }, @@ -453,16 +453,16 @@ package jmespath // func Test_jpTimeBetween(t *testing.T) { // type args struct { -// arguments []interface{} +// arguments []any // } // tests := []struct { // name string // args args -// want interface{} +// want any // wantErr bool // }{{ // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "2021-01-02T17:04:05-07:00", // "2021-01-02T15:04:05-07:00", // "2021-01-02T18:04:05-07:00", @@ -471,7 +471,7 @@ package jmespath // want: true, // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "2021-01-02T15:04:05-07:00", // "2021-01-02T15:04:05-07:00", // "2021-01-02T18:04:05-07:00", @@ -480,7 +480,7 @@ package jmespath // want: false, // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "2021-01-02T18:04:05-07:00", // "2021-01-02T15:04:05-07:00", // "2021-01-02T18:04:05-07:00", @@ -489,7 +489,7 @@ package jmespath // want: false, // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // 1, // "2021-01-02T15:04:05-07:00", // "2021-01-02T18:04:05-07:00", @@ -498,7 +498,7 @@ package jmespath // wantErr: true, // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "2021-01-02T15:04:05-07:00", // 1, // "2021-01-02T18:04:05-07:00", @@ -507,7 +507,7 @@ package jmespath // wantErr: true, // }, { // args: args{ -// arguments: []interface{}{ +// arguments: []any{ // "2021-01-02T15:04:05-07:00", // "2021-01-02T18:04:05-07:00", // 1, diff --git a/pkg/engine/template/kyverno/utils.go b/pkg/engine/template/kyverno/utils.go index 771c6276..7d3bb1ca 100644 --- a/pkg/engine/template/kyverno/utils.go +++ b/pkg/engine/template/kyverno/utils.go @@ -6,7 +6,7 @@ import ( "reflect" ) -func validateArg(f string, arguments []interface{}, index int, expectedType reflect.Kind) (reflect.Value, error) { +func validateArg(f string, arguments []any, index int, expectedType reflect.Kind) (reflect.Value, error) { if index >= len(arguments) { return reflect.Value{}, formatError(argOutOfBoundsError, f, index+1, len(arguments)) } diff --git a/pkg/engine/template/template.go b/pkg/engine/template/template.go index 4d0d50e8..8b785eb4 100644 --- a/pkg/engine/template/template.go +++ b/pkg/engine/template/template.go @@ -16,7 +16,7 @@ var ( parser = parsing.NewParser() ) -func String(ctx context.Context, in string, value interface{}, bindings binding.Bindings, opts ...Option) string { +func String(ctx context.Context, in string, value any, bindings binding.Bindings, opts ...Option) string { groups := variable.FindAllStringSubmatch(in, -1) for _, group := range groups { statement := strings.TrimSpace(group[1]) @@ -34,7 +34,7 @@ func String(ctx context.Context, in string, value interface{}, bindings binding. return in } -func Execute(ctx context.Context, statement string, value interface{}, bindings binding.Bindings, opts ...Option) (interface{}, error) { +func Execute(ctx context.Context, statement string, value any, bindings binding.Bindings, opts ...Option) (any, error) { o := buildOptions(opts...) vm := interpreter.NewInterpreter(nil, bindings) compiled, err := parser.Parse(statement)