From f48c56d02571dafa576cee8e3461bcb048d72ed7 Mon Sep 17 00:00:00 2001 From: Zlatko Bratkovic Date: Thu, 29 Feb 2024 11:22:33 +0100 Subject: [PATCH] MINOR: add set-var-fmt for tcp request connection rule --- configuration/tcp_request_rule.go | 7 +++++++ go.mod | 2 +- go.sum | 4 ++-- test/configuration_test.go | 3 ++- test/expected/structured.json | 8 ++++++++ test/tcp_request_rule_test.go | 6 +++++- 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/configuration/tcp_request_rule.go b/configuration/tcp_request_rule.go index 86d9b866..33e6d33a 100644 --- a/configuration/tcp_request_rule.go +++ b/configuration/tcp_request_rule.go @@ -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 diff --git a/go.mod b/go.mod index eb5ee84f..ef0c2775 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index a2051a6a..5c374e8c 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/test/configuration_test.go b/test/configuration_test.go index aced8ec7..cae699f2 100644 --- a/test/configuration_test.go +++ b/test/configuration_test.go @@ -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 @@ -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 diff --git a/test/expected/structured.json b/test/expected/structured.json index 95eb6560..72dcfa1c 100644 --- a/test/expected/structured.json +++ b/test/expected/structured.json @@ -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": { diff --git a/test/tcp_request_rule_test.go b/test/tcp_request_rule_test.go index 312a16a5..ba877e19 100644 --- a/test/tcp_request_rule_test.go +++ b/test/tcp_request_rule_test.go @@ -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())