Skip to content
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

#506 : Fixing issue with rules in limbo due to no State set. #507

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/models/activity_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ def get_state_change(target, artifact):
o_state = Cfg_states.query.filter(Cfg_states.state == state_history.deleted[0]).first()
n_state = Cfg_states.query.filter(Cfg_states.state == state_history.added[0]).first()

if o_state.is_release_state > 0 or o_state.is_retired_state > 0 or o_state.is_staging_state > 0\
if o_state is None or o_state.is_release_state > 0 or o_state.is_retired_state > 0 or o_state.is_staging_state > 0\
or n_state.is_release_state > 0 or n_state.is_retired_state > 0 or n_state.is_staging_state > 0:
activity_text = "State for '%s' was toggled from '%s' to '%s'" \
% (artifact, o_state.state, n_state.state)
% (artifact, o_state.state if o_state is not None else 'None', n_state.state)

return activity_text

Expand Down
4 changes: 4 additions & 0 deletions app/routes/yara_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ def create_yara_rule():
rule_state = request.json.get("state", None).get("state", None)
except:
rule_state = request.json.get("state", None)
if rule_state is None:
raise Exception("State is mandatory.")

unique_rule_name_enforcement = Cfg_settings.get_setting("ENFORCE_UNIQUE_YARA_RULE_NAMES")
if unique_rule_name_enforcement and distutils.util.strtobool(unique_rule_name_enforcement):
Expand Down Expand Up @@ -497,6 +499,8 @@ def update_yara_rule(id):
rule_state = request.json.get("state", None).get("state", None)
except:
rule_state = request.json.get("state", None)
if rule_state is None:
raise Exception("State is mandatory.")

unique_rule_name_enforcement = Cfg_settings.get_setting("ENFORCE_UNIQUE_YARA_RULE_NAMES")
if unique_rule_name_enforcement and distutils.util.strtobool(unique_rule_name_enforcement):
Expand Down
2 changes: 1 addition & 1 deletion app/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def filter_entities(entity,
pass

if not include_merged:
entities = entities.filter(entity.state != 'Merged')
entities = entities.filter(or_(entity.state != 'Merged', entity.state == None))

entities = entities.filter(operator(*clauses))
filtered_entities = entities
Expand Down