class Proxy::OpenSCAP::ContentParser

Public Class Methods

new(scap_content) click to toggle source
# File lib/smart_proxy_openscap/openscap_content_parser.rb, line 7
def initialize(scap_content)
  OpenSCAP.oscap_init
  @source = OpenSCAP::Source.new(:content => scap_content)
end

Public Instance Methods

extract_policies() click to toggle source
# File lib/smart_proxy_openscap/openscap_content_parser.rb, line 12
def extract_policies
  policies = {}
  bench = benchmark_profiles
  bench.profiles.each do |key, profile|
    policies[key] = profile.title
  end
  bench.destroy
  policies.to_json
end
guide(policy) click to toggle source
# File lib/smart_proxy_openscap/openscap_content_parser.rb, line 37
def guide(policy)
  sds = OpenSCAP::DS::Sds.new @source
  sds.select_checklist
  profile_id = policy ? nil : policy
  html = sds.html_guide profile_id
  sds.destroy
  {:html => html.force_encoding('UTF-8')}.to_json
end
validate() click to toggle source
# File lib/smart_proxy_openscap/openscap_content_parser.rb, line 22
def validate
  errors = []
  allowed_type = 'SCAP Source Datastream'
  if @source.type != allowed_type
    errors << "Uploaded file is not #{allowed_type}"
  end

  begin
    @source.validate!
  rescue OpenSCAP::OpenSCAPError
    errors << "Invalid SCAP file type"
  end
  {:errors => errors}.to_json
end

Private Instance Methods

benchmark_profiles() click to toggle source
# File lib/smart_proxy_openscap/openscap_content_parser.rb, line 48
def benchmark_profiles
  sds          = ::OpenSCAP::DS::Sds.new(@source)
  bench_source = sds.select_checklist!
  benchmark = ::OpenSCAP::Xccdf::Benchmark.new(bench_source)
  sds.destroy
  benchmark
end