Skip to content

Commit 6e27266

Browse files
committed
Policies are owned by policy model.
1 parent 681ced2 commit 6e27266

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

lib/openscap/xccdf/policy_model.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111

1212
require 'openscap/exceptions'
1313
require 'openscap/xccdf/benchmark'
14+
require 'openscap/xccdf/policy'
1415

1516
module OpenSCAP
1617
module Xccdf
1718
class PolicyModel
19+
attr_reader :raw
20+
1821
def initialize(b)
1922
case b
2023
when OpenSCAP::Xccdf::Benchmark
@@ -26,13 +29,36 @@ def initialize(b)
2629
OpenSCAP.raise! if @raw.null?
2730
end
2831

32+
def policies
33+
@policies ||= policies_init
34+
end
35+
2936
def destroy
3037
OpenSCAP.xccdf_policy_model_free @raw
3138
@raw = nil
3239
end
40+
41+
private
42+
43+
def policies_init
44+
policies = {}
45+
polit = OpenSCAP.xccdf_policy_model_get_policies raw
46+
while OpenSCAP.xccdf_policy_iterator_has_more polit
47+
policy_p = OpenSCAP.xccdf_policy_iterator_next polit
48+
policy = OpenSCAP::Xccdf::Policy.new policy_p
49+
policies[policy.id] = policy
50+
end
51+
OpenSCAP.xccdf_policy_iterator_free polit
52+
policies
53+
end
3354
end
3455
end
3556

3657
attach_function :xccdf_policy_model_new, [:pointer], :pointer
3758
attach_function :xccdf_policy_model_free, [:pointer], :void
59+
60+
attach_function :xccdf_policy_model_get_policies, [:pointer], :pointer
61+
attach_function :xccdf_policy_iterator_has_more, [:pointer], :bool
62+
attach_function :xccdf_policy_iterator_next, [:pointer], :pointer
63+
attach_function :xccdf_policy_iterator_free, [:pointer], :void
3864
end

0 commit comments

Comments
 (0)