Class: Conjur::WebServer::Server

Inherits:
Object
  • Object
show all
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

#openObject



80
81
82
83
84
85
86
# File 'lib/conjur/webserver/server.rb', line 80

def open
  require 'launchy'
  url = "http://localhost:#{port}/login?sessionid=#{sessionid}"
  # as launchy sometimes silently fails, we need human-friendly failover
  $stderr.puts "UI should be available now at #{url}" 
  Launchy.open(url)
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
# 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'
  require 'pry'

  sessionid = self.sessionid
  cookie_options = {
    secret: SecureRandom.hex(32),
    expire_after: 24*60*60
  }

  api_stack = [
    [Rack::Session::Cookie, cookie_options],
    #[Conjur::WebServer::Authorize, sessionid],
    [Conjur::WebServer::ConjurInfo]
  ]

  app = Rack::Builder.app do
    map "/login" do
      use Rack::Session::Cookie, cookie_options
      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).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
  options = {
    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
  Conjur.configuration.env

  Rack::Server.start(options)
end