Skip to content

Commit

Permalink
MINOR: add set-var-fmt for tcp request connection rule
Browse files Browse the repository at this point in the history
  • Loading branch information
oktalz committed Feb 29, 2024
1 parent d05e585 commit f48c56d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 5 deletions.
7 changes: 7 additions & 0 deletions configuration/tcp_request_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,13 @@ func ParseTCPRequestRule(f types.TCPType) (rule *models.TCPRequestRule, err erro
rule.Expr = a.Expr.String()
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *actions.SetVarFmt:
rule.Action = models.TCPRequestRuleActionSetDashVarDashFmt
rule.VarName = a.VarName
rule.VarFormat = strings.Join(a.Fmt.Expr, " ")
rule.VarScope = a.VarScope
rule.Cond = a.Cond
rule.CondTest = a.CondTest
case *actions.UnsetVar:
rule.Action = models.TCPRequestRuleActionUnsetDashVar
rule.VarScope = a.Scope
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/google/go-cmp v0.6.0
github.com/google/renameio v1.0.1
github.com/google/uuid v1.6.0
github.com/haproxytech/config-parser/v5 v5.1.1-0.20240223102144-ffe6142ca8e4
github.com/haproxytech/config-parser/v5 v5.1.1-0.20240228090858-f72c25c8ad69
github.com/json-iterator/go v1.1.12
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/mitchellh/mapstructure v1.5.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ github.com/google/renameio v1.0.1 h1:Lh/jXZmvZxb0BBeSY5VKEfidcbcbenKjZFzM/q0fSeU
github.com/google/renameio v1.0.1/go.mod h1:t/HQoYBZSsWSNK35C6CO/TpPLDVWvxOHboWUAweKUpk=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/haproxytech/config-parser/v5 v5.1.1-0.20240223102144-ffe6142ca8e4 h1:Iszl0fMqYG34rNmNskZVEoFvuN2RZ626y98kvmxqgaQ=
github.com/haproxytech/config-parser/v5 v5.1.1-0.20240223102144-ffe6142ca8e4/go.mod h1:iy8nBB1eopwYbyeh3FQpjxZUxfcIDyTV9bW0F1t+cVA=
github.com/haproxytech/config-parser/v5 v5.1.1-0.20240228090858-f72c25c8ad69 h1:BEYm9WBinWoD4MUaRERONJzzAdsDzXEnr0P+ZQhZnNg=
github.com/haproxytech/config-parser/v5 v5.1.1-0.20240228090858-f72c25c8ad69/go.mod h1:iy8nBB1eopwYbyeh3FQpjxZUxfcIDyTV9bW0F1t+cVA=
github.com/haproxytech/go-logger v1.1.0 h1:HgGtYaI1ApkvbQdsm7f9AzQQoxTB7w37criTflh7IQE=
github.com/haproxytech/go-logger v1.1.0/go.mod h1:OekUd8HCb7ubxMplzHUPBTHNxZmddOWfOjWclZsqIeM=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
Expand Down
3 changes: 2 additions & 1 deletion test/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ frontend test
http-request track-sc2 src table tr2 if TRUE
http-request track-sc5 src table test if TRUE
http-request set-bc-mark 123 if TRUE
http-request set-bc-tos 0x22
http-request set-bc-tos 0x22
http-request set-fc-mark hdr(port)
http-request set-fc-tos 255 if FALSE
http-response allow if src 192.168.0.0/16
Expand Down Expand Up @@ -532,6 +532,7 @@ frontend test
tcp-request content set-bc-tos 2 if FALSE
tcp-request content set-fc-mark hdr(port) if TRUE
tcp-request content set-fc-tos req.hdr_cnt("X-Secret")
tcp-request connection set-var-fmt(txn.ip_port) %%[dst]:%%[dst_port]
log global
no log
log 127.0.0.1:514 local0 notice notice
Expand Down
8 changes: 8 additions & 0 deletions test/expected/structured.json
Original file line number Diff line number Diff line change
Expand Up @@ -2632,6 +2632,14 @@
"index": 40,
"type": "content",
"expr": "req.hdr_cnt(\"X-Secret\")"
},
{
"action": "set-var-fmt",
"index": 41,
"type": "connection",
"var_format": "%%[dst]:%%[dst_port]",
"var_scope": "txn",
"var_name": "ip_port"
}
],
"binds": {
Expand Down
6 changes: 5 additions & 1 deletion test/tcp_request_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ func TestCreateEditDeleteTCPRequestRule(t *testing.T) {
}

// TestDeleteTCPRequest
N := int64(41) // number of tcp-request rules in frontend "test"
_, rules, err := clientTest.GetTCPRequestRules(configuration.FrontendParentName, "test", "")
if err != nil {
t.Error(err.Error())
}
N := int64(len(rules)) - 1
err = clientTest.DeleteTCPRequestRule(N, configuration.FrontendParentName, "test", "", version)
if err != nil {
t.Error(err.Error())
Expand Down

0 comments on commit f48c56d

Please sign in to comment.