Class: Proxy::OpenSCAP::ContentParser

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

Instance Method Summary collapse

Constructor Details

#initialize(scap_content) ⇒ ContentParser

Returns a new instance of ContentParser.



7
8
9
10
# 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

Instance Method Details

#extract_policiesObject



12
13
14
15
16
17
18
19
20
# 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) ⇒ Object



37
38
39
40
41
42
43
44
# 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

#validateObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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