openscap_parser 1.0.0 → 1.0.1

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: 5bbc310b2adc402a398f0b9e8524199a91c06e0b74c2f2757a9fdae292c645c5
4
- data.tar.gz: 1d8314602c86e916aff3b19b09d88a858892635beaee738bd79177bf38434abb
3
+ metadata.gz: ec101e20e8153fa638aa705ab0bfdcf48624a8c70e74670727454f3811adc175
4
+ data.tar.gz: 0b2fe6ab34ff284a586709cc6d4a91054d54e4f41749b1fdecffd8af3cc6a37e
5
5
  SHA512:
6
- metadata.gz: f2d316e18f0d82b9597b24b306dbae8615a044648102c085170005d1eaa9737263c11ec6a3c4e8af4e355cc59a9e57f78f560fe46f11c0e2cabfd134220153d7
7
- data.tar.gz: 59f11993820161a4ece0d23df623ea3412cfb90d1895a5dd7a11fd1fa519e8eb3afbd0812c9a4a78ba1d254c74bcb58578f849ec773ace989ca91b07cffa4fab
6
+ metadata.gz: b4dc7ff782e6d0b2dc61c066462291b039f649d70fc56adef4507c99d55e90626adc839c1ac23352e39b2401011f5e7196e8b63a066d1402b3754b2fee6d94e0
7
+ data.tar.gz: 0b9141c770ba031dadb3a720e80d61ef3077895c6d6356db39ee1be5b92338b13cf935e1e7a3f83cf4c77abb05a725cb34cef7d6e0fb0c5288ce8f66a45cd7d9
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+ require 'openscap_parser/xml_node'
3
+ require 'openscap_parser/subs'
4
+
5
+ module OpenscapParser
6
+ class Fix < XmlNode
7
+ include OpenscapParser::Subs
8
+
9
+ def id
10
+ @id ||= @parsed_xml['id']
11
+ end
12
+
13
+ def system
14
+ @system ||= @parsed_xml['system']
15
+ end
16
+
17
+ def complexity
18
+ @complexity ||= @parsed_xml['complexity']
19
+ end
20
+
21
+ def disruption
22
+ @disruption ||= @parsed_xml['disruption']
23
+ end
24
+
25
+ def strategy
26
+ @strategy ||= @parsed_xml['strategy']
27
+ end
28
+
29
+ def full_text(set_values)
30
+ full_text_lines(set_values).join('')
31
+ end
32
+
33
+ def full_text_lines(set_values)
34
+ map_child_nodes(set_values).map do |text_node|
35
+ text_node.respond_to?(:text) ? text_node.text : ''
36
+ end
37
+ end
38
+
39
+ def map_child_nodes(set_values = [])
40
+ map_sub_nodes @parsed_xml.children, set_values
41
+ end
42
+
43
+ def to_h
44
+ {
45
+ :id => id,
46
+ :system => system,
47
+ :complexity => complexity,
48
+ :disruption => disruption,
49
+ :strategy => strategy,
50
+ :text => text,
51
+ :subs => subs.map(&:to_h)
52
+ }
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openscap_parser/fix'
4
+
5
+ module OpenscapParser
6
+ module Fixes
7
+ def self.included(base)
8
+ base.class_eval do
9
+ def fixes
10
+ @fixes ||= fix_nodes.map do |fix_node|
11
+ OpenscapParser::Fix.new(parsed_xml: fix_node)
12
+ end
13
+ end
14
+
15
+ def fix_nodes(xpath = ".//fix")
16
+ xpath_nodes(xpath)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -24,13 +24,6 @@ module OpenscapParser
24
24
  @parsed_xml.xpath("select[@selected='true']/@idref").map(&:text)
25
25
  end
26
26
 
27
- def set_values
28
- @set_values ||= @parsed_xml.xpath("set-value") &&
29
- @parsed_xml.xpath("set-value").map do |set_value|
30
- [set_value['idref'], set_value.text]
31
- end.to_h
32
- end
33
-
34
27
  def to_h
35
28
  { :id => id, :title => title, :description => description }
36
29
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'openscap_parser/rule_identifier'
4
4
  require 'openscap_parser/rule_references'
5
+ require 'openscap_parser/fixes'
5
6
  require 'openscap_parser/xml_file'
6
7
 
7
8
  # Mimics openscap-ruby Rule interface
@@ -9,6 +10,7 @@ module OpenscapParser
9
10
  class Rule < XmlNode
10
11
  include OpenscapParser::Util
11
12
  include OpenscapParser::RuleReferences
13
+ include OpenscapParser::Fixes
12
14
 
13
15
  def id
14
16
  @id ||= parsed_xml['id']
@@ -54,5 +56,17 @@ module OpenscapParser
54
56
  def identifier_node
55
57
  @identifier_node ||= parsed_xml.at_xpath('ident')
56
58
  end
59
+
60
+ def to_h
61
+ {
62
+ :id => id,
63
+ :selected => selected,
64
+ :severity => severity,
65
+ :title => title,
66
+ :description => description,
67
+ :rationale => rationale,
68
+ :identifier => rule_identifier.to_h
69
+ }
70
+ end
57
71
  end
58
72
  end
@@ -10,5 +10,12 @@ module OpenscapParser
10
10
  def system
11
11
  @system ||= @parsed_xml && @parsed_xml['system']
12
12
  end
13
+
14
+ def to_h
15
+ {
16
+ :label => label,
17
+ :system => system
18
+ }
19
+ end
13
20
  end
14
21
  end
@@ -22,6 +22,16 @@ module OpenscapParser
22
22
  @result ||= parsed_xml.at_xpath('result') &&
23
23
  parsed_xml.at_xpath('result').text || ''
24
24
  end
25
+
26
+ def to_h
27
+ {
28
+ :id => id,
29
+ :time => time,
30
+ :severity => severity,
31
+ :weight => weight,
32
+ :result => result
33
+ }
34
+ end
25
35
  end
26
36
  end
27
37
 
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openscap_parser/set_values'
4
+
5
+ module OpenscapParser
6
+ module Selectors
7
+ include OpenscapParser::SetValues
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ require 'openscap_parser/xml_node'
3
+
4
+ module OpenscapParser
5
+ class SetValue < XmlNode
6
+ def id
7
+ @id ||= @parsed_xml['idref']
8
+ end
9
+
10
+ def text
11
+ @text ||= @parsed_xml.text
12
+ end
13
+
14
+ def to_h
15
+ { :id => id, :text => text }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openscap_parser/set_value'
4
+
5
+ module OpenscapParser
6
+ module SetValues
7
+ def self.included(base)
8
+ base.class_eval do
9
+ def set_values
10
+ @set_values ||= set_value_nodes.map do |set_value_node|
11
+ OpenscapParser::SetValue.new(parsed_xml: set_value_node)
12
+ end
13
+ end
14
+
15
+ def set_value_nodes(xpath = ".//set-value")
16
+ xpath_nodes(xpath)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ require 'openscap_parser/xml_node'
3
+
4
+ module OpenscapParser
5
+ class Sub < XmlNode
6
+ def id
7
+ @id ||= @parsed_xml['idref']
8
+ end
9
+
10
+ def use
11
+ @use ||= @parsed_xml['use']
12
+ end
13
+
14
+ def to_h
15
+ { :id => id, :text => text, :use => use }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openscap_parser/sub'
4
+
5
+ module OpenscapParser
6
+ module Subs
7
+ def self.included(base)
8
+ base.class_eval do
9
+ def subs
10
+ return [] unless sub_nodes
11
+ @subs ||= sub_nodes.map do |xml|
12
+ Sub.new(parsed_xml: xml)
13
+ end
14
+ end
15
+
16
+ def sub_nodes(xpath = './/sub')
17
+ @sub_nodes ||= xpath_nodes(xpath)
18
+ end
19
+
20
+ def map_sub_nodes(children, set_values)
21
+ children.map do |child|
22
+ next child if child.name == 'text'
23
+ next replace_sub(Sub.new(parsed_xml: child), set_values) if child.name == 'sub'
24
+ child
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def replace_sub(sub, set_values)
31
+ set_value = set_values.find { |set_value| set_value.id == sub.id }
32
+ return unless set_value
33
+ set_value.parsed_xml.children.first
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'openscap_parser/tailorings'
4
+
3
5
  module OpenscapParser
4
6
  # A class to represent a tailoring XmlFile
5
7
  class TailoringFile < XmlFile
@@ -1,10 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'openscap_parser/rule_results'
4
+ require 'openscap_parser/selectors'
4
5
 
5
6
  module OpenscapParser
6
7
  class TestResult < XmlNode
7
8
  include OpenscapParser::RuleResults
9
+ include OpenscapParser::Selectors
8
10
 
9
11
  def target
10
12
  @target ||= parsed_xml.at_xpath('target') &&
@@ -1,3 +1,3 @@
1
1
  module OpenscapParser
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -19,6 +19,10 @@ module OpenscapParser
19
19
  @parsed_xml.remove_namespaces!
20
20
  end
21
21
 
22
+ def text
23
+ @parsed_xml.text
24
+ end
25
+
22
26
  def xpath_node(xpath)
23
27
  parsed_xml && parsed_xml.at_xpath(xpath)
24
28
  end
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = %q{Parse OpenSCAP content}
13
13
  spec.description = %q{This gem is a Ruby interface into SCAP content. It can parse SCAP datastream files (i.e. ssg-rhel7-ds.xml), scan result files output by oscap eval, and tailoring files.}
14
- spec.homepage = 'https://github.com/dLobatog/openscap_parser'
14
+ spec.homepage = 'https://github.com/OpenSCAP/openscap_parser'
15
15
  spec.license = 'MIT'
16
16
 
17
17
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
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.0
4
+ version: 1.0.1
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: 2019-10-15 00:00:00.000000000 Z
12
+ date: 2020-01-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -149,6 +149,8 @@ files:
149
149
  - lib/openscap_parser/benchmark.rb
150
150
  - lib/openscap_parser/benchmarks.rb
151
151
  - lib/openscap_parser/datastream_file.rb
152
+ - lib/openscap_parser/fix.rb
153
+ - lib/openscap_parser/fixes.rb
152
154
  - lib/openscap_parser/profile.rb
153
155
  - lib/openscap_parser/profiles.rb
154
156
  - lib/openscap_parser/rule.rb
@@ -158,6 +160,11 @@ files:
158
160
  - lib/openscap_parser/rule_result.rb
159
161
  - lib/openscap_parser/rule_results.rb
160
162
  - lib/openscap_parser/rules.rb
163
+ - lib/openscap_parser/selectors.rb
164
+ - lib/openscap_parser/set_value.rb
165
+ - lib/openscap_parser/set_values.rb
166
+ - lib/openscap_parser/sub.rb
167
+ - lib/openscap_parser/subs.rb
161
168
  - lib/openscap_parser/tailoring.rb
162
169
  - lib/openscap_parser/tailoring_file.rb
163
170
  - lib/openscap_parser/tailorings.rb
@@ -174,7 +181,7 @@ files:
174
181
  - lib/ssg/unarchiver.rb
175
182
  - lib/tasks/ssg.rake
176
183
  - openscap_parser.gemspec
177
- homepage: https://github.com/dLobatog/openscap_parser
184
+ homepage: https://github.com/OpenSCAP/openscap_parser
178
185
  licenses:
179
186
  - MIT
180
187
  metadata: {}
@@ -193,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
200
  - !ruby/object:Gem::Version
194
201
  version: '0'
195
202
  requirements: []
196
- rubygems_version: 3.0.6
203
+ rubygems_version: 3.0.3
197
204
  signing_key:
198
205
  specification_version: 4
199
206
  summary: Parse OpenSCAP content