1515 def enforcement ( key , options , context )
1616 ComplianceEngine . log . level = Logger ::DEBUG
1717
18+ @compat = options [ 'compliance_markup_compatibility' ]
19+
1820 case key
1921 when 'lookup_options'
2022 return context . not_found
@@ -27,18 +29,28 @@ def enforcement(key, options, context)
2729 # If we have no profiles to work with, we can't do anything.
2830 return context . not_found if profiles . empty?
2931
30- data = ComplianceEngine ::Data . new
31- data . facts = closure_scope . lookupvar ( 'facts' )
32- data . enforcement_tolerance = enforcement_tolerance || options [ 'enforcement_tolerance' ]
33- data . open ( ComplianceEngine ::EnvironmentLoader . new ( *closure_scope . environment . full_modulepath . select { |path | File . directory? ( path ) } ) )
34-
35- unless compliance_map . empty?
36- data . open ( ComplianceEngine ::DataLoader . new ( compliance_map ) )
32+ if context . cache_has_key ( :compliance_engine )
33+ ComplianceEngine . log . debug ( 'Using cached ComplianceEngine::Data object' )
34+ data = context . cached_value ( :compliance_engine )
35+ else
36+ data = ComplianceEngine ::Data . new
37+ data . facts = closure_scope . lookupvar ( 'facts' )
38+ data . enforcement_tolerance = enforcement_tolerance || options [ 'enforcement_tolerance' ]
39+ data . open ( ComplianceEngine ::EnvironmentLoader . new ( *closure_scope . environment . full_modulepath . select { |path | File . directory? ( path ) } ) )
40+
41+ unless compliance_map . empty?
42+ data . open ( ComplianceEngine ::DataLoader . new ( compliance_map ) )
43+ end
44+ context . cache ( :compliance_engine , data )
3745 end
3846
3947 context . cache_all ( data . hiera ( profiles ) )
4048
4149 return context . interpolate ( context . cached_value ( key ) ) if context . cache_has_key ( key )
50+ # if data.hiera(profiles).key?(key)
51+ # context.cache(key, data.hiera(profiles)[key])
52+ # return context.interpolate(data.hiera(profiles)[key])
53+ # end
4254
4355 context . not_found
4456 rescue StandardError => e
@@ -52,7 +64,9 @@ def profiles
5264 profile_list = call_function ( 'lookup' , 'compliance_engine::enforcement' , { 'default_value' => [ ] } )
5365
5466 # For backwards compatibility with compliance_markup.
55- profile_list += call_function ( 'lookup' , 'compliance_markup::enforcement' , { 'default_value' => [ ] } )
67+ if @compat
68+ profile_list += call_function ( 'lookup' , 'compliance_markup::enforcement' , { 'default_value' => [ ] } )
69+ end
5670
5771 profile_list . uniq
5872 end
@@ -61,14 +75,20 @@ def compliance_map
6175 hiera_compliance_map = call_function ( 'lookup' , 'compliance_engine::compliance_map' , { 'default_value' => { } } )
6276
6377 # For backwards compatibility with compliance_markup.
64- DeepMerge . deep_merge! ( call_function ( 'lookup' , 'compliance_markup::compliance_map' , { 'default_value' => { } } ) , hiera_compliance_map )
78+ if @compat
79+ hiera_compliance_map = DeepMerge . deep_merge! ( call_function ( 'lookup' , 'compliance_markup::compliance_map' , { 'default_value' => { } } ) , hiera_compliance_map )
80+ end
81+
82+ hiera_compliance_map
6583 end
6684
6785 def enforcement_tolerance
6886 tolerance = call_function ( 'lookup' , 'compliance_engine::enforcement_tolerance' , { 'default_value' => nil } )
6987
7088 # For backwards compatibility with compliance_markup.
71- tolerance = call_function ( 'lookup' , 'compliance_markup::enforcement_tolerance_level' , { 'default_value' => nil } ) if tolerance . nil?
89+ if @compat
90+ tolerance = call_function ( 'lookup' , 'compliance_markup::enforcement_tolerance_level' , { 'default_value' => nil } ) if tolerance . nil?
91+ end
7292
7393 tolerance
7494 end
0 commit comments