|
1
|
|
|
#!/usr/bin/env python |
|
2
|
|
|
|
|
3
|
|
|
from __future__ import print_function |
|
4
|
|
|
|
|
5
|
|
|
import os |
|
6
|
|
|
import sys |
|
7
|
|
|
|
|
8
|
|
|
import ssg.build_remediations |
|
9
|
|
|
import ssg.constants |
|
10
|
|
|
import ssg.fixes |
|
11
|
|
|
import ssg.rules |
|
12
|
|
|
import ssg.utils |
|
13
|
|
|
import ssg.yaml |
|
14
|
|
|
|
|
15
|
|
|
REMEDIATION_LANGS = list(ssg.build_remediations.REMEDIATION_TO_EXT_MAP) |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
def main(): |
|
19
|
|
|
""" |
|
20
|
|
|
Walk through all known products in the ssg root specified in sys.argv[1], |
|
21
|
|
|
and ensure that all fixes in all rule directories are parsable under |
|
22
|
|
|
ssg.fixes.parse_platform(...). |
|
23
|
|
|
""" |
|
24
|
|
|
|
|
25
|
|
|
if len(sys.argv) != 2: |
|
26
|
|
|
print("Error! Must supply only path to root of ssg directory", |
|
27
|
|
|
file=sys.stderr) |
|
28
|
|
|
sys.exit(1) |
|
29
|
|
|
|
|
30
|
|
|
ssg_root = sys.argv[1] |
|
31
|
|
|
|
|
32
|
|
|
known_dirs = set() |
|
33
|
|
|
for product in ssg.constants.product_directories: |
|
34
|
|
|
product_dir = os.path.join(ssg_root, product) |
|
35
|
|
|
product_yaml_path = os.path.join(product_dir, "product.yml") |
|
36
|
|
|
product_yaml = ssg.yaml.open_raw(product_yaml_path) |
|
37
|
|
|
|
|
38
|
|
|
guide_dir = os.path.join(product_dir, product_yaml['benchmark_root']) |
|
39
|
|
|
additional_content_directories = product_yaml.get("additional_content_directories", []) |
|
40
|
|
|
add_content_dirs = [os.path.abspath(os.path.join(product_dir, rd)) for rd in additional_content_directories] |
|
41
|
|
|
|
|
42
|
|
|
for cur_dir in [guide_dir] + add_content_dirs: |
|
43
|
|
|
if cur_dir not in known_dirs: |
|
44
|
|
|
parse_platform(cur_dir) |
|
45
|
|
|
known_dirs.add(cur_dir) |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
def parse_platform(cur_dir): |
|
49
|
|
|
for rule_dir in ssg.rules.find_rule_dirs(cur_dir): |
|
50
|
|
|
for lang in REMEDIATION_LANGS: |
|
51
|
|
|
for fix in ssg.build_remediations.get_rule_dir_remediations(rule_dir, lang): |
|
52
|
|
|
fix_contents = ssg.utils.read_file_list(fix) |
|
53
|
|
|
results = ssg.fixes.parse_platform(fix_contents) |
|
54
|
|
|
|
|
55
|
|
|
assert results is not None |
|
56
|
|
|
assert isinstance(results, int) |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
if __name__ == "__main__": |
|
60
|
|
|
main() |
|
61
|
|
|
|