Please review pull request #445: (#8465) Support SSL in HTTP report via HttpPool opened by (lotheac)

Description:

Made http reporting use Puppet::Network::HttpPool as per http://projects.puppetlabs.com/issues/8465#note-7 adding support for SSL with verification.

  • Opened: Thu Feb 02 02:28:53 UTC 2012
  • Based on: puppetlabs:master (fb36b5ab157261e0ee77e1293ea8f3abee4757b0)
  • Requested merge: lotheac:https-reporturl (ce44885ff63086620ec200b4e1b22b56eeec97e9)

Diff follows:

diff --git a/lib/puppet/network/http_pool.rb b/lib/puppet/network/http_pool.rb
index 8baf48c..d7b0d42 100644
--- a/lib/puppet/network/http_pool.rb
+++ b/lib/puppet/network/http_pool.rb
@@ -23,7 +23,7 @@ def self.cert_setup(http)
 
   # Retrieve a cached http instance if caching is enabled, else return
   # a new one.
-  def self.http_instance(host, port, reset = false)
+  def self.http_instance(host, port, reset = false, use_ssl = true)
     args = [host, port]
     if Puppet[:http_proxy_host] == "none"
       args << nil << nil
@@ -36,7 +36,7 @@ def self.http_instance(host, port, reset = false)
     # give us a reader for ca_file... Grr...
     class << http; attr_accessor :ca_file; end
 
-    http.use_ssl = true
+    http.use_ssl = use_ssl
     # Use configured timeout (#1176)
     http.read_timeout = Puppet[:configtimeout]
     http.open_timeout = Puppet[:configtimeout]
diff --git a/lib/puppet/reports/http.rb b/lib/puppet/reports/http.rb
index 7ac54df..21855ca 100644
--- a/lib/puppet/reports/http.rb
+++ b/lib/puppet/reports/http.rb
@@ -1,5 +1,5 @@
 require 'puppet'
-require 'net/http'
+require 'puppet/network/http_pool'
 require 'uri'
 
 Puppet::Reports.register_report(:http) do
@@ -15,7 +15,9 @@ def process
     req = Net::HTTP::Post.new(url.path)
     req.body = self.to_yaml
     req.content_type = "application/x-yaml"
-    Net::HTTP.new(url.host, url.port).start {|http|
+    conn = Puppet::Network::HttpPool.http_instance(url.host, url.port,
+                                                   ssl=(url.scheme == 'https'))
+    conn.start {|http|
       http.request(req)
     }
   end
diff --git a/spec/unit/reports/http_spec.rb b/spec/unit/reports/http_spec.rb
index d7c37bf..f26532a 100755
--- a/spec/unit/reports/http_spec.rb
+++ b/spec/unit/reports/http_spec.rb
@@ -21,9 +21,10 @@ def self.request(req)
 
   it { should respond_to(:process) }
 
-  it "should use the reporturl setting's host and port" do
+  it "should use the reporturl setting's host, port and ssl option" do
     uri = URI.parse(Puppet[:reporturl])
-    Net::HTTP.expects(:new).with(uri.host, uri.port).returns(stub_everything('http'))
+    ssl = (uri.scheme == 'https')
+    Puppet::Network::HttpPool.expects(:http_instance).with(uri.host, uri.port, ssl).returns(stub_everything('http'))
     subject.process
   end
 

    

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to