Class: OpenscapParser::Rule
Instance Attribute Summary
Attributes inherited from XmlNode
#namespaces
Instance Method Summary
collapse
Methods included from Fixes
included
included
Methods included from Util
#newline_to_whitespace
Methods inherited from XmlNode
#initialize, #parsed_xml, #text, #xpath_node, #xpath_nodes
Instance Method Details
#conflicts ⇒ Object
39
40
41
42
43
44
|
# File 'lib/openscap_parser/rule.rb', line 39
def conflicts
@conflicts ||= parsed_xml.xpath('./conflicts') &&
parsed_xml.xpath('./conflicts/@idref').flat_map do |c|
c.to_s&.split
end
end
|
#description ⇒ Object
46
47
48
49
50
51
|
# File 'lib/openscap_parser/rule.rb', line 46
def description
@description ||= newline_to_whitespace(
parsed_xml.at_css('description') &&
parsed_xml.at_css('description').text || ''
)
end
|
#id ⇒ Object
15
16
17
|
# File 'lib/openscap_parser/rule.rb', line 15
def id
@id ||= parsed_xml['id']
end
|
#identifier_node ⇒ Object
70
71
72
|
# File 'lib/openscap_parser/rule.rb', line 70
def identifier_node
@identifier_node ||= parsed_xml.at_xpath('ident')
end
|
#parent_id ⇒ Object
74
75
76
|
# File 'lib/openscap_parser/rule.rb', line 74
def parent_id
parsed_xml.xpath('../@id').to_s
end
|
#parent_type ⇒ Object
78
79
80
81
82
83
84
|
# File 'lib/openscap_parser/rule.rb', line 78
def parent_type
if parsed_xml.xpath("name(..)='Group'")
@parent_type = 'Group'
else
@parent_type = 'Benchmark'
end
end
|
#rationale ⇒ Object
53
54
55
56
57
58
|
# File 'lib/openscap_parser/rule.rb', line 53
def rationale
@rationale ||= newline_to_whitespace(
parsed_xml.at_css('rationale') &&
parsed_xml.at_css('rationale').text || ''
)
end
|
#requires ⇒ Object
32
33
34
35
36
37
|
# File 'lib/openscap_parser/rule.rb', line 32
def requires
@requires ||= parsed_xml.xpath('./requires') &&
parsed_xml.xpath('./requires/@idref').flat_map do |r|
r.to_s&.split
end
end
|
#rule_identifier ⇒ Object
Also known as:
identifier
65
66
67
|
# File 'lib/openscap_parser/rule.rb', line 65
def rule_identifier
@identifier ||= identifier_node && RuleIdentifier.new(parsed_xml: identifier_node)
end
|
#rule_reference_nodes(xpath = "reference") ⇒ Object
61
62
63
|
# File 'lib/openscap_parser/rule.rb', line 61
def rule_reference_nodes(xpath = "reference")
rule_reference_nodes_old(xpath)
end
|
#rule_reference_nodes_old ⇒ Object
60
|
# File 'lib/openscap_parser/rule.rb', line 60
alias :rule_reference_nodes_old :rule_reference_nodes
|
#selected ⇒ Object
19
20
21
|
# File 'lib/openscap_parser/rule.rb', line 19
def selected
@selected ||= parsed_xml['selected']
end
|
#severity ⇒ Object
23
24
25
|
# File 'lib/openscap_parser/rule.rb', line 23
def severity
@severity ||= parsed_xml['severity']
end
|
#title ⇒ Object
27
28
29
30
|
# File 'lib/openscap_parser/rule.rb', line 27
def title
@title ||= parsed_xml.at_css('title') &&
parsed_xml.at_css('title').text
end
|
#to_h ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/openscap_parser/rule.rb', line 90
def to_h
{
:id => id,
:selected => selected,
:severity => severity,
:title => title,
:requires => requires,
:conflicts => conflicts,
:description => description,
:rationale => rationale,
:identifier => rule_identifier.to_h,
:parent_id => parent_id,
:parent_type => parent_type,
:values => values
}
end
|
#values ⇒ Object
86
87
88
|
# File 'lib/openscap_parser/rule.rb', line 86
def values
parsed_xml.xpath("check/check-export").map { |r| r.at_xpath('@value-id')&.text }
end
|