Class: Hiera::Backend::Simp_compliance_enforcement_backend
- Inherits:
-
Object
- Object
- Hiera::Backend::Simp_compliance_enforcement_backend
- Defined in:
- lib/hiera/backend/simp_compliance_enforcement_backend.rb
Instance Method Summary collapse
-
#cache(key, value) ⇒ Object
This cache is explicitly per-catalog.
- #cache_has_key(key) ⇒ Object
- #cached_value(key) ⇒ Object
-
#debug(message) ⇒ Object
These functions are helpers for enforcement(), that implement the different caching systems on a v3 vs v5 backend.
-
#initialize ⇒ Simp_compliance_enforcement_backend
constructor
A new instance of Simp_compliance_enforcement_backend.
- #lookup(key, scope, order_override, resolution_type, context) ⇒ Object
Constructor Details
#initialize ⇒ Simp_compliance_enforcement_backend
Returns a new instance of Simp_compliance_enforcement_backend
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/hiera/backend/simp_compliance_enforcement_backend.rb', line 4 def initialize # # Load the shared compliance_mapper codebase # filename = File.dirname(File.dirname(File.dirname(__FILE__))) + "/puppetx/simp/compliance_mapper.rb" self.instance_eval(File.read(filename), filename) # Grab the config from hiera @config = Config[:compliance_markup] end |
Instance Method Details
#cache(key, value) ⇒ Object
This cache is explicitly per-catalog
66 67 68 |
# File 'lib/hiera/backend/simp_compliance_enforcement_backend.rb', line 66 def cache(key, value) @cache[key] = value end |
#cache_has_key(key) ⇒ Object
72 73 74 |
# File 'lib/hiera/backend/simp_compliance_enforcement_backend.rb', line 72 def cache_has_key(key) @cache.key?(key) end |
#cached_value(key) ⇒ Object
69 70 71 |
# File 'lib/hiera/backend/simp_compliance_enforcement_backend.rb', line 69 def cached_value(key) @cache[key] end |
#debug(message) ⇒ Object
These functions are helpers for enforcement(), that implement the different caching systems on a v3 vs v5 backend
61 62 63 |
# File 'lib/hiera/backend/simp_compliance_enforcement_backend.rb', line 61 def debug() Hiera.debug() end |
#lookup(key, scope, order_override, resolution_type, context) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/hiera/backend/simp_compliance_enforcement_backend.rb', line 16 def lookup(key, scope, order_override, resolution_type, context) # Monkey patch the catalog *object* to add a _compliance_cache accessor # We do this to prevent environment poisoning by monkey patching the class, # and it still allows us to have a catalog scoped cache. methods = scope.catalog.methods if (methods.include?(:_compliance_cache)) @cache = scope.catalog._compliance_cache else scope.catalog.instance_eval(" def _compliance_cache=(value) @_compliance_cache = value end def _compliance_cache @_compliance_cache end") scope.catalog._compliance_cache = {} @cache = scope.catalog._compliance_cache end answer = :not_found begin answer = enforcement(key) do |lookup, default| rscope = scope.real rscope.call_function('lookup', [lookup, { "default_value" => default }]) end rescue => e unless (e.class.to_s == "ArgumentError") debug("Threw error #{e.to_s}") end throw :no_such_key end if (answer == :not_found) throw :no_such_key end return answer end |