Merge branch '8784-dir-listings'
[arvados.git] / apps / workbench / config / load_config.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 # This file must be loaded _after_ secret_token.rb if secret_token is
6 # defined there instead of in config/application.yml.
7
8 $application_config = {}
9
10 %w(application.default application).each do |cfgfile|
11   path = "#{::Rails.root.to_s}/config/#{cfgfile}.yml"
12   if File.exists? path
13     yaml = ERB.new(IO.read path).result(binding)
14     confs = YAML.load(yaml, deserialize_symbols: true)
15     $application_config.merge!(confs['common'] || {})
16     $application_config.merge!(confs[::Rails.env.to_s] || {})
17   end
18 end
19
20 ArvadosWorkbench::Application.configure do
21   nils = []
22   $application_config.each do |k, v|
23     # "foo.bar: baz" --> { config.foo.bar = baz }
24     cfg = config
25     ks = k.split '.'
26     k = ks.pop
27     ks.each do |kk|
28       cfg = cfg.send(kk)
29     end
30     if v.nil? and cfg.respond_to?(k) and !cfg.send(k).nil?
31       # Config is nil in *.yml, but has been set already in
32       # environments/*.rb (or has a Rails default). Don't overwrite
33       # the default/upstream config with nil.
34       #
35       # After config files have been migrated, this mechanism should
36       # be removed.
37       Rails.logger.warn <<EOS
38 DEPRECATED: Inheriting config.#{ks.join '.'} from Rails config.
39             Please move this config into config/application.yml.
40 EOS
41     elsif v.nil?
42       # Config variables are not allowed to be nil. Make a "naughty"
43       # list, and present it below.
44       nils << k
45     else
46       cfg.send "#{k}=", v
47     end
48   end
49   if !nils.empty?
50     raise <<EOS
51 Refusing to start in #{::Rails.env.to_s} mode with missing configuration.
52
53 The following configuration settings must be specified in
54 config/application.yml:
55 * #{nils.join "\n* "}
56
57 EOS
58   end
59 end