mirror of
https://github.com/coredns/coredns.git
synced 2026-08-20 23:08:28 -04:00
plugin/tls: manage certificates with ACME DNS-01 (#8310)
* plugin/tls: add automatic ACME certificates Signed-off-by: houyuwushang <liuluoqianqiu@outlook.com> * chore: add houyuwushang to CODEOWNERS Signed-off-by: houyuwushang <liuluoqianqiu@outlook.com> * chore: regenerate maintainer owners Signed-off-by: houyuwushang <liuluoqianqiu@outlook.com> --------- Signed-off-by: houyuwushang <liuluoqianqiu@outlook.com>
This commit is contained in:
@@ -171,3 +171,22 @@ func GetConfig(c *caddy.Controller) *Config {
|
||||
ctx.saveConfig(key, &Config{ListenHosts: []string{""}})
|
||||
return GetConfig(c)
|
||||
}
|
||||
|
||||
// AddPluginToAllServerBlocks adds m once to every server block in c's
|
||||
// instance. It is intended for directives that must handle traffic on a
|
||||
// listener other than the one where the directive is configured.
|
||||
func AddPluginToAllServerBlocks(c *caddy.Controller, m plugin.Plugin) {
|
||||
ctx := c.Context().(*dnsContext)
|
||||
seen := make(map[*Config]struct{})
|
||||
for _, cfg := range ctx.configs {
|
||||
first := cfg.firstConfigInBlock
|
||||
if first == nil {
|
||||
first = cfg
|
||||
}
|
||||
if _, ok := seen[first]; ok {
|
||||
continue
|
||||
}
|
||||
seen[first] = struct{}{}
|
||||
first.AddPlugin(m)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/coredns/caddy"
|
||||
"github.com/coredns/coredns/plugin"
|
||||
)
|
||||
|
||||
func TestKeyForConfig(t *testing.T) {
|
||||
@@ -65,3 +66,26 @@ func TestGetConfig(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestAddPluginToAllServerBlocks(t *testing.T) {
|
||||
c := caddy.NewTestController("dns", "")
|
||||
ctx := c.Context().(*dnsContext)
|
||||
first := &Config{}
|
||||
secondZone := &Config{firstConfigInBlock: first}
|
||||
third := &Config{}
|
||||
first.firstConfigInBlock = first
|
||||
third.firstConfigInBlock = third
|
||||
ctx.configs = []*Config{first, secondZone, third}
|
||||
|
||||
AddPluginToAllServerBlocks(c, func(next plugin.Handler) plugin.Handler { return next })
|
||||
|
||||
if got := len(first.Plugin); got != 1 {
|
||||
t.Fatalf("first server block has %d plugins, want 1", got)
|
||||
}
|
||||
if got := len(secondZone.Plugin); got != 0 {
|
||||
t.Fatalf("secondary zone has %d plugins before propagation, want 0", got)
|
||||
}
|
||||
if got := len(third.Plugin); got != 1 {
|
||||
t.Fatalf("second server block has %d plugins, want 1", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ var Directives = []string{
|
||||
"metadata",
|
||||
"geoip",
|
||||
"cancel",
|
||||
"tls",
|
||||
"proxyproto",
|
||||
"quic",
|
||||
"grpc_server",
|
||||
@@ -48,6 +47,7 @@ var Directives = []string{
|
||||
"cache",
|
||||
"header",
|
||||
"dnssec",
|
||||
"tls",
|
||||
"minimal",
|
||||
"template",
|
||||
"transfer",
|
||||
|
||||
Reference in New Issue
Block a user