class Conjur::Proxy

Attributes

conjur[R]
proxy[R]

Public Class Methods

new(url, conjur) click to toggle source
# File lib/conjur/proxy.rb, line 27
def initialize url, conjur
  @conjur = conjur
  @proxy = Rack::StreamingProxy::Proxy.new nil do |request|
    url + request.path
  end
end

Public Instance Methods

call(env) click to toggle source
# File lib/conjur/proxy.rb, line 36
def call env
  env["HTTP_AUTHORIZATION"] = conjur.credentials[:headers][:authorization]

  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
start(options) click to toggle source
# File lib/conjur/proxy.rb, line 49
def start 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::Server.start app: self, Port: options[:port] || 8080, Host: options[:address] || '127.0.0.1'
end
use_ssl=(flag) click to toggle source
# File lib/conjur/proxy.rb, line 52
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