openscap_parser 1.0.1 → 1.2.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 -0
- data/lib/openscap_parser/group.rb +73 -0
- data/lib/openscap_parser/groups.rb +22 -0
- data/lib/openscap_parser/oval_report.rb +24 -0
- data/lib/openscap_parser/profile.rb +23 -1
- data/lib/openscap_parser/regex_handler.rb +9 -0
- data/lib/openscap_parser/rule.rb +31 -1
- data/lib/openscap_parser/test_result_file.rb +3 -0
- data/lib/openscap_parser/version.rb +1 -1
- data/lib/openscap_parser.rb +2 -0
- data/lib/oval/definition.rb +47 -0
- data/lib/oval/definition_result.rb +17 -0
- data/lib/oval/reference.rb +21 -0
- metadata +10 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5c95f01a6f86db68b3d0561858c9d39af294872d3d0e6689f0bc6d37d39e660
|
4
|
+
data.tar.gz: c14ce4fb133683267862decac1f6db27e84f8f504026b135a04e642d849bad52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59ed3d7a867fe0b5b230943068be977ce2d4aadc5edc0df79df5b4ce2e7c817420a3251569c70155a7f4c9626d5c0b2f51e35883770f0aeb848b23d3e345adab
|
7
|
+
data.tar.gz: b0d13aabf1dd555a7a376ea74a7092815c91e591f5cb40457ff06ac6f195e379246d31a7a1a0d5bd650c087bf654d26de6ef2cf6002d2a3163ca51626f863221
|
@@ -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
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'openscap_parser/xml_file'
|
3
|
+
require 'oval/definition_result'
|
4
|
+
require 'oval/definition'
|
5
|
+
|
6
|
+
module OpenscapParser
|
7
|
+
class OvalReport < XmlFile
|
8
|
+
def definition_results
|
9
|
+
@definition_results ||= definition_result_nodes.map { |node| ::Oval::DefinitionResult.new parsed_xml: node }
|
10
|
+
end
|
11
|
+
|
12
|
+
def definition_result_nodes(xpath = "./oval_results/results/system/definitions/definition")
|
13
|
+
xpath_nodes(xpath)
|
14
|
+
end
|
15
|
+
|
16
|
+
def definitions
|
17
|
+
@definitions ||= definition_nodes.map { |node| Oval::Definition.new parsed_xml: node }
|
18
|
+
end
|
19
|
+
|
20
|
+
def definition_nodes(xpath = "./oval_results/oval_definitions/definitions/definition")
|
21
|
+
xpath_nodes(xpath)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'openscap_parser/regex_handler'
|
2
|
+
|
1
3
|
module OpenscapParser
|
2
4
|
class Profile < XmlNode
|
3
5
|
def id
|
@@ -20,7 +22,27 @@ module OpenscapParser
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def selected_rule_ids
|
23
|
-
|
25
|
+
# Look for selected rule ids where the idref contains '_rule_' that is not preceded by 'group'
|
26
|
+
@selected_rule_ids ||= @parsed_xml.xpath("select[@selected='true']
|
27
|
+
[regex(@idref, '^((?!_group_).)*?(_rule_).*$')]
|
28
|
+
/@idref", RegexHandler) &&
|
29
|
+
@parsed_xml.xpath("select[@selected='true']
|
30
|
+
[regex(@idref, '^((?!_group_).)*?(_rule_).*$')]
|
31
|
+
/@idref", RegexHandler).map(&:text)
|
32
|
+
end
|
33
|
+
|
34
|
+
def selected_group_ids
|
35
|
+
# Look for selected group ids where the idref contains '_group_' that is not preceded by 'rule'
|
36
|
+
@selected_group_ids ||= @parsed_xml.xpath("select[@selected='true']
|
37
|
+
[regex(@idref, '^((?!_rule_).)*?(_group_).*$')]
|
38
|
+
/@idref", RegexHandler) &&
|
39
|
+
@parsed_xml.xpath("select[@selected='true']
|
40
|
+
[regex(@idref, '^((?!_rule_).)*?(_group_).*$')]
|
41
|
+
/@idref", RegexHandler).map(&:text)
|
42
|
+
end
|
43
|
+
|
44
|
+
def selected_entity_ids
|
45
|
+
@selected_entity_ids ||= @parsed_xml.xpath("select[@selected='true']/@idref") &&
|
24
46
|
@parsed_xml.xpath("select[@selected='true']/@idref").map(&:text)
|
25
47
|
end
|
26
48
|
|
data/lib/openscap_parser/rule.rb
CHANGED
@@ -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
|
data/lib/openscap_parser.rb
CHANGED
@@ -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
|
|
@@ -13,6 +14,7 @@ require 'openscap_parser/xml_file'
|
|
13
14
|
require 'openscap_parser/datastream_file'
|
14
15
|
require 'openscap_parser/test_result_file'
|
15
16
|
require 'openscap_parser/tailoring_file'
|
17
|
+
require 'openscap_parser/oval_report'
|
16
18
|
|
17
19
|
require 'date'
|
18
20
|
require 'railtie' if defined?(Rails)
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "openscap_parser/xml_node"
|
2
|
+
require "oval/reference"
|
3
|
+
|
4
|
+
module Oval
|
5
|
+
class Definition < ::OpenscapParser::XmlNode
|
6
|
+
def id
|
7
|
+
@id ||= @parsed_xml['id']
|
8
|
+
end
|
9
|
+
|
10
|
+
def version
|
11
|
+
@version ||= @parsed_xml['version']
|
12
|
+
end
|
13
|
+
|
14
|
+
def klass
|
15
|
+
@klass ||= @parsed_xml['class']
|
16
|
+
end
|
17
|
+
|
18
|
+
def title
|
19
|
+
xml = @parsed_xml.at_xpath("./metadata/title")
|
20
|
+
@title ||= xml && xml.text
|
21
|
+
end
|
22
|
+
|
23
|
+
def description
|
24
|
+
xml = @parsed_xml.at_xpath("./metadata/description")
|
25
|
+
@description ||= xml && xml.text
|
26
|
+
end
|
27
|
+
|
28
|
+
def reference_nodes
|
29
|
+
@reference_nodes ||= @parsed_xml.xpath("./metadata/reference")
|
30
|
+
end
|
31
|
+
|
32
|
+
def references
|
33
|
+
@references ||= reference_nodes.map { |node| Reference.new parsed_xml: node }
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_h
|
37
|
+
{
|
38
|
+
:id => id,
|
39
|
+
:version => version,
|
40
|
+
:klass => klass,
|
41
|
+
:title => title,
|
42
|
+
:description => description,
|
43
|
+
:references => references.map(&:to_h)
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'openscap_parser/xml_node'
|
2
|
+
|
3
|
+
module Oval
|
4
|
+
class DefinitionResult < ::OpenscapParser::XmlNode
|
5
|
+
def definition_id
|
6
|
+
@definition_id ||= @parsed_xml['definition_id']
|
7
|
+
end
|
8
|
+
|
9
|
+
def result
|
10
|
+
@result ||= @parsed_xml['result']
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_h
|
14
|
+
{ :id => definition_id, :result => result }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "openscap_parser/xml_node"
|
2
|
+
|
3
|
+
module Oval
|
4
|
+
class Reference < ::OpenscapParser::XmlNode
|
5
|
+
def source
|
6
|
+
@source ||= @parsed_xml['source']
|
7
|
+
end
|
8
|
+
|
9
|
+
def ref_id
|
10
|
+
@ref_id ||= @parsed_xml['ref_id']
|
11
|
+
end
|
12
|
+
|
13
|
+
def ref_url
|
14
|
+
@ref_url ||= @parsed_xml['ref_url']
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_h
|
18
|
+
{ :source => source, :ref_id => ref_id, :ref_url => ref_url }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
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
|
4
|
+
version: 1.2.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:
|
12
|
+
date: 2022-03-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -151,8 +151,12 @@ 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
|
156
|
+
- lib/openscap_parser/oval_report.rb
|
154
157
|
- lib/openscap_parser/profile.rb
|
155
158
|
- lib/openscap_parser/profiles.rb
|
159
|
+
- lib/openscap_parser/regex_handler.rb
|
156
160
|
- lib/openscap_parser/rule.rb
|
157
161
|
- lib/openscap_parser/rule_identifier.rb
|
158
162
|
- lib/openscap_parser/rule_reference.rb
|
@@ -175,6 +179,9 @@ files:
|
|
175
179
|
- lib/openscap_parser/version.rb
|
176
180
|
- lib/openscap_parser/xml_file.rb
|
177
181
|
- lib/openscap_parser/xml_node.rb
|
182
|
+
- lib/oval/definition.rb
|
183
|
+
- lib/oval/definition_result.rb
|
184
|
+
- lib/oval/reference.rb
|
178
185
|
- lib/railtie.rb
|
179
186
|
- lib/ssg.rb
|
180
187
|
- lib/ssg/downloader.rb
|
@@ -200,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
207
|
- !ruby/object:Gem::Version
|
201
208
|
version: '0'
|
202
209
|
requirements: []
|
203
|
-
rubygems_version: 3.
|
210
|
+
rubygems_version: 3.2.16
|
204
211
|
signing_key:
|
205
212
|
specification_version: 4
|
206
213
|
summary: Parse OpenSCAP content
|