Sha256: 2551d24da3e837784b7ac5f9a850f252451cc0435bd3c35918296f69cd668217
Contents?: true
Size: 1.25 KB
Versions: 7
Compression:
Stored size: 1.25 KB
Contents
require 'openssl' module RESTinPeace class SSLConfigCreator class MissingParam < Exception; end def initialize(config, verify = :peer) @config = config @verify = verify raise MissingParam, 'Specify :ca_cert in ssl options' unless @config[:ca_cert] raise MissingParam, 'Specify :client_key in ssl options' unless @config[:client_key] raise MissingParam, 'Specify :client_cert in ssl options' unless @config[:client_cert] end def faraday_options {client_cert: client_cert, client_key: client_key, ca_file: ca_cert_path, verify_mode: verify_mode} end def client_cert OpenSSL::X509::Certificate.new(open_file(client_cert_path)) end def client_cert_path path(@config[:client_cert]) end def client_key OpenSSL::PKey::RSA.new(open_file(client_key_path)) end def client_key_path path(@config[:client_key]) end def ca_cert_path path(@config[:ca_cert]) end def verify_mode case @verify when :peer OpenSSL::SSL::VERIFY_PEER else raise "Unknown verify variant '#{@verify}'" end end private def open_file(file) File.open(file) end def path(file) File.join(file) end end end
Version data entries
7 entries across 7 versions & 1 rubygems