Class: Hiera::Backend::Http_eyaml_backend
- Inherits:
-
Object
- Object
- Hiera::Backend::Http_eyaml_backend
- Defined in:
- lib/hiera/backend/http_eyaml_backend.rb
Instance Method Summary collapse
-
#initialize ⇒ Http_eyaml_backend
constructor
A new instance of Http_eyaml_backend.
- #lookup(key, scope, order_override, resolution_type) ⇒ Object
Constructor Details
#initialize ⇒ Http_eyaml_backend
Returns a new instance of Http_eyaml_backend.
10 11 12 13 14 15 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 |
# File 'lib/hiera/backend/http_eyaml_backend.rb', line 10 def initialize debug("Hiera HTTP-eYAML backend starting") require 'lookup_http' @config = Config[:http_eyaml] lookup_supported_params = [ :host, :port, :output, :failure, :ignore_404, :headers, :http_connect_timeout, :http_read_timeout, :use_ssl, :ssl_ca_cert, :ssl_cert, :ssl_key, :ssl_verify, :use_auth, :auth_user, :auth_pass, ] lookup_params = @config.select { |p| lookup_supported_params.include?(p) } @lookup = LookupHttp.new(lookup_params.merge( { :debug_log => "Hiera.debug" } )) @cache = {} @cache_timeout = @config[:cache_timeout] || 10 @cache_clean_interval = @config[:cache_clean_interval] || 3600 @regex_key_match = nil if confine_keys = @config[:confine_to_keys] confine_keys.map! { |r| Regexp.new(r) } @regex_key_match = Regexp.union(confine_keys) end end |
Instance Method Details
#lookup(key, scope, order_override, resolution_type) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/hiera/backend/http_eyaml_backend.rb', line 52 def lookup(key, scope, order_override, resolution_type) (scope) debug("Looking up #{key} in HTTP-eYAML backend") require 'uri' # if confine_to_keys is configured, then only proceed if one of the # regexes matches the lookup key # if @regex_key_match return nil unless key[@regex_key_match] == key end answer = nil paths = @config[:paths].map { |p| Backend.parse_string(p, scope, { 'key' => key }) } paths.insert(0, order_override) if order_override paths.each do |path| debug("Lookup #{key} from #{@config[:host]}:#{@config[:port]}#{path}") result = http_get_and_parse_with_cache(URI.escape(path)) result = result[key] if result.is_a?(Hash) next if result.nil? parsed_result = parse_answer(result, scope) case resolution_type when :array answer ||= [] answer << parsed_result when :hash answer ||= {} answer = Backend.merge_answer(parsed_result, answer) else answer = parsed_result break end end answer end |