Merge branch 'v1.6' into v1.7
This commit is contained in:
commit
538424b01c
4 changed files with 49 additions and 14 deletions
|
@ -338,7 +338,7 @@ func (p *Provider) watchNewDomains() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(domains) == 0 {
|
if len(domains) == 0 {
|
||||||
log.Debugf("No domain parsed in rule %q", route.Rule)
|
log.Debugf("No domain parsed in rule %q in provider ACME", route.Rule)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/BurntSushi/ty/fun"
|
|
||||||
"github.com/containous/mux"
|
"github.com/containous/mux"
|
||||||
"github.com/containous/traefik/hostresolver"
|
"github.com/containous/traefik/hostresolver"
|
||||||
"github.com/containous/traefik/log"
|
"github.com/containous/traefik/log"
|
||||||
|
@ -288,9 +287,11 @@ func (r *Rules) Parse(expression string) (*mux.Route, error) {
|
||||||
// ParseDomains parses rules expressions and returns domains
|
// ParseDomains parses rules expressions and returns domains
|
||||||
func (r *Rules) ParseDomains(expression string) ([]string, error) {
|
func (r *Rules) ParseDomains(expression string) ([]string, error) {
|
||||||
var domains []string
|
var domains []string
|
||||||
|
isHostRule := false
|
||||||
|
|
||||||
err := r.parseRules(expression, func(functionName string, function interface{}, arguments []string) error {
|
err := r.parseRules(expression, func(functionName string, function interface{}, arguments []string) error {
|
||||||
if functionName == "Host" {
|
if functionName == "Host" {
|
||||||
|
isHostRule = true
|
||||||
domains = append(domains, arguments...)
|
domains = append(domains, arguments...)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -299,5 +300,18 @@ func (r *Rules) ParseDomains(expression string) ([]string, error) {
|
||||||
return nil, fmt.Errorf("error parsing domains: %v", err)
|
return nil, fmt.Errorf("error parsing domains: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return fun.Map(strings.ToLower, domains).([]string), nil
|
var cleanDomains []string
|
||||||
|
for _, domain := range domains {
|
||||||
|
canonicalDomain := strings.ToLower(domain)
|
||||||
|
if len(canonicalDomain) > 0 {
|
||||||
|
cleanDomains = append(cleanDomains, canonicalDomain)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return an error if an Host rule is detected but no domain are parsed
|
||||||
|
if isHostRule && len(cleanDomains) == 0 {
|
||||||
|
return nil, fmt.Errorf("unable to parse correctly the domains in the Host rule from %q", expression)
|
||||||
|
}
|
||||||
|
|
||||||
|
return cleanDomains, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,24 +64,38 @@ func TestParseDomains(t *testing.T) {
|
||||||
rules := &Rules{}
|
rules := &Rules{}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
expression string
|
description string
|
||||||
domain []string
|
expression string
|
||||||
|
domain []string
|
||||||
|
errorExpected bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
expression: "Host:foo.bar,test.bar",
|
description: "Many host rules",
|
||||||
domain: []string{"foo.bar", "test.bar"},
|
expression: "Host:foo.bar,test.bar",
|
||||||
|
domain: []string{"foo.bar", "test.bar"},
|
||||||
|
errorExpected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
expression: "Path:/test",
|
description: "No host rule",
|
||||||
domain: []string{},
|
expression: "Path:/test",
|
||||||
|
errorExpected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
expression: "Host:foo.bar;Path:/test",
|
description: "Host rule and another rule",
|
||||||
domain: []string{"foo.bar"},
|
expression: "Host:foo.bar;Path:/test",
|
||||||
|
domain: []string{"foo.bar"},
|
||||||
|
errorExpected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
expression: "Host: Foo.Bar ;Path:/test",
|
description: "Host rule to trim and another rule",
|
||||||
domain: []string{"foo.bar"},
|
expression: "Host: Foo.Bar ;Path:/test",
|
||||||
|
domain: []string{"foo.bar"},
|
||||||
|
errorExpected: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "Host rule with no domain",
|
||||||
|
expression: "Host: ;Path:/test",
|
||||||
|
errorExpected: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +105,12 @@ func TestParseDomains(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
domains, err := rules.ParseDomains(test.expression)
|
domains, err := rules.ParseDomains(test.expression)
|
||||||
require.NoError(t, err, "%s: Error while parsing domain.", test.expression)
|
|
||||||
|
if test.errorExpected {
|
||||||
|
require.Errorf(t, err, "unable to parse correctly the domains in the Host rule from %q", test.expression)
|
||||||
|
} else {
|
||||||
|
require.NoError(t, err, "%s: Error while parsing domain.", test.expression)
|
||||||
|
}
|
||||||
|
|
||||||
assert.EqualValues(t, test.domain, domains, "%s: Error parsing domains from expression.", test.expression)
|
assert.EqualValues(t, test.domain, domains, "%s: Error parsing domains from expression.", test.expression)
|
||||||
})
|
})
|
||||||
|
|
|
@ -540,6 +540,8 @@ func (s *Server) postLoadConfiguration() {
|
||||||
domains, err := rls.ParseDomains(route.Rule)
|
domains, err := rls.ParseDomains(route.Rule)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Error parsing domains: %v", err)
|
log.Errorf("Error parsing domains: %v", err)
|
||||||
|
} else if len(domains) == 0 {
|
||||||
|
log.Debugf("No domain parsed in rule %q", route.Rule)
|
||||||
} else {
|
} else {
|
||||||
s.globalConfiguration.ACME.LoadCertificateForDomains(domains)
|
s.globalConfiguration.ACME.LoadCertificateForDomains(domains)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue