Skip to content

Commit fa3c9c7

Browse files
rmaticevicmjuraga
authored andcommitted
MINOR: add support for do-log option
1 parent 37e8970 commit fa3c9c7

39 files changed

+608
-42
lines changed
+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
Copyright 2019 HAProxy Technologies
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
//nolint:dupl
18+
package actions
19+
20+
import (
21+
stderrors "errors"
22+
"fmt"
23+
"strings"
24+
25+
"github.com/haproxytech/client-native/v6/config-parser/common"
26+
"github.com/haproxytech/client-native/v6/config-parser/types"
27+
)
28+
29+
type DoLog struct {
30+
Cond string
31+
CondTest string
32+
Comment string
33+
}
34+
35+
func (f *DoLog) Parse(parts []string, parserType types.ParserType, comment string) error {
36+
if comment != "" {
37+
f.Comment = comment
38+
}
39+
var command []string
40+
var minLen, requiredLen int
41+
switch parserType {
42+
case types.HTTP:
43+
command = parts[1:]
44+
minLen = 2
45+
requiredLen = 4
46+
case types.TCP:
47+
command = parts[2:]
48+
minLen = 3
49+
requiredLen = 5
50+
}
51+
if len(parts) == minLen {
52+
return nil
53+
}
54+
if len(parts) < requiredLen {
55+
return stderrors.New("not enough params")
56+
}
57+
_, condition := common.SplitRequest(command)
58+
if len(condition) > 1 {
59+
f.Cond = condition[0]
60+
f.CondTest = strings.Join(condition[1:], " ")
61+
}
62+
return nil
63+
}
64+
65+
func (f *DoLog) String() string {
66+
if f.Cond != "" {
67+
return fmt.Sprintf("do-log %s %s", f.Cond, f.CondTest)
68+
}
69+
return "do-log"
70+
}
71+
72+
func (f *DoLog) GetComment() string {
73+
return f.Comment
74+
}

config-parser/parsers/actions/reject.go

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
//nolint:dupl
1718
package actions
1819

1920
import (

config-parser/parsers/http/http-after-response.go

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config-parser/parsers/http/http-request.go

+2
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ func (h *Requests) Parse(line string, parts []string, comment string) (string, e
147147
err = h.ParseHTTPRequest(&actions.SetFcTos{}, parts, comment)
148148
case "set-retries":
149149
err = h.ParseHTTPRequest(&actions.SetRetries{}, parts, comment)
150+
case "do-log":
151+
err = h.ParseHTTPRequest(&actions.DoLog{}, parts, comment)
150152
default:
151153
switch {
152154
case strings.HasPrefix(parts[1], "track-sc"):

config-parser/parsers/http/http-response.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (h *Responses) ParseHTTPResponse(response types.Action, parts []string, com
4747
return nil
4848
}
4949

50-
func (h *Responses) Parse(line string, parts []string, comment string) (string, error) { //nolint:cyclop
50+
func (h *Responses) Parse(line string, parts []string, comment string) (string, error) { //nolint:cyclop,gocyclo
5151
if len(parts) >= 2 && parts[0] == "http-response" {
5252
var err error
5353
switch parts[1] {
@@ -99,6 +99,8 @@ func (h *Responses) Parse(line string, parts []string, comment string) (string,
9999
err = h.ParseHTTPResponse(&actions.SetFcMark{}, parts, comment)
100100
case "set-fc-tos":
101101
err = h.ParseHTTPResponse(&actions.SetFcTos{}, parts, comment)
102+
case "do-log":
103+
err = h.ParseHTTPResponse(&actions.DoLog{}, parts, comment)
102104
default:
103105
switch {
104106
case strings.HasPrefix(parts[1], "track-sc"):

config-parser/parsers/tcp/types/connection.go

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ func (f *Connection) Parse(parts []string, comment string) error {
7878
err = f.ParseAction(&actions.SetFcMark{}, parts)
7979
case "set-fc-tos":
8080
err = f.ParseAction(&actions.SetFcTos{}, parts)
81+
case "do-log":
82+
err = f.ParseAction(&actions.DoLog{}, parts)
8183
default:
8284
switch {
8385
case strings.HasPrefix(parts[2], "track-sc"):

config-parser/parsers/tcp/types/content.go

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ func (f *Content) Parse(parts []string, comment string) error {
9696
err = f.ParseAction(&actions.SetFcTos{}, parts)
9797
case "set-retries":
9898
err = f.ParseAction(&actions.SetRetries{}, parts)
99+
case "do-log":
100+
err = f.ParseAction(&actions.DoLog{}, parts)
99101
default:
100102
switch {
101103
case strings.HasPrefix(parts[2], "track-sc"):

config-parser/parsers/tcp/types/session.go

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ func (f *Session) Parse(parts []string, comment string) error {
7474
err = f.ParseAction(&actions.SetSrcPort{}, parts)
7575
case "set-tos":
7676
err = f.ParseAction(&actions.SetTos{}, parts)
77+
case "do-log":
78+
err = f.ParseAction(&actions.DoLog{}, parts)
7779
default:
7880
switch {
7981
case strings.HasPrefix(parts[2], "track-sc"):

config-parser/tests/configs/haproxy_generated.cfg.go

+68
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)