Skip to content

Commit cd272a0

Browse files
author
George Vine
committed
BUG/MEDIUM: support multiple force-persist statements in backends
1 parent ab29ace commit cd272a0

File tree

4 files changed

+93
-29
lines changed

4 files changed

+93
-29
lines changed

parsers/force-persist.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,38 @@ import (
2424
)
2525

2626
type ForcePersist struct {
27-
data *types.ForcePersist
27+
data []types.ForcePersist
2828
preComments []string // comments that appear before the actual line
2929
}
3030

31-
func (m *ForcePersist) Parse(line string, parts []string, comment string) (string, error) {
31+
func (m *ForcePersist) parse(line string, parts []string, comment string) (*types.ForcePersist, error) {
3232
if len(parts) != 3 {
33-
return "", &errors.ParseError{Parser: "ForcePersist", Line: line}
33+
return nil, &errors.ParseError{Parser: "ForcePersist", Line: line}
3434
}
3535
if parts[0] == "force-persist" {
3636
if parts[1] != "if" && parts[1] != "unless" {
37-
return "", &errors.ParseError{Parser: "ForcePersist", Line: line}
37+
return nil, &errors.ParseError{Parser: "ForcePersist", Line: line}
3838
}
39-
m.data = &types.ForcePersist{
39+
data := &types.ForcePersist{
4040
Cond: parts[1],
4141
CondTest: parts[2],
4242
Comment: comment,
4343
}
44-
return "", nil
44+
return data, nil
4545
}
46-
return "", &errors.ParseError{Parser: "ForcePersist", Line: line}
46+
return nil, &errors.ParseError{Parser: "ForcePersist", Line: line}
4747
}
4848

4949
func (m *ForcePersist) Result() ([]common.ReturnResultLine, error) {
50-
if m.data == nil {
50+
if len(m.data) == 0 {
5151
return nil, errors.ErrFetch
5252
}
53-
return []common.ReturnResultLine{
54-
{
55-
Data: fmt.Sprintf("force-persist %s %s", m.data.Cond, m.data.CondTest),
56-
Comment: m.data.Comment,
57-
},
58-
}, nil
53+
result := make([]common.ReturnResultLine, len(m.data))
54+
for i := range m.data {
55+
result[i] = common.ReturnResultLine{
56+
Data: fmt.Sprintf("force-persist %s %s", m.data[i].Cond, m.data[i].CondTest),
57+
Comment: m.data[i].Comment,
58+
}
59+
}
60+
return result, nil
5961
}

parsers/force-persist_generated.go

Lines changed: 73 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/configs/haproxy_generated.cfg.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

types/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,7 @@ type ProcessVary struct {
13401340

13411341
//sections:backend
13421342
//name:force-persist
1343+
//is:multiple
13431344
//test:ok:force-persist if acl-name
13441345
//test:ok:force-persist unless acl-name
13451346
//test:fail:force-persist

0 commit comments

Comments
 (0)