forked from coredns/coredns
/
tls.go
37 lines (31 loc) · 751 Bytes
/
tls.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package tls
import (
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/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 plugin.Error("tls", c.Errf("TLS already configured for this server instance"))
}
for c.Next() {
args := c.RemainingArgs()
if len(args) != 3 {
return plugin.Error("tls", c.ArgErr())
}
tls, err := tls.NewTLSConfig(args[0], args[1], args[2])
if err != nil {
return plugin.Error("tls", err)
}
config.TLSConfig = tls
}
return nil
}