Class: OpenSCAP::Xccdf::Benchmark

Inherits:
Object
  • Object
show all
Includes:
ItemCommon
Defined in:
lib/openscap/xccdf/benchmark.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ItemCommon

#description, #id, #references, #title, #version

Constructor Details

#initialize(p) ⇒ Benchmark

Returns a new instance of Benchmark.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/openscap/xccdf/benchmark.rb', line 16

def initialize p
  case p
  when OpenSCAP::Source
    @raw = OpenSCAP.xccdf_benchmark_import_source p.raw
  else
    raise OpenSCAP::OpenSCAPError,
          "Cannot initialize OpenSCAP::Xccdf::Benchmark with '#{p}'"
  end
  OpenSCAP.raise! if @raw.null?

  begin
    yield self
  ensure
    destroy
  end if block_given?
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



14
15
16
# File 'lib/openscap/xccdf/benchmark.rb', line 14

def raw
  @raw
end

Instance Method Details

#destroyObject



76
77
78
79
80
81
82
83
84
# File 'lib/openscap/xccdf/benchmark.rb', line 76

def destroy
  # Policy Model takes ownership of Xccdf::Benchmark. It is one of these lovely quirks of libopenscap
  if @policy_model
    @policy_model.destroy
  else
    OpenSCAP.xccdf_benchmark_free @raw
  end
  @raw = nil
end

#each_itemObject



49
50
51
52
53
# File 'lib/openscap/xccdf/benchmark.rb', line 49

def each_item(&)
  OpenSCAP._iterate over: OpenSCAP.xccdf_item_get_content(@raw), as: 'xccdf_item' do |pointer|
    yield OpenSCAP::Xccdf::Item.build(pointer)
  end
end

#each_profileObject



55
56
57
58
59
# File 'lib/openscap/xccdf/benchmark.rb', line 55

def each_profile(&)
  OpenSCAP._iterate over: OpenSCAP.xccdf_benchmark_get_profiles(@raw), as: 'xccdf_profile' do |pointer|
    yield OpenSCAP::Xccdf::Profile.new pointer
  end
end

#each_valueObject



61
62
63
64
65
# File 'lib/openscap/xccdf/benchmark.rb', line 61

def each_value(&)
  OpenSCAP._iterate over: OpenSCAP.xccdf_benchmark_get_values(@raw), as: 'xccdf_value' do |pointer|
    yield OpenSCAP::Xccdf::Value.new pointer
  end
end

#itemsObject



45
46
47
# File 'lib/openscap/xccdf/benchmark.rb', line 45

def items
  @items ||= items_init
end

#policy_modelObject



67
68
69
# File 'lib/openscap/xccdf/benchmark.rb', line 67

def policy_model
  @policy_model ||= PolicyModel.new self
end

#profilesObject



41
42
43
# File 'lib/openscap/xccdf/benchmark.rb', line 41

def profiles
  @profiles ||= profiles_init
end

#resolved?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/openscap/xccdf/benchmark.rb', line 33

def resolved?
  OpenSCAP.xccdf_benchmark_get_resolved @raw
end

#schema_versionObject



71
72
73
74
# File 'lib/openscap/xccdf/benchmark.rb', line 71

def schema_version
  pointer = OpenSCAP.xccdf_benchmark_get_schema_version @raw
  OpenSCAP.xccdf_version_info_get_version pointer
end

#status_currentObject



37
38
39
# File 'lib/openscap/xccdf/benchmark.rb', line 37

def status_current
  Status.new OpenSCAP.xccdf_benchmark_get_status_current(@raw)
end