Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions envoyauth/evaluation.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func Eval(ctx context.Context, evalContext EvalContext, input ast.Value, result
var txnClose TransactionCloser
txn, txnClose, err = result.GetTxn(ctx, evalContext.Store())
if err != nil {
logger.WithFields(map[string]interface{}{"err": err}).Error("Unable to start new storage transaction.")
logger.WithFields(map[string]any{"err": err}).Error("Unable to start new storage transaction.")
return err
}
defer txnClose(ctx, err)
Expand All @@ -55,7 +55,7 @@ func Eval(ctx context.Context, evalContext EvalContext, input ast.Value, result
result.TxnID = result.Txn.ID()

if logger.GetLevel() == logging.Debug {
logger.WithFields(map[string]interface{}{
logger.WithFields(map[string]any{
"input": input,
"query": evalContext.ParsedQuery().String(),
"txn": result.TxnID,
Expand All @@ -79,7 +79,7 @@ func Eval(ctx context.Context, evalContext EvalContext, input ast.Value, result
return err
}

ph := hook{logger: logger.WithFields(map[string]interface{}{"decision-id": result.DecisionID})}
ph := hook{logger: logger.WithFields(map[string]any{"decision-id": result.DecisionID})}

var ndbCache builtins.NDBCache
if evalContext.Config().NDBuiltinCacheEnabled() {
Expand Down
6 changes: 3 additions & 3 deletions envoyauth/evaluation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func TestEval(t *testing.T) {
t.Fatal(err)
}

inputValue := ast.MustInterfaceToValue(map[string]interface{}{
"parsed_body": map[string]interface{}{
inputValue := ast.MustInterfaceToValue(map[string]any{
"parsed_body": map[string]any{
"firstname": "foo",
"lastname": "bar",
},
Expand Down Expand Up @@ -249,7 +249,7 @@ func (*testPlugin) Start(context.Context) error {
func (*testPlugin) Stop(context.Context) {
}

func (*testPlugin) Reconfigure(context.Context, interface{}) {
func (*testPlugin) Reconfigure(context.Context, any) {
}

func (p *testPlugin) Log(_ context.Context, event logs.EventV1) error {
Expand Down
18 changes: 9 additions & 9 deletions envoyauth/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ var v3Info = ast.NewObject(
)

// RequestToInput - Converts a CheckRequest in either protobuf 2 or 3 to an input map
func RequestToInput(req interface{}, logger logging.Logger, protoSet *protoregistry.Files, skipRequestBodyParse bool) (map[string]interface{}, error) {
func RequestToInput(req any, logger logging.Logger, protoSet *protoregistry.Files, skipRequestBodyParse bool) (map[string]any, error) {
var err error
var input map[string]interface{}
var input map[string]any

var rawBody []byte
var path, body string
Expand Down Expand Up @@ -109,8 +109,8 @@ func getParsedPathAndQuery(path string) ([]string, map[string]any, error) {
return parsedPath, parsedQueryInterface, nil
}

func getParsedBody(logger logging.Logger, headers map[string]string, body string, rawBody []byte, parsedPath []string, protoSet *protoregistry.Files) (interface{}, bool, error) {
var data interface{}
func getParsedBody(logger logging.Logger, headers map[string]string, body string, rawBody []byte, parsedPath []string, protoSet *protoregistry.Files) (any, bool, error) {
var data any

if val, ok := headers["content-type"]; ok {
if strings.Contains(val, "application/json") {
Expand Down Expand Up @@ -224,7 +224,7 @@ func getParsedBody(logger logging.Logger, headers map[string]string, body string
return nil, false, nil
}

values := map[string][]interface{}{}
values := map[string][]any{}

mr := multipart.NewReader(strings.NewReader(payload), boundary)
for {
Expand All @@ -248,7 +248,7 @@ func getParsedBody(logger logging.Logger, headers map[string]string, body string

switch {
case strings.Contains(p.Header.Get("Content-Type"), "application/json"):
var jsonValue interface{}
var jsonValue any
if err := util.UnmarshalJSON(value, &jsonValue); err != nil {
return nil, false, err
}
Expand All @@ -269,7 +269,7 @@ func getParsedBody(logger logging.Logger, headers map[string]string, body string
return data, false, nil
}

func getGRPCBody(logger logging.Logger, in []byte, parsedPath []string, data interface{}, files *protoregistry.Files) (found, truncated bool, _ error) {
func getGRPCBody(logger logging.Logger, in []byte, parsedPath []string, data any, files *protoregistry.Files) (found, truncated bool, _ error) {

// the first 5 bytes are part of gRPC framing. We need to remove them to be able to parse
// https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md
Expand All @@ -296,12 +296,12 @@ func getGRPCBody(logger logging.Logger, in []byte, parsedPath []string, data int
// Note: we've already checked that len(path)>=2
svc, err := findService(parsedPath[0], files)
if err != nil {
logger.WithFields(map[string]interface{}{"err": err}).Debug("could not find service")
logger.WithFields(map[string]any{"err": err}).Debug("could not find service")
return false, false, nil
}
msgDesc, err := findMessageInputDesc(parsedPath[1], svc)
if err != nil {
logger.WithFields(map[string]interface{}{"err": err}).Debug("could not find message")
logger.WithFields(map[string]any{"err": err}).Debug("could not find message")
return false, false, nil
}

Expand Down
42 changes: 21 additions & 21 deletions envoyauth/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func TestGetParsedBody(t *testing.T) {
}
}`
expectedNumber := json.Number("42")
expectedObject := map[string]interface{}{
expectedObject := map[string]any{
"firstname": "foo",
"lastname": "bar",
}
Expand All @@ -303,25 +303,25 @@ func TestGetParsedBody(t *testing.T) {
"firstname": {"foo"},
"lastname": {"bar", "foobar"},
}
expectedArray := []interface{}{"hello", "opa"}
expectedJSONSpecialChars := []interface{}{`"`, `\`, "/", "/", "\b", "\f", "\n", "\r", "\t", "A"}
expectedMultipartFormData := map[string][]interface{}{
expectedArray := []any{"hello", "opa"}
expectedJSONSpecialChars := []any{`"`, `\`, "/", "/", "\b", "\f", "\n", "\r", "\t", "A"}
expectedMultipartFormData := map[string][]any{
"foo": {"bar"},
}
expectedMultipartFormDataWithJSON := map[string][]interface{}{
expectedMultipartFormDataWithJSON := map[string][]any{
"foo": {"bar"},
"bar": {
map[string]interface{}{"name": "bar"},
map[string]any{"name": "bar"},
},
}
expectedContentTypeJSONRawBody := map[string]interface{}{
expectedContentTypeJSONRawBody := map[string]any{
"firstname": "foo",
"lastname": "bar",
}

tests := map[string]struct {
input *ext_authz.CheckRequest
want interface{}
want any
isBodyTruncated bool
err error
}{
Expand Down Expand Up @@ -552,17 +552,17 @@ func TestGetParsedBodygRPC(t *testing.T) {
}
`

expectedObject := map[string]interface{}{
"Data": map[string]interface{}{
expectedObject := map[string]any{
"Data": map[string]any{
"Body": "Body value",
"Name": "Name Value",
},
"Metadata": map[string]interface{}{
"Metadata": map[string]any{
"SeverityNumber": "SecNumber",
"SeverityText": "ERROR",
},
}
expectedObjectExampleBook := map[string]interface{}{"author": "John"}
expectedObjectExampleBook := map[string]any{"author": "John"}
protoDescriptorPath := "../test/files/combined.pb"
protoSet, err := internal_util.ReadProtoSet(protoDescriptorPath)
if err != nil {
Expand All @@ -571,7 +571,7 @@ func TestGetParsedBodygRPC(t *testing.T) {

tests := map[string]struct {
input *ext_authz.CheckRequest
want interface{}
want any
isBodyTruncated bool
err error
}{
Expand All @@ -581,7 +581,7 @@ func TestGetParsedBodygRPC(t *testing.T) {
"valid_parsed_book": {input: createCheckRequest(requestValidBook), want: expectedObjectExampleBook, isBodyTruncated: false, err: nil},
"unknown_service": {input: createCheckRequest(requestUnknownService), want: nil, isBodyTruncated: false, err: nil},
"unknown_method": {input: createCheckRequest(requestUnknownMethod), want: nil, isBodyTruncated: false, err: nil},
"empty_request": {input: createCheckRequest(requestEmpty), want: map[string]interface{}{}, isBodyTruncated: false, err: nil},
"empty_request": {input: createCheckRequest(requestEmpty), want: map[string]any{}, isBodyTruncated: false, err: nil},
"compressed_payload": {input: createCheckRequest(requestCompressedPayload), want: nil, isBodyTruncated: false, err: nil},
"truncated_payload": {input: createCheckRequest(requestTruncatedPayload), want: nil, isBodyTruncated: true, err: nil},
}
Expand Down Expand Up @@ -618,37 +618,37 @@ func TestParsedPathAndQuery(t *testing.T) {
var tests = []struct {
request *ext_authz.CheckRequest
expectedPath []string
expectedQuery map[string]interface{}
expectedQuery map[string]any
}{
{
createExtReqWithPath("/my/test/path"),
[]string{"my", "test", "path"},
map[string]interface{}{},
map[string]any{},
},
{
createExtReqWithPath("/my/test/path?a=1"),
[]string{"my", "test", "path"},
map[string]interface{}{"a": []string{"1"}},
map[string]any{"a": []string{"1"}},
},
{
createExtReqWithPath("/my/test/path?a=1&a=2"),
[]string{"my", "test", "path"},
map[string]interface{}{"a": []string{"1", "2"}},
map[string]any{"a": []string{"1", "2"}},
},
{
createExtReqWithPath("/my/test/path?a=1&b=2"),
[]string{"my", "test", "path"},
map[string]interface{}{"a": []string{"1"}, "b": []string{"2"}},
map[string]any{"a": []string{"1"}, "b": []string{"2"}},
},
{
createExtReqWithPath("/my/test/path?a=1&a=new%0aline"),
[]string{"my", "test", "path"},
map[string]interface{}{"a": []string{"1", "new\nline"}},
map[string]any{"a": []string{"1", "new\nline"}},
},
{
createExtReqWithPath("%2Fmy%2Ftest%2Fpath?a=1&a=new%0aline"),
[]string{"my", "test", "path"},
map[string]interface{}{"a": []string{"1", "new\nline"}},
map[string]any{"a": []string{"1", "new\nline"}},
},
}

Expand Down
38 changes: 19 additions & 19 deletions envoyauth/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type EvalResult struct {
Revisions map[string]string
DecisionID string
TxnID uint64
Decision interface{}
Decision any
Metrics metrics.Metrics
Txn storage.Transaction
NDBuiltinCache builtins.NDBCache
Expand Down Expand Up @@ -122,8 +122,8 @@ func (result *EvalResult) IsAllowed() (bool, error) {
switch decision := result.Decision.(type) {
case bool:
return decision, nil
case map[string]interface{}:
var val interface{}
case map[string]any:
var val any
var ok, allowed bool

if val, ok = decision["allowed"]; !ok {
Expand All @@ -144,9 +144,9 @@ func (result *EvalResult) getStringSliceFromDecision(fieldName string) ([]string
switch decision := result.Decision.(type) {
case bool:
return nil, nil
case map[string]interface{}:
case map[string]any:
var ok bool
var val interface{}
var val any

if val, ok = decision[fieldName]; !ok {
return nil, nil
Expand All @@ -155,7 +155,7 @@ func (result *EvalResult) getStringSliceFromDecision(fieldName string) ([]string
switch val := val.(type) {
case []string:
return val, nil
case []interface{}:
case []any:
ss := make([]string, len(val))
for i, v := range val {
s, ok := v.(string)
Expand Down Expand Up @@ -255,7 +255,7 @@ func (result *EvalResult) GetResponseHTTPHeadersToAdd() ([]*ext_core_v3.HeaderVa

// HasResponseBody returns true if the decision defines a body (only true for structured decisions)
func (result *EvalResult) HasResponseBody() bool {
decision, ok := result.Decision.(map[string]interface{})
decision, ok := result.Decision.(map[string]any)

if !ok {
return false
Expand All @@ -269,11 +269,11 @@ func (result *EvalResult) HasResponseBody() bool {
// GetResponseBody returns the http body to return if they are part of the decision
func (result *EvalResult) GetResponseBody() (string, error) {
var ok bool
var val interface{}
var val any
var body string
var decision map[string]interface{}
var decision map[string]any

if decision, ok = result.Decision.(map[string]interface{}); !ok {
if decision, ok = result.Decision.(map[string]any); !ok {
return "", nil
}

Expand All @@ -291,7 +291,7 @@ func (result *EvalResult) GetResponseBody() (string, error) {
// GetResponseHTTPStatus returns the http status to return if they are part of the decision
func (result *EvalResult) GetResponseHTTPStatus() (int, error) {
var ok bool
var val interface{}
var val any
var statusCode json.Number

status := http.StatusForbidden
Expand All @@ -303,7 +303,7 @@ func (result *EvalResult) GetResponseHTTPStatus() (int, error) {
}

return status, nil
case map[string]interface{}:
case map[string]any:
if val, ok = decision["http_status"]; !ok {
return status, nil
}
Expand Down Expand Up @@ -334,16 +334,16 @@ func (result *EvalResult) GetDynamicMetadata() (*_structpb.Struct, error) {
if decision {
return nil, fmt.Errorf("dynamic metadata undefined for boolean decision")
}
case map[string]interface{}:
case map[string]any:
var (
val interface{}
val any
ok bool
)
if val, ok = decision["dynamic_metadata"]; !ok {
return nil, nil
}

metadata, ok := val.(map[string]interface{})
metadata, ok := val.(map[string]any)
if !ok {
return nil, fmt.Errorf("type assertion error, expected dynamic_metadata to be of type 'object' but got '%T'", val)
}
Expand Down Expand Up @@ -387,7 +387,7 @@ func transformHeadersMapToHeadersBag(headers map[string]any, hb headersBag) erro
for _, v := range val {
hb.add(key, v)
}
case []interface{}:
case []any:
hb.allocate(len(val))
for _, v := range val {
s, ok := v.(string)
Expand Down Expand Up @@ -428,13 +428,13 @@ func (result *EvalResult) GetRequestQueryParametersToSet() ([]*ext_core_v3.Query
switch decision := result.Decision.(type) {
case bool:
return nil, nil
case map[string]interface{}:
case map[string]any:
val, ok := decision["query_parameters_to_set"]
if !ok {
return nil, nil
}

params, ok := val.(map[string]interface{})
params, ok := val.(map[string]any)
if !ok {
return nil, fmt.Errorf("type assertion error, expected query_parameters_to_set to be a map but got '%T'", val)
}
Expand All @@ -448,7 +448,7 @@ func (result *EvalResult) GetRequestQueryParametersToSet() ([]*ext_core_v3.Query
Key: key,
Value: v,
})
case []interface{}:
case []any:
result = slices.Grow(result, len(v))
for _, item := range v {
strItem, ok := item.(string)
Expand Down
Loading