mirror of https://github.com/jumpserver/jumpserver
fix: 修复 Release 应用账号的逻辑,解决首次连接远程应用可能出现没有可用账号的问题
parent
81fb080c67
commit
3c9239eb09
|
@ -544,12 +544,12 @@ class SuperConnectionTokenViewSet(ConnectionTokenViewSet):
|
||||||
|
|
||||||
@action(methods=['DELETE', 'POST'], detail=False, url_path='applet-account/release')
|
@action(methods=['DELETE', 'POST'], detail=False, url_path='applet-account/release')
|
||||||
def release_applet_account(self, *args, **kwargs):
|
def release_applet_account(self, *args, **kwargs):
|
||||||
account_id = self.request.data.get('id')
|
lock_key = self.request.data.get('id')
|
||||||
released = ConnectionToken.release_applet_account(account_id)
|
released = ConnectionToken.release_applet_account(lock_key)
|
||||||
|
|
||||||
if released:
|
if released:
|
||||||
logger.debug('Release applet account success: {}'.format(account_id))
|
logger.debug('Release applet account success: {}'.format(lock_key))
|
||||||
return Response({'msg': 'released'})
|
return Response({'msg': 'released'})
|
||||||
else:
|
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)
|
return Response({'error': 'not found or expired'}, status=400)
|
||||||
|
|
|
@ -199,28 +199,23 @@ class ConnectionToken(JMSOrgBaseModel):
|
||||||
if not host_account:
|
if not host_account:
|
||||||
raise JMSException({'error': 'No host account available'})
|
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
|
gateway = host.domain.select_gateway() if host.domain else None
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'id': account.id,
|
'id': lock_key,
|
||||||
'applet': applet,
|
'applet': applet,
|
||||||
'host': host,
|
'host': host,
|
||||||
'gateway': gateway,
|
'gateway': gateway,
|
||||||
'account': account,
|
'account': account,
|
||||||
'remote_app_option': self.get_remote_app_option()
|
'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
|
return data
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def release_applet_account(account_id):
|
def release_applet_account(lock_key):
|
||||||
token_account_relate_key = f'token_account_relate_{account_id}'
|
|
||||||
lock_key = cache.get(token_account_relate_key)
|
|
||||||
if lock_key:
|
if lock_key:
|
||||||
cache.delete(lock_key)
|
cache.delete(lock_key)
|
||||||
cache.delete(token_account_relate_key)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@lazyproperty
|
@lazyproperty
|
||||||
|
|
|
@ -299,8 +299,7 @@ class Applet(JMSBaseModel):
|
||||||
res = {
|
res = {
|
||||||
'host': host,
|
'host': host,
|
||||||
'account': account,
|
'account': account,
|
||||||
'lock_key': lock_key,
|
'lock_key': lock_key
|
||||||
'ttl': ttl
|
|
||||||
}
|
}
|
||||||
logger.debug('Select host and account: {}'.format(res))
|
logger.debug('Select host and account: {}'.format(res))
|
||||||
return res
|
return res
|
||||||
|
|
Loading…
Reference in New Issue