-
Notifications
You must be signed in to change notification settings - Fork 9
Filter updated control files #51
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/usr/bin/python3 | ||
import logging | ||
import json, logging | ||
from sys import stderr | ||
from ctf import cli, diff_analysis, connect_to_labels, ContentTests, DiffLogging | ||
from ctf.diff import git_wrapper | ||
|
@@ -30,7 +30,7 @@ | |
changed_files = git_wrapper.git_diff_files(options.base_branch, | ||
new_branch=options.branch, | ||
pr_number=options.pr_number) | ||
|
||
controls_files = [] | ||
# Analyze each file separately and make set of tests for each one | ||
while True: | ||
if not changed_files: # Finish when all files are analysed | ||
|
@@ -43,6 +43,10 @@ | |
if file_record["filepath"].startswith(".github"): | ||
continue | ||
|
||
# Filter the updated control files | ||
if "controls/" in file_record["filepath"]: | ||
controls_files.append(file_record["filepath"]) | ||
|
||
try: | ||
diff_structure = diff_analysis.analyse_file(file_record) | ||
except diff_analysis.UnknownAnalysisFileType: | ||
|
@@ -55,11 +59,19 @@ | |
already_analysed.append(file_record["filepath"]) | ||
# If change affected any other file -> analyse it | ||
changed_files.extend(diff_structure.affected_files) | ||
|
||
list_of_tests = connect_to_labels.get_labels(tests, options.output) | ||
if options.output == "json": | ||
logs.print_json(list_of_tests) | ||
else: | ||
logs.print_all_logs(list_of_tests, output_format=options.output_format) | ||
|
||
# Save the updated controls to a file for syncing OSCAL catalog | ||
logger.debug(f"The updated controls: {controls_files}") | ||
if options.output == "json": | ||
controls_updates = {"controls": controls_files} | ||
try: | ||
with open('controls_updates.json', 'w', encoding='utf-8') as file: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think that would be helpful to save the output for other changes, in profiles and maybe rules? If so, we could create a generic function to save files. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeap. Sounds good. Updated. All the updates will be saved to output.json |
||
json.dump(controls_updates, file, ensure_ascii=False, indent=4) | ||
logger.debug("Controls saved to controls_updates.json successfully.") | ||
except Exception as e: | ||
logger.error(f"Error saving controls updates: {e}") | ||
logger.debug("Finished") |
Uh oh!
There was an error while loading. Please reload this page.