Skip to content

Fix the version lock update code #1064

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

Merged
merged 2 commits into from
Mar 25, 2021
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
7 changes: 6 additions & 1 deletion detection_rules/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ def manage_versions(rules: List[TOMLRule], deprecated_rules: list = None, curren

if save_changes:
if changed_rules or (new_rules and add_new):
current_versions.update(new_rules if add_new else {})
if add_new:
for rule in new_rules:
current_versions[rule.id] = rule.contents.lock_info()
for rule in changed_rules:
current_versions[rule.id] = rule.contents.lock_info()

current_versions = OrderedDict(sorted(current_versions.items(), key=lambda x: x[1]['rule_name']))

save_etc_dump(current_versions, 'version.lock.json')
Expand Down
3 changes: 3 additions & 0 deletions detection_rules/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ def id(self) -> definitions.UUIDString:
def name(self) -> str:
return self.data.name

def lock_info(self) -> dict:
return {"rule_name": self.name, "sha256": self.sha256(), "version": self.autobumped_version}

@property
def is_dirty(self) -> Optional[bool]:
"""Determine if the rule has changed since its version was locked."""
Expand Down