Module: AbideDevUtils::XCCDF

Defined in:
lib/abide_dev_utils/xccdf.rb

Overview

Contains modules and classes for working with XCCDF files

Defined Under Namespace

Modules: Common Classes: Benchmark, ChangeSet, Control, Controls, ObjectContainer, Profile, Profiles, XccdfElement

Class Method Summary collapse

Class Method Details

.diff(file1, file2, opts) ⇒ Object

Diffs two xccdf files



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/abide_dev_utils/xccdf.rb', line 36

def self.diff(file1, file2, opts)
  bm1 = Benchmark.new(file1)
  bm2 = Benchmark.new(file2)
  profile = opts.fetch(:profile, nil)
  profile_diff = if profile.nil?
                   bm1.diff_profiles(bm2).each do |_, v|
                     v.transform_values! { |x| x.map!(&:to_s) }
                   end
                 else
                   bm1.diff_profiles(bm2)[profile].transform_values! { |x| x.map!(&:to_s) }
                 end
  profile_key = profile.nil? ? 'all_profiles' : profile
  {
    'benchmark' => bm1.diff_title_version(bm2),
    profile_key => profile_diff
  }
end

.gen_map(xccdf_file, **opts) ⇒ Object

Generate map for CEM



14
15
16
17
18
19
20
21
22
# File 'lib/abide_dev_utils/xccdf.rb', line 14

def self.gen_map(xccdf_file, **opts)
  type = opts.fetch(:type, 'cis')
  case type.downcase
  when 'cis'
    Benchmark.new(xccdf_file).gen_map(**opts)
  else
    raise AbideDevUtils::Errors::UnsupportedXCCDFError, "XCCDF type #{type} is unsupported!"
  end
end

.to_hiera(xccdf_file, opts) ⇒ Object

Converts and xccdf file to a Hiera representation



25
26
27
28
29
30
31
32
33
# File 'lib/abide_dev_utils/xccdf.rb', line 25

def self.to_hiera(xccdf_file, opts)
  type = opts.fetch(:type, 'cis')
  case type.downcase
  when 'cis'
    Benchmark.new(xccdf_file).to_hiera(**opts)
  else
    raise AbideDevUtils::Errors::UnsupportedXCCDFError, "XCCDF type #{type} is unsupported!"
  end
end