mirror of https://github.com/jumpserver/jumpserver
fix: 修复创建命令过滤规则失败的问题
parent
1faba95a48
commit
6adeafd1d2
|
@ -133,9 +133,10 @@ class CommandFilterRule(OrgModelMixin):
|
|||
s = r'{}'.format('|'.join(regex))
|
||||
return s
|
||||
|
||||
def compile_regex(self, regex):
|
||||
@staticmethod
|
||||
def compile_regex(regex, ignore_case):
|
||||
try:
|
||||
if self.ignore_case:
|
||||
if ignore_case:
|
||||
pattern = re.compile(regex, re.IGNORECASE)
|
||||
else:
|
||||
pattern = re.compile(regex)
|
||||
|
@ -146,7 +147,7 @@ class CommandFilterRule(OrgModelMixin):
|
|||
return True, '', pattern
|
||||
|
||||
def match(self, data):
|
||||
succeed, error, pattern = self.compile_regex(regex=self.pattern)
|
||||
succeed, error, pattern = self.compile_regex(self.pattern, self.ignore_case)
|
||||
if not succeed:
|
||||
return self.ACTION_UNKNOWN, ''
|
||||
|
||||
|
|
|
@ -66,7 +66,8 @@ class CommandFilterRuleSerializer(BulkOrgResourceModelSerializer):
|
|||
regex = CommandFilterRule.construct_command_regex(content)
|
||||
else:
|
||||
regex = content
|
||||
succeed, error, pattern = CommandFilterRule.compile_regex(regex)
|
||||
ignore_case = self.initial_data.get('ignore_case')
|
||||
succeed, error, pattern = CommandFilterRule.compile_regex(regex, ignore_case)
|
||||
if not succeed:
|
||||
raise serializers.ValidationError(error)
|
||||
return content
|
||||
|
|
Loading…
Reference in New Issue