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')
|
||||
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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue