Commit ebc465d0 authored by Miek Gieben's avatar Miek Gieben Committed by Yong Tang

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: default avatarMiek Gieben <miek@miek.nl>
parent ca57dd35
...@@ -46,11 +46,11 @@ type zone struct { ...@@ -46,11 +46,11 @@ type zone struct {
type zones map[string][]*zone type zones map[string][]*zone
// New reads from the keys map which uses domain names as its key and hosted // 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 // zone id lists as its values, validates that each domain name/zone id pair
// exist, and returns a new *Route53. In addition to this, upstream is passed // does exist, and returns a new *Route53. In addition to this, upstream is use
// for doing recursive queries against CNAMEs. // for doing recursive queries against CNAMEs. Returns error if it cannot
// Returns error if it cannot verify any given domain name/zone id pair. // 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) { func New(ctx context.Context, c route53iface.Route53API, keys map[string][]string, refresh time.Duration) (*Route53, error) {
zones := make(map[string][]*zone, len(keys)) zones := make(map[string][]*zone, len(keys))
zoneNames := make([]string, 0, len(keys)) zoneNames := make([]string, 0, len(keys))
for dns, hostedZoneIDs := range keys { for dns, hostedZoneIDs := range keys {
...@@ -72,7 +72,7 @@ func New(ctx context.Context, c route53iface.Route53API, keys map[string][]strin ...@@ -72,7 +72,7 @@ func New(ctx context.Context, c route53iface.Route53API, keys map[string][]strin
client: c, client: c,
zoneNames: zoneNames, zoneNames: zoneNames,
zones: zones, zones: zones,
upstream: up, upstream: upstream.New(),
refresh: refresh, refresh: refresh,
}, nil }, nil
} }
......
...@@ -9,7 +9,6 @@ import ( ...@@ -9,7 +9,6 @@ import (
"github.com/coredns/coredns/plugin/pkg/dnstest" "github.com/coredns/coredns/plugin/pkg/dnstest"
"github.com/coredns/coredns/plugin/pkg/fall" "github.com/coredns/coredns/plugin/pkg/fall"
"github.com/coredns/coredns/plugin/pkg/upstream"
"github.com/coredns/coredns/plugin/test" "github.com/coredns/coredns/plugin/test"
crequest "github.com/coredns/coredns/request" crequest "github.com/coredns/coredns/request"
...@@ -80,7 +79,7 @@ func (fakeRoute53) ListResourceRecordSetsPagesWithContext(_ aws.Context, in *rou ...@@ -80,7 +79,7 @@ func (fakeRoute53) ListResourceRecordSetsPagesWithContext(_ aws.Context, in *rou
func TestRoute53(t *testing.T) { func TestRoute53(t *testing.T) {
ctx := context.Background() 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 { if err != nil {
t.Fatalf("Failed to create Route53: %v", err) t.Fatalf("Failed to create Route53: %v", err)
} }
...@@ -88,7 +87,7 @@ func TestRoute53(t *testing.T) { ...@@ -88,7 +87,7 @@ func TestRoute53(t *testing.T) {
t.Fatalf("Expected errors for zone bad.") 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 { if err != nil {
t.Fatalf("Failed to create Route53: %v", err) t.Fatalf("Failed to create Route53: %v", err)
} }
......
...@@ -11,7 +11,6 @@ import ( ...@@ -11,7 +11,6 @@ import (
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/pkg/fall" "github.com/coredns/coredns/plugin/pkg/fall"
clog "github.com/coredns/coredns/plugin/pkg/log" 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"
"github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/credentials"
...@@ -54,8 +53,6 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro ...@@ -54,8 +53,6 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro
var providers []credentials.Provider var providers []credentials.Provider
var fall fall.F var fall fall.F
up := upstream.New()
refresh := time.Duration(1) * time.Minute // default update frequency to 1 minute refresh := time.Duration(1) * time.Minute // default update frequency to 1 minute
args := c.RemainingArgs() args := c.RemainingArgs()
...@@ -63,14 +60,14 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro ...@@ -63,14 +60,14 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro
for i := 0; i < len(args); i++ { for i := 0; i < len(args); i++ {
parts := strings.SplitN(args[i], ":", 2) parts := strings.SplitN(args[i], ":", 2)
if len(parts) != 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] dns, hostedZoneID := parts[0], parts[1]
if dns == "" || hostedZoneID == "" { 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 { 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{}{} keyPairs[args[i]] = struct{}{}
...@@ -82,7 +79,7 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro ...@@ -82,7 +79,7 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro
case "aws_access_key": case "aws_access_key":
v := c.RemainingArgs() v := c.RemainingArgs()
if len(v) < 2 { 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{ providers = append(providers, &credentials.StaticProvider{
Value: credentials.Value{ Value: credentials.Value{
...@@ -112,16 +109,16 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro ...@@ -112,16 +109,16 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro
} }
refresh, err = time.ParseDuration(refreshStr) refresh, err = time.ParseDuration(refreshStr)
if err != nil { 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 { 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 { } else {
return c.ArgErr() return plugin.Error("route53", c.ArgErr())
} }
default: 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{ providers = append(providers, &credentials.EnvProvider{}, sharedProvider, &ec2rolecreds.EC2RoleProvider{
...@@ -129,13 +126,13 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro ...@@ -129,13 +126,13 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro
}) })
client := f(credentials.NewChainCredentials(providers)) client := f(credentials.NewChainCredentials(providers))
ctx := context.Background() ctx := context.Background()
h, err := New(ctx, client, keys, up, refresh) h, err := New(ctx, client, keys, refresh)
if err != nil { 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 h.Fall = fall
if err := h.Run(ctx); err != nil { 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 { dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
h.Next = next h.Next = next
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment