in security-policies/dev/update_rule_status.py [0:0]
def generate_md_table(benchmark_id):
"""
Generate Markdown table with implemented rules status for current service.
:param benchmark_id: Benchmark ID
:return: Markdown table
"""
rules_data, sections = common.parse_rules_data_from_excel(benchmark_id)
# Rename "Title" column to "Description"
rules_data.rename(columns={"Title": "Description"}, inplace=True)
# Get list of all rules in sheet
all_rules = rules_data["Rule Number"].to_list()
# Get list of implemented rules
implemented_rules = get_implemented_rules(all_rules, benchmark_id)
# Get integration tests for benchmark
test_cases = get_integration_test_cases(benchmark_id)
# Add implemented rules' and Integration Tests column to the data
for rule, total_status in implemented_rules.items():
rules_data.loc[rules_data["Rule Number"] == rule, "Status"] = total_status
rules_data.loc[rules_data["Rule Number"] == rule, "Integration Tests"] = generate_integration_test_cel(
test_cases,
rule,
)
rules_data["Section"] = rules_data["Section"].apply(
lambda section_id: sections[section_id],
)
new_order = ["Rule Number", "Section", "Description", "Status", "Integration Tests", "Type"]
rules_data = rules_data.reindex(columns=new_order)
rules_data = rules_data.sort_values("Rule Number")
rules_data["Rule Number"] = rules_data["Rule Number"].apply(
get_rule_path,
benchmark_id=benchmark_id,
implemented_rules=implemented_rules,
)
# Convert DataFrame to Markdown table
table = rules_data.to_markdown(
index=False,
tablefmt="pipe",
colalign=colalign.values(),
)
# Add table title
total_rules, total_implemented, total_status = total_rules_status(rules_data)
total_automated, automated_implemented, automated_status = automated_rules_status(
rules_data,
)
total_manual, manual_implemented, manual_status = manual_rules_status(rules_data)
total_expected_tests, implemented_tests, test_status = integration_test_status(all_rules, test_cases)
description = f"### {total_implemented}/{total_rules} implemented rules ({total_status:.0%})\n\n"
description += f"#### Automated rules: {automated_implemented}/{total_automated} ({automated_status:.0%})\n\n"
description += f"#### Manual rules: {manual_implemented}/{total_manual} ({manual_status:.0%})\n\n"
description += (
f"#### Integration Tests Coverage: {implemented_tests}/{total_expected_tests} ({test_status:.0%})\n\n"
)
total_percentage = total_status * 100
return table, description, total_percentage