plugin/route53: various updates (#3108)
In the setup function use plugin.Error() to wrap the errors with the plugin name. Because there isn't a separate setup() function this is done for all returned errors. Remove *upstream.Upstream from the New parameters as this is always set and adjust the tests to account for this. Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
parent
ca57dd3568
commit
ebc465d0dc
3 changed files with 19 additions and 23 deletions
|
@ -46,11 +46,11 @@ type zone struct {
|
|||
type zones map[string][]*zone
|
||||
|
||||
// New reads from the keys map which uses domain names as its key and hosted
|
||||
// zone id lists as its values, validates that each domain name/zone id pair does
|
||||
// exist, and returns a new *Route53. In addition to this, upstream is passed
|
||||
// for doing recursive queries against CNAMEs.
|
||||
// Returns error if it cannot verify any given domain name/zone id pair.
|
||||
func New(ctx context.Context, c route53iface.Route53API, keys map[string][]string, up *upstream.Upstream, refresh time.Duration) (*Route53, error) {
|
||||
// zone id lists as its values, validates that each domain name/zone id pair
|
||||
// does exist, and returns a new *Route53. In addition to this, upstream is use
|
||||
// for doing recursive queries against CNAMEs. Returns error if it cannot
|
||||
// verify any given domain name/zone id pair.
|
||||
func New(ctx context.Context, c route53iface.Route53API, keys map[string][]string, refresh time.Duration) (*Route53, error) {
|
||||
zones := make(map[string][]*zone, len(keys))
|
||||
zoneNames := make([]string, 0, len(keys))
|
||||
for dns, hostedZoneIDs := range keys {
|
||||
|
@ -72,7 +72,7 @@ func New(ctx context.Context, c route53iface.Route53API, keys map[string][]strin
|
|||
client: c,
|
||||
zoneNames: zoneNames,
|
||||
zones: zones,
|
||||
upstream: up,
|
||||
upstream: upstream.New(),
|
||||
refresh: refresh,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
|
||||
"github.com/coredns/coredns/plugin/pkg/dnstest"
|
||||
"github.com/coredns/coredns/plugin/pkg/fall"
|
||||
"github.com/coredns/coredns/plugin/pkg/upstream"
|
||||
"github.com/coredns/coredns/plugin/test"
|
||||
crequest "github.com/coredns/coredns/request"
|
||||
|
||||
|
@ -80,7 +79,7 @@ func (fakeRoute53) ListResourceRecordSetsPagesWithContext(_ aws.Context, in *rou
|
|||
func TestRoute53(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
r, err := New(ctx, fakeRoute53{}, map[string][]string{"bad.": {"0987654321"}}, &upstream.Upstream{}, time.Duration(1) * time.Minute)
|
||||
r, err := New(ctx, fakeRoute53{}, map[string][]string{"bad.": {"0987654321"}}, time.Duration(1)*time.Minute)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create Route53: %v", err)
|
||||
}
|
||||
|
@ -88,7 +87,7 @@ func TestRoute53(t *testing.T) {
|
|||
t.Fatalf("Expected errors for zone bad.")
|
||||
}
|
||||
|
||||
r, err = New(ctx, fakeRoute53{}, map[string][]string{"org.": {"1357986420", "1234567890"}, "gov.": {"Z098765432", "1234567890"}}, &upstream.Upstream{}, time.Duration(90) * time.Second)
|
||||
r, err = New(ctx, fakeRoute53{}, map[string][]string{"org.": {"1357986420", "1234567890"}, "gov.": {"Z098765432", "1234567890"}}, time.Duration(90)*time.Second)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create Route53: %v", err)
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
"github.com/coredns/coredns/plugin"
|
||||
"github.com/coredns/coredns/plugin/pkg/fall"
|
||||
clog "github.com/coredns/coredns/plugin/pkg/log"
|
||||
"github.com/coredns/coredns/plugin/pkg/upstream"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||
|
@ -54,8 +53,6 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro
|
|||
var providers []credentials.Provider
|
||||
var fall fall.F
|
||||
|
||||
up := upstream.New()
|
||||
|
||||
refresh := time.Duration(1) * time.Minute // default update frequency to 1 minute
|
||||
|
||||
args := c.RemainingArgs()
|
||||
|
@ -63,14 +60,14 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro
|
|||
for i := 0; i < len(args); i++ {
|
||||
parts := strings.SplitN(args[i], ":", 2)
|
||||
if len(parts) != 2 {
|
||||
return c.Errf("invalid zone '%s'", args[i])
|
||||
return plugin.Error("route53", c.Errf("invalid zone '%s'", args[i]))
|
||||
}
|
||||
dns, hostedZoneID := parts[0], parts[1]
|
||||
if dns == "" || hostedZoneID == "" {
|
||||
return c.Errf("invalid zone '%s'", args[i])
|
||||
return plugin.Error("route53", c.Errf("invalid zone '%s'", args[i]))
|
||||
}
|
||||
if _, ok := keyPairs[args[i]]; ok {
|
||||
return c.Errf("conflict zone '%s'", args[i])
|
||||
return plugin.Error("route53", c.Errf("conflict zone '%s'", args[i]))
|
||||
}
|
||||
|
||||
keyPairs[args[i]] = struct{}{}
|
||||
|
@ -82,7 +79,7 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro
|
|||
case "aws_access_key":
|
||||
v := c.RemainingArgs()
|
||||
if len(v) < 2 {
|
||||
return c.Errf("invalid access key '%v'", v)
|
||||
return plugin.Error("route53", c.Errf("invalid access key '%v'", v))
|
||||
}
|
||||
providers = append(providers, &credentials.StaticProvider{
|
||||
Value: credentials.Value{
|
||||
|
@ -112,16 +109,16 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro
|
|||
}
|
||||
refresh, err = time.ParseDuration(refreshStr)
|
||||
if err != nil {
|
||||
return c.Errf("Unable to parse duration: '%v'", err)
|
||||
return plugin.Error("route53", c.Errf("Unable to parse duration: '%v'", err))
|
||||
}
|
||||
if refresh <= 0 {
|
||||
return c.Errf("refresh interval must be greater than 0: %s", refreshStr)
|
||||
return plugin.Error("route53", c.Errf("refresh interval must be greater than 0: %s", refreshStr))
|
||||
}
|
||||
} else {
|
||||
return c.ArgErr()
|
||||
return plugin.Error("route53", c.ArgErr())
|
||||
}
|
||||
default:
|
||||
return c.Errf("unknown property '%s'", c.Val())
|
||||
return plugin.Error("route53", c.Errf("unknown property '%s'", c.Val()))
|
||||
}
|
||||
}
|
||||
providers = append(providers, &credentials.EnvProvider{}, sharedProvider, &ec2rolecreds.EC2RoleProvider{
|
||||
|
@ -129,13 +126,13 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro
|
|||
})
|
||||
client := f(credentials.NewChainCredentials(providers))
|
||||
ctx := context.Background()
|
||||
h, err := New(ctx, client, keys, up, refresh)
|
||||
h, err := New(ctx, client, keys, refresh)
|
||||
if err != nil {
|
||||
return c.Errf("failed to create Route53 plugin: %v", err)
|
||||
return plugin.Error("route53", c.Errf("failed to create Route53 plugin: %v", err))
|
||||
}
|
||||
h.Fall = fall
|
||||
if err := h.Run(ctx); err != nil {
|
||||
return c.Errf("failed to initialize Route53 plugin: %v", err)
|
||||
return plugin.Error("route53", c.Errf("failed to initialize Route53 plugin: %v", err))
|
||||
}
|
||||
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
|
||||
h.Next = next
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue