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

Package notice file with release #32

Merged
merged 4 commits into from
Jul 8, 2020
Merged
Changes from 2 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
21 changes: 14 additions & 7 deletions detection_rules/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
RELEASE_DIR = get_path("releases")
PACKAGE_FILE = get_etc_path('packages.yml')
RULE_VERSIONS = get_etc_path('version.lock.json')
NOTICE_FILE = get_path('NOTICE.txt')


def filter_rule(rule, config_filter): # type: (Rule,dict) -> bool # rule.contents (not api), filter_dict -> match
Expand Down Expand Up @@ -122,12 +123,20 @@ def _add_versions(self, current_versions, update_versions_lock=False):
"""Add versions to rules at load time."""
return manage_versions(self.rules, current_versions=current_versions, save_changes=update_versions_lock)

@staticmethod
def _package_notice_file(save_dir):
"""convert and save notice file with package."""
brokensound77 marked this conversation as resolved.
Show resolved Hide resolved
with open(NOTICE_FILE, 'r') as f:
rw-access marked this conversation as resolved.
Show resolved Hide resolved
notice_txt = f.read()

with open(os.path.join(save_dir, 'notice.ts'), 'w') as f:
commented_notice = [' * ' + line for line in notice_txt.splitlines()]
lines = ['/* eslint-disable @kbn/eslint/require-license-header */', '', '/* @notice']
lines = lines + commented_notice + [' */', '']
f.write('\n'.join(lines))

def save_release_files(self, directory, changed_rules, new_rules):
"""Release a package."""
# TODO:
# xslx of mitre coverage
# release notes

with open(os.path.join(directory, '{}-summary.txt'.format(self.name)), 'w') as f:
f.write(self.generate_summary(changed_rules, new_rules))
with open(os.path.join(directory, '{}-consolidated.json'.format(self.name)), 'w') as f:
Expand Down Expand Up @@ -157,6 +166,7 @@ def save(self, verbose=True):

if self.release:
self.save_release_files(extras_dir, self.changed_rules, self.new_rules)
self._package_notice_file(rules_dir)
rw-access marked this conversation as resolved.
Show resolved Hide resolved

# zip all rules only and place in extras
shutil.make_archive(os.path.join(extras_dir, self.name), 'zip', root_dir=os.path.dirname(rules_dir),
Expand Down Expand Up @@ -228,9 +238,6 @@ def generate_summary(self, changed_rules, new_rules):
modified_rules = 'Modified Rules: \n{}'.format('\n'.join(' - ' + s for s in sorted(changed)) if new else 'N/A')
return '\n'.join([total, sha256, ecs_versions, indices, new_rules, modified_rules])

def generate_change_notes(self):
"""Generate change release notes."""

def bump_versions(self, save_changes=False, current_versions=None):
"""Bump the versions of all production rules included in a release and optionally save changes."""
return manage_versions(self.rules, current_versions=current_versions, save_changes=save_changes)