From 5a9815481a91a539cea93483c916a0f2a17e7e71 Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 17 Apr 2024 13:52:00 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BF=AE=E6=94=B9=20token=20expire=20?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/authentication/api/connection_token.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/apps/authentication/api/connection_token.py b/apps/authentication/api/connection_token.py index fbeacb96b..37fb3e968 100644 --- a/apps/authentication/api/connection_token.py +++ b/apps/authentication/api/connection_token.py @@ -512,20 +512,16 @@ class SuperConnectionTokenViewSet(ConnectionTokenViewSet): token.is_valid() serializer = self.get_serializer(instance=token) - expire_now = request.data.get('expire_now', None) + expire_now = request.data.get('expire_now', True) asset_type = token.asset.type # 设置默认值 - if expire_now is None: - # TODO 暂时特殊处理 k8s 不过期 - if asset_type in ['k8s', 'kubernetes']: - expire_now = False - else: - expire_now = not settings.CONNECTION_TOKEN_REUSABLE + if asset_type in ['k8s', 'kubernetes']: + expire_now = False - if is_false(expire_now): - logger.debug('Api specified, now expire now') - elif token.is_reusable and settings.CONNECTION_TOKEN_REUSABLE: + if token.is_reusable and settings.CONNECTION_TOKEN_REUSABLE: logger.debug('Token is reusable, not expire now') + elif is_false(expire_now): + logger.debug('Api specified, now expire now') else: token.expire()