Skip to content

Commit

Permalink
Add ExpiredAt()
Browse files Browse the repository at this point in the history
  • Loading branch information
mikutas committed Jan 20, 2022
1 parent 1eb5eed commit f25bb11
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
9 changes: 6 additions & 3 deletions cmd/saml2aws/commands/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ func Login(loginFlags *flags.LoginExecFlags) error {
return nil
}

expired, expireTime := sharedCreds.Expired()
if !expired && !loginFlags.Force {
logger.Debug("Credentials are not expired. It will expire at ", expireTime, ". Skipping.")
if !sharedCreds.Expired() && !loginFlags.Force {
logger.Debug("Credentials are not expired. Skipping.")
expiredAt := sharedCreds.ExpiredAt()
if expiredAt != nil {
logger.Debug("Credentials will expire at", &expiredAt)
}
previousCreds, err := sharedCreds.Load()
if err != nil {
log.Println("Unable to load cached credentials.")
Expand Down
15 changes: 12 additions & 3 deletions pkg/awsconfig/awsconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,22 @@ func (p *CredentialsProvider) Load() (*AWSCredentials, error) {
}

// Expired checks if the current credentials are expired
func (p *CredentialsProvider) Expired() (bool, *time.Time) {
func (p *CredentialsProvider) Expired() bool {
creds, err := p.Load()
if err != nil {
return true, nil
return true
}

return time.Now().After(creds.Expires), &creds.Expires
return time.Now().After(creds.Expires)
}

func (p *CredentialsProvider) ExpiredAt() *time.Time {
creds, err := p.Load()
if err != nil {
return nil
}

return &creds.Expires
}

// ensureConfigExists verify that the config file exists
Expand Down

0 comments on commit f25bb11

Please sign in to comment.