Skip to content

Commit 4db2bda

Browse files
committedFeb 4, 2016
Fix session expiration calculation
The previous implementation was only recreating the session 5 minutes *after* the session expired, instead of before.
1 parent 03a1a7d commit 4db2bda

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed
 

Diff for: ‎credentials.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const (
1818
var (
1919
// matches char that is not valid in a STS role session name
2020
invalidSessionNameRegexp = regexp.MustCompile(`[^\w+=,.@-]`)
21+
22+
sessionExpiration = 5 * time.Minute
2123
)
2224

2325
type credentials struct {
@@ -38,7 +40,7 @@ func (c credentials) ExpiredAt(at time.Time) bool {
3840
}
3941

4042
func (c credentials) ExpiresIn(d time.Duration) bool {
41-
return c.ExpiredAt(time.Now().Add(-d))
43+
return c.ExpiredAt(time.Now().Add(d))
4244
}
4345

4446
type containerCredentials struct {
@@ -49,7 +51,7 @@ type containerCredentials struct {
4951
func (c containerCredentials) IsValid(container containerInfo) bool {
5052
return c.containerInfo.IamRole.Equals(container.IamRole) &&
5153
c.containerInfo.ID == container.ID &&
52-
!c.credentials.ExpiresIn(5*time.Minute)
54+
!c.credentials.ExpiresIn(sessionExpiration)
5355
}
5456

5557
type credentialsProvider struct {

0 commit comments

Comments
 (0)
Please sign in to comment.