-
Notifications
You must be signed in to change notification settings - Fork 818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add rule break support #73
Open
flyer5200
wants to merge
5
commits into
momosecurity:master
Choose a base branch
from
flyer5200:feature/rule_match_info
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4462da7
add rule break support
2922ae7
add variable init value, adjust the break logic
b27f190
the allow_break field is compatible with the old rules
0a99f23
adjust the break logic, return the control and weight of the current …
ee3a5d8
optimize initialization method
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,8 @@ def query_handler(req_body): | |
try: | ||
assert rule_id | ||
rule_id = str(rule_id) | ||
control, weight = calculate_rule(rule_id, req_body, rules=rules, ac=ac) | ||
result = {'control': control, 'weight': weight} | ||
control, weight, custom = calculate_rule(rule_id, req_body, rules=rules, ac=ac) | ||
result = {'control': control, 'weight': weight, 'custom': custom} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个custom在目前的设计中不应该返回给业务方,这个主要是后续客服人员看的 |
||
except AssertionError: | ||
error = 'must contain rule_id' | ||
ec = 100 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,11 @@ | |
import json | ||
|
||
from django import forms | ||
from django.forms import BooleanField | ||
from django.forms.utils import flatatt | ||
from django.utils import timezone | ||
from django.utils.encoding import force_text | ||
from django.utils.html import format_html | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
from core.forms import BaseFilterForm, BaseForm | ||
|
@@ -30,11 +34,38 @@ | |
} | ||
|
||
|
||
class PrettyCheckboxWidget(forms.widgets.CheckboxInput): | ||
def render(self, name, value, attrs=None): | ||
attrs = {type: 'checkbox', name: name} | ||
final_attrs = self.build_attrs(attrs) | ||
if self.check_test(value): | ||
final_attrs['checked'] = 'checked' | ||
if not (value is True or value is False or value is None or value == ''): | ||
final_attrs['value'] = force_text(value) | ||
if 'prettycheckbox-label' in final_attrs: | ||
label = _(final_attrs.pop('prettycheckbox-label')) | ||
else: | ||
label = '' | ||
return format_html('<label for="{0}"><input{1} /> {2}</label>', attrs['id'], flatatt(final_attrs), label) | ||
|
||
|
||
class PrettyCheckboxField(BooleanField): | ||
widget = PrettyCheckboxWidget | ||
|
||
def __init__(self, *args, **kwargs): | ||
if kwargs['label']: | ||
kwargs['widget'].attrs['prettycheckbox-label'] = kwargs['label'] | ||
kwargs['label'] = '' | ||
super(PrettyCheckboxField, self).__init__(*args, **kwargs) | ||
|
||
|
||
class RulesForm(BaseForm): | ||
title = forms.CharField(label=_(u"规则名称")) | ||
describe = forms.CharField(required=False, label=_(u"规则描述"), | ||
widget=forms.Textarea) | ||
status = forms.ChoiceField(label=_(u"状态"), choices=STATUS_CHOICES) | ||
#allow_break = PrettyCheckboxField(label=_(u"允许策略短路"), widget=PrettyCheckboxWidget()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个 PrettyCheckboxField 如果没有用到的话,连同上面的一起全部删掉吧,减少无效代码量 |
||
allow_break = forms.BooleanField(label=_(u"允许策略短路"), initial=True, required=True) | ||
end_time = forms.DateTimeField() | ||
strategy = forms.ChoiceField(label=_("策略原子"), required=False) | ||
control = forms.ChoiceField(label=_("管控原子"), choices=CONTROL_CHOICES, | ||
|
@@ -131,6 +162,7 @@ def save(self, *args, **kwargs): | |
return RuleModel.create(creator_name=self.request.user.username, | ||
title=cd['title'], | ||
describe=cd['describe'], status=cd['status'], | ||
allow_break=cd['allow_break'], | ||
end_time=cd['end_time'], | ||
strategy_confs=zip(names, strategys, controls, | ||
customs, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里多了一个 ,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
另外是,需要兼容一下旧配置,此处应该给个默认值False