Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multi-line backend extras with line separator || #90

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion actions/reconfigure.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,13 @@ func (m *Reconfigure) parseFrontTemplate(src string, sr *proxy.Service) string {

func (m *Reconfigure) parseBackTemplate(src, usersList string, sr *proxy.Service) string {
tmplUsersList, _ := template.New("template").Parse(usersList)
tmpl, _ := template.New("").Parse(src)
funcMap := template.FuncMap{
"Split": func(s string, d string) []string {
arr := strings.Split(s, d)
return arr
},
}
tmpl, _ := template.New("").Funcs(funcMap).Parse(src)
var bufUsersList bytes.Buffer
var buf bytes.Buffer
tmplUsersList.Execute(&bufUsersList, sr)
Expand Down
13 changes: 7 additions & 6 deletions actions/reconfigure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,8 @@ backend myService-be5555_2

func (s ReconfigureTestSuite) Test_GetTemplates_AddsHttpRequestSetPath_WhenReqPathSearchReplaceFormattedIsPresent() {
s.reconfigure.ServiceDest = []proxy.ServiceDest{{
Port: "1234",
Index: 0,
Port: "1234",
Index: 0,
ReqPathSearchReplaceFormatted: []string{"this,that", "foo,bar"},
HttpsPort: 1234,
}}
Expand All @@ -558,16 +558,17 @@ backend https-myService-be1234_0
}

func (s ReconfigureTestSuite) Test_GetTemplates_AddsBackendExtra() {
s.reconfigure.BackendExtra = "Additional backend"
s.reconfigure.BackendExtra = "Additional backend line 1||Additional backend line 2"
s.reconfigure.ServiceDest = []proxy.ServiceDest{{Port: "1234", Index: 0}}
expected := fmt.Sprintf(`
backend myService-be1234_0
mode http
http-request add-header X-Forwarded-Proto https if { ssl_fc }
server myService myService:1234
%s`,
s.reconfigure.BackendExtra,
)

Additional backend line 1
Additional backend line 2
`)

_, backend, _ := s.reconfigure.GetTemplates()

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/jessevdk/go-flags v1.4.0
github.com/kelseyhightower/envconfig v1.3.0
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.0.0
github.com/mitchellh/mapstructure v1.1.2
github.com/prometheus/client_golang v0.8.0
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 // indirect
github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0j
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mitchellh/mapstructure v1.0.0 h1:vVpGvMXJPqSDh2VYHF7gsfQj8Ncx+Xw5Y1KHeTRY+7I=
github.com/mitchellh/mapstructure v1.0.0/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v0.8.0 h1:1921Yw9Gc3iSc4VQh3PIoOqgPCZS7G/4xQNVUp8Mda8=
Expand Down
8 changes: 6 additions & 2 deletions proxy/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,9 @@ backend {{$.AclName}}-be{{$sd.Port}}_{{.Index}}
{{- end}}
{{- end}}
{{- if ne $.BackendExtra ""}}
{{ $.BackendExtra }}
{{$arr := Split $.BackendExtra "||"}}
{{range $k, $v := $arr}} {{$v}}
{{end}}
{{- end}}
{{- end}}
{{- end}}
Expand Down Expand Up @@ -382,7 +384,9 @@ backend https-{{$.AclName}}-be{{.HttpsPort}}_{{.Index}}
{{- end}}
{{- end}}
{{- if ne $.BackendExtra ""}}
{{ $.BackendExtra }}
{{$arr := Split $.BackendExtra "||"}}
{{range $k, $v := $arr}} {{$v}}
{{end}}
{{- end}}
{{- end}}
{{- end}}`
Expand Down