mirror of
https://github.com/TecharoHQ/anubis.git
synced 2026-04-21 15:46:41 +00:00
fix: replace checker.NewMapIterator with newMapIterator for HTTPHeaders and URLValues
Signed-off-by: Jason Cameron <jason.cameron@stanwith.me>
This commit is contained in:
committed by
Jason Cameron
parent
8e9b641280
commit
33ea6c714f
@@ -5,7 +5,6 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/TecharoHQ/anubis/lib/policy/checker"
|
|
||||||
"github.com/google/cel-go/common/types"
|
"github.com/google/cel-go/common/types"
|
||||||
"github.com/google/cel-go/common/types/ref"
|
"github.com/google/cel-go/common/types/ref"
|
||||||
"github.com/google/cel-go/common/types/traits"
|
"github.com/google/cel-go/common/types/traits"
|
||||||
@@ -68,7 +67,7 @@ func (h HTTPHeaders) Get(key ref.Val) ref.Val {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h HTTPHeaders) Iterator() traits.Iterator {
|
func (h HTTPHeaders) Iterator() traits.Iterator {
|
||||||
return checker.NewMapIterator(h.Header)
|
return newMapIterator(h.Header)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h HTTPHeaders) IsZeroValue() bool {
|
func (h HTTPHeaders) IsZeroValue() bool {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package checker
|
package expressions
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/google/cel-go/common/types/traits"
|
"github.com/google/cel-go/common/types/traits"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrNotImplemented = errors.New("cel: functionality not implemented")
|
var ErrNotImplemented = errors.New("expressions: not implemented")
|
||||||
|
|
||||||
type stringSliceIterator struct {
|
type stringSliceIterator struct {
|
||||||
keys []string
|
keys []string
|
||||||
@@ -32,7 +32,6 @@ func (s *stringSliceIterator) ConvertToType(typeValue ref.Type) ref.Val {
|
|||||||
|
|
||||||
func (s *stringSliceIterator) Equal(other ref.Val) ref.Val {
|
func (s *stringSliceIterator) Equal(other ref.Val) ref.Val {
|
||||||
return types.NewErr("can't compare %q to %q", types.IteratorType, other.Type())
|
return types.NewErr("can't compare %q to %q", types.IteratorType, other.Type())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stringSliceIterator) Type() ref.Type {
|
func (s *stringSliceIterator) Type() ref.Type {
|
||||||
@@ -53,7 +52,7 @@ func (s *stringSliceIterator) Next() ref.Val {
|
|||||||
return types.String(val)
|
return types.String(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMapIterator(m map[string][]string) traits.Iterator {
|
func newMapIterator(m map[string][]string) traits.Iterator {
|
||||||
return &stringSliceIterator{
|
return &stringSliceIterator{
|
||||||
keys: slices.Collect(maps.Keys(m)),
|
keys: slices.Collect(maps.Keys(m)),
|
||||||
idx: 0,
|
idx: 0,
|
||||||
@@ -1,19 +1,15 @@
|
|||||||
package expressions
|
package expressions
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/TecharoHQ/anubis/lib/policy/checker"
|
|
||||||
"github.com/google/cel-go/common/types"
|
"github.com/google/cel-go/common/types"
|
||||||
"github.com/google/cel-go/common/types/ref"
|
"github.com/google/cel-go/common/types/ref"
|
||||||
"github.com/google/cel-go/common/types/traits"
|
"github.com/google/cel-go/common/types/traits"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrNotImplemented = errors.New("expressions: not implemented")
|
|
||||||
|
|
||||||
// URLValues is a type wrapper to expose url.Values into CEL programs.
|
// URLValues is a type wrapper to expose url.Values into CEL programs.
|
||||||
type URLValues struct {
|
type URLValues struct {
|
||||||
url.Values
|
url.Values
|
||||||
@@ -71,7 +67,7 @@ func (u URLValues) Get(key ref.Val) ref.Val {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u URLValues) Iterator() traits.Iterator {
|
func (u URLValues) Iterator() traits.Iterator {
|
||||||
return checker.NewMapIterator(u.Values)
|
return newMapIterator(u.Values)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u URLValues) IsZeroValue() bool {
|
func (u URLValues) IsZeroValue() bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user