Skip to content

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

Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions content_test_filtering.py
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
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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")
2 changes: 2 additions & 0 deletions ctf/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading