From d31f264576404d40663c567364cf8ea4ab3b267b Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Thu, 24 Aug 2017 15:33:31 +0900 Subject: [PATCH] cache creds for keys/credentials auth type --- pkg/api/cloudwatch/cloudwatch.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/api/cloudwatch/cloudwatch.go b/pkg/api/cloudwatch/cloudwatch.go index 98ed1eabae2..8188e3913e9 100644 --- a/pkg/api/cloudwatch/cloudwatch.go +++ b/pkg/api/cloudwatch/cloudwatch.go @@ -96,7 +96,7 @@ var awsCredentialCache map[string]cache = make(map[string]cache) var credentialCacheLock sync.RWMutex func GetCredentials(dsInfo *DatasourceInfo) (*credentials.Credentials, error) { - cacheKey := dsInfo.Profile + ":" + dsInfo.AssumeRoleArn + cacheKey := dsInfo.AccessKey + ":" + dsInfo.Profile + ":" + dsInfo.AssumeRoleArn credentialCacheLock.RLock() if _, ok := awsCredentialCache[cacheKey]; ok { if awsCredentialCache[cacheKey].expiration != nil && @@ -150,6 +150,10 @@ func GetCredentials(dsInfo *DatasourceInfo) (*credentials.Credentials, error) { sessionToken = *resp.Credentials.SessionToken expiration = resp.Credentials.Expiration } + } else { + now := time.Now() + e := now.Add(5 * time.Minute) + expiration = &e } sess, err := session.NewSession()