From f72ed34aa31ad15ad044ba6a7b7954efaf224014 Mon Sep 17 00:00:00 2001 From: brokensound77 Date: Wed, 8 Jul 2020 10:29:41 -0500 Subject: [PATCH 1/4] Package notice file with release --- detection_rules/packaging.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/detection_rules/packaging.py b/detection_rules/packaging.py index 9b565555494..d7863096069 100644 --- a/detection_rules/packaging.py +++ b/detection_rules/packaging.py @@ -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 @@ -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): + """Verify notices.txt is properly populated and save with package.""" + with open(NOTICE_FILE, 'r') as f: + 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: @@ -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) # 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), @@ -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) From bc96a06c4a2cf14801d0fb865ecd6e3031a76ae7 Mon Sep 17 00:00:00 2001 From: brokensound77 Date: Wed, 8 Jul 2020 10:37:41 -0500 Subject: [PATCH 2/4] update method description --- detection_rules/packaging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detection_rules/packaging.py b/detection_rules/packaging.py index d7863096069..012e44c3d0b 100644 --- a/detection_rules/packaging.py +++ b/detection_rules/packaging.py @@ -125,7 +125,7 @@ def _add_versions(self, current_versions, update_versions_lock=False): @staticmethod def _package_notice_file(save_dir): - """Verify notices.txt is properly populated and save with package.""" + """convert and save notice file with package.""" with open(NOTICE_FILE, 'r') as f: notice_txt = f.read() From 50ca68743797282014354f34f33f76e23765251c Mon Sep 17 00:00:00 2001 From: brokensound77 Date: Wed, 8 Jul 2020 10:57:49 -0500 Subject: [PATCH 3/4] always package notice file with rules --- detection_rules/packaging.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/detection_rules/packaging.py b/detection_rules/packaging.py index 012e44c3d0b..c0e69eba89c 100644 --- a/detection_rules/packaging.py +++ b/detection_rules/packaging.py @@ -126,7 +126,7 @@ def _add_versions(self, current_versions, update_versions_lock=False): @staticmethod def _package_notice_file(save_dir): """convert and save notice file with package.""" - with open(NOTICE_FILE, 'r') as f: + with open(NOTICE_FILE, 'rt') as f: notice_txt = f.read() with open(os.path.join(save_dir, 'notice.ts'), 'w') as f: @@ -164,9 +164,10 @@ def save(self, verbose=True): for rule in self.rules: rule.save(new_path=os.path.join(rules_dir, os.path.basename(rule.path))) + self._package_notice_file(rules_dir) + if self.release: self.save_release_files(extras_dir, self.changed_rules, self.new_rules) - self._package_notice_file(rules_dir) # 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), From a0ff26e37670de64b945258a8b68d89c5e8c066c Mon Sep 17 00:00:00 2001 From: Justin Ibarra Date: Wed, 8 Jul 2020 13:09:36 -0500 Subject: [PATCH 4/4] Update detection_rules/packaging.py Co-authored-by: Ross Wolf <31489089+rw-access@users.noreply.github.com> --- detection_rules/packaging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detection_rules/packaging.py b/detection_rules/packaging.py index c0e69eba89c..064f1b66439 100644 --- a/detection_rules/packaging.py +++ b/detection_rules/packaging.py @@ -125,7 +125,7 @@ def _add_versions(self, current_versions, update_versions_lock=False): @staticmethod def _package_notice_file(save_dir): - """convert and save notice file with package.""" + """Convert and save notice file with package.""" with open(NOTICE_FILE, 'rt') as f: notice_txt = f.read()