openscap_parser 1.3.1 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 57e07f88ca48d82d504596ec2e4818468add46d3c66cf185157be8f72e532a6e
4
- data.tar.gz: cca3d01362ac56d18b20d1769bbc1036fdf2acfd88a1da86fdb558fb9694c8fb
3
+ metadata.gz: e421ccf596a13137a881d3e122bf990e01daeb8c22318bb4c09283264b0a5c11
4
+ data.tar.gz: 5fedddd4b213a41902e7db014ea168090ab421ad507370bc3450277cabfe9356
5
5
  SHA512:
6
- metadata.gz: f95cddb6c80df271400e5f7e43d39767a02861994b3cfff12127daf1099c109b88be6c0188cac6fac12822da1d0d516b4d7a43653d681d834eca447c595028eb
7
- data.tar.gz: b00439e3ed9853bd090f153a49440d94fdd0ad62fc3af5aa4a12ae4f898304cc604631b35e3b973acb4e72f43c972756b7e670ba5b13b062b6c55f53c708e596
6
+ metadata.gz: 7a3ea53ee21055986e306269fe3793b574c5cf01e4f2ebd4e46b5c446b274fc791eecb16117962be2a9d0d86ddfdf35ebc9908abc1befee10381fc396d136f04
7
+ data.tar.gz: 4d5ddbc06cc09a596a19157cc03cb13bbe1848f8d2725a11cf65f3d54ce0517e3c137944fb9dd2cef962aab5a76c731a29a59e075ee223a32f6a2c52dac1fb9b
@@ -6,6 +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/value_definitions'
9
10
 
10
11
  # Mimics openscap-ruby Benchmark interface
11
12
  module OpenscapParser
@@ -15,6 +16,7 @@ module OpenscapParser
15
16
  include OpenscapParser::RuleReferences
16
17
  include OpenscapParser::Profiles
17
18
  include OpenscapParser::Groups
19
+ include OpenscapParser::ValueDefinitions
18
20
 
19
21
  def id
20
22
  @id ||= @parsed_xml['id']
@@ -48,6 +48,10 @@ module OpenscapParser
48
48
  @parent_id = parsed_xml.xpath('../@id').to_s
49
49
  end
50
50
 
51
+ def parent_ids
52
+ @parent_ids = parsed_xml.xpath('ancestor::Group/@id').map(&:value)
53
+ end
54
+
51
55
  def parent_type
52
56
  if parsed_xml.xpath("name(..)='Group'")
53
57
  @parent_type = 'Group'
@@ -83,6 +83,10 @@ module OpenscapParser
83
83
  end
84
84
  end
85
85
 
86
+ def values
87
+ parsed_xml.xpath("check/check-export").map { |r| r.at_xpath('@value-id')&.text }
88
+ end
89
+
86
90
  def to_h
87
91
  {
88
92
  :id => id,
@@ -95,7 +99,8 @@ module OpenscapParser
95
99
  :rationale => rationale,
96
100
  :identifier => rule_identifier.to_h,
97
101
  :parent_id => parent_id,
98
- :parent_type => parent_type
102
+ :parent_type => parent_type,
103
+ :values => values
99
104
  }
100
105
  end
101
106
  end
@@ -0,0 +1,58 @@
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
@@ -0,0 +1,22 @@
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
@@ -1,3 +1,3 @@
1
1
  module OpenscapParser
2
- VERSION = "1.3.1"
2
+ VERSION = "1.5.0"
3
3
  end
@@ -7,6 +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/value_definitions'
10
11
  require 'openscap_parser/rule_results'
11
12
  require 'openscap_parser/tailorings'
12
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.3.1
4
+ version: 1.5.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-11-25 00:00:00.000000000 Z
12
+ date: 2022-12-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -176,6 +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/value_definition.rb
180
+ - lib/openscap_parser/value_definitions.rb
179
181
  - lib/openscap_parser/version.rb
180
182
  - lib/openscap_parser/xml_file.rb
181
183
  - lib/openscap_parser/xml_node.rb