openscap_parser 0.1.1 → 0.1.2

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: '052590f79683808b35a0a1ec9522ea93d1da0d44c610502f580dc641750f06a2'
4
- data.tar.gz: d3af21c11dbd5c59860cb95f1ed8fdd83215f0b6663082ebe5840fb30b1408a0
3
+ metadata.gz: 04a15bff1610dd289e619dfe869fa31f0af4309acac276aae1f5c10b15197238
4
+ data.tar.gz: 0706ef0b61d96b7d3dfa73ed7f6696caaa18bbeb6a4d81eb922ef8ca75b5f4f7
5
5
  SHA512:
6
- metadata.gz: b9b98661c7eb180e586b685a961269246f867db3b1c5cd8a51ca20fc99b60999c99586c61e4a3b9fae31b5151d6c4627b87f0495f61fab41535fc6a655e824b9
7
- data.tar.gz: 8b2644c9b9945c9b7f92fb47a1a9a6ea98e04e76248c016489c27f3703a0cf1b7a5b2d90bbf4d25503020d7ee4dee2640d05d658a5af593d48a704567c0eab17
6
+ metadata.gz: 2b066da57a23d5da4c235b97ce59c560f2c132e2275750e3861f7951905b5b56911388380aa81ff73ffe0e01c6b69b82821fa23a36738ed085548116a748b12b
7
+ data.tar.gz: 66aa26a5e7a4bf1cd89392304eb1d0cb77d4716384dd4a920684534ab4f3a5d360a0941419add841e003d724810acc08f07542ce01825a902cd2902cc5d1917d
data/.gitignore CHANGED
@@ -6,3 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ Gemfile.lock
@@ -5,6 +5,7 @@ require 'openscap_parser/rule_result'
5
5
  require 'openscap_parser/rules'
6
6
  require 'openscap_parser/version'
7
7
  require 'openscap_parser/xml_report'
8
+ require 'openscap_parser/ds'
8
9
 
9
10
  require 'date'
10
11
 
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+ require 'openscap_parser/xml_file'
3
+
4
+ module OpenscapParser
5
+ class Ds
6
+ include OpenscapParser::XmlFile
7
+
8
+ def initialize(report)
9
+ report_xml report
10
+ end
11
+
12
+ def profiles
13
+ @profiles ||= profile_nodes
14
+ end
15
+
16
+ private
17
+
18
+ def profile_nodes
19
+ @report_xml.xpath(".//Profile").map do |node|
20
+ id = node.attribute('id')&.value
21
+ title = node.at_xpath('./title')&.text
22
+ description = node.at_xpath('./description')&.text
23
+ { :id => id, :title => title, :description => description }
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,9 @@
1
+ module OpenscapParser
2
+ class Profile
3
+ attr_acessor :id, :title, :description
4
+
5
+ def to_h
6
+ { :id => id, :title => title, :description => description }
7
+ end
8
+ end
9
+ end
@@ -15,7 +15,7 @@ module OpenscapParser
15
15
  private
16
16
 
17
17
  def profile_node
18
- @report_xml.at_xpath(".//xmlns:Profile\
18
+ @report_xml.at_xpath(".//Profile\
19
19
  [contains('#{test_result_node['id']}', @id)]")
20
20
  end
21
21
 
@@ -26,6 +26,19 @@ module OpenscapParser
26
26
  def rationale
27
27
  @rationale ||= @rule_xml.at_css('rationale').children.text.delete("\n")
28
28
  end
29
+
30
+ def references
31
+ @references ||= @rule_xml.css('reference').map do |node|
32
+ { href: node['href'], label: node.text }
33
+ end
34
+ end
35
+
36
+ def identifier
37
+ @identifier ||= {
38
+ label: @rule_xml.at_css('ident')&.text,
39
+ system: (ident = @rule_xml.at_css('ident')) && ident['system']
40
+ }
41
+ end
29
42
  end
30
43
  end
31
44
 
@@ -6,7 +6,7 @@ module OpenscapParser
6
6
  def self.included(base)
7
7
  base.class_eval do
8
8
  def rule_ids
9
- test_result_node.xpath('.//xmlns:rule-result/@idref').map(&:value)
9
+ test_result_node.xpath('.//rule-result/@idref').map(&:value)
10
10
  end
11
11
 
12
12
  def rule_objects
@@ -1,3 +1,3 @@
1
1
  module OpenscapParser
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ require 'nokogiri'
3
+
4
+ module OpenscapParser
5
+ module XmlFile
6
+ def report_xml(report_contents = '')
7
+ @report_xml ||= ::Nokogiri::XML.parse(report_contents)
8
+ @report_xml.remove_namespaces!
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require 'nokogiri'
3
+ require 'openscap_parser/xml_file'
3
4
 
4
5
  module OpenscapParser
5
6
  # Methods related with parsing directly the XML from the Report
@@ -7,6 +8,8 @@ module OpenscapParser
7
8
  module XMLReport
8
9
  def self.included(base)
9
10
  base.class_eval do
11
+ include OpenscapParser::XmlFile
12
+
10
13
  def host
11
14
  @report_xml.search('target').text
12
15
  end
@@ -14,11 +17,6 @@ module OpenscapParser
14
17
  def description
15
18
  @report_xml.search('description').first.text
16
19
  end
17
-
18
- def report_xml(report_contents = '')
19
- @report_xml ||= ::Nokogiri::XML.parse(report_contents)
20
- @report_xml.remove_namespaces! if @report_xml.namespaces.keys.include? 'xmlns:arf'
21
- end
22
20
  end
23
21
  end
24
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openscap_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Lobato Garcia
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-05 00:00:00.000000000 Z
11
+ date: 2019-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -97,11 +97,14 @@ files:
97
97
  - bin/console
98
98
  - bin/setup
99
99
  - lib/openscap_parser.rb
100
+ - lib/openscap_parser/ds.rb
101
+ - lib/openscap_parser/profile.rb
100
102
  - lib/openscap_parser/profiles.rb
101
103
  - lib/openscap_parser/rule.rb
102
104
  - lib/openscap_parser/rule_result.rb
103
105
  - lib/openscap_parser/rules.rb
104
106
  - lib/openscap_parser/version.rb
107
+ - lib/openscap_parser/xml_file.rb
105
108
  - lib/openscap_parser/xml_report.rb
106
109
  - openscap_parser.gemspec
107
110
  homepage: