Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,33 @@ type Config struct {

UseMaxRetries bool
MaxRetries int

// Cache aws config for preserving creds to avoid sts rate limit
useConfigCache bool
configCache *aws.Config
}

// Session creates AWS session from the Config values.
func (c Config) Session() (*session.Session, error) {
return session.NewSession(c.AWSConfig())
}

// SetConfigCache caches *aws.Config.
func (c *Config) SetConfigCache() {
c.configCache = c.awsConfig()
c.useConfigCache = true
}

// AWSConfig creates *aws.Config object from the fields.
func (c Config) AWSConfig() *aws.Config {
if c.useConfigCache {
return c.configCache
}
return c.awsConfig()
}

// awsConfig creates *aws.Config object from the fields.
func (c Config) awsConfig() *aws.Config {
cred := c.awsCredentials()
awsConf := &aws.Config{
Credentials: cred,
Expand Down