Class: Hiera::Backend::Http_backend
- Inherits:
-
Object
- Object
- Hiera::Backend::Http_backend
- Defined in:
- lib/hiera/backend/http_backend.rb
Instance Method Summary collapse
-
#initialize ⇒ Http_backend
constructor
A new instance of Http_backend.
- #lookup(key, scope, order_override, resolution_type) ⇒ Object
Constructor Details
#initialize ⇒ Http_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 38 |
# File 'lib/hiera/backend/http_backend.rb', line 5 def initialize require 'net/http' require 'net/https' @config = Config[:http] @http = Net::HTTP.new(@config[:host], @config[:port]) @http.read_timeout = @config[:http_read_timeout] || 10 @http.open_timeout = @config[:http_connect_timeout] || 10 @cache = {} @cache_timeout = @config[:cache_timeout] || 10 @cache_clean_interval = @config[:cache_clean_interval] || 3600 if @config[:use_ssl] @http.use_ssl = true if @config[:ssl_verify] == false @http.verify_mode = OpenSSL::SSL::VERIFY_NONE else @http.verify_mode = OpenSSL::SSL::VERIFY_PEER end if @config[:ssl_cert] store = OpenSSL::X509::Store.new store.add_cert(OpenSSL::X509::Certificate.new(File.read(@config[:ssl_ca_cert]))) @http.cert_store = store @http.key = OpenSSL::PKey::RSA.new(File.read(@config[:ssl_cert])) @http.cert = OpenSSL::X509::Certificate.new(File.read(@config[:ssl_key])) end else @http.use_ssl = false end end |
Instance Method Details
#lookup(key, scope, order_override, resolution_type) ⇒ Object
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 |
# File 'lib/hiera/backend/http_backend.rb', line 40 def lookup(key, scope, order_override, resolution_type) 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 |