# File lib/hiera/backend/trocla_backend.rb, line 8 def initialize Hiera.debug('Hiera Trocla backend starting') begin require 'trocla' rescue require 'rubygems' require 'trocla' end @trocla_conf = Config[:trocla] && Config[:trocla][:config] @trocla = ::Trocla.new(@trocla_conf) end
Try to retrieve a password from a hierarchy
# File lib/hiera/backend/trocla_backend.rb, line 49 def get_password_from_hierarchy(trocla_key, format, opts, scope, order_override) answer = nil Backend.datasources(scope, order_override) do |source| key = hierarchical_key(source, trocla_key) answer = @trocla.get_password(key, format, opts) break unless answer.nil? end return answer end
returns global options for password generation
# File lib/hiera/backend/trocla_backend.rb, line 83 def global_options(format, scope, order_override) g_options = Backend.lookup('trocla_options', {}, scope, order_override, :hash) Backend.parse_answer(g_options.merge(g_options[format] || {}), scope) end
# File lib/hiera/backend/trocla_backend.rb, line 71 def hierarchical_key(source, trocla_key) "hiera/#{source}/#{trocla_key}" end
returns per key options for password generation
# File lib/hiera/backend/trocla_backend.rb, line 89 def key_options(trocla_key, format, scope, order_override) k_options = Backend.lookup('trocla_options::' + trocla_key, {}, scope, order_override, :hash) Backend.parse_answer(k_options.merge(k_options[format] || {}), scope) end
# File lib/hiera/backend/trocla_backend.rb, line 21 def lookup(key, scope, order_override, resolution_type) # return immediately if this is no trocla lookup return nil unless key[/^trocla_lookup::/] or key[/^trocla_hierarchy::/] method, format, trocla_key = key.split('::', 3) case method when 'trocla_lookup' trocla_lookup(trocla_key, format, scope, order_override) when 'trocla_hierarchy' trocla_hierarchy(trocla_key, format, scope, order_override) end end
retrieve options hash and merge the format specific settings into the defaults
# File lib/hiera/backend/trocla_backend.rb, line 76 def options(trocla_key, format, scope, order_override) g_options = global_options(format, scope, order_override) k_options = key_options(trocla_key, format, scope, order_override) g_options.merge(k_options) end
Set the password in the hierarchy at the top level or whatever level is specified in the options hash with 'order_override'
# File lib/hiera/backend/trocla_backend.rb, line 61 def set_password_in_hierarchy(trocla_key, format, opts, scope, order_override) answer = nil Backend.datasources(scope, opts['order_override']) do |source| key = hierarchical_key(source, trocla_key) answer = @trocla.password(key, format, opts) break unless answer.nil? end return answer end
# File lib/hiera/backend/trocla_backend.rb, line 41 def trocla_hierarchy(trocla_key, format, scope, order_override) opts = options(trocla_key, format, scope, order_override) tk = opts.delete('trocla_key') || trocla_key get_password_from_hierarchy(tk, format, opts, scope, order_override) || set_password_in_hierarchy(tk, format, opts, scope, order_override) end
This is a simple lookup which will return a password for the key
# File lib/hiera/backend/trocla_backend.rb, line 36 def trocla_lookup(trocla_key, format, scope, order_override) opts = options(trocla_key, format, scope, order_override) @trocla.password(opts.delete('trocla_key')||trocla_key, format, opts) end