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

Co-authored-by: feng626 <1304903146@qq.com>
pull/8022/head
fit2bot 3 years ago committed by GitHub
parent e602bc0341
commit a936092020
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -18,7 +18,6 @@ from common.utils import get_logger
from common.exceptions import JMSException
from .models import AbstractSessionCommand
logger = get_logger(__file__)
@ -27,7 +26,7 @@ class InvalidElasticsearch(JMSException):
default_detail = _('Invalid elasticsearch config')
class CommandStore():
class CommandStore(object):
def __init__(self, config):
hosts = config.get("HOSTS")
kwargs = config.get("OTHER", {})
@ -208,7 +207,7 @@ class CommandStore():
elif org_id in (real_default_org_id, ''):
match.pop('org_id')
should.append({
'bool':{
'bool': {
'must_not': [
{
'wildcard': {'org_id': '*'}

@ -13,8 +13,6 @@ from rest_framework.validators import UniqueValidator
# Replay storage serializers
# --------------------------
def replay_storage_endpoint_format_validator(endpoint):
h = urlparse(endpoint)
if h.path:
@ -116,9 +114,8 @@ class ReplayStorageTypeAzureSerializer(serializers.Serializer):
label=_('Endpoint suffix'), allow_null=True,
)
# mapping
# mapping
replay_storage_type_serializer_classes_mapping = {
const.ReplayStorageTypeChoices.s3.value: ReplayStorageTypeS3Serializer,
const.ReplayStorageTypeChoices.ceph.value: ReplayStorageTypeCephSerializer,
@ -129,10 +126,9 @@ replay_storage_type_serializer_classes_mapping = {
const.ReplayStorageTypeChoices.cos.value: ReplayStorageTypeCOSSerializer
}
# Command storage serializers
# ---------------------------
def command_storage_es_host_format_validator(host):
h = urlparse(host)
default_error_msg = _('The address format is incorrect')
@ -151,7 +147,6 @@ def command_storage_es_host_format_validator(host):
class CommandStorageTypeESSerializer(serializers.Serializer):
hosts_help_text = '''
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)
@ -169,17 +164,14 @@ class CommandStorageTypeESSerializer(serializers.Serializer):
source='OTHER.IGNORE_VERIFY_CERTS', allow_null=True,
)
# mapping
# mapping
command_storage_type_serializer_classes_mapping = {
const.CommandStorageTypeChoices.es.value: CommandStorageTypeESSerializer
}
# BaseStorageSerializer
class BaseStorageSerializer(serializers.ModelSerializer):
storage_type_serializer_classes_mapping = {}
meta = MethodSerializer()
@ -223,8 +215,6 @@ class BaseStorageSerializer(serializers.ModelSerializer):
# CommandStorageSerializer
class CommandStorageSerializer(BaseStorageSerializer):
storage_type_serializer_classes_mapping = command_storage_type_serializer_classes_mapping
@ -236,8 +226,6 @@ class CommandStorageSerializer(BaseStorageSerializer):
# ReplayStorageSerializer
class ReplayStorageSerializer(BaseStorageSerializer):
storage_type_serializer_classes_mapping = replay_storage_type_serializer_classes_mapping

Loading…
Cancel
Save