Parse XML results to JSON files
after running XCCDF or OVAL scans, parses results.xml file to
results.json one in the format acceptable by our `worp` API.
vendored-in is `untangle` lib v1.1.0
(https://github.com/stchris/untangle, MIT License)
Change-Id: I87f106c4b8b678e1b125ffab832f80ee261a4781
Related-Issue: https://mirantis.jira.com/browse/PROD-23159
Related-Issue: https://mirantis.jira.com/browse/PROD-23160
diff --git a/_modules/oscap/commands.py b/_modules/oscap/commands.py
index 44c703d..6682ae3 100644
--- a/_modules/oscap/commands.py
+++ b/_modules/oscap/commands.py
@@ -2,6 +2,7 @@
import tempfile
import os
from oscap.utils import build_tailoring, normalize_id, run
+from oscap.utils import xccdf_xml_to_json, oval_xml_to_json
def oscap_has_sce():
(stdout, _, _) = run('oscap -V')
@@ -40,6 +41,9 @@
f.write(build_tailoring(pillar_data, tailoring_id))
stdout, stderr, rc = run(cmd, tempdir)
+ res_file = os.path.join(tempdir, 'results.xml')
+ if os.path.isfile(res_file):
+ xccdf_xml_to_json(res_file)
return stdout, stderr, rc, tempdir
def oval(benchmark):
@@ -48,4 +52,7 @@
cmd = cmd.format(benchmark)
stdout, stderr, rc = run(cmd, tempdir)
+ res_file = os.path.join(tempdir, 'results.xml')
+ if os.path.isfile(res_file):
+ oval_xml_to_json(res_file)
return stdout, stderr, rc, tempdir