diff --git a/README.md b/README.md index ac0dfef..cee5a0c 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ Both options have common optional arguments: Output from the tool. --profile Print only profile tests. --rule Print only rule tests. + --control Print the updates of control files. ``` ### Remote vs local analysis diff --git a/content_test_filtering.py b/content_test_filtering.py index 465b2ab..b36e4df 100644 --- a/content_test_filtering.py +++ b/content_test_filtering.py @@ -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,11 @@ if file_record["filepath"].startswith(".github"): continue + # Filter the updated control files for syncing OSCAL catalog + if "controls/" in file_record["filepath"]: + control_file = file_record["filepath"].split('/')[-1] + controls_files.append(control_file) + try: diff_structure = diff_analysis.analyse_file(file_record) except diff_analysis.UnknownAnalysisFileType: @@ -55,11 +60,13 @@ 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) + logger.debug(f"The updated controls: {controls_files}") + if controls_files and options.control_output: + controls_updates = [{"controls": controls_files}] + logs.print_json(controls_updates) else: logs.print_all_logs(list_of_tests, output_format=options.output_format) - logger.debug("Finished") diff --git a/ctf/cli.py b/ctf/cli.py index ae58dfe..506a7af 100644 --- a/ctf/cli.py +++ b/ctf/cli.py @@ -37,6 +37,8 @@ def parse_args(): action="store_true", help="Print only profile tests.") common_parser.add_argument("--rule", dest="rule_output", default=False, action="store_true", help="Print only rule tests.") + common_parser.add_argument("--control", dest="control_output", default=False, + action="store_true", help="Print control updates.") parser.set_defaults(pr_number=None, branch=None)