Skip to content

Commit a472e95

Browse files
committed
refactor: dynamically determine established benchmarks
1 parent be17ae1 commit a472e95

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/mscp/generate/baseline.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,31 @@ def collect_tags_and_benchmarks(
4646
return sorted(tags_set), benchmark_platforms
4747

4848

49+
def collect_established_benchmarks(
50+
rules: list[Macsecurityrule],
51+
) -> list[str]:
52+
"""
53+
Attempts to collect all established benchmarks in the MSCP library. An established
54+
benchmark is one where an ODV has been defined for a given benchmark.
55+
56+
Args:
57+
rules (list[Macsecurityrule]): A list of collected rules from the library.
58+
59+
Returns:
60+
list: A sorted set of discovered benchmarks
61+
"""
62+
established_benchmarks_set: set[str] = set()
63+
64+
for rule in rules:
65+
for odv in rule.odv or []:
66+
established_benchmarks_set.add(odv)
67+
68+
# remove "hint" from available benchmarks
69+
established_benchmarks_set.remove("hint")
70+
71+
return sorted(established_benchmarks_set)
72+
73+
4974
def print_keyword_summary(
5075
tags: list[str], benchmark_platforms: dict[str, set[str]]
5176
) -> None:
@@ -97,7 +122,7 @@ def generate_baseline(args: argparse.Namespace) -> None:
97122
baselines_data: dict = open_file(
98123
Path(config.get("includes_dir", ""), "800-53_baselines.yaml")
99124
)
100-
established_benchmarks: tuple[str, ...] = ("stig", "cis_lvl1", "cis_lvl2")
125+
101126
# removing misc_tags, unsure we need it.
102127
# misc_tags: tuple[str, str, str, str] = (
103128
# "permanent",
@@ -148,6 +173,8 @@ def replace_vars(text: str) -> str:
148173

149174
all_tags, benchmark_map = collect_tags_and_benchmarks(all_rules)
150175

176+
established_benchmarks: tuple[str, ...] = collect_established_benchmarks(all_rules)
177+
151178
if args.list_tags:
152179
print_keyword_summary(all_tags, benchmark_map)
153180

0 commit comments

Comments
 (0)