Class: Hiera::Backend::Http_backend

Inherits:
Object
  • Object
show all
Defined in:
lib/hiera/backend/http_backend.rb

Instance Method Summary collapse

Constructor Details

#initializeHttp_backend

Returns a new instance of Http_backend.



5
6
7
8
9
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
# File 'lib/hiera/backend/http_backend.rb', line 5

def initialize
  require 'lookup_http'
  @config = Config[:http]

  lookup_supported_params = [
    :host,
    :port,
    :output,
    :failure,
    :ignore_404,
    :headers,
    :http_connect_timeout,
    :http_read_timeout,
    :paths,
    :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

end

Instance Method Details

#lookup(key, scope, order_override, resolution_type) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
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
# File 'lib/hiera/backend/http_backend.rb', line 39

def lookup(key, scope, order_override, resolution_type)

  # 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|

    Hiera.debug("[hiera-http]: Lookup #{key} from #{@config[:host]}:#{@config[:port]}#{path}")

    result = http_get_and_parse_with_cache(path)
    result = result[key] if result.is_a?(Hash)
    next if result.nil?

    parsed_result = Backend.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