Skip to content

Commit 27ae3ba

Browse files
committed
RFC: Adds service index for http/https ACL
1 parent 1320143 commit 27ae3ba

2 files changed

Lines changed: 14 additions & 16 deletions

File tree

proxy/ha_proxy_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -791,10 +791,10 @@ func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_AddsServicePathExclude(
791791
`%s
792792
acl url_my-service-11111_0 path_beg /path-1
793793
acl url_exclude_my-service-11111_0 path_beg /path-2 path_beg /path-3
794-
acl http_my-service-1 dst_port 80
795-
acl https_my-service-1 dst_port 443
796-
use_backend my-service-1-be1111_0 if url_my-service-11111_0 !url_exclude_my-service-11111_0 http_my-service-1
797-
use_backend https-my-service-1-be1111_0 if url_my-service-11111_0 !url_exclude_my-service-11111_0 https_my-service-1%s`,
794+
acl http_my-service-1_0 dst_port 80
795+
acl https_my-service-1_0 dst_port 443
796+
use_backend my-service-1-be1111_0 if url_my-service-11111_0 !url_exclude_my-service-11111_0 http_my-service-1_0
797+
use_backend https-my-service-1-be1111_0 if url_my-service-11111_0 !url_exclude_my-service-11111_0 https_my-service-1_0%s`,
798798
tmpl,
799799
s.ServicesContent,
800800
)
@@ -1833,10 +1833,10 @@ func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_AddsContentFrontEndWith
18331833
expectedData := fmt.Sprintf(
18341834
`%s
18351835
acl url_my-service1111_0 path_beg /path
1836-
acl http_my-service dst_port 80
1837-
acl https_my-service dst_port 443
1838-
use_backend my-service-be1111_0 if url_my-service1111_0 http_my-service
1839-
use_backend https-my-service-be1111_0 if url_my-service1111_0 https_my-service%s`,
1836+
acl http_my-service_0 dst_port 80
1837+
acl https_my-service_0 dst_port 443
1838+
use_backend my-service-be1111_0 if url_my-service1111_0 http_my-service_0
1839+
use_backend https-my-service-be1111_0 if url_my-service1111_0 https_my-service_0%s`,
18401840
tmpl,
18411841
s.ServicesContent,
18421842
)

proxy/template.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,10 @@ func getFrontTemplate(s Service) string {
3737
acl hdr_{{$.AclName}}{{$sd.Port}}_{{incIndex}} hdr({{$key}}) {{$value}}
3838
{{- end}}
3939
{{- end}}
40-
{{- end}}
41-
{{- if gt $.HttpsPort 0 }}
42-
acl http_{{.ServiceName}} dst_port 80
43-
acl https_{{.ServiceName}} dst_port 443
44-
{{- end}}
45-
{{- range $sd := .ServiceDest}}
40+
{{- if gt $.HttpsPort 0 }}
41+
acl http_{{$.ServiceName}}_{{.Index}} dst_port 80
42+
acl https_{{$.ServiceName}}_{{.Index}} dst_port 443
43+
{{- end}}
4644
{{- range $rd := $sd.RedirectFromDomain}}
4745
http-request redirect code 301 prefix http://{{index $sd.ServiceDomain 0}} if { hdr_beg(host) -i {{$rd}} }
4846
{{- end}}
@@ -60,8 +58,8 @@ func getFrontTemplate(s Service) string {
6058
{{- range $sd := .ServiceDest}}
6159
{{- if eq .ReqMode "http"}}{{- if ne .Port ""}}
6260
use_backend {{$.AclName}}-be{{.Port}}_{{.Index}} if url_{{$.AclName}}{{.Port}}_{{.Index}}{{if .ServicePathExclude}} !url_exclude_{{$.AclName}}{{.Port}}_{{.Index}}{{end}}{{if .ServiceDomain}} domain_{{$.AclName}}{{.Port}}_{{.Index}}{{end}}{{if .ServiceHeader}}{{resetIndex}}{{range $key, $value := .ServiceHeader}} hdr_{{$.AclName}}{{$sd.Port}}_{{incIndex}}{{end}}{{end}}{{.SrcPortAclName}}
63-
{{- if gt $.HttpsPort 0 }} http_{{$.ServiceName}}
64-
use_backend https-{{$.AclName}}-be{{.Port}}_{{.Index}} if url_{{$.AclName}}{{.Port}}_{{.Index}}{{if .ServicePathExclude}} !url_exclude_{{$.AclName}}{{.Port}}_{{.Index}}{{end}}{{if .ServiceDomain}} domain_{{$.AclName}}{{.Port}}_{{.Index}}{{end}} https_{{$.ServiceName}}
61+
{{- if gt $.HttpsPort 0 }} http_{{$.ServiceName}}_{{.Index}}
62+
use_backend https-{{$.AclName}}-be{{.Port}}_{{.Index}} if url_{{$.AclName}}{{.Port}}_{{.Index}}{{if .ServicePathExclude}} !url_exclude_{{$.AclName}}{{.Port}}_{{.Index}}{{end}}{{if .ServiceDomain}} domain_{{$.AclName}}{{.Port}}_{{.Index}}{{end}} https_{{$.ServiceName}}_{{.Index}}
6563
{{- end}}
6664
{{- $length := len .UserAgent.Value}}{{if gt $length 0}} user_agent_{{$.AclName}}_{{.UserAgent.AclName}}_{{.Index}}{{end}}
6765
{{- if $.IsDefaultBackend}}

0 commit comments

Comments
 (0)