Allow Træfik to know if a Host rule is malformed
This commit is contained in:
parent
b98f5ed8b1
commit
913d8737cc
4 changed files with 55 additions and 16 deletions
|
@ -9,7 +9,6 @@ import (
|
|||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/BurntSushi/ty/fun"
|
||||
"github.com/containous/mux"
|
||||
"github.com/containous/traefik/types"
|
||||
)
|
||||
|
@ -270,9 +269,11 @@ func (r *Rules) Parse(expression string) (*mux.Route, error) {
|
|||
// ParseDomains parses rules expressions and returns domains
|
||||
func (r *Rules) ParseDomains(expression string) ([]string, error) {
|
||||
var domains []string
|
||||
isHostRule := false
|
||||
|
||||
err := r.parseRules(expression, func(functionName string, function interface{}, arguments []string) error {
|
||||
if functionName == "Host" {
|
||||
isHostRule = true
|
||||
domains = append(domains, arguments...)
|
||||
}
|
||||
return nil
|
||||
|
@ -281,5 +282,18 @@ func (r *Rules) ParseDomains(expression string) ([]string, error) {
|
|||
return nil, fmt.Errorf("error parsing domains: %v", err)
|
||||
}
|
||||
|
||||
return fun.Map(types.CanonicalDomain, domains).([]string), nil
|
||||
var cleanDomains []string
|
||||
for _, domain := range domains {
|
||||
canonicalDomain := types.CanonicalDomain(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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue