summaryrefslogtreecommitdiff
path: root/modules/caddytls/tls.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2020-03-17 21:00:45 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2020-03-17 21:00:45 -0600
commitfc7340e11aa9ca6326909aedfd36bb2c5b53d2a8 (patch)
treeb057f7368a355192bdb40784b6d95716982e6923 /modules/caddytls/tls.go
parent3f48a2eb455167af8d77c5c4543bd17a80a93260 (diff)
httpcaddyfile: Many tls-related improvements including on-demand support
Holy heck this was complicated
Diffstat (limited to 'modules/caddytls/tls.go')
-rw-r--r--modules/caddytls/tls.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/modules/caddytls/tls.go b/modules/caddytls/tls.go
index c927ce2..4fc0850 100644
--- a/modules/caddytls/tls.go
+++ b/modules/caddytls/tls.go
@@ -179,9 +179,17 @@ func (t *TLS) Validate() error {
if t.Automation != nil {
// ensure that host aren't repeated; since only the first
// automation policy is used, repeating a host in the lists
- // isn't useful and is probably a mistake
+ // isn't useful and is probably a mistake; same for two
+ // catch-all/default policies
+ var hasDefault bool
hostSet := make(map[string]int)
for i, ap := range t.Automation.Policies {
+ if len(ap.Subjects) == 0 {
+ if hasDefault {
+ return fmt.Errorf("automation policy %d is the second policy that acts as default/catch-all, but will never be used", i)
+ }
+ hasDefault = true
+ }
for _, h := range ap.Subjects {
if first, ok := hostSet[h]; ok {
return fmt.Errorf("automation policy %d: cannot apply more than one automation policy to host: %s (first match in policy %d)", i, h, first)
@@ -301,7 +309,7 @@ func (t *TLS) AddAutomationPolicy(ap *AutomationPolicy) error {
// fewer names) exists, prioritize this new policy
if len(other.Subjects) < len(ap.Subjects) {
t.Automation.Policies = append(t.Automation.Policies[:i],
- append([]*AutomationPolicy{ap}, t.Automation.Policies[i+1:]...)...)
+ append([]*AutomationPolicy{ap}, t.Automation.Policies[i:]...)...)
return nil
}
}