From 9fee82cd14bd2c18a5713fe1ad294cbfe2b430be Mon Sep 17 00:00:00 2001 From: Bai Date: Tue, 19 Jan 2021 19:03:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B7=BB=E5=8A=A0=E5=BD=95=E5=83=8F?= =?UTF-8?q?=E5=AD=98=E5=82=A8endpoint=E6=A0=A1=E9=AA=8C=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/terminal/serializers/storage.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/apps/terminal/serializers/storage.py b/apps/terminal/serializers/storage.py index ab4a813c7..0f3bb4df4 100644 --- a/apps/terminal/serializers/storage.py +++ b/apps/terminal/serializers/storage.py @@ -14,6 +14,13 @@ from .. import const # -------------------------- +def replay_storage_endpoint_format_validator(endpoint): + h = urlparse(endpoint) + if h.path: + raise serializers.ValidationError(_('Endpoint invalid: remove path `{}`').format(h.path)) + return endpoint + + class ReplayStorageTypeBaseSerializer(serializers.Serializer): BUCKET = serializers.CharField( required=True, max_length=1024, label=_('Bucket'), allow_null=True @@ -27,6 +34,7 @@ class ReplayStorageTypeBaseSerializer(serializers.Serializer): allow_null=True, ) ENDPOINT = serializers.CharField( + validators=[replay_storage_endpoint_format_validator], required=True, max_length=1024, label=_('Endpoint'), allow_null=True, ) @@ -38,6 +46,7 @@ class ReplayStorageTypeS3Serializer(ReplayStorageTypeBaseSerializer): Such as: http://s3.cn-north-1.amazonaws.com.cn ''' ENDPOINT = serializers.CharField( + validators=[replay_storage_endpoint_format_validator], required=True, max_length=1024, label=_('Endpoint'), help_text=_(endpoint_help_text), allow_null=True, ) @@ -67,6 +76,7 @@ class ReplayStorageTypeOSSSerializer(ReplayStorageTypeBaseSerializer): Such as: http://oss-cn-hangzhou.aliyuncs.com ''' ENDPOINT = serializers.CharField( + validators=[replay_storage_endpoint_format_validator], max_length=1024, label=_('Endpoint'), help_text=_(endpoint_help_text), allow_null=True, ) @@ -139,7 +149,7 @@ class ReplayStorageSerializer(serializers.ModelSerializer): # --------------------------- -def es_host_format_validator(host): +def command_storage_es_host_format_validator(host): h = urlparse(host) default_error_msg = _('The address format is incorrect') if h.scheme not in ['http', 'https']: @@ -163,8 +173,8 @@ class CommandStorageTypeESSerializer(serializers.Serializer): (eg: http://www.jumpserver.a.com, http://www.jumpserver.b.com) ''' HOSTS = serializers.ListField( - child=serializers.CharField(validators=[es_host_format_validator]), label=_('Hosts'), - help_text=_(hosts_help_text), allow_null=True + child=serializers.CharField(validators=[command_storage_es_host_format_validator]), + label=_('Hosts'), help_text=_(hosts_help_text), allow_null=True ) INDEX = serializers.CharField( max_length=1024, default='jumpserver', label=_('Index'), allow_null=True