-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RHICOMPL-2481 Adding Groups to openscap parser (#34)
- Loading branch information
1 parent
3987c65
commit 0cd8828
Showing
7 changed files
with
232,963 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# frozen_string_literal: true | ||
module OpenscapParser | ||
class Group < XmlNode | ||
include OpenscapParser::Util | ||
|
||
def id | ||
@id ||= parsed_xml['id'] | ||
end | ||
|
||
def title | ||
@title ||= parsed_xml.at_css('title') && | ||
parsed_xml.at_css('title').text | ||
end | ||
|
||
def description | ||
@description ||= newline_to_whitespace( | ||
parsed_xml.at_css('description') && | ||
parsed_xml.at_css('description').text || '' | ||
) | ||
end | ||
|
||
def rationale | ||
@rationale ||= newline_to_whitespace( | ||
parsed_xml.at_css('rationale') && | ||
parsed_xml.at_css('rationale').text || '' | ||
) | ||
end | ||
|
||
def requires | ||
@requires ||= parsed_xml.xpath('./requires') && | ||
parsed_xml.xpath('./requires/@idref').flat_map do |r| | ||
r.to_s&.split | ||
end | ||
end | ||
|
||
def conflicts | ||
@conflicts ||= parsed_xml.xpath('./conflicts') && | ||
parsed_xml.xpath('./conflicts/@idref').flat_map do |c| | ||
c.to_s&.split | ||
end | ||
end | ||
|
||
def selected | ||
@selected ||= parsed_xml['selected'] | ||
end | ||
|
||
def parent_id | ||
@parent_id = parsed_xml.xpath('../@id').to_s | ||
end | ||
|
||
def parent_type | ||
if parsed_xml.xpath("name(..)='Group'") | ||
@parent_type = 'Group' | ||
else | ||
@parent_type = 'Benchmark' | ||
end | ||
end | ||
|
||
def to_h | ||
{ | ||
:id => id, | ||
:title => title, | ||
:description => description, | ||
:requires => requires, | ||
:conflicts => conflicts, | ||
:rationale => rationale, | ||
:selected => selected, | ||
:parent_id => parent_id, | ||
:parent_type => parent_type | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'openscap_parser/group' | ||
|
||
module OpenscapParser | ||
# Methods related to finding and saving rule references | ||
module Groups | ||
def self.included(base) | ||
base.class_eval do | ||
def groups | ||
@groups ||= group_nodes.map do |group_node| | ||
OpenscapParser::Group.new(parsed_xml: group_node) | ||
end | ||
end | ||
|
||
def group_nodes(xpath = './/Group') | ||
xpath_nodes(xpath) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.