Class: Proxy::OpenSCAP::ContentParser
- Inherits:
-
Object
- Object
- Proxy::OpenSCAP::ContentParser
- Defined in:
- lib/smart_proxy_openscap/openscap_content_parser.rb
Instance Method Summary collapse
- #allowed_types ⇒ Object
- #cleanup ⇒ Object
- #extract_policies ⇒ Object
- #get_profiles ⇒ Object
- #guide(policy) ⇒ Object
-
#initialize(scap_file, type = 'scap_content') ⇒ ContentParser
constructor
A new instance of ContentParser.
- #validate ⇒ Object
Constructor Details
#initialize(scap_file, type = 'scap_content') ⇒ ContentParser
Returns a new instance of ContentParser.
8 9 10 11 12 |
# File 'lib/smart_proxy_openscap/openscap_content_parser.rb', line 8 def initialize(scap_file, type = 'scap_content') OpenSCAP.oscap_init @source = OpenSCAP::Source.new(:content => scap_file) @type = type end |
Instance Method Details
#allowed_types ⇒ Object
19 20 21 22 23 24 |
# File 'lib/smart_proxy_openscap/openscap_content_parser.rb', line 19 def allowed_types { 'tailoring_file' => 'XCCDF Tailoring', 'scap_content' => 'SCAP Source Datastream' } end |
#cleanup ⇒ Object
14 15 16 17 |
# File 'lib/smart_proxy_openscap/openscap_content_parser.rb', line 14 def cleanup @source.destroy if @source OpenSCAP.oscap_cleanup end |
#extract_policies ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/smart_proxy_openscap/openscap_content_parser.rb', line 26 def extract_policies policies = {} bench = benchmark_profiles bench.profiles.each do |key, profile| policies[key] = profile.title end bench.destroy policies.to_json end |
#get_profiles ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/smart_proxy_openscap/openscap_content_parser.rb', line 36 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 |
#guide(policy) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/smart_proxy_openscap/openscap_content_parser.rb', line 60 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 ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/smart_proxy_openscap/openscap_content_parser.rb', line 45 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 |