coredns/middleware/tls/tls.go
Yue Ko 387d3f5a41 Fix TLS error message (#634)
Print corresponding error message when TLS initialization fails.
2017-04-20 09:40:18 -04:00

37 lines
771 B
Go

package tls
import (
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/middleware"
"github.com/coredns/coredns/middleware/pkg/tls"
"github.com/mholt/caddy"
)
func init() {
caddy.RegisterPlugin("tls", caddy.Plugin{
ServerType: "dns",
Action: setup,
})
}
func setup(c *caddy.Controller) error {
config := dnsserver.GetConfig(c)
if config.TLSConfig != nil {
return middleware.Error("tls", c.Errf("TLS already configured for this server instance"))
}
for c.Next() {
args := c.RemainingArgs()
if len(args) != 3 {
return middleware.Error("tls", c.ArgErr())
}
tls, err := tls.NewTLSConfig(args[0], args[1], args[2])
if err != nil {
return middleware.Error("tls", err)
}
config.TLSConfig = tls
}
return nil
}