diff --git a/pkg/hexapolicy/conditions/conditions.go b/pkg/hexapolicy/conditions/conditions.go index 112df48..7c9e649 100644 --- a/pkg/hexapolicy/conditions/conditions.go +++ b/pkg/hexapolicy/conditions/conditions.go @@ -13,7 +13,7 @@ import ( const ( AAllow string = "allow" ADeny string = "deny" - AAudit string = "audit" + // AAudit string = "audit" ) type ConditionInfo struct { diff --git a/pkg/hexapolicy/types/array.go b/pkg/hexapolicy/types/array.go index 2da0c4e..cb50a3d 100644 --- a/pkg/hexapolicy/types/array.go +++ b/pkg/hexapolicy/types/array.go @@ -1,12 +1,15 @@ package types -import "strings" +import ( + "fmt" + "strings" +) type Array struct { - values []Value + values []ComparableValue } -func NewArray(values []Value) Value { +func NewArray(values []ComparableValue) Value { return Array{values} } @@ -31,13 +34,19 @@ func ParseArray(s string) (Value, error) { val = strings.TrimSuffix(val, "]") vals := strings.Split(val, ",") - values := make([]Value, len(vals)) + values := make([]ComparableValue, len(vals)) for i, item := range vals { iValue, err := ParseValue(item) if err != nil { return nil, err } - values[i] = iValue + switch v := iValue.(type) { + case ComparableValue: + values[i] = v + default: + return nil, fmt.Errorf("arrays cannot contain sub-arrays or objects: %s", s) + } + } return NewArray(values), nil } diff --git a/pkg/hexapolicy/types/types_test.go b/pkg/hexapolicy/types/types_test.go index eca1943..6cbf4ec 100644 --- a/pkg/hexapolicy/types/types_test.go +++ b/pkg/hexapolicy/types/types_test.go @@ -61,7 +61,7 @@ func TestTypes(t *testing.T) { { "Arrays", "[\"a\", \"b\", \"c\"]", - Array{[]Value{String{"a"}, String{"b"}, String{"c"}}}, + Array{[]ComparableValue{String{"a"}, String{"b"}, String{"c"}}}, "", "", false, @@ -239,8 +239,8 @@ func TestArray(t *testing.T) { assert.NoError(t, err) assert.IsType(t, Array{}, value) assert.Equal(t, TypeArray, value.ValueType()) - assert.IsType(t, []Value{}, value.Value()) - vals := value.Value().([]Value) + assert.IsType(t, []ComparableValue{}, value.Value()) + vals := value.Value().([]ComparableValue) val2 := vals[1] assert.Equal(t, float64(2), val2.Value()) }