From 213613cf5473fad8200ef4b5f10b3b1703fd45ca Mon Sep 17 00:00:00 2001 From: icey-yu <119291641+icey-yu@users.noreply.github.com> Date: Tue, 9 Jul 2024 18:17:44 +0800 Subject: [PATCH] Fix token (#2403) * fix:log config * fix: token update expire time --- config/log.yml | 2 +- pkg/common/storage/controller/auth.go | 16 ++-------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/config/log.yml b/config/log.yml index 38926479c..1f5641622 100644 --- a/config/log.yml +++ b/config/log.yml @@ -1,7 +1,7 @@ # Log storage path, default is acceptable, change to a full path if modification is needed storageLocation: ../../../../logs/ # Log rotation period (in hours), default is acceptable -rotationTime: 1 +rotationTime: 24 # Maximum size of each log file (in MB), default is acceptable, it means unlimited maxSize: 0 # Number of log files to retain, default is acceptable, it means whenever the log file is rotated, the old log file will be deleted diff --git a/pkg/common/storage/controller/auth.go b/pkg/common/storage/controller/auth.go index fbfe30836..b725513d9 100644 --- a/pkg/common/storage/controller/auth.go +++ b/pkg/common/storage/controller/auth.go @@ -55,7 +55,6 @@ func (a *authDatabase) SetTokenMapByUidPid(ctx context.Context, userID string, p // Create Token. func (a *authDatabase) CreateToken(ctx context.Context, userID string, platformID int) (string, error) { - isCreate := true // flag is create or update tokens, err := a.cache.GetTokensWithoutError(ctx, userID, platformID) if err != nil { return "", err @@ -66,9 +65,6 @@ func (a *authDatabase) CreateToken(ctx context.Context, userID string, platformI if err != nil || v != constant.NormalToken { deleteTokenKey = append(deleteTokenKey, k) } - if v == constant.NormalToken { - isCreate = false - } } if len(deleteTokenKey) != 0 { err = a.cache.DeleteTokenByUidPid(ctx, userID, platformID, deleteTokenKey) @@ -84,16 +80,8 @@ func (a *authDatabase) CreateToken(ctx context.Context, userID string, platformI return "", errs.WrapMsg(err, "token.SignedString") } - if isCreate { - // should create,should specify expiration time - if err = a.cache.SetTokenFlagEx(ctx, userID, platformID, tokenString, constant.NormalToken); err != nil { - return "", err - } - } else { - // should update - if err = a.cache.SetTokenFlag(ctx, userID, platformID, tokenString, constant.NormalToken); err != nil { - return "", err - } + if err = a.cache.SetTokenFlagEx(ctx, userID, platformID, tokenString, constant.NormalToken); err != nil { + return "", err } return tokenString, nil }