openscap_parser 1.0.2 → 1.1.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: 65cd8f383c3d40c907ecab37235ac6c50eeddced32dc9173b7b4b8e7526c869a
4
- data.tar.gz: a1150af6f99b020a31f174b83a1b405b1375dd0e37300ced57daa633988a8be1
3
+ metadata.gz: 159fcf26b6fe71666a9d057d89d772589ac8436d783b7773556121b6b5c11654
4
+ data.tar.gz: f8181135885961c284b2dabfd4de0408d8888e7cf4271da699f0e42fc0e30bf6
5
5
  SHA512:
6
- metadata.gz: 696960d718a5eefbd435af227822ce48144c07be20df1a85ec2a93c1328bba7d8f92e823b57feafe38f479a3c3b0a3f26d365595cf247cf13de3f2160b11ccda
7
- data.tar.gz: a40766e4211f052ad1ab60c1e41dbb2bb70ab26ee221aeaa5eca664287a86b5cd1cf199f1fe47a3be23372b5723c11cf394c68db13203333abf3e0639dd1f841
6
+ metadata.gz: be89da681f6a355591027ce73b0dd3a68bcbd73bcc442a2d4e21c2a51485a9e841d493bafef8757aff5f85025e0a5251d3b1519801b2fdb1343fe070b165fe6b
7
+ data.tar.gz: 8949839744c203ec9074e3069097a3d98739eb65c7a76841c117f456eb02c55c3eee1576cf3b550501012b52f549d8aaaac0f601350d5f92e37a79e2a6602117
@@ -5,6 +5,7 @@ require 'openscap_parser/xml_file'
5
5
  require 'openscap_parser/rules'
6
6
  require 'openscap_parser/profiles'
7
7
  require 'openscap_parser/rule_references'
8
+ require 'openscap_parser/groups'
8
9
 
9
10
  # Mimics openscap-ruby Benchmark interface
10
11
  module OpenscapParser
@@ -13,6 +14,7 @@ module OpenscapParser
13
14
  include OpenscapParser::Rules
14
15
  include OpenscapParser::RuleReferences
15
16
  include OpenscapParser::Profiles
17
+ include OpenscapParser::Groups
16
18
 
17
19
  def id
18
20
  @id ||= @parsed_xml['id']
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+ module OpenscapParser
3
+ class Group < XmlNode
4
+ include OpenscapParser::Util
5
+
6
+ def id
7
+ @id ||= parsed_xml['id']
8
+ end
9
+
10
+ def title
11
+ @title ||= parsed_xml.at_css('title') &&
12
+ parsed_xml.at_css('title').text
13
+ end
14
+
15
+ def description
16
+ @description ||= newline_to_whitespace(
17
+ parsed_xml.at_css('description') &&
18
+ parsed_xml.at_css('description').text || ''
19
+ )
20
+ end
21
+
22
+ def rationale
23
+ @rationale ||= newline_to_whitespace(
24
+ parsed_xml.at_css('rationale') &&
25
+ parsed_xml.at_css('rationale').text || ''
26
+ )
27
+ end
28
+
29
+ def requires
30
+ @requires ||= parsed_xml.xpath('./requires') &&
31
+ parsed_xml.xpath('./requires/@idref').flat_map do |r|
32
+ r.to_s&.split
33
+ end
34
+ end
35
+
36
+ def conflicts
37
+ @conflicts ||= parsed_xml.xpath('./conflicts') &&
38
+ parsed_xml.xpath('./conflicts/@idref').flat_map do |c|
39
+ c.to_s&.split
40
+ end
41
+ end
42
+
43
+ def selected
44
+ @selected ||= parsed_xml['selected']
45
+ end
46
+
47
+ def parent_id
48
+ @parent_id = parsed_xml.xpath('../@id').to_s
49
+ end
50
+
51
+ def parent_type
52
+ if parsed_xml.xpath("name(..)='Group'")
53
+ @parent_type = 'Group'
54
+ else
55
+ @parent_type = 'Benchmark'
56
+ end
57
+ end
58
+
59
+ def to_h
60
+ {
61
+ :id => id,
62
+ :title => title,
63
+ :description => description,
64
+ :requires => requires,
65
+ :conflicts => conflicts,
66
+ :rationale => rationale,
67
+ :selected => selected,
68
+ :parent_id => parent_id,
69
+ :parent_type => parent_type
70
+ }
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openscap_parser/group'
4
+
5
+ module OpenscapParser
6
+ # Methods related to finding and saving rule references
7
+ module Groups
8
+ def self.included(base)
9
+ base.class_eval do
10
+ def groups
11
+ @groups ||= group_nodes.map do |group_node|
12
+ OpenscapParser::Group.new(parsed_xml: group_node)
13
+ end
14
+ end
15
+
16
+ def group_nodes(xpath = './/Group')
17
+ xpath_nodes(xpath)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -29,6 +29,20 @@ module OpenscapParser
29
29
  parsed_xml.at_css('title').text
30
30
  end
31
31
 
32
+ def requires
33
+ @requires ||= parsed_xml.xpath('./requires') &&
34
+ parsed_xml.xpath('./requires/@idref').flat_map do |r|
35
+ r.to_s&.split
36
+ end
37
+ end
38
+
39
+ def conflicts
40
+ @conflicts ||= parsed_xml.xpath('./conflicts') &&
41
+ parsed_xml.xpath('./conflicts/@idref').flat_map do |c|
42
+ c.to_s&.split
43
+ end
44
+ end
45
+
32
46
  def description
33
47
  @description ||= newline_to_whitespace(
34
48
  parsed_xml.at_css('description') &&
@@ -57,15 +71,31 @@ module OpenscapParser
57
71
  @identifier_node ||= parsed_xml.at_xpath('ident')
58
72
  end
59
73
 
74
+ def parent_id
75
+ parsed_xml.xpath('../@id').to_s
76
+ end
77
+
78
+ def parent_type
79
+ if parsed_xml.xpath("name(..)='Group'")
80
+ @parent_type = 'Group'
81
+ else
82
+ @parent_type = 'Benchmark'
83
+ end
84
+ end
85
+
60
86
  def to_h
61
87
  {
62
88
  :id => id,
63
89
  :selected => selected,
64
90
  :severity => severity,
65
91
  :title => title,
92
+ :requires => requires,
93
+ :conflicts => conflicts,
66
94
  :description => description,
67
95
  :rationale => rationale,
68
- :identifier => rule_identifier.to_h
96
+ :identifier => rule_identifier.to_h,
97
+ :parent_id => parent_id,
98
+ :parent_type => parent_type
69
99
  }
70
100
  end
71
101
  end
@@ -1,3 +1,3 @@
1
1
  module OpenscapParser
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -6,6 +6,7 @@ require 'openscap_parser/benchmarks'
6
6
  require 'openscap_parser/test_results'
7
7
  require 'openscap_parser/profiles'
8
8
  require 'openscap_parser/rules'
9
+ require 'openscap_parser/groups'
9
10
  require 'openscap_parser/rule_results'
10
11
  require 'openscap_parser/tailorings'
11
12
 
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.0.2
4
+ version: 1.1.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: 2020-12-15 00:00:00.000000000 Z
12
+ date: 2022-03-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -151,6 +151,8 @@ files:
151
151
  - lib/openscap_parser/datastream_file.rb
152
152
  - lib/openscap_parser/fix.rb
153
153
  - lib/openscap_parser/fixes.rb
154
+ - lib/openscap_parser/group.rb
155
+ - lib/openscap_parser/groups.rb
154
156
  - lib/openscap_parser/oval_report.rb
155
157
  - lib/openscap_parser/profile.rb
156
158
  - lib/openscap_parser/profiles.rb
@@ -204,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
206
  - !ruby/object:Gem::Version
205
207
  version: '0'
206
208
  requirements: []
207
- rubygems_version: 3.1.4
209
+ rubygems_version: 3.2.16
208
210
  signing_key:
209
211
  specification_version: 4
210
212
  summary: Parse OpenSCAP content