diff --git a/.golangci.yaml b/.golangci.yaml index 4280a1b87..30d27fddb 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -210,6 +210,6 @@ linters: - prealloc - unconvert - copyloopvar - # - perfsprint # reenable after https://github.com/open-policy-agent/opa-envoy-plugin/issues/729 is complete + - perfsprint - gocritic # - gosec # too many false positives \ No newline at end of file diff --git a/envoyauth/evaluation.go b/envoyauth/evaluation.go index a5e244a3a..93a4dfc8a 100644 --- a/envoyauth/evaluation.go +++ b/envoyauth/evaluation.go @@ -2,7 +2,7 @@ package envoyauth import ( "context" - "fmt" + "errors" "github.com/open-policy-agent/opa/v1/ast" "github.com/open-policy-agent/opa/v1/config" @@ -110,9 +110,9 @@ func Eval(ctx context.Context, evalContext EvalContext, input ast.Value, result case err != nil: return err case len(rs) == 0: - return fmt.Errorf("undefined decision") + return errors.New("undefined decision") case len(rs) > 1: - return fmt.Errorf("multiple evaluation results") + return errors.New("multiple evaluation results") } result.NDBuiltinCache = ndbCache diff --git a/envoyauth/request.go b/envoyauth/request.go index 276cd36c0..521070fd9 100644 --- a/envoyauth/request.go +++ b/envoyauth/request.go @@ -294,7 +294,7 @@ func getGRPCBody(logger logging.Logger, in []byte, parsedPath []string, data any // https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md if len(in) < 5 { - return false, false, fmt.Errorf("less than 5 bytes") + return false, false, errors.New("less than 5 bytes") } // Can be 0 or 1, 1 indicates that the payload is compressed. diff --git a/envoyauth/response.go b/envoyauth/response.go index 17959b758..43f699411 100644 --- a/envoyauth/response.go +++ b/envoyauth/response.go @@ -3,6 +3,7 @@ package envoyauth import ( "context" "encoding/json" + "errors" "fmt" "net/http" "slices" @@ -127,7 +128,7 @@ func (result *EvalResult) IsAllowed() (bool, error) { var ok, allowed bool if val, ok = decision["allowed"]; !ok { - return false, fmt.Errorf("unable to determine evaluation result due to missing \"allowed\" key") + return false, errors.New("unable to determine evaluation result due to missing \"allowed\" key") } if allowed, ok = val.(bool); !ok { @@ -299,7 +300,7 @@ func (result *EvalResult) GetResponseHTTPStatus() (int, error) { switch decision := result.Decision.(type) { case bool: if decision { - return http.StatusOK, fmt.Errorf("HTTP status code undefined for simple 'allow'") + return http.StatusOK, errors.New("HTTP status code undefined for simple 'allow'") } return status, nil @@ -332,7 +333,7 @@ func (result *EvalResult) GetDynamicMetadata() (*_structpb.Struct, error) { switch decision := result.Decision.(type) { case bool: if decision { - return nil, fmt.Errorf("dynamic metadata undefined for boolean decision") + return nil, errors.New("dynamic metadata undefined for boolean decision") } case map[string]any: var ( diff --git a/internal/internal.go b/internal/internal.go index a0bcd9d61..09dc453b2 100644 --- a/internal/internal.go +++ b/internal/internal.go @@ -108,7 +108,7 @@ func Validate(m *plugins.Manager, bs []byte) (*Config, error) { } if cfg.Path != "" && cfg.Query != "" { - return nil, fmt.Errorf("invalid config: specify a value for only the \"path\" field") + return nil, errors.New("invalid config: specify a value for only the \"path\" field") } var parsedQuery ast.Body diff --git a/internal/internal_test.go b/internal/internal_test.go index f49a2bed6..fd6be4acd 100644 --- a/internal/internal_test.go +++ b/internal/internal_test.go @@ -2583,5 +2583,5 @@ func (_ *testPluginError) Reconfigure(context.Context, any) { func (p *testPluginError) Log(_ context.Context, event logs.EventV1) error { p.events = append(p.events, event) - return fmt.Errorf("Bad Logger Error") + return errors.New("Bad Logger Error") }