Skip to content

Commit

Permalink
BUG/MEDIUM: support multiple ignore-persist statements in backends
Browse files Browse the repository at this point in the history
  • Loading branch information
George Vine committed May 2, 2024
1 parent 77f3590 commit 6b652f8
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 29 deletions.
30 changes: 16 additions & 14 deletions parsers/ignore-persist.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,38 @@ import (
)

type IgnorePersist struct {
data *types.IgnorePersist
data []types.IgnorePersist
preComments []string // comments that appear before the actual line
}

func (m *IgnorePersist) Parse(line string, parts []string, comment string) (string, error) {
func (m *IgnorePersist) parse(line string, parts []string, comment string) (*types.IgnorePersist, error) {
if len(parts) != 3 {
return "", &errors.ParseError{Parser: "IgnorePersist", Line: line}
return nil, &errors.ParseError{Parser: "IgnorePersist", Line: line}
}
if parts[0] == "ignore-persist" {
if parts[1] != "if" && parts[1] != "unless" {
return "", &errors.ParseError{Parser: "IgnorePersist", Line: line}
return nil, &errors.ParseError{Parser: "IgnorePersist", Line: line}
}
m.data = &types.IgnorePersist{
data := &types.IgnorePersist{
Cond: parts[1],
CondTest: parts[2],
Comment: comment,
}
return "", nil
return data, nil
}
return "", &errors.ParseError{Parser: "IgnorePersist", Line: line}
return nil, &errors.ParseError{Parser: "IgnorePersist", Line: line}
}

func (m *IgnorePersist) Result() ([]common.ReturnResultLine, error) {
if m.data == nil {
if len(m.data) == 0 {
return nil, errors.ErrFetch
}
return []common.ReturnResultLine{
{
Data: fmt.Sprintf("ignore-persist %s %s", m.data.Cond, m.data.CondTest),
Comment: m.data.Comment,
},
}, nil
result := make([]common.ReturnResultLine, len(m.data))
for i := range m.data {
result[i] = common.ReturnResultLine{
Data: fmt.Sprintf("ignore-persist %s %s", m.data[i].Cond, m.data[i].CondTest),
Comment: m.data[i].Comment,
}
}
return result, nil
}
88 changes: 73 additions & 15 deletions parsers/ignore-persist_generated.go

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

3 changes: 3 additions & 0 deletions tests/configs/haproxy_generated.cfg.go

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

1 change: 1 addition & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,7 @@ type ForcePersist struct {

//sections:backend
//name:ignore-persist
//is:multiple
//test:ok:ignore-persist if acl-name
//test:ok:ignore-persist unless acl-name
//test:fail:ignore-persist
Expand Down

0 comments on commit 6b652f8

Please sign in to comment.