Class: Hieracles::Puppetdb::FixSSLConnectionAdapter

Inherits:
HTTParty::ConnectionAdapter
  • Object
show all
Defined in:
lib/hieracles/puppetdb/fixsslconnectionadapter.rb

Instance Method Summary collapse

Instance Method Details

#attach_ssl_certificates(http, options) ⇒ Object

Raises:

  • (IOError)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/hieracles/puppetdb/fixsslconnectionadapter.rb', line 6

def attach_ssl_certificates(http, options)
  raise(IOError, "Cert file #{options['cert']} not found.") unless File.exist? options['cert'].to_s
  raise(IOError, "Key file #{options['key']} not found.") unless File.exist? options['key']
  raise(IOError, "CA file #{options['ca_file']} not found.") unless File.exist? options['ca_file']
  http.cert = OpenSSL::X509::Certificate.new(File.read(options['cert']))
  if options['key_password']
    http.key = OpenSSL::PKey::RSA.new(File.read(options['key']), options['key_password'])
  else
    http.key = OpenSSL::PKey::RSA.new(File.read(options['key']))
  end
  http.ca_file = options['ca_file']
  if options['verify_peer']
    http.verify_mode = OpenSSL::SSL::VERIFY_PEER
  else
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end
end