From 3c9239eb09685c65ed09d770e30166d7be8530f0 Mon Sep 17 00:00:00 2001 From: Bai Date: Thu, 14 Dec 2023 17:49:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Release=20=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E8=B4=A6=E5=8F=B7=E7=9A=84=E9=80=BB=E8=BE=91,?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E9=A6=96=E6=AC=A1=E8=BF=9E=E6=8E=A5=E8=BF=9C?= =?UTF-8?q?=E7=A8=8B=E5=BA=94=E7=94=A8=E5=8F=AF=E8=83=BD=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=8F=AF=E7=94=A8=E8=B4=A6=E5=8F=B7=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/authentication/api/connection_token.py | 8 ++++---- apps/authentication/models/connection_token.py | 11 +++-------- apps/terminal/models/applet/applet.py | 3 +-- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/apps/authentication/api/connection_token.py b/apps/authentication/api/connection_token.py index bc79d26a2..076767946 100644 --- a/apps/authentication/api/connection_token.py +++ b/apps/authentication/api/connection_token.py @@ -544,12 +544,12 @@ class SuperConnectionTokenViewSet(ConnectionTokenViewSet): @action(methods=['DELETE', 'POST'], detail=False, url_path='applet-account/release') def release_applet_account(self, *args, **kwargs): - account_id = self.request.data.get('id') - released = ConnectionToken.release_applet_account(account_id) + lock_key = self.request.data.get('id') + released = ConnectionToken.release_applet_account(lock_key) if released: - logger.debug('Release applet account success: {}'.format(account_id)) + logger.debug('Release applet account success: {}'.format(lock_key)) return Response({'msg': 'released'}) else: - logger.error('Release applet account error: {}'.format(account_id)) + logger.error('Release applet account error: {}'.format(lock_key)) return Response({'error': 'not found or expired'}, status=400) diff --git a/apps/authentication/models/connection_token.py b/apps/authentication/models/connection_token.py index 6cd5648db..2ef28eab1 100644 --- a/apps/authentication/models/connection_token.py +++ b/apps/authentication/models/connection_token.py @@ -199,28 +199,23 @@ class ConnectionToken(JMSOrgBaseModel): if not host_account: raise JMSException({'error': 'No host account available'}) - host, account, lock_key, ttl = bulk_get(host_account, ('host', 'account', 'lock_key', 'ttl')) + host, account, lock_key = bulk_get(host_account, ('host', 'account', 'lock_key')) gateway = host.domain.select_gateway() if host.domain else None data = { - 'id': account.id, + 'id': lock_key, 'applet': applet, 'host': host, 'gateway': gateway, 'account': account, 'remote_app_option': self.get_remote_app_option() } - token_account_relate_key = f'token_account_relate_{account.id}' - cache.set(token_account_relate_key, lock_key, ttl) return data @staticmethod - def release_applet_account(account_id): - token_account_relate_key = f'token_account_relate_{account_id}' - lock_key = cache.get(token_account_relate_key) + def release_applet_account(lock_key): if lock_key: cache.delete(lock_key) - cache.delete(token_account_relate_key) return True @lazyproperty diff --git a/apps/terminal/models/applet/applet.py b/apps/terminal/models/applet/applet.py index c018275ac..3110b506f 100644 --- a/apps/terminal/models/applet/applet.py +++ b/apps/terminal/models/applet/applet.py @@ -299,8 +299,7 @@ class Applet(JMSBaseModel): res = { 'host': host, 'account': account, - 'lock_key': lock_key, - 'ttl': ttl + 'lock_key': lock_key } logger.debug('Select host and account: {}'.format(res)) return res