From b39010578614fd8786fbbbbbdcecfb6b722ee554 Mon Sep 17 00:00:00 2001 From: samwaf Date: Fri, 31 Jan 2025 19:29:19 +0800 Subject: [PATCH] feat:token expire #126 --- cache/waf_cache.go | 3 +++ waftask/task_config.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/cache/waf_cache.go b/cache/waf_cache.go index 43bace7..3009e6b 100644 --- a/cache/waf_cache.go +++ b/cache/waf_cache.go @@ -1,6 +1,7 @@ package cache import ( + "SamWaf/common/zlog" "errors" "strings" "sync" @@ -107,6 +108,7 @@ func (wafCache *WafCache) GetLastTime(key string) (time.Time, error) { if time.Since(item.createTime) <= item.ttl { return item.lastTime, nil } + zlog.Debug("GetLastTime CLEAR CACHE EXPIRE :" + key) delete(wafCache.cache, key) return time.Time{}, errors.New("数据已过期") } @@ -114,6 +116,7 @@ func (wafCache *WafCache) ClearExpirationCache() { now := time.Now() for key, item := range wafCache.cache { if now.Sub(item.createTime) > item.ttl { + zlog.Debug("ClearExpirationCache CLEAR CACHE EXPIRE :" + key) delete(wafCache.cache, key) } } diff --git a/waftask/task_config.go b/waftask/task_config.go index 93f22b1..3e79b6b 100644 --- a/waftask/task_config.go +++ b/waftask/task_config.go @@ -54,6 +54,9 @@ func setConfigIntValue(name string, value int64, change int) { case "record_all_src_byte_info": global.GCONFIG_RECORD_ALL_SRC_BYTE_INFO = value break + case "token_expire_time": + global.GCONFIG_RECORD_TOKEN_EXPIRE_MINTUTES = value + break default: zlog.Warn("Unknown config item:", name) } @@ -162,5 +165,6 @@ func TaskLoadSetting(initLoad bool) { updateConfigIntItem(initLoad, "network", "keepalive_time_out", global.GCONFIG_RECORD_KEEPALIVE_TIME_OUT, "保持活动超时(默认30s)", "int", "") updateConfigIntItem(initLoad, "system", "record_all_src_byte_info", global.GCONFIG_RECORD_ALL_SRC_BYTE_INFO, "启动记录原始请求BODY报文(1启动 0关闭)", "int", "") + updateConfigIntItem(initLoad, "system", "token_expire_time", global.GCONFIG_RECORD_TOKEN_EXPIRE_MINTUTES, "管理平台令牌有效期,单位分钟(默认5分钟)", "int", "") }