Package notice file with release (#32)

This commit is contained in:
Justin Ibarra
2020-07-08 13:17:42 -05:00
committed by GitHub
parent c577426510
commit 29a92f8976
+15 -7
View File
@@ -19,6 +19,7 @@ from .utils import get_path, get_etc_path
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 @@ class Package(object):
"""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."""
with open(NOTICE_FILE, 'rt') 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:
@@ -155,6 +164,8 @@ class Package(object):
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)
@@ -228,9 +239,6 @@ class Package(object):
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)