Skip to content

Commit

Permalink
Use timestamp for expiration in credentials file (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
patricksanders authored Jan 21, 2021
1 parent bec4466 commit 07b69e1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 4 additions & 2 deletions cmd/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package cmd
import (
"fmt"
"path"
"strconv"
"time"

"gopkg.in/ini.v1"
Expand Down Expand Up @@ -136,10 +137,11 @@ func isExpiring(filename, profile string, thresholdMinutes int) (bool, error) {
if err != nil {
return true, err
}
expirationTime, err := expiration.Time()
expirationInt, err := expiration.Int64()
if err != nil {
return true, err
}
expirationTime := time.Unix(expirationInt, 0)
diff := time.Duration(thresholdMinutes) * time.Minute
timeUntilExpiration := expirationTime.Sub(time.Now()).Round(0)
log.Debugf("%s until expiration, refresh threshold is %s", timeUntilExpiration, diff)
Expand Down Expand Up @@ -179,7 +181,7 @@ func writeCredentialsFile(credentials *creds.AwsCredentials, profile, filename s
credentialsINI.Section(profile).Key("aws_access_key_id").SetValue(credentials.AccessKeyId)
credentialsINI.Section(profile).Key("aws_secret_access_key").SetValue(credentials.SecretAccessKey)
credentialsINI.Section(profile).Key("aws_session_token").SetValue(credentials.SessionToken)
credentialsINI.Section(profile).Key("expiration").SetValue(credentials.Expiration.Format("2006-01-02T15:04:05Z07:00"))
credentialsINI.Section(profile).Key("expiration").SetValue(strconv.FormatInt(credentials.Expiration.Unix(), 10))
err = credentialsINI.SaveTo(filename)
if err != nil {
return err
Expand Down
2 changes: 0 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ func initLogging() {
log.SetLevel(log.InfoLevel)
}

log.Debug("configuring logging")

// Set the log format. Default to Text
if logFormat == "json" {
log.SetFormatter(&log.JSONFormatter{})
Expand Down

0 comments on commit 07b69e1

Please sign in to comment.