Class: Proxy::OpenSCAP::ProfilesParser

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_proxy_openscap/profiles_parser.rb

Instance Method Summary collapse

Instance Method Details

#profiles(file_type, scap_file) ⇒ Object

Raises:



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/smart_proxy_openscap/profiles_parser.rb', line 7

def profiles(file_type, scap_file)
  profiles = []
  error_msg = 'Failed to parse profiles'
  begin
    case file_type
    when 'scap_content'
      profiles = ::OpenscapParser::DatastreamFile.new(scap_file).benchmark.profiles
    when 'tailoring_file'
      profiles = ::OpenscapParser::TailoringFile.new(scap_file).tailoring.profiles
    else
      raise OpenSCAPException, "Unknown file type, expected 'scap_content' or 'tailoring_file'"
    end
  rescue Nokogiri::XML::SyntaxError
    raise OpenSCAPException, error_msg
  end

  raise OpenSCAPException, error_msg if profiles.empty?

  profiles.reduce({}) do |memo, profile|
    memo.tap { |acc| acc[profile.id] = profile.title }
  end.to_json
end