1
|
|
|
#!/usr/bin/env python |
2
|
|
|
|
3
|
|
|
from __future__ import print_function |
4
|
|
|
|
5
|
|
|
import argparse |
6
|
|
|
import os |
7
|
|
|
import os.path |
8
|
|
|
|
9
|
|
|
import ssg.build_yaml |
10
|
|
|
import ssg.utils |
11
|
|
|
import ssg.environment |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
def parse_args(): |
15
|
|
|
parser = argparse.ArgumentParser( |
16
|
|
|
description="Converts SCAP Security Guide YAML benchmark data " |
17
|
|
|
"(benchmark, rules, groups) to XCCDF Shorthand Format" |
18
|
|
|
) |
19
|
|
|
parser.add_argument( |
20
|
|
|
"--build-config-yaml", required=True, |
21
|
|
|
help="YAML file with information about the build configuration. " |
22
|
|
|
"e.g.: ~/scap-security-guide/build/build_config.yml" |
23
|
|
|
) |
24
|
|
|
parser.add_argument( |
25
|
|
|
"--product-yaml", required=True, |
26
|
|
|
help="YAML file with information about the product we are building. " |
27
|
|
|
"e.g.: ~/scap-security-guide/rhel7/product.yml" |
28
|
|
|
) |
29
|
|
|
parser.add_argument("--output", required=True, |
30
|
|
|
help="Output XCCDF shorthand file. " |
31
|
|
|
"e.g.: /tmp/shorthand.xml") |
32
|
|
|
parser.add_argument("--resolved-base", |
33
|
|
|
help="To which directory to put processed rule/group/value YAMLs.") |
34
|
|
|
return parser.parse_args() |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
def main(): |
38
|
|
|
args = parse_args() |
39
|
|
|
|
40
|
|
|
env_yaml = ssg.environment.open_environment( |
41
|
|
|
args.build_config_yaml, args.product_yaml) |
42
|
|
|
base_dir = os.path.dirname(args.product_yaml) |
43
|
|
|
benchmark_root = ssg.utils.required_key(env_yaml, "benchmark_root") |
44
|
|
|
|
45
|
|
|
# we have to "absolutize" the paths the right way, relative to the |
46
|
|
|
# product_yaml path |
47
|
|
|
if not os.path.isabs(benchmark_root): |
48
|
|
|
benchmark_root = os.path.join(base_dir, benchmark_root) |
49
|
|
|
|
50
|
|
|
loader = ssg.build_yaml.LinearLoader( |
51
|
|
|
env_yaml, args.resolved_base) |
52
|
|
|
loader.load_compiled_content() |
53
|
|
|
loader.load_benchmark(benchmark_root) |
54
|
|
|
|
55
|
|
|
loader.export_benchmark_to_file(args.output) |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
if __name__ == "__main__": |
59
|
|
|
main() |
60
|
|
|
|