perf: es相关代码格式优化 (#8020)

Co-authored-by: feng626 <1304903146@qq.com>
pull/8022/head
fit2bot 2022-04-02 13:26:18 +08:00 committed by GitHub
parent e602bc0341
commit a936092020
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 34 deletions

View File

@ -18,7 +18,6 @@ from common.utils import get_logger
from common.exceptions import JMSException from common.exceptions import JMSException
from .models import AbstractSessionCommand from .models import AbstractSessionCommand
logger = get_logger(__file__) logger = get_logger(__file__)
@ -27,7 +26,7 @@ class InvalidElasticsearch(JMSException):
default_detail = _('Invalid elasticsearch config') default_detail = _('Invalid elasticsearch config')
class CommandStore(): class CommandStore(object):
def __init__(self, config): def __init__(self, config):
hosts = config.get("HOSTS") hosts = config.get("HOSTS")
kwargs = config.get("OTHER", {}) kwargs = config.get("OTHER", {})

View File

@ -13,8 +13,6 @@ from rest_framework.validators import UniqueValidator
# Replay storage serializers # Replay storage serializers
# -------------------------- # --------------------------
def replay_storage_endpoint_format_validator(endpoint): def replay_storage_endpoint_format_validator(endpoint):
h = urlparse(endpoint) h = urlparse(endpoint)
if h.path: if h.path:
@ -116,9 +114,8 @@ class ReplayStorageTypeAzureSerializer(serializers.Serializer):
label=_('Endpoint suffix'), allow_null=True, label=_('Endpoint suffix'), allow_null=True,
) )
# mapping # mapping
replay_storage_type_serializer_classes_mapping = { replay_storage_type_serializer_classes_mapping = {
const.ReplayStorageTypeChoices.s3.value: ReplayStorageTypeS3Serializer, const.ReplayStorageTypeChoices.s3.value: ReplayStorageTypeS3Serializer,
const.ReplayStorageTypeChoices.ceph.value: ReplayStorageTypeCephSerializer, const.ReplayStorageTypeChoices.ceph.value: ReplayStorageTypeCephSerializer,
@ -129,10 +126,9 @@ replay_storage_type_serializer_classes_mapping = {
const.ReplayStorageTypeChoices.cos.value: ReplayStorageTypeCOSSerializer const.ReplayStorageTypeChoices.cos.value: ReplayStorageTypeCOSSerializer
} }
# Command storage serializers # Command storage serializers
# --------------------------- # ---------------------------
def command_storage_es_host_format_validator(host): def command_storage_es_host_format_validator(host):
h = urlparse(host) h = urlparse(host)
default_error_msg = _('The address format is incorrect') default_error_msg = _('The address format is incorrect')
@ -151,7 +147,6 @@ def command_storage_es_host_format_validator(host):
class CommandStorageTypeESSerializer(serializers.Serializer): class CommandStorageTypeESSerializer(serializers.Serializer):
hosts_help_text = ''' hosts_help_text = '''
Tip: If there are multiple hosts, use a comma (,) to separate them. <br> Tip: If there are multiple hosts, use a comma (,) to separate them. <br>
(eg: http://www.jumpserver.a.com:9100, http://www.jumpserver.b.com:9100) (eg: http://www.jumpserver.a.com:9100, http://www.jumpserver.b.com:9100)
@ -169,17 +164,14 @@ class CommandStorageTypeESSerializer(serializers.Serializer):
source='OTHER.IGNORE_VERIFY_CERTS', allow_null=True, source='OTHER.IGNORE_VERIFY_CERTS', allow_null=True,
) )
# mapping # mapping
command_storage_type_serializer_classes_mapping = { command_storage_type_serializer_classes_mapping = {
const.CommandStorageTypeChoices.es.value: CommandStorageTypeESSerializer const.CommandStorageTypeChoices.es.value: CommandStorageTypeESSerializer
} }
# BaseStorageSerializer # BaseStorageSerializer
class BaseStorageSerializer(serializers.ModelSerializer): class BaseStorageSerializer(serializers.ModelSerializer):
storage_type_serializer_classes_mapping = {} storage_type_serializer_classes_mapping = {}
meta = MethodSerializer() meta = MethodSerializer()
@ -223,8 +215,6 @@ class BaseStorageSerializer(serializers.ModelSerializer):
# CommandStorageSerializer # CommandStorageSerializer
class CommandStorageSerializer(BaseStorageSerializer): class CommandStorageSerializer(BaseStorageSerializer):
storage_type_serializer_classes_mapping = command_storage_type_serializer_classes_mapping storage_type_serializer_classes_mapping = command_storage_type_serializer_classes_mapping
@ -236,8 +226,6 @@ class CommandStorageSerializer(BaseStorageSerializer):
# ReplayStorageSerializer # ReplayStorageSerializer
class ReplayStorageSerializer(BaseStorageSerializer): class ReplayStorageSerializer(BaseStorageSerializer):
storage_type_serializer_classes_mapping = replay_storage_type_serializer_classes_mapping storage_type_serializer_classes_mapping = replay_storage_type_serializer_classes_mapping