Skip to content

Commit

Permalink
MINOR: add support for do-log option
Browse files Browse the repository at this point in the history
  • Loading branch information
rmaticevic authored and mjuraga committed Dec 3, 2024
1 parent 37e8970 commit fa3c9c7
Show file tree
Hide file tree
Showing 39 changed files with 608 additions and 42 deletions.
74 changes: 74 additions & 0 deletions config-parser/parsers/actions/do-log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
Copyright 2019 HAProxy Technologies
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

//nolint:dupl
package actions

import (
stderrors "errors"
"fmt"
"strings"

"github.com/haproxytech/client-native/v6/config-parser/common"
"github.com/haproxytech/client-native/v6/config-parser/types"
)

type DoLog struct {
Cond string
CondTest string
Comment string
}

func (f *DoLog) Parse(parts []string, parserType types.ParserType, comment string) error {
if comment != "" {
f.Comment = comment
}
var command []string
var minLen, requiredLen int
switch parserType {
case types.HTTP:
command = parts[1:]
minLen = 2
requiredLen = 4
case types.TCP:
command = parts[2:]
minLen = 3
requiredLen = 5
}
if len(parts) == minLen {
return nil
}
if len(parts) < requiredLen {
return stderrors.New("not enough params")
}
_, condition := common.SplitRequest(command)
if len(condition) > 1 {
f.Cond = condition[0]
f.CondTest = strings.Join(condition[1:], " ")
}
return nil
}

func (f *DoLog) String() string {
if f.Cond != "" {
return fmt.Sprintf("do-log %s %s", f.Cond, f.CondTest)
}
return "do-log"
}

func (f *DoLog) GetComment() string {
return f.Comment
}
1 change: 1 addition & 0 deletions config-parser/parsers/actions/reject.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

//nolint:dupl
package actions

import (
Expand Down
2 changes: 2 additions & 0 deletions config-parser/parsers/http/http-after-response.go

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

2 changes: 2 additions & 0 deletions config-parser/parsers/http/http-request.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ func (h *Requests) Parse(line string, parts []string, comment string) (string, e
err = h.ParseHTTPRequest(&actions.SetFcTos{}, parts, comment)
case "set-retries":
err = h.ParseHTTPRequest(&actions.SetRetries{}, parts, comment)
case "do-log":
err = h.ParseHTTPRequest(&actions.DoLog{}, parts, comment)
default:
switch {
case strings.HasPrefix(parts[1], "track-sc"):
Expand Down
4 changes: 3 additions & 1 deletion config-parser/parsers/http/http-response.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (h *Responses) ParseHTTPResponse(response types.Action, parts []string, com
return nil
}

func (h *Responses) Parse(line string, parts []string, comment string) (string, error) { //nolint:cyclop
func (h *Responses) Parse(line string, parts []string, comment string) (string, error) { //nolint:cyclop,gocyclo
if len(parts) >= 2 && parts[0] == "http-response" {
var err error
switch parts[1] {
Expand Down Expand Up @@ -99,6 +99,8 @@ func (h *Responses) Parse(line string, parts []string, comment string) (string,
err = h.ParseHTTPResponse(&actions.SetFcMark{}, parts, comment)
case "set-fc-tos":
err = h.ParseHTTPResponse(&actions.SetFcTos{}, parts, comment)
case "do-log":
err = h.ParseHTTPResponse(&actions.DoLog{}, parts, comment)
default:
switch {
case strings.HasPrefix(parts[1], "track-sc"):
Expand Down
2 changes: 2 additions & 0 deletions config-parser/parsers/tcp/types/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ func (f *Connection) Parse(parts []string, comment string) error {
err = f.ParseAction(&actions.SetFcMark{}, parts)
case "set-fc-tos":
err = f.ParseAction(&actions.SetFcTos{}, parts)
case "do-log":
err = f.ParseAction(&actions.DoLog{}, parts)
default:
switch {
case strings.HasPrefix(parts[2], "track-sc"):
Expand Down
2 changes: 2 additions & 0 deletions config-parser/parsers/tcp/types/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ func (f *Content) Parse(parts []string, comment string) error {
err = f.ParseAction(&actions.SetFcTos{}, parts)
case "set-retries":
err = f.ParseAction(&actions.SetRetries{}, parts)
case "do-log":
err = f.ParseAction(&actions.DoLog{}, parts)
default:
switch {
case strings.HasPrefix(parts[2], "track-sc"):
Expand Down
2 changes: 2 additions & 0 deletions config-parser/parsers/tcp/types/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ func (f *Session) Parse(parts []string, comment string) error {
err = f.ParseAction(&actions.SetSrcPort{}, parts)
case "set-tos":
err = f.ParseAction(&actions.SetTos{}, parts)
case "do-log":
err = f.ParseAction(&actions.DoLog{}, parts)
default:
switch {
case strings.HasPrefix(parts[2], "track-sc"):
Expand Down
68 changes: 68 additions & 0 deletions config-parser/tests/configs/haproxy_generated.cfg.go

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

Loading

0 comments on commit fa3c9c7

Please sign in to comment.