openscap_parser 1.5.1 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/openscap_parser/benchmark.rb +2 -2
- data/lib/openscap_parser/profile.rb +12 -1
- data/lib/openscap_parser/value.rb +61 -0
- data/lib/openscap_parser/values.rb +22 -0
- data/lib/openscap_parser/version.rb +1 -1
- data/lib/openscap_parser.rb +1 -1
- metadata +4 -4
- data/lib/openscap_parser/value_definition.rb +0 -58
- data/lib/openscap_parser/value_definitions.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f10f20d16fca6f3b16000545209fcaac88b09f90543bc7e2d820aad743e74d3
|
4
|
+
data.tar.gz: 731820564df8192f546ab0b08b106a90288603c97801bbfbecd043b410223825
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9b787207f533bc039f38df9d6235e49aa22661c9f395f4f4802f8ae44e4cd9a461d3af76cf60af95b0163b268c835e163748ced0ade199619d29f718e6a78f3
|
7
|
+
data.tar.gz: b9806ee3729be9b7a8bcdaa06e7db80bb39a63e92922cc312fac3814f98a60e1c9599fe29e9590d45a55a0d5d0836e20d62009d3945c1727457e6b87c57a4bd3
|
@@ -6,7 +6,7 @@ require 'openscap_parser/rules'
|
|
6
6
|
require 'openscap_parser/profiles'
|
7
7
|
require 'openscap_parser/rule_references'
|
8
8
|
require 'openscap_parser/groups'
|
9
|
-
require 'openscap_parser/
|
9
|
+
require 'openscap_parser/values'
|
10
10
|
|
11
11
|
# Mimics openscap-ruby Benchmark interface
|
12
12
|
module OpenscapParser
|
@@ -16,7 +16,7 @@ module OpenscapParser
|
|
16
16
|
include OpenscapParser::RuleReferences
|
17
17
|
include OpenscapParser::Profiles
|
18
18
|
include OpenscapParser::Groups
|
19
|
-
include OpenscapParser::
|
19
|
+
include OpenscapParser::Values
|
20
20
|
|
21
21
|
def id
|
22
22
|
@id ||= @parsed_xml['id']
|
@@ -46,8 +46,19 @@ module OpenscapParser
|
|
46
46
|
@parsed_xml.xpath("select[@selected='true']/@idref").map(&:text)
|
47
47
|
end
|
48
48
|
|
49
|
+
def refined_values
|
50
|
+
@refined_values ||= @parsed_xml.xpath("refine-value").each_with_object({}) do |element, rv|
|
51
|
+
rv[element.at_xpath('@idref').text] = element.at_xpath('@selector').text
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
49
55
|
def to_h
|
50
|
-
{
|
56
|
+
{
|
57
|
+
:id => id,
|
58
|
+
:title => title,
|
59
|
+
:description => description,
|
60
|
+
:refined_values => refined_values
|
61
|
+
}
|
51
62
|
end
|
52
63
|
end
|
53
64
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module OpenscapParser
|
3
|
+
class Value < XmlNode
|
4
|
+
include OpenscapParser::Util
|
5
|
+
|
6
|
+
def id
|
7
|
+
@id ||= parsed_xml['id']
|
8
|
+
end
|
9
|
+
|
10
|
+
def description
|
11
|
+
@description ||= newline_to_whitespace(parsed_xml.at_css('description')&.text)
|
12
|
+
end
|
13
|
+
|
14
|
+
def title
|
15
|
+
@title ||= parsed_xml.at_css('title')&.text
|
16
|
+
end
|
17
|
+
|
18
|
+
def type
|
19
|
+
@type ||= parsed_xml['type'] || 'string'
|
20
|
+
end
|
21
|
+
|
22
|
+
def generic_selector(type, selector = nil)
|
23
|
+
cache = instance_variable_get("@#{type}")
|
24
|
+
|
25
|
+
unless cache
|
26
|
+
element_name = type.to_s.sub('_', '-')
|
27
|
+
cache = parsed_xml.xpath(element_name).each_with_object({}) do |element, elements|
|
28
|
+
elements[element.at_xpath('@selector')&.text.presence] = element&.text
|
29
|
+
end
|
30
|
+
instance_variable_set("@#{type}", cache)
|
31
|
+
end
|
32
|
+
|
33
|
+
return cache[selector] if selector
|
34
|
+
|
35
|
+
cache[nil] || cache.values.first
|
36
|
+
end
|
37
|
+
|
38
|
+
def upper_bound(selector = nil)
|
39
|
+
generic_selector(:upper_bound, selector)
|
40
|
+
end
|
41
|
+
|
42
|
+
def lower_bound(selector = nil)
|
43
|
+
generic_selector(:lower_bound, selector)
|
44
|
+
end
|
45
|
+
|
46
|
+
def value(selector = nil)
|
47
|
+
generic_selector(:value, selector)
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_h
|
51
|
+
{
|
52
|
+
:id => id,
|
53
|
+
:title => title,
|
54
|
+
:description => description,
|
55
|
+
:type => type,
|
56
|
+
:lower_bound => lower_bound,
|
57
|
+
:upper_bound => upper_bound
|
58
|
+
}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openscap_parser/value'
|
4
|
+
|
5
|
+
module OpenscapParser
|
6
|
+
# Methods related to parsing values
|
7
|
+
module Values
|
8
|
+
def self.included(base)
|
9
|
+
base.class_eval do
|
10
|
+
def values
|
11
|
+
@values ||= value_nodes.map do |vdn|
|
12
|
+
Value.new(parsed_xml: vdn)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def value_nodes(xpath = ".//Value")
|
17
|
+
xpath_nodes(xpath)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/openscap_parser.rb
CHANGED
@@ -7,7 +7,7 @@ require 'openscap_parser/test_results'
|
|
7
7
|
require 'openscap_parser/profiles'
|
8
8
|
require 'openscap_parser/rules'
|
9
9
|
require 'openscap_parser/groups'
|
10
|
-
require 'openscap_parser/
|
10
|
+
require 'openscap_parser/values'
|
11
11
|
require 'openscap_parser/rule_results'
|
12
12
|
require 'openscap_parser/tailorings'
|
13
13
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openscap_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Lobato Garcia
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-12-
|
12
|
+
date: 2022-12-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -176,8 +176,8 @@ files:
|
|
176
176
|
- lib/openscap_parser/test_result_file.rb
|
177
177
|
- lib/openscap_parser/test_results.rb
|
178
178
|
- lib/openscap_parser/util.rb
|
179
|
-
- lib/openscap_parser/
|
180
|
-
- lib/openscap_parser/
|
179
|
+
- lib/openscap_parser/value.rb
|
180
|
+
- lib/openscap_parser/values.rb
|
181
181
|
- lib/openscap_parser/version.rb
|
182
182
|
- lib/openscap_parser/xml_file.rb
|
183
183
|
- lib/openscap_parser/xml_node.rb
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module OpenscapParser
|
3
|
-
class ValueDefinition < XmlNode
|
4
|
-
include OpenscapParser::Util
|
5
|
-
|
6
|
-
def id
|
7
|
-
@id ||= parsed_xml['id']
|
8
|
-
end
|
9
|
-
|
10
|
-
def description
|
11
|
-
@description ||= newline_to_whitespace(parsed_xml.at_css('description')&.text)
|
12
|
-
end
|
13
|
-
|
14
|
-
def title
|
15
|
-
@title ||= parsed_xml.at_css('title')&.text
|
16
|
-
end
|
17
|
-
|
18
|
-
def type
|
19
|
-
@type ||= parsed_xml['type'] || 'string'
|
20
|
-
end
|
21
|
-
|
22
|
-
def lower_bound
|
23
|
-
@lower_bound ||= begin
|
24
|
-
lower_bound_element = parsed_xml.at_xpath("lower-bound[@selector='']") || parsed_xml.at_xpath('lower-bound[not(@selector)]')
|
25
|
-
lower_bound_element&.text
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def upper_bound
|
30
|
-
@upper_bound ||= begin
|
31
|
-
upper_bound_element = parsed_xml.at_xpath("upper-bound[@selector='']") || parsed_xml.at_xpath('upper-bound[not(@selector)]')
|
32
|
-
upper_bound_element&.text
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def default_value
|
37
|
-
# The default value is the value element with a empty or absent @selector
|
38
|
-
# If there is no value element with an empty or absent @selector, the first value in
|
39
|
-
# the top down processing shall be the default element
|
40
|
-
@default_value ||= begin
|
41
|
-
value_element = parsed_xml.at_xpath("value[@selector='']") || parsed_xml.at_xpath('value[not(@selector)]') || parsed_xml.xpath("value")[0]
|
42
|
-
value_element&.text
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def to_h
|
47
|
-
{
|
48
|
-
:id => id,
|
49
|
-
:title => title,
|
50
|
-
:description => description,
|
51
|
-
:type => type,
|
52
|
-
:lower_bound => lower_bound,
|
53
|
-
:upper_bound => upper_bound,
|
54
|
-
:default_value => default_value
|
55
|
-
}
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'openscap_parser/value_definition'
|
4
|
-
|
5
|
-
module OpenscapParser
|
6
|
-
# Methods related to parsing values
|
7
|
-
module ValueDefinitions
|
8
|
-
def self.included(base)
|
9
|
-
base.class_eval do
|
10
|
-
def value_definitions
|
11
|
-
@value_definitions ||= value_definition_nodes.map do |vdn|
|
12
|
-
ValueDefinition.new(parsed_xml: vdn)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def value_definition_nodes(xpath = ".//Value")
|
17
|
-
xpath_nodes(xpath)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|