refactor: get rid of package expressions by moving the code into package expression

Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
Xe Iaso 2025-07-25 19:57:47 +00:00
parent a494d26708
commit 9f3eb71ef6
No known key found for this signature in database
8 changed files with 13 additions and 14 deletions

View File

@ -6,7 +6,6 @@ import (
"github.com/TecharoHQ/anubis/internal"
"github.com/TecharoHQ/anubis/lib/checker/expression/environment"
"github.com/TecharoHQ/anubis/lib/policy/expressions"
"github.com/google/cel-go/cel"
"github.com/google/cel-go/common/types"
)
@ -72,15 +71,15 @@ func (cr *CELRequest) ResolveName(name string) (any, bool) {
case "path":
return cr.URL.Path, true
case "query":
return expressions.URLValues{Values: cr.URL.Query()}, true
return URLValues{Values: cr.URL.Query()}, true
case "headers":
return expressions.HTTPHeaders{Header: cr.Header}, true
return HTTPHeaders{Header: cr.Header}, true
case "load_1m":
return expressions.Load1(), true
return Load1(), true
case "load_5m":
return expressions.Load5(), true
return Load5(), true
case "load_15m":
return expressions.Load15(), true
return Load15(), true
default:
return nil, false
}

View File

@ -1,4 +1,4 @@
package expressions
package expression
import (
"net/http"

View File

@ -1,4 +1,4 @@
package expressions
package expression
import (
"net/http"

View File

@ -1,4 +1,4 @@
package expressions
package expression
import (
"context"

View File

@ -1,4 +1,4 @@
package expressions
package expression
import (
"errors"

View File

@ -1,4 +1,4 @@
package expressions
package expression
import (
"net/url"

View File

@ -1,8 +1,8 @@
package policy
import (
"github.com/TecharoHQ/anubis/lib/checker/expression/environment"
"github.com/TecharoHQ/anubis/lib/policy/config"
"github.com/TecharoHQ/anubis/lib/policy/expressions"
"github.com/google/cel-go/cel"
)
@ -16,12 +16,12 @@ func ParsedThresholdFromConfig(t config.Threshold) (*Threshold, error) {
Threshold: t,
}
env, err := expressions.ThresholdEnvironment()
env, err := environment.Threshold()
if err != nil {
return nil, err
}
program, err := expressions.Compile(env, t.Expression.String())
program, err := environment.Compile(env, t.Expression.String())
if err != nil {
return nil, err
}