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

Fixed time log format. #293

Open
wants to merge 2 commits into
base: release/1.2.11
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
10 changes: 6 additions & 4 deletions sinks/utils/aliyun_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
const (
ConfigPath = "/var/addon/token-config"
StsTokenTimeLayout = "2006-01-02T15:04:05Z"
TimeLogLayout = "2006-01-02 15:04:05 -07 UTC"
)

type AKInfo struct {
Expand All @@ -33,8 +34,6 @@ func (akInfo *AKInfo) IsExpired() bool {
return true
}

klog.V(7).Infof("akinfo Expiration: %v, Now: %v", akInfo.Expiration, time.Now().Format(StsTokenTimeLayout))

if len(akInfo.AccessKeyId) > 0 && len(akInfo.AccessKeySecret) > 0 && len(akInfo.SecurityToken) == 0 {
return false
}
Expand All @@ -44,8 +43,11 @@ func (akInfo *AKInfo) IsExpired() bool {
klog.Errorf("failed to parse time layout, akInfo Expiration: %v, err: %v", akInfo.Expiration, err)
return true
}

klog.V(7).Infof("akinfo Expiration: %v, Now: %v", t.Local().Format(TimeLogLayout), time.Now().Local().Format(TimeLogLayout))

if t.Before(time.Now()) {
klog.Errorf("invalid token which is expired, akInfo Expiration: %v, now: %v", akInfo.Expiration, time.Now())
klog.Errorf("invalid token which is expired, akInfo Expiration: %v, now: %v", t.Local().Format(TimeLogLayout), time.Now().Local().Format(TimeLogLayout))
return true
}
return false
Expand Down Expand Up @@ -149,7 +151,7 @@ func ParseAKInfoFromMeta() (*AKInfo, error) {
akInfo.AccessKeyId = auth.AccessKeyId
akInfo.AccessKeySecret = auth.AccessKeySecret
akInfo.SecurityToken = auth.SecurityToken
akInfo.Expiration = auth.Expiration.Format(StsTokenTimeLayout)
akInfo.Expiration = auth.Expiration.UTC().Format(StsTokenTimeLayout)

return &akInfo, nil
}
Expand Down