Completed
Push — master ( 291ee9...9d841e )
by Matěj
20s queued 12s
created

ssg._stig.main()   B

Complexity

Conditions 5

Size

Total Lines 25
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 22
nop 0
dl 0
loc 25
rs 8.0894
c 0
b 0
f 0
1
#!/usr/bin/env python2
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
3
import sys
4
import csv
5
6
from ssg._xml import ElementTree as ET
0 ignored issues
show
Unused Code introduced by
Unused ElementTree imported from ssg._xml as ET
Loading history...
7
from ssg._xml import parse_file as parse_xml_file
8
from ssg._constants import XCCDF11_NS as xccdf_ns
9
from ssg._constants import *
0 ignored issues
show
Coding Style introduced by
The usage of wildcard imports like ssg._constants should generally be avoided.
Loading history...
Unused Code introduced by
datetime was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
os was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
JINJA_MACROS_DEFINITIONS was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
xml_version was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
datastream_namespace was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
ocil_namespace was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
oval_footer was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
oval_namespace was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
ocil_cs was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
xccdf_header was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
xccdf_footer was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
bash_system was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
ansible_system was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
puppet_system was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
anaconda_system was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
cce_uri was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
stig_ns was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
disa_srguri was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
ssg_version_uri was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
OSCAP_VENDOR was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
OSCAP_DS_STRING was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
OSCAP_GROUP was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
OSCAP_GROUP_PCIDSS was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
OSCAP_GROUP_VAL was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
OSCAP_GROUP_NON_PCI was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
XCCDF11_NS was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
XCCDF12_NS was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
min_ansible_version was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
ansible_version_requirement_pre_task_name was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
oval_header was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
timestamp was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
PKG_MANAGER_TO_SYSTEM was imported with wildcard, but is not used.
Loading history...
10
11
# This script creates a CSV file from an XCCDF file formatted in the
12
# structure of a STIG.  This should enable its ingestion into VMS,
13
# as well as its comparison with VMS output.
14
15
16
def _reflist(refs):
17
    refstring = ', '.join(refs)
18
    return refstring
19
20
21
def _node_to_text(node):
22
    textslist = node.xpath(".//text()")
23
    return ''.join(textslist)
24
25
26
def main():
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
27
    if len(sys.argv) < 2:
28
        print("Provide an XCCDF file to convert into a CSV file.")
29
        sys.exit(1)
30
31
    xccdffile = sys.argv[1]
32
    xccdftree = parse_xml_file(xccdffile)
33
    rules = xccdftree.findall(".//{%s}Rule" % xccdf_ns)
34
    rulewriter = csv.writer(sys.stdout, quoting=csv.QUOTE_ALL)
35
36
    for rule in rules:
37
        args = (xccdf_ns, disa_cciuri)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable disa_cciuri does not seem to be defined.
Loading history...
38
        cci_refs = [ref.text for ref in rule.findall("{%s}ident[@system='%s']"
39
                                                     % args)]
40
        srg_refs = [ref.text for ref in rule.findall("{%s}ident[@system='%s']"
41
                                                     % args)]
42
        title = rule.find("{%s}title" % xccdf_ns).text
43
        description = _node_to_text(rule.find("{%s}description" % xccdf_ns))
44
        fixtext = _node_to_text(rule.find("{%s}fixtext" % xccdf_ns))
45
        checktext = _node_to_text(rule.find(".//{%s}check-content" % xccdf_ns))
46
        row = [_reflist(cci_refs), _reflist(srg_refs), title,
47
               description, fixtext, checktext]
48
        rulewriter.writerow(row)
49
50
    sys.exit(0)
51
52
if __name__ == "__main__":
53
    main()
54