Skip to content

Commit 8e64139

Browse files
committed
Wildcard domain support
1 parent 5462484 commit 8e64139

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

actions/reconfigure.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,18 @@ func (m *Reconfigure) getTemplateFromGo(sr ServiceReconfigure) (frontend, backen
321321
sr.Host = m.OutboundHostname
322322
}
323323
if len(sr.ServiceDomain) > 0 {
324-
sr.Acl = `
325-
acl domain_{{.ServiceName}} hdr_dom(host) -i{{range .ServiceDomain}} {{.}}{{end}}`
324+
domFunc := "hdr_dom"
325+
for i, domain := range sr.ServiceDomain {
326+
if strings.HasPrefix(domain, "*") {
327+
sr.ServiceDomain[i] = strings.Trim(domain, "*")
328+
domFunc = "hdr_end"
329+
}
330+
}
331+
sr.Acl = fmt.Sprintf(
332+
`
333+
acl domain_{{.ServiceName}} %s(host) -i{{range .ServiceDomain}} {{.}}{{end}}`,
334+
domFunc,
335+
)
326336
sr.AclCondition = fmt.Sprintf(" domain_%s", sr.ServiceName)
327337
}
328338
if len(sr.ServiceColor) > 0 {

actions/reconfigure_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,17 @@ func (s ReconfigureTestSuite) Test_GetTemplates_AddsHosts() {
250250
s.Equal(s.ConsulTemplateFe, actual)
251251
}
252252

253+
func (s ReconfigureTestSuite) Test_GetTemplates_AddsHostsStartingWithWildcard() {
254+
s.ConsulTemplateFe = `
255+
acl url_myService path_beg path/to/my/service/api path_beg path/to/my/other/service/api
256+
acl domain_myService hdr_end(host) -i acme.com .domain.com
257+
use_backend myService-be if url_myService domain_myService`
258+
s.reconfigure.ServiceDomain = []string{"acme.com", "*.domain.com"}
259+
actual, _, _ := s.reconfigure.GetTemplates(s.reconfigure.ServiceReconfigure)
260+
261+
s.Equal(s.ConsulTemplateFe, actual)
262+
}
263+
253264
func (s ReconfigureTestSuite) Test_GetTemplates_AddsReqRep_WhenReqRepSearchAndReqRepReplaceArePresent() {
254265
s.reconfigure.ReqRepSearch = "this"
255266
s.reconfigure.ReqRepReplace = "that"

0 commit comments

Comments
 (0)