Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[config] Add 'UseConfigCache' into config for preserving creds to avoid sts rate limit #84

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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