forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession_store.rb
47 lines (43 loc) · 1.63 KB
/
session_store.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
if ENV['RAILS_USE_MEMORY_STORE'] || (!Rails.env.development? && !Rails.env.production?)
Vmdb::Application.config.session_store(:memory_store)
else
session_store =
case Settings.server.session_store
when "sql" then :active_record_store
when "memory" then :memory_store
when "cache" then :mem_cache_store
end
session_options = {}
if MiqEnvironment::Command.is_appliance?
session_options[:secure] = true unless ENV["ALLOW_INSECURE_SESSION"]
session_options[:httponly] = true
end
if session_store == :mem_cache_store
require 'dalli'
session_options = session_options.merge(
:cache => Dalli::Client.new(MiqMemcached.server_address, :namespace => "MIQ:VMDB", :value_max_bytes => 10.megabytes),
:expire_after => 24.hours,
:key => "_vmdb_session",
)
require 'rack/session/dalli'
Rack::Session::Dalli.prepend Module.new {
# As we monkey-patch marshal to support autoloading, Dalli can
# cause a load to occur. Consequently, we need to manage things
# carefully to prevent a deadlock between the Rails Interlock and
# Dalli's own exclusive lock.
def with_lock(*args)
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
super(*args) do
ActiveSupport::Dependencies.interlock.running do
yield
end
end
end
end
}
end
Vmdb::Application.config.session_store(session_store, session_options)
msg = "Using session_store: #{Vmdb::Application.config.session_store}"
$log.info("MIQ(SessionStore) #{msg}")
puts "** #{msg}" unless Rails.env.production?
end