Support for multiple AWS profiles (#1548)

* added support for multiple AWS credential profiles

Signed-off-by: Pranav Gaikwad <pgaikwad@redhat.com>
This commit is contained in:
Pranav Gaikwad
2019-06-07 11:01:39 -07:00
committed by KubeKween
parent 16a08b82a9
commit bb12cbd2d7
5 changed files with 24 additions and 12 deletions
+11 -8
View File
@@ -36,12 +36,13 @@ import (
)
const (
s3URLKey = "s3Url"
publicURLKey = "publicUrl"
kmsKeyIDKey = "kmsKeyId"
s3ForcePathStyleKey = "s3ForcePathStyle"
bucketKey = "bucket"
signatureVersionKey = "signatureVersion"
s3URLKey = "s3Url"
publicURLKey = "publicUrl"
kmsKeyIDKey = "kmsKeyId"
s3ForcePathStyleKey = "s3ForcePathStyle"
bucketKey = "bucket"
signatureVersionKey = "signatureVersion"
credentialProfileKey = "profile"
)
type s3Interface interface {
@@ -81,6 +82,7 @@ func (o *ObjectStore) Init(config map[string]string) error {
kmsKeyIDKey,
s3ForcePathStyleKey,
signatureVersionKey,
credentialProfileKey,
); err != nil {
return err
}
@@ -92,6 +94,7 @@ func (o *ObjectStore) Init(config map[string]string) error {
kmsKeyID = config[kmsKeyIDKey]
s3ForcePathStyleVal = config[s3ForcePathStyleKey]
signatureVersion = config[signatureVersionKey]
credentialProfile = config[credentialProfileKey]
// note that bucket is automatically added to the config map
// by the server from the ObjectStorageProviderConfig so
@@ -124,7 +127,7 @@ func (o *ObjectStore) Init(config map[string]string) error {
return err
}
serverSession, err := getSession(serverConfig)
serverSession, err := getSession(serverConfig, credentialProfile)
if err != nil {
return err
}
@@ -145,7 +148,7 @@ func (o *ObjectStore) Init(config map[string]string) error {
if err != nil {
return err
}
publicSession, err := getSession(publicConfig)
publicSession, err := getSession(publicConfig, credentialProfile)
if err != nil {
return err
}
+7 -4
View File
@@ -48,8 +48,10 @@ type VolumeSnapshotter struct {
ec2 *ec2.EC2
}
func getSession(config *aws.Config) (*session.Session, error) {
sess, err := session.NewSession(config)
// takes AWS credential config & a profile to create a new session
func getSession(config *aws.Config, profile string) (*session.Session, error) {
sessionOptions := session.Options{Config: *config, Profile: profile}
sess, err := session.NewSessionWithOptions(sessionOptions)
if err != nil {
return nil, errors.WithStack(err)
}
@@ -66,18 +68,19 @@ func NewVolumeSnapshotter(logger logrus.FieldLogger) *VolumeSnapshotter {
}
func (b *VolumeSnapshotter) Init(config map[string]string) error {
if err := cloudprovider.ValidateVolumeSnapshotterConfigKeys(config, regionKey); err != nil {
if err := cloudprovider.ValidateVolumeSnapshotterConfigKeys(config, regionKey, credentialProfileKey); err != nil {
return err
}
region := config[regionKey]
credentialProfile := config[credentialProfileKey]
if region == "" {
return errors.Errorf("missing %s in aws configuration", regionKey)
}
awsConfig := aws.NewConfig().WithRegion(region)
sess, err := getSession(awsConfig)
sess, err := getSession(awsConfig, credentialProfile)
if err != nil {
return err
}