| Total Complexity | 6 |
| Total Lines | 53 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import re |
||
|
|
|||
| 2 | |||
| 3 | from ssg._constants import * |
||
| 4 | |||
| 5 | |||
| 6 | def get_content_ref_if_exists_and_not_remote(check): |
||
| 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) |
||
| 16 | if checkcontentref is None: |
||
| 17 | return None |
||
| 18 | if is_content_href_remote(checkcontentref): |
||
| 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 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.