-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathgenyaml.py
More file actions
44 lines (34 loc) · 1.48 KB
/
Copy pathgenyaml.py
File metadata and controls
44 lines (34 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
"""
genyaml.py can be used to create the cis-benchmarks.yaml file from the spreadsheet
('CIS-Audit-Reqs-Windows2019Server.xlsx'). So edit the spreadsheet, or the YAML
file directly to customise e.g. Subcategory names to match auditpol command output,
or change the verdicts.
"""
import pandas as pd
from collections import defaultdict
from ruamel.yaml import YAML
from ruamel.yaml.scalarstring import DoubleQuotedScalarString as dq
# Read the Excel file
excel_file = 'CIS-Audit-Reqs-Windows2019Server.xlsx'
df = pd.read_excel(excel_file, engine='openpyxl')
# Remove leading and trailing whitespace from column names
df.columns = [col.strip() for col in df.columns]
# Construct the YAML data
yaml_data = defaultdict(dict)
for _, row in df.iterrows():
category = dq(row['Category'].strip())
subcategory = dq(row['Subcategory'].strip())
# Convert "yes"/"no" to boolean values for "CIS Benchmark"
cis_benchmark = True if row['CIS Benchmark'].strip().lower() == 'yes' else False
# Remove trailing spaces and single quotes from "CIS Recommended" values, and add quotation marks
cis_recommended = dq(row['CIS Recommended'].strip().strip("'"))
yaml_data[category][subcategory] = {
dq('CIS Benchmark'): cis_benchmark,
dq('CIS Recommended'): cis_recommended
}
# Write the YAML data to a file
yaml = YAML()
yaml.indent(mapping=2, sequence=4, offset=2)
with open('cis-benchmarks.yaml', 'w') as yaml_file:
yaml.dump(dict(yaml_data), yaml_file)