Skip to content

Commit 0971c09

Browse files
committed
fix(backend): 修复解密token问题 #11262
# Reviewed, transaction id: 47656
1 parent a90277f commit 0971c09

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

dbm-ui/backend/iam_app/handlers/drf_perm/proxypass.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from backend.core.encrypt.handlers import AsymmetricHandler
2121
from backend.db_proxy.constants import DB_CLOUD_TOKEN_EXPIRE_TIME
2222
from backend.utils.local import local
23-
from backend.utils.redis import check_set_member_in_redis
23+
from backend.utils.redis import RedisConn
2424

2525

2626
class ProxyPassPermission(permissions.BasePermission):
@@ -54,7 +54,16 @@ def has_permission(self, request, view):
5454
cache_key = f"cache_db_cloud_token_{bk_cloud_id}"
5555
# 判断是否在缓存集合中,不在cache中则走解密流程并cache。
5656
# 由于Redis的list不能直接判断元素是否存在,所以选择set存取
57-
check_set_member_in_redis(cache_key, db_cloud_token, self.verify_token, DB_CLOUD_TOKEN_EXPIRE_TIME)
57+
# check_set_member_in_redis(cache_key, db_cloud_token, self.verify_token, DB_CLOUD_TOKEN_EXPIRE_TIME)
58+
if not RedisConn.sismember(cache_key, db_cloud_token):
59+
self.verify_token(db_cloud_token, bk_cloud_id)
60+
# 如果这个cache_key刚创建,则需要设置过期时间
61+
if not RedisConn.exists(cache_key):
62+
RedisConn.sadd(cache_key, db_cloud_token)
63+
RedisConn.expire(cache_key, DB_CLOUD_TOKEN_EXPIRE_TIME)
64+
else:
65+
RedisConn.sadd(cache_key, db_cloud_token)
66+
5867
request.data.pop("db_cloud_token")
5968

6069
# 通过鉴权后,修改调用方式为内部调用

0 commit comments

Comments
 (0)