mirror of https://github.com/jumpserver/jumpserver
fix: 添加录像存储endpoint校验逻辑
parent
9126c7780d
commit
9fee82cd14
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue