From 891a5157a75c8b5123349c27750897ebde14a5c4 Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Wed, 9 Jun 2021 20:10:34 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96token=E6=97=B6?= =?UTF-8?q?=E9=97=B4=20(#6252)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * perf: 修复上次引起的小bug * perf: 优化token时间 Co-authored-by: ibuler --- apps/authentication/api/connection_token.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/apps/authentication/api/connection_token.py b/apps/authentication/api/connection_token.py index a50de0371..76d6e934d 100644 --- a/apps/authentication/api/connection_token.py +++ b/apps/authentication/api/connection_token.py @@ -50,7 +50,7 @@ class UserConnectionTokenViewSet(RootOrgViewMixin, SerializerMixin2, GenericView raise PermissionDenied(error) return True - def create_token(self, user, asset, application, system_user): + def create_token(self, user, asset, application, system_user, ttl=5*60): if not settings.CONNECTION_TOKEN_ENABLED: raise PermissionDenied('Connection token disabled') if not user: @@ -80,7 +80,7 @@ class UserConnectionTokenViewSet(RootOrgViewMixin, SerializerMixin2, GenericView }) key = self.CACHE_KEY_PREFIX.format(token) - cache.set(key, value, timeout=30*60) + cache.set(key, value, timeout=ttl) return token def create(self, request, *args, **kwargs): @@ -165,7 +165,6 @@ class UserConnectionTokenViewSet(RootOrgViewMixin, SerializerMixin2, GenericView @staticmethod def _get_application_secret_detail(application): - from applications.models import Application from perms.models import Action gateway = None @@ -224,8 +223,6 @@ class UserConnectionTokenViewSet(RootOrgViewMixin, SerializerMixin2, GenericView raise serializers.ValidationError("User not valid, disabled or expired") system_user = get_object_or_404(SystemUser, id=value.get('system_user')) - if system_user.ad_domain: - system_user.username = '{0.username}@{0.ad_domain}'.format(system_user) asset = None app = None