Sha256: 207206e462ec40ea7cc54194ed1648d2710641274998c9dea4be2de0942d304b
Contents?: true
Size: 1.81 KB
Versions: 1
Compression:
Stored size: 1.81 KB
Contents
require 'openscap/ds/sds' require 'openscap/source' require 'openscap/xccdf/benchmark' require 'openscap/xccdf/tailoring' module Proxy::OpenSCAP class ContentParser def initialize(scap_file, type = 'scap_content') @source = OpenSCAP::Source.new(:content => scap_file) @type = type end def cleanup @source.destroy if @source end def allowed_types { 'tailoring_file' => 'XCCDF Tailoring', 'scap_content' => 'SCAP Source Datastream' } end def extract_policies policies = {} bench = benchmark_profiles bench.profiles.each do |key, profile| policies[key] = profile.title end bench.destroy policies.to_json end def get_profiles tailoring = ::OpenSCAP::Xccdf::Tailoring.new(@source, nil) profiles = tailoring.profiles.inject({}) do |memo, (key, profile)| memo.tap { |hash| hash[key] = profile.title } end tailoring.destroy profiles.to_json end def validate errors = [] if @source.type != allowed_types[@type] errors << "Uploaded file is #{@source.type}, unexpected file type" end begin @source.validate! rescue OpenSCAP::OpenSCAPError errors << "Invalid SCAP file type" end {:errors => errors}.to_json end 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 private 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 end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
smart_proxy_openscap-0.6.5 | lib/smart_proxy_openscap/openscap_content_parser.rb |