8784: Fix test for latest firefox.
[arvados.git] / services / api / config / initializers / load_config.rb
1 begin
2   # If secret_token.rb exists here, we need to load it first.
3   require_relative 'secret_token.rb'
4 rescue LoadError
5   # Normally secret_token.rb is missing and the secret token is
6   # configured by application.yml (i.e., here!) instead.
7 end
8
9 if (File.exist?(File.expand_path '../omniauth.rb', __FILE__) and
10     not defined? WARNED_OMNIAUTH_CONFIG)
11   Rails.logger.warn <<-EOS
12 DEPRECATED CONFIGURATION:
13  Please move your SSO provider config into config/application.yml
14  and delete config/initializers/omniauth.rb.
15 EOS
16   # Real values will be copied from globals by omniauth_init.rb. For
17   # now, assign some strings so the generic *.yml config loader
18   # doesn't overwrite them or complain that they're missing.
19   Rails.configuration.sso_app_id = 'xxx'
20   Rails.configuration.sso_app_secret = 'xxx'
21   Rails.configuration.sso_provider_url = '//xxx'
22   WARNED_OMNIAUTH_CONFIG = true
23 end
24
25 $application_config = {}
26
27 %w(application.default application).each do |cfgfile|
28   path = "#{::Rails.root.to_s}/config/#{cfgfile}.yml"
29   if File.exist? path
30     yaml = ERB.new(IO.read path).result(binding)
31     confs = YAML.load(yaml, deserialize_symbols: true)
32     # Ignore empty YAML file:
33     next if confs == false
34     $application_config.merge!(confs['common'] || {})
35     $application_config.merge!(confs[::Rails.env.to_s] || {})
36   end
37 end
38
39 Server::Application.configure do
40   nils = []
41   $application_config.each do |k, v|
42     # "foo.bar: baz" --> { config.foo.bar = baz }
43     cfg = config
44     ks = k.split '.'
45     k = ks.pop
46     ks.each do |kk|
47       cfg = cfg.send(kk)
48     end
49     if cfg.respond_to?(k.to_sym) and !cfg.send(k).nil?
50       # Config must have been set already in environments/*.rb.
51       #
52       # After config files have been migrated, this mechanism should
53       # be deprecated, then removed.
54     elsif v.nil?
55       # Config variables are not allowed to be nil. Make a "naughty"
56       # list, and present it below.
57       nils << k
58     else
59       cfg.send "#{k}=", v
60     end
61   end
62   if !nils.empty?
63     raise <<EOS
64 Refusing to start in #{::Rails.env.to_s} mode with missing configuration.
65
66 The following configuration settings must be specified in
67 config/application.yml:
68 * #{nils.join "\n* "}
69
70 EOS
71   end
72   config.secret_key_base = config.secret_token
73 end