|
1
|
|
|
from org_fedora_oscap import common |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
class PolicyDataHandler: |
|
5
|
|
|
def __init__(self, policy_data): |
|
6
|
|
|
self._policy_data = policy_data |
|
7
|
|
|
|
|
8
|
|
|
def content_is_fetchable(self): |
|
9
|
|
|
return ( |
|
10
|
|
|
self._policy_data.content_url and |
|
11
|
|
|
self._policy_data.content_type != "scap-security-guide" |
|
12
|
|
|
) |
|
13
|
|
|
|
|
14
|
|
|
def content_defined(self): |
|
15
|
|
|
return ( |
|
16
|
|
|
self._policy_data.content_url or |
|
17
|
|
|
self._policy_data.content_type == "scap-security-guide" |
|
18
|
|
|
) |
|
19
|
|
|
|
|
20
|
|
|
def use_system_content(self): |
|
21
|
|
|
self._policy_data.clear_all() |
|
22
|
|
|
self._policy_data.content_type = "scap-security-guide" |
|
23
|
|
|
self._policy_data.content_path = common.get_ssg_path() |
|
24
|
|
|
|
|
25
|
|
|
def use_downloaded_content(self, content): |
|
26
|
|
|
preferred_content = content.get_preferred_content( |
|
27
|
|
|
self._policy_data.content_path) |
|
28
|
|
|
|
|
29
|
|
|
# We know that we have ended up with a datastream-like content, |
|
30
|
|
|
# but if we can't convert an archive to a datastream. |
|
31
|
|
|
# self._policy_data.content_type = "datastream" |
|
32
|
|
|
content_type = self._policy_data.content_type |
|
33
|
|
|
if content_type in ("archive", "rpm"): |
|
34
|
|
|
self._policy_data.content_path = str( |
|
35
|
|
|
preferred_content.relative_to(content.root)) |
|
36
|
|
|
else: |
|
37
|
|
|
self._policy_data.content_path = str(preferred_content) |
|
38
|
|
|
|
|
39
|
|
|
preferred_tailoring = content.get_preferred_tailoring( |
|
40
|
|
|
self._policy_data.tailoring_path) |
|
41
|
|
|
if content.tailoring: |
|
42
|
|
|
if content_type in ("archive", "rpm"): |
|
43
|
|
|
self._policy_data.tailoring_path = str( |
|
44
|
|
|
preferred_tailoring.relative_to(content.root)) |
|
45
|
|
|
else: |
|
46
|
|
|
self._policy_data.tailoring_path = str(preferred_tailoring) |
|
47
|
|
|
|
|
48
|
|
|
def set_url(self, url): |
|
49
|
|
|
self._policy_data.content_url = url |
|
50
|
|
|
if url.endswith(".rpm"): |
|
51
|
|
|
self._policy_data.content_type = "rpm" |
|
52
|
|
|
elif any(url.endswith(arch_type) for arch_type in common.SUPPORTED_ARCHIVES): |
|
53
|
|
|
self._policy_data.content_type = "archive" |
|
54
|
|
|
else: |
|
55
|
|
|
self._policy_data.content_type = "datastream" |
|
56
|
|
|
|