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

ssg._checks   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 6

3 Functions

Rating   Name   Duplication   Size   Complexity  
A get_content_ref_if_exists_and_not_remote() 0 16 3
A is_cce_valid() 0 10 1
A is_content_href_remote() 0 17 2
1
import re
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
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
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
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...
Unused Code introduced by
disa_cciuri 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...
4
5
6
def get_content_ref_if_exists_and_not_remote(check):
0 ignored issues
show
Coding Style Naming introduced by
The name get_content_ref_if_exists_and_not_remote does not conform to the function naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
7
    """
8
    Given an OVAL check element, examine the ``xccdf_ns:check-content-ref``
9
10
    If it exists and it isn't remote, pass it as the return value.
11
    Otherwise, return None.
12
13
    ..see-also:: is_content_href_remote
14
    """
15
    checkcontentref = check.find("./{%s}check-content-ref" % XCCDF11_NS)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable XCCDF11_NS does not seem to be defined.
Loading history...
16
    if checkcontentref is None:
17
        return None
18
    if is_content_href_remote(checkcontentref):
0 ignored issues
show
unused-code introduced by
Unnecessary "else" after "return"
Loading history...
19
        return None
20
    else:
21
        return checkcontentref
22
23
24
def is_content_href_remote(check_content_ref):
25
    """
26
    Given an OVAL check-content-ref element, examine the 'href' attribute.
27
28
    If it starts with 'http://' or 'https://', return True, otherwise
29
    return False.
30
31
    Raises RuntimeError if the ``href`` element doesn't exist.
32
    """
33
    hrefattr = check_content_ref.get("href")
34
    if hrefattr is None:
35
        # @href attribute of <check-content-ref> is required by XCCDF standard
36
        msg = "Invalid OVAL <check-content-ref> detected - missing the " \
37
              "'href' attribute!"
38
        raise RuntimeError(msg)
39
40
    return hrefattr.startswith("http://") or hrefattr.startswith("https://")
41
42
43
def is_cce_valid(cceid):
44
    """
45
    IF CCE ID IS IN VALID FORM (either 'CCE-XXXX-X' or 'CCE-XXXXX-X'
46
    where each X is a digit, and the final X is a check-digit)
47
    based on Requirement A17:
48
49
    http://people.redhat.com/swells/nist-scap-validation/scap-val-requirements-1.2.html
50
    """
51
    match = re.match(r'^CCE-\d{4,5}-\d$', cceid)
52
    return match is not None
53