Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
Debug: update cel protobuf pkg name
Browse files Browse the repository at this point in the history
  • Loading branch information
jweny committed Jul 15, 2021
1 parent bfaaebe commit 24d7c8f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
9 changes: 4 additions & 5 deletions pkg/cel/cel.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ type CustomLib struct {
func InitCelOptions() CustomLib {
custom := CustomLib{}
custom.envOptions = []cel.EnvOption{
cel.Container("utils"),
cel.Container("proto"),
// 类型注入
cel.Types(
&proto.UrlType{},
Expand All @@ -381,8 +381,8 @@ func InitCelOptions() CustomLib {
),
// 定义变量变量
cel.Declarations(
decls.NewVar("request", decls.NewObjectType("utils.Request")),
decls.NewVar("response", decls.NewObjectType("utils.Response")),
decls.NewVar("request", decls.NewObjectType("proto.Request")),
decls.NewVar("response", decls.NewObjectType("proto.Response")),
),
// 定义
cel.Declarations(
Expand All @@ -407,7 +407,6 @@ func InitCelOptions() CustomLib {
}

// 如果有set:追加set变量到 cel options
// 这里得注意下 reverse的顺序问题 map可能是随机的
func (c *CustomLib) AddRuleSetOptions(args []yaml.MapItem) {
for _, arg := range args {
// 在执行之前是不知道变量的类型的,所以统一声明为字符型
Expand All @@ -419,7 +418,7 @@ func (c *CustomLib) AddRuleSetOptions(args []yaml.MapItem) {
if strings.HasPrefix(v, "randomInt") {
d = decls.NewVar(k, decls.Int)
} else if strings.HasPrefix(v, "newReverse") {
d = decls.NewVar(k, decls.NewObjectType("util.Reverse"))
d = decls.NewVar(k, decls.NewObjectType("proto.Reverse"))
} else {
d = decls.NewVar(k, decls.String)
}
Expand Down
45 changes: 22 additions & 23 deletions pkg/cel/proto/http.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion poc/rule/cel.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (cc *CelController) InitSet(poc *Poc, newReq *proto.Request) (err error) {
}
out, err := cel2.Evaluate(cc.Env, value, cc.ParamMap)
if err != nil {
continue
return err
}
switch value := out.Value().(type) {
// set value 无论是什么类型都先转成string
Expand Down

0 comments on commit 24d7c8f

Please sign in to comment.