pref: 修改 connect token 一些 Url

pull/9128/head
ibuler 2022-11-28 15:01:16 +08:00
parent b2bb46a51e
commit a1d72a1746
6 changed files with 22 additions and 38 deletions

View File

@ -159,7 +159,7 @@ class RDPFileClientProtocolURLMixin:
'ip': endpoint.host,
'port': str(endpoint.ssh_port),
'username': 'JMS-{}'.format(str(token.id)),
'password': token.secret
'password': token.value
}
token = json.dumps(data)
return filename, token
@ -176,9 +176,9 @@ class ExtraActionApiMixin(RDPFileClientProtocolURLMixin):
get_serializer: callable
perform_create: callable
@action(methods=['POST', 'GET'], detail=False, url_path='rdp/file')
def get_rdp_file(self, request, *args, **kwargs):
token = self.create_connection_token()
@action(methods=['POST', 'GET'], detail=True, url_path='rdp-file')
def get_rdp_file(self, *args, **kwargs):
token = self.get_object()
token.is_valid()
filename, content = self.get_rdp_file_info(token)
filename = '{}.rdp'.format(filename)
@ -186,9 +186,9 @@ class ExtraActionApiMixin(RDPFileClientProtocolURLMixin):
response['Content-Disposition'] = 'attachment; filename*=UTF-8\'\'%s' % filename
return response
@action(methods=['POST', 'GET'], detail=False, url_path='client-url')
def get_client_protocol_url(self, request, *args, **kwargs):
token = self.create_connection_token()
@action(methods=['POST', 'GET'], detail=True, url_path='client-url')
def get_client_protocol_url(self, *args, **kwargs):
token = self.get_object()
token.is_valid()
try:
protocol_data = self.get_client_protocol_data(token)
@ -207,14 +207,6 @@ class ExtraActionApiMixin(RDPFileClientProtocolURLMixin):
instance.expire()
return Response(status=status.HTTP_204_NO_CONTENT)
def create_connection_token(self):
data = self.request.query_params if self.request.method == 'GET' else self.request.data
serializer = self.get_serializer(data=data)
serializer.is_valid(raise_exception=True)
self.perform_create(serializer)
token: ConnectionToken = serializer.instance
return token
class ConnectionTokenViewSet(ExtraActionApiMixin, RootOrgViewMixin, JMSModelViewSet):
filterset_fields = (

View File

@ -1,17 +1,17 @@
import time
from datetime import timedelta
from django.conf import settings
from django.db import models
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django.db import models
from django.conf import settings
from rest_framework.exceptions import PermissionDenied
from orgs.mixins.models import OrgModelMixin
from assets.const import Protocol
from common.db.fields import EncryptCharField
from common.db.models import JMSBaseModel
from common.utils import lazyproperty, pretty_string
from common.utils.timezone import as_current_tz
from common.db.models import JMSBaseModel
from common.db.fields import EncryptCharField
from assets.const import Protocol
from orgs.mixins.models import OrgModelMixin
def date_expired_default():
@ -21,7 +21,7 @@ def date_expired_default():
class ConnectionToken(OrgModelMixin, JMSBaseModel):
value = models.CharField(max_length=64, default='', verbose_name=_("Value"))
user = models.ForeignKey(
'users.User', on_delete=models.SET_NULL, null=True, blank=True,
'users.User', on_delete=models.SET_NULL, null=True, blank=True,
related_name='connection_tokens', verbose_name=_('User')
)
asset = models.ForeignKey(
@ -29,8 +29,8 @@ class ConnectionToken(OrgModelMixin, JMSBaseModel):
related_name='connection_tokens', verbose_name=_('Asset'),
)
account_name = models.CharField(max_length=128, verbose_name=_("Account name")) # 登录账号Name
input_username = models.CharField(max_length=128, default='', verbose_name=_("Input Username"))
input_secret = EncryptCharField(max_length=64, default='', verbose_name=_("Input Secret"))
input_username = models.CharField(max_length=128, default='', blank=True, verbose_name=_("Input Username"))
input_secret = EncryptCharField(max_length=64, default='', blank=True, verbose_name=_("Input Secret"))
protocol = models.CharField(
choices=Protocol.choices, max_length=16, default=Protocol.ssh, verbose_name=_("Protocol")
)

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:adfa9c01178d5f6490e616f62d41c71974d42f9e3bd078fcf1b3c7124384df0b
size 117024
oid sha256:4a5338177d87680e0030c77f187a06664136d5dea63c8dffc43fa686091f2da4
size 117102

View File

@ -603,14 +603,10 @@ msgid "All"
msgstr "すべて"
#: assets/models/account.py:46
#, fuzzy
#| msgid "Manually input"
msgid "Manual input"
msgstr "手動入力"
#: assets/models/account.py:47
#, fuzzy
#| msgid "Dynamic code"
msgid "Dynamic user"
msgstr "動的コード"

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:eeaa813f4ea052a1cd85b8ae5addfde6b088fd21a0261f8724d62823835512a2
size 104043
oid sha256:30ae571e06eb7d2f0fee70013a812ea3bdb8e14715e1a1f4eb5e2c92311034f8
size 104086

View File

@ -578,16 +578,12 @@ msgid "All"
msgstr "全部"
#: assets/models/account.py:46
#, fuzzy
#| msgid "Manually input"
msgid "Manual input"
msgstr "手动输入"
#: assets/models/account.py:47
#, fuzzy
#| msgid "Dynamic code"
msgid "Dynamic user"
msgstr "动态"
msgstr "动态用户"
#: assets/models/account.py:55
msgid "Su from"