class Hiera::Backend::Eyaml::Encryptors::Vault::Httphandler

Public Class Methods

http_send(uri, request, headers={}, options={}) click to toggle source
# File lib/hiera/backend/eyaml/encryptors/vault/httphandler.rb, line 30
def http_send(uri, request, headers={}, options={})
  request.add_field('Content-Type', options[:content_type]) if options[:content_type]

  headers.each do |header, value|
    request.add_field(header, value)
  end

  http = Net::HTTP.new(uri.host, uri.port)
  if options[:ssl]
    http.use_ssl = true
    http.verify_mode = options[:ssl_verify] ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
    http.cert = OpenSSL::X509::Certificate.new(options[:ssl_cert]) if options[:ssl_cert]
    http.key = OpenSSL::PKey::RSA.new(options[:ssl_key]) if options[:ssl_key]
  end

  begin
    response = http.request(request)
    return response
  rescue => e
    raise HTTPError, e.message
  end
end
post(uri_str, data={}, headers={}, options={}) click to toggle source
# File lib/hiera/backend/eyaml/encryptors/vault/httphandler.rb, line 15
def post(uri_str, data={}, headers={}, options={})
  uri = URI.parse(uri_str)
  request = Net::HTTP::Post.new(uri.path)
  request.body = data.to_json
  http_send(uri, request, headers, options)
end
put(uri_str, data={}, headers={}, options={}) click to toggle source
# File lib/hiera/backend/eyaml/encryptors/vault/httphandler.rb, line 22
def put(uri_str, data={}, headers={}, options={})
  uri = URI.parse(uri_str)
  request = Net::HTTP::Put.new(uri.path)
  request.body = data.to_json
  http_send(uri, request, headers, options)
end