Class: Conjur::Proxy
- Inherits:
-
Object
- Object
- Conjur::Proxy
- Defined in:
- lib/conjur/proxy.rb
Instance Attribute Summary collapse
-
#auth_method ⇒ Object
readonly
Returns the value of attribute auth_method.
-
#basic_password ⇒ Object
readonly
Returns the value of attribute basic_password.
-
#basic_username ⇒ Object
readonly
Returns the value of attribute basic_username.
-
#conjur ⇒ Object
readonly
Returns the value of attribute conjur.
-
#proxy ⇒ Object
readonly
Returns the value of attribute proxy.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #configure(options = {}) ⇒ Object
-
#initialize(url, conjur) ⇒ Proxy
constructor
A new instance of Proxy.
- #start(options = {}) ⇒ Object
Constructor Details
#initialize(url, conjur) ⇒ Proxy
Returns a new instance of Proxy.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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 |
Instance Attribute Details
#auth_method ⇒ Object (readonly)
Returns the value of attribute auth_method.
46 47 48 |
# File 'lib/conjur/proxy.rb', line 46 def auth_method @auth_method end |
#basic_password ⇒ Object (readonly)
Returns the value of attribute basic_password.
46 47 48 |
# File 'lib/conjur/proxy.rb', line 46 def basic_password @basic_password end |
#basic_username ⇒ Object (readonly)
Returns the value of attribute basic_username.
46 47 48 |
# File 'lib/conjur/proxy.rb', line 46 def basic_username @basic_username end |
#conjur ⇒ Object (readonly)
Returns the value of attribute conjur.
46 47 48 |
# File 'lib/conjur/proxy.rb', line 46 def conjur @conjur end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
46 47 48 |
# File 'lib/conjur/proxy.rb', line 46 def proxy @proxy end |
Instance Method Details
#call(env) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/conjur/proxy.rb', line 48 def call env if @auth_method == "basic" header = Base64.strict_encode64(@basic_username+':'+@basic_password) = 'Basic '+header env['HTTP_AUTHORIZATION'] = 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 = {}) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/conjur/proxy.rb', line 75 def configure = {} if [: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 [:cacert] OpenSSL::SSL::SSLContext::DEFAULT_CERT_STORE.add_file [: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 [:t] == "basic" @auth_method = "basic" @basic_username = @conjur.variable([:u]).value @basic_password = @conjur.variable([:w]).value end end |
#start(options = {}) ⇒ Object
115 116 117 118 119 |
# File 'lib/conjur/proxy.rb', line 115 def start = {} configure Rack::Server.start app: self, Port: [:port] || 8080, Host: [:address] || '127.0.0.1' end |