-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider.go
58 lines (52 loc) · 1.44 KB
/
provider.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"context"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/route53"
)
type cloud interface {
List(ctx context.Context) ([]zone, error)
ZonesString() string
}
func newProviders(provider, awsAccessKey, awsSecretKey string, config *Config) ([]cloud, error) {
awsConf := initAwsConfig(awsAccessKey, awsSecretKey)
var providers []cloud
for _, r := range config.Roles {
sess := session.New(awsConf)
var p *r53Provider
if r.RoleArn == "none" {
// use AWS Chain credentials
p = &r53Provider{
client: route53.New(sess),
zoneIds: r.Zones,
}
} else {
// use AWS Chain with AssumeRole credential provider
creds := stscreds.NewCredentials(sess, r.RoleArn)
p = &r53Provider{
client: route53.New(sess, &aws.Config{Credentials: creds}),
zoneIds: r.Zones,
}
}
providers = append(providers, p)
}
return providers, nil
}
func initAwsConfig(accessKey, secretKey string) *aws.Config {
awsConfig := aws.NewConfig()
creds := credentials.NewChainCredentials([]credentials.Provider{
&credentials.StaticProvider{
Value: credentials.Value{
AccessKeyID: accessKey,
SecretAccessKey: secretKey,
},
},
&credentials.EnvProvider{},
&credentials.SharedCredentialsProvider{},
})
awsConfig.WithCredentials(creds)
return awsConfig
}