diff --git a/apps/audits/signal_handlers.py b/apps/audits/signal_handlers.py index 9a33c2ef2..9741d93f6 100644 --- a/apps/audits/signal_handlers.py +++ b/apps/audits/signal_handlers.py @@ -26,9 +26,8 @@ from common.signals import django_ready from common.utils import get_request_ip, get_logger, get_syslogger from common.utils.encode import data_to_json from jumpserver.utils import current_request -from terminal.backends.command.serializers import SessionCommandSerializer from terminal.models import Session, Command -from terminal.serializers import SessionSerializer +from terminal.serializers import SessionSerializer, SessionCommandSerializer from users.models import User from users.signals import post_user_change_password from . import models, serializers diff --git a/apps/terminal/api/session/command.py b/apps/terminal/api/session/command.py index 3858aca07..86d56b026 100644 --- a/apps/terminal/api/session/command.py +++ b/apps/terminal/api/session/command.py @@ -11,11 +11,12 @@ from terminal.filters import CommandFilter from orgs.utils import current_org from common.api import JMSBulkModelViewSet from common.utils import get_logger -from terminal.backends.command.serializers import InsecureCommandAlertSerializer +from terminal.serializers import ( + SessionCommandSerializer, InsecureCommandAlertSerializer +) from terminal.exceptions import StorageInvalid from terminal.backends import ( - get_command_storage, get_multi_command_storage, - SessionCommandSerializer, + get_command_storage, get_multi_command_storage ) from terminal.notifications import CommandAlertMessage diff --git a/apps/terminal/backends/__init__.py b/apps/terminal/backends/__init__.py index 4b3dbfa5f..450cc5435 100644 --- a/apps/terminal/backends/__init__.py +++ b/apps/terminal/backends/__init__.py @@ -3,8 +3,6 @@ from django.conf import settings from django.utils.functional import LazyObject from common.utils import get_logger -from .command.serializers import SessionCommandSerializer - logger = get_logger(__file__) diff --git a/apps/terminal/serializers/__init__.py b/apps/terminal/serializers/__init__.py index 019c3623c..92d535c65 100644 --- a/apps/terminal/serializers/__init__.py +++ b/apps/terminal/serializers/__init__.py @@ -1,9 +1,10 @@ # -*- coding: utf-8 -*- # -from .terminal import * +from .applet import * +from .command import * from .session import * from .storage import * from .sharing import * +from .terminal import * from .endpoint import * -from .applet import * from .applet_host import * diff --git a/apps/terminal/backends/command/serializers.py b/apps/terminal/serializers/command.py similarity index 92% rename from apps/terminal/backends/command/serializers.py rename to apps/terminal/serializers/command.py index 63920a846..e1ddba74a 100644 --- a/apps/terminal/backends/command/serializers.py +++ b/apps/terminal/serializers/command.py @@ -3,18 +3,20 @@ from django.utils.translation import ugettext_lazy as _ from rest_framework import serializers from common.utils import pretty_string -from .models import AbstractSessionCommand +from common.serializers.fields import LabeledChoiceField +from terminal.backends.command.models import AbstractSessionCommand __all__ = ['SessionCommandSerializer', 'InsecureCommandAlertSerializer'] class SimpleSessionCommandSerializer(serializers.Serializer): + """ 简单Session命令序列类, 用来提取公共字段 """ user = serializers.CharField(label=_("User")) # 限制 64 字符,见 validate_user asset = serializers.CharField(max_length=128, label=_("Asset")) input = serializers.CharField(max_length=2048, label=_("Command")) session = serializers.CharField(max_length=36, label=_("Session ID")) - risk_level = serializers.ChoiceField( + risk_level = LabeledChoiceField( required=False, label=_("Risk level"), choices=AbstractSessionCommand.RISK_LEVEL_CHOICES ) org_id = serializers.CharField(