Class: Conjur::WebServer::Server
- Inherits:
-
Object
- Object
- Conjur::WebServer::Server
- Defined in:
- lib/conjur/webserver/server.rb
Overview
Launch a web server which serves local files and proxies to the remote Conjur API.
Instance Method Summary collapse
Instance Method Details
#open(headless) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/conjur/webserver/server.rb', line 87 def open headless require 'launchy' url = "http://localhost:#{port}/login?sessionid=#{sessionid}" # as launchy sometimes silently fails, we need human-friendly failover if ENV['DONT_OPEN_IN_BROWSER'] or headless puts "Running in headless mode." puts "To reach this UI server via SSH tunnel, run the following command:" puts "ssh -N -L #{port}:localhost:#{port} user@hostname" puts "Then open your browser to the following URL:" puts url else $stderr.puts "If your browser did not opened the UI automatically, point it to #{url}" Launchy.open(url) end end |
#set_port(p) ⇒ Object
103 104 105 |
# File 'lib/conjur/webserver/server.rb', line 103 def set_port p @port = p end |
#start(root) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 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 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/conjur/webserver/server.rb', line 26 def start(root) require 'rack' require 'conjur/webserver/login' require 'conjur/webserver/authorize' require 'conjur/webserver/api_proxy' require 'conjur/webserver/home' require 'conjur/webserver/conjur_info' # Pry is optional begin require 'pry' rescue LoadError end sessionid = self.sessionid = { secret: SecureRandom.hex(32), expire_after: 24*60*60 } api_stack = [ [Rack::Session::Cookie, ], #[Conjur::WebServer::Authorize, sessionid], [Conjur::WebServer::ConjurInfo] ] app = Rack::Builder.app do map "/login" do use Rack::Session::Cookie, run Conjur::WebServer::Login.new sessionid end map "/api" do api_stack.each{|args| use *args} run Conjur::WebServer::APIProxy.new end %w(js css fonts images maps).each do |path| map "/#{path}" do run Rack::File.new(File.join(root, path), 'Cache-Control' => 'max-age=0') end end map "/ui" do run Conjur::WebServer::Home.new(root) end end = { app: app, Port: port, Threads: '0:64', Verbose: true } # this vivifies the env for correct url settings # otherwise puma sets it to development and # confusion ensues # HR: it won't work anymore since API 4.10.2 (because it relies on sticky configuration feature which is removed) # instead we just explicitly set RACK_ENV to "production" on the command call -- this is also bad, but... good enough for now, until we'll fix API configuration logic Conjur.configuration.env Rack::Server.start() end |