perf: 修改 connect token

pull/9128/head
ibuler 2 years ago
parent 5e503ec5b8
commit 23f3f903f5

@ -1,7 +1,6 @@
import base64 import base64
import json import json
import os import os
import time
import urllib.parse import urllib.parse
from django.http import HttpResponse from django.http import HttpResponse

@ -77,7 +77,7 @@ class ConnectionToken(OrgModelMixin, JMSBaseModel):
def permed_account(self): def permed_account(self):
from perms.utils import PermAccountUtil from perms.utils import PermAccountUtil
permed_account = PermAccountUtil().validate_permission( permed_account = PermAccountUtil().validate_permission(
self.user, self.asset, self.login self.user, self.asset, self.account_name
) )
return permed_account return permed_account
@ -100,13 +100,13 @@ class ConnectionToken(OrgModelMixin, JMSBaseModel):
is_valid = False is_valid = False
error = _('No asset or inactive asset') error = _('No asset or inactive asset')
return is_valid, error return is_valid, error
if not self.login: if not self.account_name:
error = _('No account') error = _('No account')
raise PermissionDenied(error) raise PermissionDenied(error)
if not self.permed_account or not self.permed_account.actions: if not self.permed_account or not self.permed_account.actions:
msg = 'user `{}` not has asset `{}` permission for login `{}`'.format( msg = 'user `{}` not has asset `{}` permission for login `{}`'.format(
self.user, self.asset, self.login self.user, self.asset, self.account_name
) )
raise PermissionDenied(msg) raise PermissionDenied(msg)
@ -123,10 +123,10 @@ class ConnectionToken(OrgModelMixin, JMSBaseModel):
if not self.asset: if not self.asset:
return None return None
account = self.asset.accounts.filter(name=self.login).first() account = self.asset.accounts.filter(name=self.account_name).first()
if self.login == '@INPUT' or not account: if self.account_name == '@INPUT' or not account:
return { return {
'name': self.login, 'name': self.account_name,
'username': self.username, 'username': self.username,
'secret_type': 'password', 'secret_type': 'password',
'secret': self.secret 'secret': self.secret

@ -154,7 +154,7 @@ class ConnectionTokenSecretSerializer(OrgResourceModelSerializerMixin):
class Meta: class Meta:
model = ConnectionToken model = ConnectionToken
fields = [ fields = [
'id', 'secret', 'user', 'asset', 'account', 'id', 'value', 'user', 'asset', 'account',
'protocol', 'domain', 'gateway', 'protocol', 'domain', 'gateway',
'actions', 'expire_at', 'platform', 'actions', 'expire_at', 'platform',
] ]

Loading…
Cancel
Save