Class: Proxy::OpenSCAP::ScapProfiles

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

Instance Method Summary collapse

Instance Method Details

#benchmark_profiles(source) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/smart_proxy_openscap/scap_profiles.rb', line 43

def benchmark_profiles(source)
  sds          = ::OpenSCAP::DS::Sds.new(source)
  bench_source = sds.select_checklist!
  ::OpenSCAP::Xccdf::Benchmark.new(bench_source)
ensure
  sds.destroy if sds
end

#collect_profiles(profile_source) ⇒ Object



37
38
39
40
41
# File 'lib/smart_proxy_openscap/scap_profiles.rb', line 37

def collect_profiles(profile_source)
  profile_source.profiles.inject({}) do |memo, (key, profile)|
    memo.tap { |hash| hash[key] = profile.title.strip }
  end
end

#profiles(in_file, out_file, type) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/smart_proxy_openscap/scap_profiles.rb', line 11

def profiles(in_file, out_file, type)
  ::OpenSCAP.oscap_init
  source = ::OpenSCAP::Source.new(in_file)
  json = type == 'scap_content' ? scap_content_profiles(source) : tailoring_profiles(source)
  File.write out_file, json
ensure
  source.destroy if source
  ::OpenSCAP.oscap_cleanup
end

#scap_content_profiles(source) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/smart_proxy_openscap/scap_profiles.rb', line 21

def scap_content_profiles(source)
  bench = benchmark_profiles source
  profiles = collect_profiles bench
  profiles.to_json
ensure
  bench.destroy if bench
end

#tailoring_profiles(source) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/smart_proxy_openscap/scap_profiles.rb', line 29

def tailoring_profiles(source)
  tailoring = ::OpenSCAP::Xccdf::Tailoring.new(source, nil)
  profiles = collect_profiles tailoring
  profiles.to_json
ensure
  tailoring.destroy if tailoring
end