Debian Codegraph @

tests/sce/python_is16.py

raw symbols SCIP
1 #!/usr/bin/env python3
2
3 import os, sys
4
5 # The following code is meant as a snippet and might go into a reusable package
6 # in the future. For now it's just a proof of concept that languages can employ
7 # means to make reading bound xccdf values more convenient
8
9 class XccdfValue(object):
10 """A wrapper containing all exposed XCCDF value binding data
11 """
12
13 def __init__(self, type_, name, value, operator):
14 self.type_ = type_
15 self.name = name
16 self.value = value
17 self.operator = operator
18
19 def get_xccdf_values():
20 """Parses all passed environment variables and tries to deduce XccdfValues
21
22 the result is delivered as a dict mapping value name to xccdf value wrapper
23 containing all exposed info
24 """
25
26 ret = {}
27 for key, value in os.environ.items():
28 if key.startswith("XCCDF_VALUE_"):
29 name = key[12:]
30 value = value
31 type_ = os.environ["XCCDF_TYPE_%s" % (name)]
32
33 operator = "EQUALS"
34 try:
35 operator = os.environ["XCCDF_OPERATOR_%s" % (name)]
36 except:
37 # operator is not mandatory
38 pass
39
40 wrapper = XccdfValue(type_, name, value, operator)
41 ret[name] = wrapper
42
43 return ret
44
45 values = get_xccdf_values()
46
47 passed_value = values["passed_value"]
48
49 if int(passed_value.value) == 16:
50 sys.exit(int(os.environ["XCCDF_RESULT_PASS"]))
51 else:
52 sys.exit(int(os.environ["XCCDF_RESULT_FAIL"]))
53