class Conjur::Proxy
Attributes
auth_method[R]
basic_password[R]
basic_username[R]
conjur[R]
proxy[R]
Public Class Methods
new(url, conjur)
click to toggle source
# File lib/conjur/proxy.rb, line 28 def initialize url, conjur @conjur = conjur @proxy = Rack::StreamingProxy::Proxy.new nil do |request| ret = "#{url}#{request.path}" unless request.query_string.empty? ret = "#{ret}?#{request.query_string}" end ret end #Added support for multiple authorization headers @auth_method = "conjur" @basic_username = "" @basic_password = "" end
Public Instance Methods
call(env)
click to toggle source
# File lib/conjur/proxy.rb, line 48 def call env if @auth_method == "basic" header = Base64.strict_encode64(@basic_username+':'+@basic_password) authorization_header = 'Basic '+header env['HTTP_AUTHORIZATION'] = authorization_header else env['HTTP_AUTHORIZATION'] = conjur.credentials[:headers][:authorization] end if (env['REQUEST_METHOD'] == 'POST' || env['REQUEST_METHOD'] == 'PUT') if !env.include?('CONTENT_LENGTH') && (!env.include?('TRANSFER_ENCODING') || env['TRANSFER_ENCODING'] != 'chunked') env['CONTENT_LENGTH'] = '0' end end ret = proxy.call env # hack for Docker Hub & Registry API if ret[1].include?('x-docker-endpoints') ret[1]['x-docker-endpoints'] = env['HTTP_HOST'] end ret end
configure(options = {})
click to toggle source
# File lib/conjur/proxy.rb, line 75 def configure options = {} if options[:insecure] Net::HTTP.class_eval do def use_ssl=(flag) flag = flag ? true : false if started? and @use_ssl != flag raise IOError, "use_ssl value changed, but session already started" end @use_ssl = flag self.verify_mode = OpenSSL::SSL::VERIFY_NONE end end end if options[:cacert] OpenSSL::SSL::SSLContext::DEFAULT_CERT_STORE.add_file options[:cacert] end Rack::StreamingProxy::Session.class_eval do # set timeout to 30 min, 30 seconds is not enought for uploading def start @piper = Servolux::Piper.new 'r', timeout: 1600 @piper.child { child } @piper.parent { parent } end end #check if the auth method is basic if options[:t] == "basic" @auth_method = "basic" @basic_username = @conjur.variable(options[:u]).value @basic_password = @conjur.variable(options[:w]).value end end
start()
click to toggle source
set timeout to 30 min, 30 seconds is not enought for uploading
# File lib/conjur/proxy.rb, line 96 def start @piper = Servolux::Piper.new 'r', timeout: 1600 @piper.child { child } @piper.parent { parent } end
use_ssl=(flag)
click to toggle source
# File lib/conjur/proxy.rb, line 78 def use_ssl=(flag) flag = flag ? true : false if started? and @use_ssl != flag raise IOError, "use_ssl value changed, but session already started" end @use_ssl = flag self.verify_mode = OpenSSL::SSL::VERIFY_NONE end