mirror of
https://github.com/coredns/coredns.git
synced 2025-11-02 10:13:14 -05:00
plugins/route53: add AWS credentials file support (#2118)
Automatically submitted.
This commit is contained in:
@@ -36,7 +36,15 @@ func init() {
|
||||
|
||||
func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Route53API) error {
|
||||
keys := map[string]string{}
|
||||
credential := credentials.NewEnvCredentials()
|
||||
|
||||
// Route53 plugin attempts to find AWS credentials by using ChainCredentials.
|
||||
// And the order of that provider chain is as follows:
|
||||
// Static AWS keys -> Environment Variables -> Credentials file -> IAM role
|
||||
// With that said, even though a user doesn't define any credentials in
|
||||
// Corefile, we should still attempt to read the default credentials file,
|
||||
// ~/.aws/credentials with the default profile.
|
||||
sharedProvider := &credentials.SharedCredentialsProvider{}
|
||||
var providers []credentials.Provider
|
||||
var fall fall.F
|
||||
|
||||
up, _ := upstream.New(nil)
|
||||
@@ -65,7 +73,12 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro
|
||||
if len(v) < 2 {
|
||||
return c.Errf("invalid access key '%v'", v)
|
||||
}
|
||||
credential = credentials.NewStaticCredentials(v[0], v[1], "")
|
||||
providers = append(providers, &credentials.StaticProvider{
|
||||
Value: credentials.Value{
|
||||
AccessKeyID: v[0],
|
||||
SecretAccessKey: v[1],
|
||||
},
|
||||
})
|
||||
case "upstream":
|
||||
args := c.RemainingArgs()
|
||||
// TODO(dilyevsky): There is a bug that causes coredns to crash
|
||||
@@ -78,6 +91,15 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro
|
||||
if err != nil {
|
||||
return c.Errf("invalid upstream: %v", err)
|
||||
}
|
||||
case "credentials":
|
||||
if c.NextArg() {
|
||||
sharedProvider.Profile = c.Val()
|
||||
} else {
|
||||
return c.ArgErr()
|
||||
}
|
||||
if c.NextArg() {
|
||||
sharedProvider.Filename = c.Val()
|
||||
}
|
||||
case "fallthrough":
|
||||
fall.SetZonesFromArgs(c.RemainingArgs())
|
||||
default:
|
||||
@@ -85,7 +107,9 @@ func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Ro
|
||||
}
|
||||
}
|
||||
}
|
||||
client := f(credential)
|
||||
providers = append(providers, &credentials.EnvProvider{}, sharedProvider)
|
||||
|
||||
client := f(credentials.NewChainCredentials(providers))
|
||||
ctx := context.Background()
|
||||
h, err := New(ctx, client, keys, &up)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user