hiera-http 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/hiera/backend/http_backend.rb +23 -6
  2. metadata +2 -2
@@ -4,19 +4,35 @@ class Hiera
4
4
 
5
5
  def initialize
6
6
  require 'net/http'
7
+ require 'net/https'
7
8
  @config = Config[:http]
9
+
10
+ @http = Net::HTTP.new(@config[:host], @config[:port])
11
+ @http.read_timeout = @config[:http_read_timeout] || 10
12
+ @http.open_timeout = @config[:http_connect_timeout] || 10
13
+
14
+ if @config[:use_ssl]
15
+ @http.use_ssl = true
16
+ if @config[:ssl_cert]
17
+ @http.verify_mode = OpenSSL::SSL::VERIFY_PEER
18
+ store = OpenSSL::X509::Store.new
19
+ store.add_cert(OpenSSL::X509::Certificate.new(File.read(@config[:ssl_ca_cert])))
20
+ @http.cert_store = store
21
+
22
+ @http.key = OpenSSL::PKey::RSA.new(File.read(@config[:ssl_cert]))
23
+ @http.cert = OpenSSL::X509::Certificate.new(File.read(@config[:ssl_key]))
24
+ end
25
+ else
26
+ @http.use_ssl = false
27
+ end
8
28
  end
9
29
 
10
30
  def lookup(key, scope, order_override, resolution_type)
11
31
 
12
32
  answer = nil
13
33
 
14
- paths.insert(0, order_override) if order_override
15
34
  paths = @config[:paths].map { |p| Backend.parse_string(p, scope, { 'key' => key }) }
16
-
17
- http = Net::HTTP.new(@config[:host], @config[:port])
18
- http.read_timeout = @config[:http_read_timeout] || 10
19
- http.open_timeout = @config[:http_connect_timeout] || 10
35
+ paths.insert(0, order_override) if order_override
20
36
 
21
37
 
22
38
  paths.each do |path|
@@ -25,7 +41,7 @@ class Hiera
25
41
  httpreq = Net::HTTP::Get.new(path)
26
42
 
27
43
  begin
28
- httpres = http.request(httpreq)
44
+ httpres = @http.request(httpreq)
29
45
  rescue Exception => e
30
46
  Hiera.warn("[hiera-http]: Net::HTTP threw exception #{e.message}")
31
47
  raise Exception, e.message unless @config[:failure] == 'graceful'
@@ -34,6 +50,7 @@ class Hiera
34
50
 
35
51
  unless httpres.kind_of?(Net::HTTPSuccess)
36
52
  Hiera.debug("[hiera-http]: bad http response from #{@config[:host]}:#{@config[:port]}#{path}")
53
+ Hiera.debug("HTTP response code was #{httpres.code}")
37
54
  raise Exception, 'Bad HTTP response' unless @config[:failure] == 'graceful'
38
55
  next
39
56
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiera-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-21 00:00:00.000000000 Z
12
+ date: 2012-12-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hiera